From 5245e8d4ddd85097692cf0f9f4e21a80e670a745 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Tue, 26 May 2009 00:30:51 +0000 Subject: [PATCH] - I_CheckNativeMouse() now checks the foreground window to determine if the mouse should be grabbed. This fixes the case where you start the game in the background and it grabs the mouse anyway. - Changed raw mouse grabbing to call ShowCursor() directly instead of through SetCursorState(), since changing the pointer isn't working with it (probably due to the lack of legacy mouse messages), and the others work fine by setting an invisible cursor. - Fixed: Raw mouse input passes wheel movements in an unsigned field, but the value is signed, so it requires a cast to use it. - Reverted accidental changes to src/sdl/i_input.cpp. SVN r1605 (trunk) --- docs/rh-log.txt | 13 +++++++++++- src/sdl/i_input.cpp | 3 ++- src/win32/i_mouse.cpp | 46 +++++++++++++++++++++++++------------------ 3 files changed, 41 insertions(+), 21 deletions(-) diff --git a/docs/rh-log.txt b/docs/rh-log.txt index 8e8e1e718..55efbe3a2 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,4 +1,15 @@ -May 23, 2009 +May 25, 2009 +- I_CheckNativeMouse() now checks the foreground window to determine if the + mouse should be grabbed. This fixes the case where you start the game in + the background and it grabs the mouse anyway. +- Changed raw mouse grabbing to call ShowCursor() directly instead of through + SetCursorState(), since changing the pointer isn't working with it + (probably due to the lack of legacy mouse messages), and the others work + fine by setting an invisible cursor. +- Fixed: Raw mouse input passes wheel movements in an unsigned field, but the + value is signed, so it requires a cast to use it. + +May 23, 2009 - SetCursorState() now calls ShowCursor() again, because capturing the mouse with RIDEV_NOLEGACY apparently prevents SetCursor() from doing anything. - Split mouse code off from i_input.cpp into i_mouse.cpp and added raw mouse diff --git a/src/sdl/i_input.cpp b/src/sdl/i_input.cpp index b42c0385e..ab27dfde6 100644 --- a/src/sdl/i_input.cpp +++ b/src/sdl/i_input.cpp @@ -21,7 +21,8 @@ static void I_CheckGUICapture (); static void I_CheckNativeMouse (); -bool GUICapture; +static bool GUICapture; +static bool NativeMouse = true; extern int paused; diff --git a/src/win32/i_mouse.cpp b/src/win32/i_mouse.cpp index b41693664..1b233042b 100644 --- a/src/win32/i_mouse.cpp +++ b/src/win32/i_mouse.cpp @@ -175,18 +175,9 @@ static void SetCursorState(bool visible) { HCURSOR usingCursor = visible ? TheArrowCursor : TheInvisibleCursor; SetClassLongPtr(Window, GCLP_HCURSOR, (LONG_PTR)usingCursor); - //if (HaveFocus) + if (HaveFocus) { SetCursor(usingCursor); - if (visible) - { - ShowCursor(TRUE); - } - else - { - while (ShowCursor(FALSE) >= 0) - { } - } } } @@ -223,18 +214,33 @@ static bool CaptureMode_InGame() void I_CheckNativeMouse(bool preferNative) { - bool wantNative = (GetFocus() != Window) || - ((!screen || !screen->IsFullscreen()) && - (!CaptureMode_InGame() || GUICapture || paused || preferNative || !use_mouse || demoplayback)); + bool windowed = (screen == NULL) || !screen->IsFullscreen(); + bool want_native; + + if (!windowed) + { + want_native = false; + } + else + { + want_native = + (GetForegroundWindow() != Window) || + !CaptureMode_InGame() || + GUICapture || + paused || + preferNative || + !use_mouse || + demoplayback; + } //Printf ("%d %d %d\n", wantNative, preferNative, NativeMouse); - if (wantNative != NativeMouse) + if (want_native != NativeMouse) { if (Mouse != NULL) { - NativeMouse = wantNative; - if (wantNative) + NativeMouse = want_native; + if (want_native) { Mouse->Ungrab(); } @@ -493,6 +499,7 @@ void FRawMouse::ProcessInput() // //========================================================================== +extern BOOL AppActive; void FRawMouse::Grab() { if (!Grabbed) @@ -507,7 +514,8 @@ void FRawMouse::Grab() { GetCursorPos(&UngrabbedPointerPos); Grabbed = true; - SetCursorState(false); + while (ShowCursor(FALSE) >= 0) + { } // 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. @@ -537,7 +545,7 @@ void FRawMouse::Ungrab() Grabbed = false; ClearButtonState(); } - SetCursorState(true); + ShowCursor(TRUE); SetCursorPos(UngrabbedPointerPos.x, UngrabbedPointerPos.y); } } @@ -589,7 +597,7 @@ bool FRawMouse::WndProcHook(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPara } if (raw->data.mouse.usButtonFlags & RI_MOUSE_WHEEL) { - WheelMoved(raw->data.mouse.usButtonData); + WheelMoved((SHORT)raw->data.mouse.usButtonData); } PostMouseMove(m_noprescale ? raw->data.mouse.lLastX : raw->data.mouse.lLastX<<2, -raw->data.mouse.lLastY);