From b94d5825bbde2fe1a05da7e66160e50c5c33ad38 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Mon, 20 Mar 2023 00:37:35 -0500 Subject: [PATCH] feat(event): handle size input events for windows --- src/event/win/Input.cpp | 44 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/event/win/Input.cpp b/src/event/win/Input.cpp index cc46fa5..100c6b2 100644 --- a/src/event/win/Input.cpp +++ b/src/event/win/Input.cpp @@ -3,6 +3,9 @@ #include #include +static RECT s_defaultWindowRect; +static int32_t s_savedResize; + void CenterMouse() { // TODO } @@ -233,7 +236,40 @@ int32_t HandleMouseUp(uint32_t message, uintptr_t wparam, bool* xbutton, HWND hw } int32_t OsInputGet(OSINPUT* id, int32_t* param0, int32_t* param1, int32_t* param2, int32_t* param3) { - // TODO window rect comparisons + *id = static_cast(-1); + + if (s_savedResize) { + auto hwnd = static_cast(OsGuiGetWindow(0)); + + if (!IsIconic(hwnd)) { + s_savedResize = 0; + + RECT windowRect; + GetWindowRect(hwnd, &windowRect); + + auto style = GetWindowLong(hwnd, GWL_STYLE); + RECT clientArea = { 0, 0, 0, 0 }; + AdjustWindowRectEx(&clientArea, style, false, 0); + + auto width = windowRect.right - clientArea.right - (windowRect.left - clientArea.left); + auto height = windowRect.bottom - clientArea.bottom - (windowRect.top - clientArea.top); + + if (s_defaultWindowRect.right != width || s_defaultWindowRect.bottom != height) { + s_defaultWindowRect.left = 0; + s_defaultWindowRect.top = 0; + s_defaultWindowRect.right = width; + s_defaultWindowRect.bottom = height; + + *id = OS_INPUT_SIZE; + *param0 = width; + *param1 = height; + *param2 = 0; + *param3 = 0; + + return 1; + } + } + } if (Input::s_queueTail != Input::s_queueHead) { OsQueueGet(id, param0, param1, param2, param3); @@ -304,6 +340,12 @@ int32_t OsWindowProc(void* window, uint32_t message, uintptr_t wparam, intptr_t switch (message) { // TODO handle remaining message types + case WM_SIZE: + case WM_DISPLAYCHANGE: { + s_savedResize = lparam; + break; + } + case WM_ACTIVATE: { auto isMinimized = IsIconic(hwnd); auto isActive = wparam != WA_INACTIVE;