on commence l'interface là ouais
This commit is contained in:
49
src/GraphicalUI/GraphApp.cpp
Normal file
49
src/GraphicalUI/GraphApp.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#include "GraphApp.h"
|
||||
|
||||
#include "AppMenus/AppMenu.h"
|
||||
#include "AppMenus/MainAppMenu.h"
|
||||
#include "Settings.h"
|
||||
|
||||
#include <stack>
|
||||
#include <memory>
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
static const double TIME_BETWEEN_FRAMES = (1000.f / 60.f);
|
||||
|
||||
|
||||
GraphApp::GraphApp() {
|
||||
this->settings = std::make_shared<Settings>();
|
||||
this->menuStack = std::make_shared<std::stack<AppMenu>>();
|
||||
this->window = std::make_shared<sf::RenderWindow>();
|
||||
}
|
||||
|
||||
void GraphApp::startApp() {
|
||||
changeVideoMode(*this->window, this->settings->getVideoMode());
|
||||
this->menuStack->push(MainAppMenu(this->menuStack, this->settings, this->window));
|
||||
|
||||
bool quit = false;
|
||||
double timeAtNextFrame = 0;
|
||||
sf::Clock clock;
|
||||
while (!quit) {
|
||||
while (const std::optional event = this->window->pollEvent()) {
|
||||
if (event->is<sf::Event::Closed>()) {
|
||||
quit = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!quit) {
|
||||
if (clock.getElapsedTime().asMilliseconds() > timeAtNextFrame) {
|
||||
timeAtNextFrame += TIME_BETWEEN_FRAMES;
|
||||
this->menuStack->top().computeFrame();
|
||||
|
||||
if (this->menuStack->empty()) {
|
||||
quit = true;
|
||||
}
|
||||
else {
|
||||
this->menuStack->top().drawFrame();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
window->close();
|
||||
}
|
||||
Reference in New Issue
Block a user