diff options
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; |