summaryrefslogtreecommitdiff
path: root/application.cpp
blob: cafaeab3bf9c82958cc7bb65238ce82c70d5ae9a (plain)
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
#include "application.h"

#include <stdexcept>

Application::Application() {
	please_quit = false;
}

Application::~Application() {
	
}

void Application::init_window(unsigned int w, unsigned int h, bool fs) {
	window = new sf::Window(sf::VideoMode(w, h, 32), "Foo");
	
	window->UseVerticalSync(true);
}

void Application::run() {
	while(1) {
		sf::Event e;
		while(window->GetEvent(e)) {
			event(e);
		}
		
		if(please_quit) {
			return;
		}
		
		update();
		
		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;
		default:
			break;
	}
}