From d05542a7932b66a530557d6b23ad394d5003a2b8 Mon Sep 17 00:00:00 2001 From: LaBodilsen Date: Sat, 29 Jan 2022 17:40:37 +0100 Subject: [PATCH 1/3] Update olcPixelGameEngine.h --- olcPixelGameEngine.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/olcPixelGameEngine.h b/olcPixelGameEngine.h index fd077c4..08fbb36 100644 --- a/olcPixelGameEngine.h +++ b/olcPixelGameEngine.h @@ -4732,11 +4732,19 @@ namespace olc // Windows Event Handler - this is statically connected to the windows event system static LRESULT CALLBACK olc_WindowEvent(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) + static BOOL bTrackMouseEventSet = FALSE; + switch (uMsg) { - switch (uMsg) - { - case WM_MOUSEMOVE: + case WM_MOUSEMOVE: + { + if (!bTrackMouseEventSet) { + bTrackMouseEventSet = TRUE; + TRACKMOUSEEVENT tme{ sizeof(TRACKMOUSEEVENT), TME_LEAVE, hWnd }; TrackMouseEvent(&tme); + ptrPGE->olc_UpdateMouseState(0, wParam == MK_LBUTTON); + ptrPGE->olc_UpdateMouseState(1, wParam == MK_RBUTTON); + ptrPGE->olc_UpdateMouseState(2, wParam == MK_MBUTTON); + } // Thanks @ForAbby (Discord) uint16_t x = lParam & 0xFFFF; uint16_t y = (lParam >> 16) & 0xFFFF; int16_t ix = *(int16_t*)&x; int16_t iy = *(int16_t*)&y; @@ -4745,7 +4753,7 @@ namespace olc } case WM_SIZE: ptrPGE->olc_UpdateWindowSize(lParam & 0xFFFF, (lParam >> 16) & 0xFFFF); return 0; case WM_MOUSEWHEEL: ptrPGE->olc_UpdateMouseWheel(GET_WHEEL_DELTA_WPARAM(wParam)); return 0; - case WM_MOUSELEAVE: ptrPGE->olc_UpdateMouseFocus(false); return 0; + case WM_MOUSELEAVE: bTrackMouseEventSet = FALSE; ptrPGE->olc_UpdateMouseFocus(false); return 0; case WM_SETFOCUS: ptrPGE->olc_UpdateKeyFocus(true); return 0; case WM_KILLFOCUS: ptrPGE->olc_UpdateKeyFocus(false); return 0; case WM_KEYDOWN: ptrPGE->olc_UpdateKeyState(mapKeys[wParam], true); return 0; From e3ea3b250f5b84acb075965e0fb9806cd39585e2 Mon Sep 17 00:00:00 2001 From: LaBodilsen Date: Sat, 29 Jan 2022 18:04:15 +0100 Subject: [PATCH 2/3] fixed a missing { in the pull request fixed a missing { in the pull request --- olcPixelGameEngine.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/olcPixelGameEngine.h b/olcPixelGameEngine.h index 08fbb36..4afa23e 100644 --- a/olcPixelGameEngine.h +++ b/olcPixelGameEngine.h @@ -195,7 +195,7 @@ Author ~~~~~~ - David Barr, aka javidx9, ©OneLoneCoder 2018, 2019, 2020, 2021, 2022 + David Barr, aka javidx9, ©OneLoneCoder 2018, 2019, 2020, 2021, 2022 */ #pragma endregion @@ -4732,6 +4732,7 @@ namespace olc // Windows Event Handler - this is statically connected to the windows event system static LRESULT CALLBACK olc_WindowEvent(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) + { static BOOL bTrackMouseEventSet = FALSE; switch (uMsg) { From 0336c8086a4dd4c6d853afa3e3b9f8e50dcfd6dd Mon Sep 17 00:00:00 2001 From: LaBodilsen Date: Sun, 30 Jan 2022 18:18:53 +0100 Subject: [PATCH 3/3] Changed mouse button values to engines. Changed the check mouse button under WM_MOUSEMOVE to use the Engine constants for mouse button 0, 1, 2. --- olcPixelGameEngine.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/olcPixelGameEngine.h b/olcPixelGameEngine.h index 4afa23e..abe1401 100644 --- a/olcPixelGameEngine.h +++ b/olcPixelGameEngine.h @@ -4742,9 +4742,9 @@ namespace olc { bTrackMouseEventSet = TRUE; TRACKMOUSEEVENT tme{ sizeof(TRACKMOUSEEVENT), TME_LEAVE, hWnd }; TrackMouseEvent(&tme); - ptrPGE->olc_UpdateMouseState(0, wParam == MK_LBUTTON); - ptrPGE->olc_UpdateMouseState(1, wParam == MK_RBUTTON); - ptrPGE->olc_UpdateMouseState(2, wParam == MK_MBUTTON); + ptrPGE->olc_UpdateMouseState(olc::Mouse::LEFT, wParam == MK_LBUTTON); + ptrPGE->olc_UpdateMouseState(olc::Mouse::RIGHT, wParam == MK_RBUTTON); + ptrPGE->olc_UpdateMouseState(olc::Mouse::MIDDLE, wParam == MK_MBUTTON); } // Thanks @ForAbby (Discord) uint16_t x = lParam & 0xFFFF; uint16_t y = (lParam >> 16) & 0xFFFF;