mirror of
https://bitbucket.org/CPMADevs/cnq3
synced 2024-11-12 23:44:29 +00:00
fixed and unified Windows mouse wheel handling
This commit is contained in:
parent
5689cb3d1e
commit
b4d78a1bc1
2 changed files with 20 additions and 45 deletions
|
@ -29,7 +29,7 @@ static cvar_t* in_noGrab;
|
||||||
|
|
||||||
|
|
||||||
struct Mouse {
|
struct Mouse {
|
||||||
Mouse() : active(qfalse), wheel(0) {}
|
Mouse() : active(qfalse) {}
|
||||||
|
|
||||||
qbool IsActive() const { return active; }
|
qbool IsActive() const { return active; }
|
||||||
|
|
||||||
|
@ -42,7 +42,6 @@ protected:
|
||||||
void UpdateWheel( int delta ); // queues mouse wheel events if needed
|
void UpdateWheel( int delta ); // queues mouse wheel events if needed
|
||||||
|
|
||||||
qbool active;
|
qbool active;
|
||||||
int wheel;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static Mouse* mouse;
|
static Mouse* mouse;
|
||||||
|
@ -51,18 +50,18 @@ static qbool mouseSettingsSet = qfalse;
|
||||||
|
|
||||||
void Mouse::UpdateWheel( int delta )
|
void Mouse::UpdateWheel( int delta )
|
||||||
{
|
{
|
||||||
wheel += delta;
|
if (delta > 0) {
|
||||||
|
while (delta >= WHEEL_DELTA) {
|
||||||
while (wheel >= WHEEL_DELTA) {
|
WIN_QueEvent( g_wv.sysMsgTime, SE_KEY, K_MWHEELUP, qtrue, 0, NULL );
|
||||||
WIN_QueEvent( g_wv.sysMsgTime, SE_KEY, K_MWHEELUP, qtrue, 0, NULL );
|
WIN_QueEvent( g_wv.sysMsgTime, SE_KEY, K_MWHEELUP, qfalse, 0, NULL );
|
||||||
WIN_QueEvent( g_wv.sysMsgTime, SE_KEY, K_MWHEELUP, qfalse, 0, NULL );
|
delta -= WHEEL_DELTA;
|
||||||
wheel -= WHEEL_DELTA;
|
}
|
||||||
}
|
} else {
|
||||||
|
while (delta <= -WHEEL_DELTA) {
|
||||||
while (wheel <= -WHEEL_DELTA) {
|
WIN_QueEvent( g_wv.sysMsgTime, SE_KEY, K_MWHEELDOWN, qtrue, 0, NULL );
|
||||||
WIN_QueEvent( g_wv.sysMsgTime, SE_KEY, K_MWHEELDOWN, qtrue, 0, NULL );
|
WIN_QueEvent( g_wv.sysMsgTime, SE_KEY, K_MWHEELDOWN, qfalse, 0, NULL );
|
||||||
WIN_QueEvent( g_wv.sysMsgTime, SE_KEY, K_MWHEELDOWN, qfalse, 0, NULL );
|
delta += WHEEL_DELTA;
|
||||||
wheel += WHEEL_DELTA;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,8 +81,6 @@ static rawmouse_t rawmouse;
|
||||||
|
|
||||||
qbool rawmouse_t::Init()
|
qbool rawmouse_t::Init()
|
||||||
{
|
{
|
||||||
wheel = 0;
|
|
||||||
|
|
||||||
// Problems with the RIDEV_NOLEGACY flag:
|
// Problems with the RIDEV_NOLEGACY flag:
|
||||||
// - When focusing the app while pressing a mouse button, the cursor becomes visible and stays so indefinitely
|
// - When focusing the app while pressing a mouse button, the cursor becomes visible and stays so indefinitely
|
||||||
// despite properly having done the repeated calls to ShowCursor(FALSE) until the counter is negative.
|
// despite properly having done the repeated calls to ShowCursor(FALSE) until the counter is negative.
|
||||||
|
@ -111,7 +108,6 @@ qbool rawmouse_t::Init()
|
||||||
|
|
||||||
qbool rawmouse_t::Activate( qbool _active )
|
qbool rawmouse_t::Activate( qbool _active )
|
||||||
{
|
{
|
||||||
wheel = 0;
|
|
||||||
active = _active;
|
active = _active;
|
||||||
|
|
||||||
return qtrue;
|
return qtrue;
|
||||||
|
@ -160,7 +156,7 @@ qbool rawmouse_t::ProcessMessage( UINT msg, WPARAM wParam, LPARAM lParam )
|
||||||
if (!ri.data.mouse.usButtonFlags) // no button or wheel transitions
|
if (!ri.data.mouse.usButtonFlags) // no button or wheel transitions
|
||||||
return qfalse;
|
return qfalse;
|
||||||
|
|
||||||
if (active && (ri.data.mouse.usButtonFlags & RI_MOUSE_WHEEL) != 0)
|
if ((ri.data.mouse.usButtonFlags & RI_MOUSE_WHEEL) != 0)
|
||||||
UpdateWheel( (SHORT)ri.data.mouse.usButtonData );
|
UpdateWheel( (SHORT)ri.data.mouse.usButtonData );
|
||||||
|
|
||||||
for (int i = 0; i < 5; ++i) {
|
for (int i = 0; i < 5; ++i) {
|
||||||
|
@ -204,7 +200,6 @@ void winmouse_t::UpdateWindowCenter()
|
||||||
|
|
||||||
qbool winmouse_t::Activate( qbool _active )
|
qbool winmouse_t::Activate( qbool _active )
|
||||||
{
|
{
|
||||||
wheel = 0;
|
|
||||||
active = _active;
|
active = _active;
|
||||||
|
|
||||||
if (!_active)
|
if (!_active)
|
||||||
|
@ -219,8 +214,12 @@ qbool winmouse_t::Activate( qbool _active )
|
||||||
|
|
||||||
qbool winmouse_t::ProcessMessage( UINT msg, WPARAM wParam, LPARAM lParam )
|
qbool winmouse_t::ProcessMessage( UINT msg, WPARAM wParam, LPARAM lParam )
|
||||||
{
|
{
|
||||||
if ( !active )
|
if ( !active ) {
|
||||||
|
if ( msg == WM_MOUSEWHEEL )
|
||||||
|
UpdateWheel( GET_WHEEL_DELTA_WPARAM(wParam) );
|
||||||
|
|
||||||
return qfalse;
|
return qfalse;
|
||||||
|
}
|
||||||
|
|
||||||
UpdateWindowCenter();
|
UpdateWindowCenter();
|
||||||
|
|
||||||
|
|
|
@ -214,30 +214,6 @@ LRESULT CALLBACK MainWndProc (
|
||||||
{
|
{
|
||||||
switch (uMsg)
|
switch (uMsg)
|
||||||
{
|
{
|
||||||
|
|
||||||
case WM_MOUSEWHEEL:
|
|
||||||
{
|
|
||||||
int i = (short)HIWORD(wParam);
|
|
||||||
// note: apparently the vista mouse driver often returns < WHEEL_DELTA
|
|
||||||
// but anyone running vista is a moron anyway, so fkit :P
|
|
||||||
if (i > 0) {
|
|
||||||
while (i >= WHEEL_DELTA) {
|
|
||||||
WIN_QueEvent( g_wv.sysMsgTime, SE_KEY, K_MWHEELUP, qtrue, 0, NULL );
|
|
||||||
WIN_QueEvent( g_wv.sysMsgTime, SE_KEY, K_MWHEELUP, qfalse, 0, NULL );
|
|
||||||
i -= WHEEL_DELTA;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
while (i <= -WHEEL_DELTA) {
|
|
||||||
WIN_QueEvent( g_wv.sysMsgTime, SE_KEY, K_MWHEELDOWN, qtrue, 0, NULL );
|
|
||||||
WIN_QueEvent( g_wv.sysMsgTime, SE_KEY, K_MWHEELDOWN, qfalse, 0, NULL );
|
|
||||||
i += WHEEL_DELTA;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// when an application processes the WM_MOUSEWHEEL message, it must return zero
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WM_CREATE:
|
case WM_CREATE:
|
||||||
|
|
||||||
g_wv.hWnd = hWnd;
|
g_wv.hWnd = hWnd;
|
||||||
|
@ -373,7 +349,7 @@ LRESULT CALLBACK MainWndProc (
|
||||||
default:
|
default:
|
||||||
// this is complicated because Win32 seems to pack multiple mouse events into
|
// this is complicated because Win32 seems to pack multiple mouse events into
|
||||||
// one update sometimes, so we always check all states and look for events
|
// one update sometimes, so we always check all states and look for events
|
||||||
if ( uMsg == WM_INPUT || (uMsg >= WM_MOUSEFIRST && uMsg <= WM_MOUSELAST) )
|
if ( uMsg == WM_INPUT || (uMsg >= WM_MOUSEFIRST && uMsg <= WM_MOUSELAST) || uMsg == WM_MOUSEWHEEL )
|
||||||
if ( IN_ProcessMessage(uMsg, wParam, lParam) )
|
if ( IN_ProcessMessage(uMsg, wParam, lParam) )
|
||||||
return 0;
|
return 0;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue