#include "application.h" #include "gl.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, const std::string& title) { window->Create(sf::VideoMode(w, h, 32), title, sf::Style::Resize | sf::Style::Close | (fs ? sf::Style::Fullscreen : 0)); window->UseVerticalSync(true); } void Application::init_window(unsigned int w, unsigned int h, bool fs, const std::string& title) { renderwindow = new sf::RenderWindow(); window = renderwindow; create_window(w, h, fs, title); #ifdef WIN32 win32_gl_init(); #endif input_backend = &window->GetInput(); window_title = title; } 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; case sf::Event::Resized: event_reshape(e.Size.Width, e.Size.Height); 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, window_title); event_reshape(window->GetWidth(), window->GetHeight()); init(); break; default: break; } } void Application::event_reshape(int width, int height) { }