Fix cursor in menus

it didn't work correctly because the mouse isn't grabbed
(in contrast to dhewm3).
It's fixed now by returning absolute coordinates when a menu
is open, furthermore the cursor is now always hidden.
This commit is contained in:
Daniel Gibson 2012-12-18 00:27:37 +01:00
parent 9c477c6bd9
commit dd987814f7
2 changed files with 35 additions and 10 deletions

View file

@ -607,10 +607,16 @@ void Sys_GrabMouseCursor( bool grabIt )
int flags;
if( grabIt )
flags = GRAB_ENABLE | GRAB_HIDECURSOR | GRAB_SETSTATE;
{
// DG: disabling the cursor is now done once in GLimp_Init() because it should always be disabled
flags = GRAB_ENABLE | GRAB_SETSTATE;
// DG end
}
else
{
flags = GRAB_SETSTATE;
}
GLimp_GrabInput( flags );
}
@ -678,8 +684,9 @@ sysEvent_t Sys_GetEvent()
newmod |= KMOD_CAPS;
SDL_SetModState( ( SDL_Keymod )newmod );
GLimp_GrabInput( GRAB_ENABLE | GRAB_REENABLE | GRAB_HIDECURSOR );
// DG: disabling the cursor is now done once in GLimp_Init() because it should always be disabled
GLimp_GrabInput( GRAB_ENABLE | GRAB_REENABLE );
// DG end
break;
}
@ -786,9 +793,21 @@ sysEvent_t Sys_GetEvent()
#endif
case SDL_MOUSEMOTION:
res.evType = SE_MOUSE;
res.evValue = ev.motion.xrel;
res.evValue2 = ev.motion.yrel;
// DG: return event with absolute mouse-coordinates when in menu
// to fix cursor problems in windowed mode
if( game && game->Shell_IsActive() )
{
res.evType = SE_MOUSE_ABSOLUTE;
res.evValue = ev.motion.x;
res.evValue2 = ev.motion.y;
}
else // this is the old, default behavior
{
res.evType = SE_MOUSE;
res.evValue = ev.motion.xrel;
res.evValue2 = ev.motion.yrel;
}
// DG end
mouse_polls.Append( mouse_poll_t( M_DELTAX, ev.motion.xrel ) );
mouse_polls.Append( mouse_poll_t( M_DELTAY, ev.motion.yrel ) );

View file

@ -267,6 +267,10 @@ bool GLimp_Init( glimpParms_t parms )
QGL_Init( "nodriverlib" );
// DG: disable cursor, we have two cursors in menu (because mouse isn't grabbed in menu)
SDL_ShowCursor( SDL_DISABLE );
// DG end
return true;
}
@ -374,11 +378,13 @@ void GLimp_GrabInput( int flags )
}
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_ShowCursor( flags & GRAB_HIDECURSOR ? SDL_DISABLE : SDL_ENABLE );
SDL_SetRelativeMouseMode( flags & GRAB_HIDECURSOR ? SDL_TRUE : SDL_FALSE );
// DG: disabling the cursor is now done once in GLimp_Init() because it should always be disabled
// DG: check for GRAB_ENABLE instead of GRAB_HIDECURSOR because we always wanna hide it
SDL_SetRelativeMouseMode( flags & GRAB_ENABLE ? SDL_TRUE : SDL_FALSE );
SDL_SetWindowGrab( window, grab ? SDL_TRUE : SDL_FALSE );
#else
SDL_ShowCursor( flags & GRAB_HIDECURSOR ? SDL_DISABLE : SDL_ENABLE );
// DG end
SDL_WM_GrabInput( grab ? SDL_GRAB_ON : SDL_GRAB_OFF );
#endif
}