ShishGL  1.0
A simple modular cross-platform graphics library
FpsLabel.hpp
Go to the documentation of this file.
1 /*============================================================================*/
2 #ifndef SHISHGL_FPS_LABEL_HPP
3 #define SHISHGL_FPS_LABEL_HPP
4 /*============================================================================*/
5 #include "UILabel.hpp"
6 #include "Time.hpp"
7 /*============================================================================*/
8 namespace Sh {
9 
10  class FpsLabel : public UILabel {
11  public:
12 
13  explicit FpsLabel(const Frame& frame)
14  : UILabel(frame, std::string_view(fps_buf, sizeof(fps_buf) - 1))
15  , frames_count(0) {
16  timer.reset();
17  }
18 
19  void onRender() override {
20 
21  TimeDelta elapsed = timer.elapsed();
22  if (elapsed.count() > 1000000000LL) {
23 
24  snprintf(fps_buf, sizeof(fps_buf),
25  "fps: %lu", frames_count);
26 
27  frames_count = 0;
28  timer.reset();
29 
30  } else {
31 
32  ++frames_count;
33  }
34 
36  }
37 
38  private:
39 
40  char fps_buf[16] = "";
41 
42  Timer timer;
43  size_t frames_count;
44 
45  };
46 
47 }
48 /*============================================================================*/
49 #endif //SHISHGL_FPS_LABEL_HPP
50 /*============================================================================*/
Sh::FpsLabel::FpsLabel
FpsLabel(const Frame &frame)
Definition: FpsLabel.hpp:13
Sh::FpsLabel::onRender
void onRender() override
Definition: FpsLabel.hpp:19
Sh::Timer::reset
void reset()
Definition: Time.cpp:11
Sh::Frame
Definition: Frame.hpp:9
UILabel.hpp
Sh::UIWindow::onRender
void onRender() override
Definition: UIWindow.cpp:46
Sh::Timer::elapsed
TimeDelta elapsed() const
Definition: Time.cpp:17
Sh
Definition: CoreApplication.hpp:10
Time.hpp
Sh::UILabel
Definition: UILabel.hpp:11
Sh::FpsLabel
Definition: FpsLabel.hpp:10
Sh::TimeDelta
Clock::duration TimeDelta
Definition: Time.hpp:11
Sh::Timer
Definition: Time.hpp:15