- 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)
This commit is contained in:
Randy Heit 2010-08-08 01:28:20 +00:00
parent f5a1aa994b
commit d32d8b4f9f
4 changed files with 48 additions and 51 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 326 B

View file

@ -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;

View file

@ -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);
}
}
/**************************************************************************/
/**************************************************************************/

View file

@ -444,13 +444,6 @@ BEGIN
END
/////////////////////////////////////////////////////////////////////////////
//
// Cursor
//
IDC_INVISIBLECURSOR CURSOR "cursor1.cur"
/////////////////////////////////////////////////////////////////////////////
//
// Bitmap