Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
60 lines (49 loc) · 1.69 KB
/
Copy pathmain.cpp
File metadata and controls
60 lines (49 loc) · 1.69 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
/**
* @file main.cpp
* @brief Application entry point: initializes SFML, ImGui-SFML, and the shared font, then runs the main loop.
*/
#include <iostream>
#include <cstdlib>
#include <ctime>
#include "Visualizer.hpp"
#include "UIUtils.hpp"
int main()
{
std::srand(static_cast<unsigned int>(std::time(nullptr)));
sf::RenderWindow main_window(sf::VideoMode({1280, 760}), "Data Structures Visualizer", sf::Style::Default);
main_window.setFramerateLimit(60);
if (!ImGui::SFML::Init(main_window)) {
std::cerr << "Error inicializando ImGui-SFML" << std::endl;
return -1;
}
UIUtils::applyModernTheme();
// Try loading the font from the working directory first, then parent directory (e.g. when launched from build/).
sf::Font font;
if (!font.openFromFile("assets/arial.ttf")) {
if (!font.openFromFile("../assets/arial.ttf")) {
std::cerr << "Error: No se pudo cargar assets/arial.ttf" << std::endl;
ImGui::SFML::Shutdown();
return -1;
}
}
auto cmp = [](int a, int b) { return a > b; };
Visualizer<int> app(cmp);
sf::Clock deltaClock;
// Main event, update, and render loop.
while (main_window.isOpen())
{
while (const std::optional event = main_window.pollEvent())
{
ImGui::SFML::ProcessEvent(main_window, *event);
app.handle_events(main_window, *event);
if (event->is<sf::Event::Closed>()) {
main_window.close();
}
}
main_window.clear(sf::Color(22, 25, 34));
app.update_and_run(main_window, deltaClock, font);
main_window.display();
}
ImGui::SFML::Shutdown();
return 0;
}