From 759b5f6906c4caf17c721fc86f571ae2cd534e8b Mon Sep 17 00:00:00 2001 From: Peter Slattery Date: Tue, 4 Feb 2020 23:46:11 -0800 Subject: [PATCH] Handle releasing the mouse button outside the window when the button was pressed over top of the window. --- src/foldhaus_app.cpp | 1 - src/win32_foldhaus.cpp | 24 ++++++++++++++++++++++++ todo.txt | 4 ++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/foldhaus_app.cpp b/src/foldhaus_app.cpp index 27a7d76..5cd1745 100644 --- a/src/foldhaus_app.cpp +++ b/src/foldhaus_app.cpp @@ -140,7 +140,6 @@ INITIALIZE_APPLICATION(InitializeApplication) Font->BitmapTextureHandle = Context.PlatformGetGPUTextureHandle(Font->BitmapMemory, Font->BitmapWidth, Font->BitmapHeight); - } else {} } diff --git a/src/win32_foldhaus.cpp b/src/win32_foldhaus.cpp index be25e13..db441e6 100644 --- a/src/win32_foldhaus.cpp +++ b/src/win32_foldhaus.cpp @@ -378,6 +378,15 @@ HandleWindowMessage (MSG Message, window* Window, input_queue* InputQueue, mouse Mouse->LeftButtonState = KeyState_IsDown & ~KeyState_WasDown; Mouse->DownPos = Mouse->Pos; + + // :Win32MouseEventCapture + // NOTE(Peter): We capture events when the mouse goes down so that + // if the user drags outside the window, we still get the mouse up + // event and can process it. Otherwise, we can get into cases where + // an event was started, didn't end, but the user can click again and + // try to start the event again. + // We relase event capture on mouse up. + SetCapture(Window->Handle); }break; case WM_MBUTTONDOWN: @@ -389,6 +398,9 @@ HandleWindowMessage (MSG Message, window* Window, input_queue* InputQueue, mouse AddInputEventEntry(InputQueue, KeyCode_MouseMiddleButton, false, true, ShiftDown, AltDown, CtrlDown, false); Mouse->MiddleButtonState = KeyState_IsDown & ~KeyState_WasDown; + + // :Win32MouseEventCapture + SetCapture(Window->Handle); }break; case WM_RBUTTONDOWN: @@ -401,6 +413,9 @@ HandleWindowMessage (MSG Message, window* Window, input_queue* InputQueue, mouse ShiftDown, AltDown, CtrlDown, false); Mouse->RightButtonState = KeyState_IsDown & ~KeyState_WasDown; Mouse->DownPos = Mouse->Pos; + + // :Win32MouseEventCapture + SetCapture(Window->Handle); }break; case WM_LBUTTONUP: @@ -412,6 +427,9 @@ HandleWindowMessage (MSG Message, window* Window, input_queue* InputQueue, mouse AddInputEventEntry(InputQueue, KeyCode_MouseLeftButton, true, false, ShiftDown, AltDown, CtrlDown, false); Mouse->LeftButtonState = ~KeyState_IsDown & KeyState_WasDown; + + // :Win32MouseEventCapture + ReleaseCapture(); }break; case WM_MBUTTONUP: @@ -423,6 +441,9 @@ HandleWindowMessage (MSG Message, window* Window, input_queue* InputQueue, mouse AddInputEventEntry(InputQueue, KeyCode_MouseMiddleButton, true, false, ShiftDown, AltDown, CtrlDown, false); Mouse->MiddleButtonState = ~KeyState_IsDown & KeyState_WasDown; + + // :Win32MouseEventCapture + ReleaseCapture(); }break; case WM_RBUTTONUP: @@ -434,6 +455,9 @@ HandleWindowMessage (MSG Message, window* Window, input_queue* InputQueue, mouse AddInputEventEntry(InputQueue, KeyCode_MouseRightButton, true, false, ShiftDown, AltDown, CtrlDown, false); Mouse->RightButtonState = ~KeyState_IsDown & KeyState_WasDown; + + // :Win32MouseEventCapture + ReleaseCapture(); }break; case WM_SYSKEYDOWN: diff --git a/todo.txt b/todo.txt index 7c5b274..2f27839 100644 --- a/todo.txt +++ b/todo.txt @@ -15,6 +15,10 @@ x Hot Code Reloading - math.h: present for trig functions - windows.h: only thing left is InterlockedIncrement and InterlockedAdd +- Win32 Platform Layer + x Capture Mouse Events that start on the window but end outside + x Mouse up when mouse down was in the window + - File Loading - Gracefully handle File Not found