-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.cpp
More file actions
91 lines (71 loc) · 2.35 KB
/
application.cpp
File metadata and controls
91 lines (71 loc) · 2.35 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "application.h"
#include <stdio.h>
std::queue<Event*> EventsQueue::queue;
Application::Application(int width, int height, const char* appName):
engineApp(width, height, appName),
backgroundColor(0, 0, 0, 255) {}
Application::Application(const char *appName, AppMode appMode):
backgroundColor(0, 0, 0, 255){
if (AppMode::fullscreen == appMode) {
engineApp.setupFullScreenApp(appName);
} else
fprintf(stderr, "Error: wrong application mode\n");
}
void Application::close() {
appOpen = false;
}
void Application::setBackgroundColor(unsigned char r, unsigned char g, unsigned char b, unsigned char alpha) {
backgroundColor = Color(r, g, b, alpha);
}
void Application::setBackgroundColor(const Color &color) {
backgroundColor = color;
}
void Application::addDrawableObject(Window *drawableObject) {
windowsList.push_back(drawableObject);
}
SystemEventSender* Application::getSystemEventManager() {
return &systemEventSender;
}
void Application::run() {
appOpen = true;
while (appOpen) {
engineApp.pollEvent(EventsQueue::queue);
while (!EventsQueue::queue.empty()) {
auto event = std::unique_ptr<Event>(EventsQueue::queue.front());
EventsQueue::queue.pop();
if (event->type == Event::Closed) {
close();
}
EventManager::sendEvent(&systemEventSender, event);
}
engineApp.clear(backgroundColor);
for (auto window: windowsList) {
window->draw(engineApp);
}
engineApp.display();
}
engineApp.close();
}
void Application::loadImageFromFile(const std::string_view& path,
const std::string& name) {
engineApp.addImage(path, name);
}
void Application::loadFontFromFile(const std::string_view& path,
const std::string& name) {
engineApp.addFont(path, name);
}
void Application::getEvent(std::unique_ptr<Event>& event) {
switch (event->type)
{
case Event::SavePixels:
savePixels(event);
break;
default:
break;
}
}
void Application::savePixels(std::unique_ptr<Event>& event) {
auto savePixelsEvent = dynamic_cast<SavePixelsEvent*>(event.get());
engineApp.savePixels(savePixelsEvent->pixels,
savePixelsEvent->filePath);
}