diff options
author | Nao Pross <naopross@thearcway.org> | 2019-01-21 20:11:29 +0100 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2019-01-21 20:25:38 +0100 |
commit | 8a0f6d6eee6162d1a10b20512e2f2c86a0278a34 (patch) | |
tree | 44c8202165566c7206bf6ac44b2febed0919588e /test | |
parent | Update wrapsdl2::window to use Renderer instead of Surface (diff) | |
download | libwsdl2-8a0f6d6eee6162d1a10b20512e2f2c86a0278a34.tar.gz libwsdl2-8a0f6d6eee6162d1a10b20512e2f2c86a0278a34.zip |
Add events wrapper
Diffstat (limited to 'test')
-rw-r--r-- | test/makefile | 4 | ||||
-rw-r--r-- | test/window_test.cpp | 56 |
2 files changed, 38 insertions, 22 deletions
diff --git a/test/makefile b/test/makefile index ee8569a..a2d6800 100644 --- a/test/makefile +++ b/test/makefile @@ -9,6 +9,10 @@ OBJS := $(patsubst %.cpp,build/%.o,$(SRCS)) # Recipes all: build/window_test +.PHONY: run +run: build/window_test + ./build/window_test + build/window_test: build/window_test.o $(CPP) $(CFLAGS) -o $@ $< $(LFLAGS) diff --git a/test/window_test.cpp b/test/window_test.cpp index 2136488..c473a34 100644 --- a/test/window_test.cpp +++ b/test/window_test.cpp @@ -1,39 +1,51 @@ +#include "../debug.hpp" + #include "wrapsdl2.hpp" #include "video.hpp" +#include "event.hpp" #include <iostream> #include <thread> #include <mutex> int main(int argc, char *argv[]) { - wrapsdl2::initialize(); - - { - using namespace wrapsdl2; - - window win("Window Test", 800, 600); - std::mutex win_mutex; - std::cout << "press ENTER to show the window" << std::endl; - std::cin.get(); - - win.show(); - - std::thread win_update([&]() { - std::lock_guard<std::mutex> lock(win_mutex); - while (win.is_open()) { - win.update(); - wrapsdl2::delay(200); + using namespace wrapsdl2; + wrapsdl2::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(); + } } - }); - std::cout << "press ENTER to quit" << std::endl; - std::cin.get(); + win.update(); + } while (win.is_open()); + }); - win_update.join(); - } + win_update.join(); wrapsdl2::quit(); return 0; |