From d32d8b4f9f858be151b4d60b69dd3dc60a90b436 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sun, 8 Aug 2010 01:28:20 +0000 Subject: [PATCH] - Removed TheInvisibleCursor, since passing NULL to SetCursor() has exactly the same effect. - Two tweaks to raw mouse input to make it better behaved when the window suddenly has focus removed (e.g. because of a debugger break): * Keep the pointer centered in the window, as for Win32Mouse. Even though it's not generating any traditional input events, it's still moving all over the screen. e.g. If we have focus yanked away and you're pressing the right mouse button as it happens, you can suddenly find yourself with a popup menu open. * Use SetCursorState() like the other mouse modes instead of ShowCursor() to hide the pointer. This way, we don't need to worry about being stuck with trying to use the system with an invisible pointer, because only the game window will be pointer-less. SVN r2495 (trunk) --- src/win32/cursor1.cur | Bin 326 -> 0 bytes src/win32/i_main.cpp | 3 +- src/win32/i_mouse.cpp | 89 ++++++++++++++++++++++-------------------- src/win32/zdoom.rc | 7 ---- 4 files changed, 48 insertions(+), 51 deletions(-) delete mode 100644 src/win32/cursor1.cur diff --git a/src/win32/cursor1.cur b/src/win32/cursor1.cur deleted file mode 100644 index 048f06b4aefde54e0ff825ccb5a5db4d7001d513..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 326 zcmZQzU}9ioP*7k10|Q0|1~DK@1BexX*a3(cfe;L!6oi8y|NsAw;0zE8=!O9W0CiJ? AlK=n! diff --git a/src/win32/i_main.cpp b/src/win32/i_main.cpp index a76380bda0..e590fbd3b5 100644 --- a/src/win32/i_main.cpp +++ b/src/win32/i_main.cpp @@ -118,7 +118,7 @@ extern BYTE *ST_Util_BitsForBitmap (BITMAPINFO *bitmap_info); extern EXCEPTION_POINTERS CrashPointers; extern BITMAPINFO *StartupBitmap; extern UINT TimerPeriod; -extern HCURSOR TheArrowCursor, TheInvisibleCursor; +extern HCURSOR TheArrowCursor; // PUBLIC DATA DEFINITIONS ------------------------------------------------- @@ -931,7 +931,6 @@ void DoMain (HINSTANCE hInstance) x = y = 0; } - TheInvisibleCursor = LoadCursor (hInstance, MAKEINTRESOURCE(IDC_INVISIBLECURSOR)); TheArrowCursor = LoadCursor (NULL, IDC_ARROW); WNDCLASS WndClass; diff --git a/src/win32/i_mouse.cpp b/src/win32/i_mouse.cpp index 80c00bdbe6..87de7269af 100644 --- a/src/win32/i_mouse.cpp +++ b/src/win32/i_mouse.cpp @@ -87,8 +87,6 @@ public: void Ungrab(); protected: - void CenterMouse(int x, int y); - POINT UngrabbedPointerPos; LONG PrevX, PrevY; bool Grabbed; @@ -112,6 +110,7 @@ static void SetCursorState(bool visible); static FMouse *CreateWin32Mouse(); static FMouse *CreateDInputMouse(); static FMouse *CreateRawMouse(); +static void CenterMouse(int x, int y, LONG *centx, LONG *centy); // EXTERNAL DATA DECLARATIONS ---------------------------------------------- @@ -136,7 +135,6 @@ static FMouse *(*MouseFactory[])() = FMouse *Mouse; HCURSOR TheArrowCursor; -HCURSOR TheInvisibleCursor; CVAR (Bool, use_mouse, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR (Bool, m_noprescale, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) @@ -183,7 +181,7 @@ CUSTOM_CVAR(Int, mouse_capturemode, 1, CVAR_GLOBALCONFIG|CVAR_ARCHIVE) static void SetCursorState(bool visible) { - HCURSOR usingCursor = visible ? TheArrowCursor : TheInvisibleCursor; + HCURSOR usingCursor = visible ? TheArrowCursor : NULL; SetClassLongPtr(Window, GCLP_HCURSOR, (LONG_PTR)usingCursor); if (GetForegroundWindow() == Window) { @@ -191,6 +189,37 @@ static void SetCursorState(bool visible) } } +//========================================================================== +// +// CenterMouse +// +// Moves the mouse to the center of the window, but only if the current +// position isn't already in the center. +// +//========================================================================== + +static void CenterMouse(int curx, int cury, LONG *centxp, LONG *centyp) +{ + RECT rect; + + GetWindowRect(Window, &rect); + + int centx = (rect.left + rect.right) >> 1; + int centy = (rect.top + rect.bottom) >> 1; + + // Reduce the number of WM_MOUSEMOVE messages that get sent + // by only calling SetCursorPos when we really need to. + if (centx != curx || centy != cury) + { + if (centxp != NULL) + { + *centxp = centx; + *centyp = centy; + } + SetCursorPos(centx, centy); + } +} + //========================================================================== // // CaptureMode_InGame @@ -512,12 +541,11 @@ void FRawMouse::Grab() { GetCursorPos(&UngrabbedPointerPos); Grabbed = true; - while (ShowCursor(FALSE) >= 0) - { } + SetCursorState(false); // By setting the cursor position, we force the pointer image // to change right away instead of having it delayed until // some time in the future. - SetCursorPos(0, 0); + CenterMouse(-1, -1, NULL, NULL); } } } @@ -543,7 +571,7 @@ void FRawMouse::Ungrab() Grabbed = false; ClearButtonState(); } - ShowCursor(TRUE); + SetCursorState(true); SetCursorPos(UngrabbedPointerPos.x, UngrabbedPointerPos.y); } } @@ -586,8 +614,13 @@ bool FRawMouse::ProcessRawInput(RAWINPUT *raw, int code) { WheelMoved(1, (SHORT)raw->data.mouse.usButtonData); } - PostMouseMove(m_noprescale ? raw->data.mouse.lLastX : raw->data.mouse.lLastX<<2, - -raw->data.mouse.lLastY); + int x = m_noprescale ? raw->data.mouse.lLastX : raw->data.mouse.lLastX << 2; + int y = -raw->data.mouse.lLastY; + PostMouseMove(x, y); + if (x | y) + { + CenterMouse(-1, -1, NULL, NULL); + } return true; } @@ -920,7 +953,7 @@ void FWin32Mouse::ProcessInput() } if (x | y) { - CenterMouse(pt.x, pt.y); + CenterMouse(pt.x, pt.y, &PrevX, &PrevY); } PostMouseMove(x, y); } @@ -944,13 +977,13 @@ bool FWin32Mouse::WndProcHook(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa { if (wParam == SIZE_MAXIMIZED || wParam == SIZE_RESTORED) { - CenterMouse(-1, -1); + CenterMouse(-1, -1, &PrevX, &PrevY); return true; } } else if (message == WM_MOVE) { - CenterMouse(-1, -1); + CenterMouse(-1, -1, &PrevX, &PrevY); return true; } else if (message == WM_SYSCOMMAND) @@ -1059,7 +1092,7 @@ void FWin32Mouse::Grab() ClipCursor(&rect); SetCursorState(false); - CenterMouse(-1, -1); + CenterMouse(-1, -1, &PrevX, &PrevY); Grabbed = true; } @@ -1085,34 +1118,6 @@ void FWin32Mouse::Ungrab() ClearButtonState(); } -//========================================================================== -// -// FWin32Mouse :: CenterMouse -// -// Moves the mouse to the center of the window, but only if the current -// position isn't already in the center. -// -//========================================================================== - -void FWin32Mouse::CenterMouse(int curx, int cury) -{ - RECT rect; - - GetWindowRect (Window, &rect); - - int centx = (rect.left + rect.right) >> 1; - int centy = (rect.top + rect.bottom) >> 1; - - // Reduce the number of WM_MOUSEMOVE messages that get sent - // by only calling SetCursorPos when we really need to. - if (centx != curx || centy != cury) - { - PrevX = centx; - PrevY = centy; - SetCursorPos (centx, centy); - } -} - /**************************************************************************/ /**************************************************************************/ diff --git a/src/win32/zdoom.rc b/src/win32/zdoom.rc index 7c953edaca..bddfc13477 100644 --- a/src/win32/zdoom.rc +++ b/src/win32/zdoom.rc @@ -444,13 +444,6 @@ BEGIN END -///////////////////////////////////////////////////////////////////////////// -// -// Cursor -// - -IDC_INVISIBLECURSOR CURSOR "cursor1.cur" - ///////////////////////////////////////////////////////////////////////////// // // Bitmap