From 092512c44a49390513df48bf17fc9244188afc48 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Wed, 27 May 2009 22:57:21 +0000 Subject: [PATCH] - Fixed: The mouse wheel generated no events in GUI mode if you weren't fullscreen. (e.g. You could no longer scroll the console with the mouse buffer.) - Fixed: Wheeling down was seen as wheeling up with the Win32 mouse. SVN r1618 (trunk) --- docs/rh-log.txt | 4 +++ src/win32/i_input.cpp | 27 ++++++++++++++++++ src/win32/i_input.h | 1 + src/win32/i_mouse.cpp | 66 ++++++++++++++++++++----------------------- 4 files changed, 63 insertions(+), 35 deletions(-) diff --git a/docs/rh-log.txt b/docs/rh-log.txt index d2b7da7359..4a17236acd 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,4 +1,8 @@ May 27, 2009 +- Fixed: The mouse wheel generated no events in GUI mode if you weren't + fullscreen. (e.g. You could no longer scroll the console with the mouse + buffer.) +- Fixed: Wheeling down was seen as wheeling up with the Win32 mouse. - EV_GUI_Key(Down|Up|Repeat) events no longer provide shifted key codes in data2. This was just unnecessary overhead that wasn't really needed anywhere. diff --git a/src/win32/i_input.cpp b/src/win32/i_input.cpp index 6290663e0e..f23248f122 100644 --- a/src/win32/i_input.cpp +++ b/src/win32/i_input.cpp @@ -143,6 +143,7 @@ extern menu_t JoystickMenu; EXTERN_CVAR (String, language) EXTERN_CVAR (Bool, lookstrafe) +static int WheelDelta; extern BOOL paused; static bool noidle = false; @@ -415,6 +416,32 @@ bool GUIWndProcHook(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESU } D_PostEvent(&ev); return true; + + // Note: If the mouse is grabbed, it sends the mouse wheel events itself. + case WM_MOUSEWHEEL: + if (wParam & MK_SHIFT) ev.data3 |= GKM_SHIFT; + if (wParam & MK_CONTROL) ev.data3 |= GKM_CTRL; + if (GetKeyState(VK_MENU) & 0x8000) ev.data3 |= GKM_ALT; + WheelDelta += (SHORT)HIWORD(wParam); + if (WheelDelta < 0) + { + ev.subtype = EV_GUI_WheelDown; + while (WheelDelta <= -WHEEL_DELTA) + { + D_PostEvent(&ev); + WheelDelta += WHEEL_DELTA; + } + } + else + { + ev.subtype = EV_GUI_WheelUp; + while (WheelDelta >= WHEEL_DELTA) + { + D_PostEvent(&ev); + WheelDelta -= WHEEL_DELTA; + } + } + return true; } return false; } diff --git a/src/win32/i_input.h b/src/win32/i_input.h index c0e885510f..b474ffb69d 100644 --- a/src/win32/i_input.h +++ b/src/win32/i_input.h @@ -80,6 +80,7 @@ protected: void PostButtonEvent(int button, bool down); void ClearButtonState(); + int WheelMove; int LastX, LastY; // for m_filter WORD ButtonState; // bit mask of current button states (1=down, 0=up) }; diff --git a/src/win32/i_mouse.cpp b/src/win32/i_mouse.cpp index 7de6d62cc5..410c9a411f 100644 --- a/src/win32/i_mouse.cpp +++ b/src/win32/i_mouse.cpp @@ -266,6 +266,7 @@ FMouse::FMouse() { LastX = LastY = 0; ButtonState = 0; + WheelMove = 0; } //========================================================================== @@ -316,49 +317,42 @@ void FMouse::WheelMoved(int wheelmove) event_t ev = { 0 }; int dir; - if (GUICapture) + WheelMove += wheelmove; + + if (WheelMove < 0) { - ev.type = EV_GUI_Event; - if (wheelmove < 0) - { - dir = WHEEL_DELTA; - ev.subtype = EV_GUI_WheelDown; - } - else - { - dir = -WHEEL_DELTA; - ev.subtype = EV_GUI_WheelUp; - } - /* FIXME - ev.data3 = ((KeyState[VK_SHIFT]&128) ? GKM_SHIFT : 0) | - ((KeyState[VK_CONTROL]&128) ? GKM_CTRL : 0) | - ((KeyState[VK_MENU]&128) ? GKM_ALT : 0); - */ - while (abs(wheelmove) >= WHEEL_DELTA) - { - D_PostEvent(&ev); - wheelmove += dir; - } + dir = WHEEL_DELTA; + ev.data1 = KEY_MWHEELDOWN; } else { - if (wheelmove < 0) - { - dir = WHEEL_DELTA; - ev.data1 = KEY_MWHEELDOWN; - } - else - { - dir = -WHEEL_DELTA; - ev.data1 = KEY_MWHEELUP; - } - while (abs(wheelmove) >= WHEEL_DELTA) + dir = -WHEEL_DELTA; + ev.data1 = KEY_MWHEELUP; + } + + if (!GUICapture) + { + while (abs(WheelMove) >= WHEEL_DELTA) { ev.type = EV_KeyDown; D_PostEvent(&ev); ev.type = EV_KeyUp; D_PostEvent(&ev); - wheelmove += dir; + WheelMove += dir; + } + } + else + { + ev.type = EV_GUI_Event; + ev.subtype = (WheelMove < 0) ? EV_GUI_WheelDown : EV_GUI_WheelUp; + if (GetKeyState(VK_SHIFT) & 0x8000) ev.data3 |= GKM_SHIFT; + if (GetKeyState(VK_CONTROL) & 0x8000) ev.data3 |= GKM_CTRL; + if (GetKeyState(VK_MENU) & 0x8000) ev.data3 |= GKM_ALT; + ev.data1 = 0; + while (abs(WheelMove) >= WHEEL_DELTA) + { + D_PostEvent(&ev); + WheelMove += dir; } } } @@ -420,6 +414,8 @@ void FMouse::ClearButtonState() } ButtonState = 0; } + // Reset mouse wheel accumulation to 0. + WheelMove = 0; } //========================================================================== @@ -967,7 +963,7 @@ bool FWin32Mouse::WndProcHook(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa } else if (message == WM_MOUSEWHEEL) { - WheelMoved(HIWORD(wParam)); + WheelMoved((SHORT)HIWORD(wParam)); return true; } else if (message >= WM_LBUTTONDOWN && message <= WM_MBUTTONUP)