-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
140 lines (123 loc) · 5.63 KB
/
main.cpp
File metadata and controls
140 lines (123 loc) · 5.63 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <iostream>
#include "SFML/Graphics.hpp"
#include "TGUI/TGUI.hpp"
#include "TGUI/Backend/SFML-Graphics.hpp"
#include "Utils/StringHelper.hpp"
#include "include/Examples/funcHelper.hpp"
#include "include/Examples/EventHelper.hpp"
#include "include/Examples/Stopwatch.hpp"
#include "include/Examples/StringHelper.hpp"
#include "include/Examples/UpdateLimiter.hpp"
#include "include/Examples/Log.hpp"
#include "include/Examples/iniParser.hpp"
#include "include/Examples/TerminatingFunction.hpp"
#include "include/Examples/LiveVar.hpp"
#include "include/Examples/VarDisplay.hpp"
#include "include/Examples/CommandHandler.hpp"
#include "include/Examples/CommandPrompt.hpp"
#include "include/Examples/TFuncDisplay.hpp"
#include "include/Examples/Graph.hpp"
#include "include/Examples/TestHelper.hpp"
using namespace std;
using namespace sf;
int main()
{
std::cout << GET_FUNCTION_INFO() << std::endl;
// TestHelperTest::test();
// funcHelperTest::test();
EventHelperTest::test();
// StopwatchTest::test();
// StringHelperTest::test();
// UpdateLimiterTest::test();
// LogTest::test();
// iniParserTest::test();
// TerminatingFunctionTest::test();
// // live var test is put after the VarDisplay is initalized so the vars will be in the display
VarDisplayTest::test();
CommandHandlerTest::test();
// setup for sfml and tgui
sf::RenderWindow window(sf::VideoMode::getDesktopMode(), "C++ Utilities");
window.setFramerateLimit(144);
window.setPosition(Vector2i(-8, -8));
tgui::Gui gui{window};
gui.setRelativeView({0, 0, 1920/(float)window.getSize().x, 1080/(float)window.getSize().y});
tgui::Theme::getDefault()->load("themes/Dark.txt");
// -----------------------
//! Adding a command for showing off the different themes
Command::Handler::get().addCommand("setTheme", "Function used to set the theme of the UI (The previous outputs in the command prompt will not get updated color)",
{Command::print, "Trying calling one of the sub commands"});
Command::Handler::get().findCommand("setTheme") // no need to check if nullptr since we just added it
->addCommand("dark", "Sets the them to the dark theme",
[](){
tgui::Theme::getDefault()->load("themes/Dark.txt");
})
.addCommand("black", "Sets the them to the black theme",
[](){
tgui::Theme::getDefault()->load("themes/Black.txt");
})
.addCommand("grey", "Sets the them to the transparent grey theme",
[](){
tgui::Theme::getDefault()->load("themes/TransparentGrey.txt");
});
//! -----------------------------------------------------
Command::Handler::get().addCommand("tests", "Function used to test the different features of the library\nMultiple line description\nWhat about a line that is way to long to find on one line so that it wraps aroundaooidshfiogushdofiguhsdoifughisdufhgisdhfiguhsdifhgsiudhfgilsuhdfiguhsidfughsiudfhisuhdfiugsdfhiuiusdhfgoiudshfogiusdhfoiguhsdoifughsdiufhg", {Command::print, "Trying calling one of the sub commands"});
Command::Handler::get().findCommand("tests") // no need to check if nullptr since we just added it
->addCommand("liveVar", "Tests the live var feature", [](){ LiveVarTest::test(); })
.addCommand("varDisplay", "Tests the var display feature", [](){ VarDisplayTest::test(); })
.addCommand("tFuncDisplay", "Tests the tFuncDisplay feature", [](){ TFuncDisplayTest::test(); });
//! Required to initialize VarDisplay and CommandPrompt
// creates the UI for the VarDisplay
VarDisplay::init(gui);
// creates the UI for the CommandPrompt
Command::Prompt::init(gui);
// create the UI for the TFuncDisplay
TFuncDisplay::init(gui);
//! ---------------------------------------------------
//* CommandPromptTest
// CommandPromptTest::test(); // Needs to be called after CommandPrompt is initalized
//* TFuncDisplayTest
// TFuncDisplayTest::test();
// TFuncDisplay::setVisible(true);
//* LiveVarTest
// LiveVarTest::test(); //! NOTE - live vars will not show in the VarDisplay unless added after VarDisplay is initalized
//* GraphTest
// GraphTest::test(gui);
float deltaTime = 0;
sf::Clock deltaClock;
while (window.isOpen())
{
//! should be called first thing every frame
EventHelper::Event::Synchronized::update();
//! ----------------------------------------
window.clear();
// updating the delta time var
deltaTime = deltaClock.restart().asSeconds();
while (const std::optional<sf::Event> event = window.pollEvent())
{
//! Required CommandPrompt to work as intended
if (Command::Prompt::UpdateEvent(event.value()))
continue;
//! ------------------------------------------
if (gui.handleEvent(event.value()))
continue;
//! Required for Live Vars to work as intended
LiveVar::UpdateLiveVars(event.value());
//! ------------------------------------------
if (event->is<sf::Event::Closed>())
window.close();
}
//! Updates all the vars being displayed
VarDisplay::Update();
//! ------------------------------=-----
//! Updates all Terminating Functions
TerminatingFunction::UpdateFunctions(deltaTime);
//* Updates for the terminating functions display
TFuncDisplay::Update();
//! ------------------------------
// draw for tgui
gui.draw();
// display for sfml window
window.display();
}
return EXIT_SUCCESS;
}