Blamite Game Engine - blam!  00296.01.12.21.0102.blamite
The core library for the Blamite Game Engine.
fpscounter.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <sstream>
4 #include <iomanip>
5 
6 #include "../../render_stack.h"
7 
9 {
13  class FPSCounter : public StackObjectBase
14  {
15  private:
16  BitmapText* fps_counter;
17 
18  public:
23  {
25 
26  fps_counter = new BitmapText();
27 
28  fps_counter->font_id = Blam::Config::GetConfig()->GetString("ui_default_font");
29  fps_counter->use_shadow = true;
30  fps_counter->color = D2D1::ColorF(1, 1, 1, 1);
31 
32  fps_counter->SetTranslation(10, 30);
33 
34  //BlamRendering::RenderStack::AddToStack("fps_counter_text", fps_counter);
35  }
36 
41  {
42  delete fps_counter;
43  delete this;
44  }
45 
52  void Draw()
53  {
54  fps_counter->visible = visible;
55 
56  if (visible)
57  {
58  // We aren't actually drawing anything, just updating fps counter data
59 
60  std::stringstream fps_stream;
61  fps_stream << std::fixed << std::setprecision(2) << ImGui::GetIO().Framerate;
62  std::string fps = fps_stream.str();
63 
64  if (ImGui::GetIO().Framerate >= 30)
65  {
66  fps_counter->color = D2D1::ColorF(0, 1, 0, 1);
67  }
68  else if (ImGui::GetIO().Framerate < 15)
69  {
70  fps_counter->color = D2D1::ColorF(1, 0, 0, 1);
71  }
72  else if (ImGui::GetIO().Framerate < 30)
73  {
74  fps_counter->color = D2D1::ColorF(1, 1, 0, 1);
75  }
76 
77  fps_counter->text = "fps: " + fps + "";
78  }
79 
80  fps_counter->Draw();
81  }
82 
84  {
85 
86  }
87  };
88 }
BlamRendering::RenderStack::StackObjectBase::visible
bool visible
Whether or not the object is visible.
Definition: render_stack.h:375
BlamRendering::RenderStack::FPSCounter::ShowImPropertyEditor
void ShowImPropertyEditor()
Shows a set of ImGUI properties associated with the object.
Definition: fpscounter.hpp:83
BlamRendering::RenderStack::BitmapText::font_id
std::string font_id
The ID of the font.
Definition: render_stack.h:844
BitmapText
@ BitmapText
Bitmap-based text, uses Blamite font system.
Definition: render_stack.h:72
BlamRendering::RenderStack::StackObjectBase::type_label
StackType type_label
The type of the object.
Definition: render_stack.h:372
Blam::Config::GetConfig
BLAM ConfigFile * GetConfig()
Definition: compat.cpp:5
BlamRendering::RenderStack
Namespace containing things relating to the Render Stack.
Definition: drawing.h:14
BlamRendering::RenderStack::BitmapText::text
std::string text
The text to display.
Definition: render_stack.h:846
BlamRendering::RenderStack::StackObjectBase::color
D2D1_COLOR_F color
The color of the object.
Definition: render_stack.h:370
BlamRendering::RenderStack::BitmapText::Draw
void Draw()
Draws the stack object.
Definition: BitmapText.cpp:13
STACKTYPE_FPS_COUNTER
#define STACKTYPE_FPS_COUNTER
Definition: render_stack.h:25
BlamRendering::RenderStack::BitmapText::use_shadow
bool use_shadow
Whether or not to draw the text with a drop shadow.
Definition: render_stack.h:852
BlamRendering::RenderStack::StackObjectBase::SetTranslation
void SetTranslation(float new_x, float new_y)
Sets the translation of the object.
Definition: StackObjectBase.cpp:55
BlamRendering::RenderStack::FPSCounter::Draw
void Draw()
Draws the FPS counter onscreen.
Definition: fpscounter.hpp:52
BlamRendering::RenderStack::FPSCounter::FPSCounter
FPSCounter()
Prepares the FPS counter.
Definition: fpscounter.hpp:22
BlamRendering::RenderStack::FPSCounter
Class used for the FPS counter.
Definition: fpscounter.hpp:13
Blam::Config::ConfigFile::GetString
std::string GetString(std::string option)
Definition: compat.cpp:58
BlamRendering::RenderStack::BitmapText
Class representing text drawn using a Bitmap-based engine font.
Definition: render_stack.h:794
BlamRendering::RenderStack::StackObjectBase
Base class for all render stack objects.
Definition: render_stack.h:194
BlamRendering::RenderStack::FPSCounter::~FPSCounter
~FPSCounter()
Cleans up any resources used by the FPS counter.
Definition: fpscounter.hpp:40