summaryrefslogtreecommitdiffstats
path: root/test/window_test.cpp
blob: 6ba1eaaf2fc2c0fe6aaa17ca891967c47ca6ca86 (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
#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();

                // 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();
            // ~60 fps test
            wsdl2::delay(1000.0/60.0);
        } while (win.is_open());
    });

    win_update.join();

    wsdl2::quit();
    return 0;
}