#include "application.h" #include #include extern const sf::Input* input_backend; sf::RenderWindow *renderwindow; Application::Application() { please_quit = false; } Application::~Application() { } void Application::create_window(unsigned int w, unsigned int h, bool fs) { window->Create(sf::VideoMode(w, h, 32), "Foo", sf::Style::Resize | sf::Style::Close | (fs ? sf::Style::Fullscreen : 0)); } void Application::init_window(unsigned int w, unsigned int h, bool fs) { renderwindow = new sf::RenderWindow(); window = renderwindow; create_window(w, h, fs); window->UseVerticalSync(true); input_backend = &window->GetInput(); } void Application::run() { while(1) { sf::Event e; while(window->GetEvent(e)) { event(e); } if(please_quit) { return; } update(); swap(); } } void Application::swap() { window->Display(); } void Application::quit() { please_quit = true; } void Application::event(const sf::Event& e) { switch(e.Type) { case sf::Event::Closed: quit(); break; case sf::Event::KeyPressed: event_keypress(e.Key.Code); break; default: break; } } void Application::event_keypress(sf::Key::Code key) { switch(key) { case sf::Key::Escape: quit(); break; case sf::Key::F: fullscreen = !fullscreen; create_window(1024, 768, fullscreen); init(); break; default: break; } }