-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUITestCode.cpp
More file actions
76 lines (56 loc) · 1.75 KB
/
Copy pathUITestCode.cpp
File metadata and controls
76 lines (56 loc) · 1.75 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "Display.h"
#include "BaseEventHandler.h"
#include "Slider.h"
#include "Text.h"
#include "FPSCounter.h"
#include <string>
#include <iostream>
void buttonTest()
{
SDL_Log("button works");
}
int UiTest()
{
FPSCounter fpsCounter(1);
Display::init();
Display display(200, 200, "testWindow", {0, 255, 0, 255});
BaseEventHandler handler;
SDL_Rect buttonRect = { 10, 30, 100, 50 };
Button testButton(buttonRect, buttonTest);
testButton.AddTexture(display.renderer, "textures/quitButton.png");
handler.AddInteractable(&testButton);
display.AddRenderable(&testButton);
SDL_Rect sliderRect = { 10, 90, 180, 0 };
Slider testSlider(sliderRect);
testSlider.AddTexture(display.renderer, "textures/sliderNode.png");
handler.AddInteractable(&testSlider);
display.AddRenderable(&testSlider);
SDL_Rect textRect = { 10, 95, 0, 0 };
Text testText(display.renderer, "", 15, textRect);
display.AddRenderable(&testText);
SDL_Rect textRect2 = { 5, 5, 0, 0 };
Text testText2(display.renderer, "This is test text", 15, textRect2);
display.AddRenderable(&testText2);
SDL_Rect fpsTextRect = { 145, 10, 0, 0 };
Text fpsText(display.renderer, "0", 15, fpsTextRect);
display.AddRenderable(&fpsText);
while (true)
{
display.PrepareRender();
testText.ChangeText(display.renderer, std::to_string(testSlider.GetValue()).c_str());
char fpsLabel[15] = "fps: ";
#ifdef _WIN32 // wacky compiler differences
strcat_s(fpsLabel, std::to_string(fpsCounter.GetFrameCount()).c_str());
#else
strcat(fpsLabel, std::to_string(fpsCounter.GetFrameCount()).c_str());
#endif
fpsText.ChangeText(display.renderer, fpsLabel);
handler.Handle();
display.RenderAll();
display.ProcessRender();
fpsCounter.IncreaseFrameCount();
SDL_Delay(10);
}
Display::exit();
return 0;
}