Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Clean up cursor activation
  • Loading branch information
mbasaglia committed Oct 21, 2015
1 parent 2a60d01 commit e7319a1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 46 deletions.
11 changes: 2 additions & 9 deletions daemon/src/engine/client/cl_input.cpp
Expand Up @@ -1447,14 +1447,7 @@ void IN_SetCursorMode(bool cursor)
if ( cursor != cursor_mode )
{
cursor_mode = cursor;
if ( cursor_mode )
{
IN_ActivateCursor();
IN_CenterMouse();
}
else
{
IN_DeactivateCursor();
}
IN_SetCursorActive( cursor_mode );
IN_CenterMouse();
}
}
6 changes: 1 addition & 5 deletions daemon/src/engine/null/null_input.cpp
Expand Up @@ -75,10 +75,6 @@ bool IN_IsNumLockDown()
return false;
}

void IN_ActivateCursor()
{
}

void IN_DeactivateCursor()
void IN_SetCursorActive( bool )
{
}
3 changes: 1 addition & 2 deletions daemon/src/engine/qcommon/qcommon.h
Expand Up @@ -558,8 +558,7 @@ void IN_Shutdown();
bool IN_IsNumLockDown();
void IN_DropInputsForFrame();
void IN_CenterMouse();
void IN_ActivateCursor();
void IN_DeactivateCursor();
void IN_SetCursorActive( bool active );

/*
==============================================================
Expand Down
58 changes: 28 additions & 30 deletions daemon/src/engine/sys/sdl_input.cpp
Expand Up @@ -566,44 +566,47 @@ static keyNum_t IN_TranslateSDLToQ3Key( SDL_Keysym *keysym, bool down )
return key;
}

/*
* When this is true, the cursor is free to move and cgame will receive
* mouse coordinates.
* When this is false, the cursor will be locked in the window and cgame
* will receive deltas
*/
static bool cursor_active = true;

void IN_ActivateCursor()
{
if ( !mouseAvailable || !SDL_WasInit( SDL_INIT_VIDEO ) )
{
return;
}

SDL_ShowCursor( 1 );
SDL_SetRelativeMouseMode( SDL_FALSE );
SDL_SetWindowGrab( window, SDL_FALSE );

cursor_active = true;

}

void IN_DeactivateCursor()
/*
* Activates the cursor, the system cursor will still be disabled and
* the game is responsible of drawing the cursor image
*/
void IN_SetCursorActive( bool active )
{
if ( !mouseAvailable || !SDL_WasInit( SDL_INIT_VIDEO ) )
{
return;
}

SDL_ShowCursor( 0 );
SDL_SetRelativeMouseMode( SDL_TRUE );
SDL_SetWindowGrab( window, SDL_FALSE );
SDL_ShowCursor( SDL_DISABLE );
auto grab = active || in_nograb->integer ? SDL_FALSE : SDL_TRUE;
SDL_SetRelativeMouseMode( grab );
SDL_SetWindowGrab( window, grab );

cursor_active = false;
cursor_active = active;
}

/*
* Moves the mouse at the center of the window
*/
void IN_CenterMouse()
{
int w, h;
SDL_GetWindowSize( window, &w, &h );
SDL_WarpMouseInWindow( window, w / 2, h / 2 );
}

/*
* Toggles forced cursor, this ensure that the cursor is active and visible
* even when not in cursor mode
*/
static void ForceCursor(bool force)
{
static bool forced_cursor = false;
Expand All @@ -617,14 +620,8 @@ static void ForceCursor(bool force)

if ( !IN_GetCursorMode() )
{
if ( forced_cursor )
{
IN_ActivateCursor();
}
else
{
IN_DeactivateCursor();
}
IN_SetCursorActive( forced_cursor );
SDL_ShowCursor( forced_cursor );
}

}
Expand Down Expand Up @@ -1599,7 +1596,8 @@ void IN_Init( void *windowData )
in_xbox360ControllerDebug = Cvar_Get( "in_xbox360ControllerDebug", "0", CVAR_TEMP );
SDL_StartTextInput();
mouseAvailable = ( in_mouse->value != 0 );
IN_ActivateCursor();
ForceCursor( false );
IN_SetCursorActive( true );

appState = SDL_GetWindowFlags( window );
Cvar_SetValue( "com_unfocused", !( appState & SDL_WINDOW_INPUT_FOCUS ) );
Expand All @@ -1616,7 +1614,7 @@ IN_Shutdown
void IN_Shutdown()
{
SDL_StopTextInput();
IN_SetCursorMode(true);
ForceCursor(true);
mouseAvailable = false;

IN_ShutdownJoystick();
Expand Down

0 comments on commit e7319a1

Please sign in to comment.