-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathperformance_window.hpp
59 lines (51 loc) · 1.24 KB
/
performance_window.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* @file performance_window.hpp
* @author Forairaaaaa
* @brief
* @version 0.1
* @date 2023-11-04
*
* @copyright Copyright (c) 2023
*
*/
#pragma once
#include "lgfx/v1/platforms/sdl/common.hpp"
#include "lgfx/v1_autodetect/LGFX_AutoDetect_sdl.hpp"
#include <LGFX_AUTODETECT.hpp>
#include <LovyanGFX.hpp>
#include <SDL2/SDL.h>
#include <SDL_timer.h>
#include <cstdint>
class PerformanceWindow
{
private:
LGFX* _display;
LGFX_Sprite* _canvas;
unsigned long _last_ticks;
unsigned long _delta_ticks;
int _fps;
public:
PerformanceWindow()
{
_display = new LGFX(180, 60);
_display->init();
_canvas = new LGFX_Sprite(_display);
_canvas->createSprite(_display->width(), _display->height());
_canvas->setFont(&fonts::efontCN_24);
}
~PerformanceWindow()
{
delete _canvas;
delete _display;
}
void update()
{
_delta_ticks = lgfx::micros() - _last_ticks;
_canvas->fillScreen(TFT_BLACK);
_canvas->setCursor(0, 0);
_canvas->printf("% 10f ms\n", (double)_delta_ticks / 1000);
_canvas->printf("% 10ld fps", 1000000 / _delta_ticks);
_canvas->pushSprite(0, 0);
_last_ticks = lgfx::micros();
}
};