blob: 17c7cf441c28eea471cb9cbc6aeff0ee48cd7122 (
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
|
#include "../debug.hpp"
#include "wsdl2.hpp"
#include "video.hpp"
#include "event.hpp"
#include <iostream>
#include <thread>
#include <mutex>
int main(int argc, char *argv[]) {
using namespace wsdl2;
wsdl2::initialize();
window win("Window Test", 800, 600);
std::mutex win_mutex;
win.open();
std::thread win_update([&]() {
std::lock_guard<std::mutex> lock(win_mutex);
do {
std::optional<event> ev = poll_event();
if (ev.has_value()) {
event& event = ev.value();
npdebug("received event", event.sdl().type);
// TODO: remove this sdl code
if (event.sdl().type == SDL_WINDOWEVENT) {
if (event.sdl().window.event == SDL_WINDOWEVENT_CLOSE) {
npdebug("SDL_WINDOWEVENT_CLOSE")
win.close();
}
}
if (event.sdl().type == SDL_QUIT) {
npdebug("SDL_QUIT");
win.close();
}
}
win.update();
} while (win.is_open());
});
win_update.join();
wsdl2::quit();
return 0;
}
|