From dfc9a9b37d544d3a357b560829d2a9a48e5e5f5b Mon Sep 17 00:00:00 2001 From: ladevieq Date: Sat, 16 Jan 2021 23:22:30 +0100 Subject: Add windows window event loop --- include/window.hpp | 6 ++++++ src/main.cpp | 2 ++ src/window.cpp | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/include/window.hpp b/include/window.hpp index c0e4756..550463d 100644 --- a/include/window.hpp +++ b/include/window.hpp @@ -11,6 +11,8 @@ class window { public: window(uint32_t width, uint32_t height); + void poll_events(); + xcb_connection_t* connection; xcb_window_t win; @@ -26,6 +28,10 @@ class window { public: window(uint32_t width, uint32_t height); + void poll_events(); + + LRESULT message_handler(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam); + static LRESULT CALLBACK window_procedure(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam); HWND win_handle; diff --git a/src/main.cpp b/src/main.cpp index 0a357f8..0176fdf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -153,6 +153,8 @@ int main() { vkrenderer renderer { wnd, inputs }; while(wnd.isOpen) { + wnd.poll_events(); + // To start a frame capture, call StartFrameCapture. // You can specify NULL, NULL for the device to capture on if you have only one device and // either no windows at all or only one window, and it will capture from that device. diff --git a/src/window.cpp b/src/window.cpp index a55a439..489473b 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -41,6 +41,7 @@ LRESULT CALLBACK window::window_procedure(HWND hwnd, UINT umsg, WPARAM wparam, L SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)win); } else { win = (window*)GetWindowLongPtr(hwnd, GWLP_USERDATA); + return win->message_handler(hwnd, umsg, wparam, lparam); } return DefWindowProc(hwnd, umsg, wparam, lparam); @@ -82,4 +83,22 @@ window::window(uint32_t width, uint32_t height) isOpen = true; } + +void window::poll_events() { + MSG msg = {}; + + while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } +} + +LRESULT window::message_handler(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam) { + switch(umsg) { + default: + return DefWindowProc(hwnd, umsg, wparam, lparam); + } + + return 0; +} #endif -- cgit v1.3