vgui: remove unneeded SDL calls, remove unused VGUI API function, fix mouse cursor visibility

This commit is contained in:
Alibek Omarov 2022-01-04 08:13:57 +03:00 committed by a1batross
parent 7e687b45bb
commit f63d2d747f
3 changed files with 14 additions and 41 deletions

View File

@ -83,14 +83,13 @@ void VGUI_InitCursors( void )
s_pDefaultCursor[dc_sizeall] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEALL); s_pDefaultCursor[dc_sizeall] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEALL);
s_pDefaultCursor[dc_no] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NO); s_pDefaultCursor[dc_no] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NO);
s_pDefaultCursor[dc_hand] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND); s_pDefaultCursor[dc_hand] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND);
//host.mouse_visible = true;
SDL_SetCursor( s_pDefaultCursor[dc_arrow] );
#endif #endif
} }
void GAME_EXPORT VGUI_CursorSelect(enum VGUI_DefaultCursor cursor ) void GAME_EXPORT VGUI_CursorSelect( enum VGUI_DefaultCursor cursor )
{ {
qboolean visible; qboolean visible;
if( cls.key_dest != key_game || cl.paused ) if( cls.key_dest != key_game || cl.paused )
return; return;
@ -101,35 +100,30 @@ void GAME_EXPORT VGUI_CursorSelect(enum VGUI_DefaultCursor cursor )
visible = false; visible = false;
break; break;
default: default:
visible = true; visible = true;
break; break;
} }
host.mouse_visible = visible;
#if SDL_VERSION_ATLEAST( 2, 0, 0 ) #if SDL_VERSION_ATLEAST( 2, 0, 0 )
/// TODO: platform cursors /// TODO: platform cursors
if( CVAR_TO_BOOL( touch_emulate ) ) if( CVAR_TO_BOOL( touch_emulate ) )
return; return;
if( host.mouse_visible ) if( host.mouse_visible )
{ {
SDL_SetRelativeMouseMode( SDL_FALSE );
SDL_SetCursor( s_pDefaultCursor[cursor] ); SDL_SetCursor( s_pDefaultCursor[cursor] );
SDL_ShowCursor( true ); SDL_ShowCursor( true );
} }
else else
{ {
SDL_ShowCursor( false ); SDL_ShowCursor( false );
if( host.mouse_visible )
SDL_GetRelativeMouseState( NULL, NULL );
Key_EnableTextInput( false, true ); Key_EnableTextInput( false, true );
} }
//SDL_SetRelativeMouseMode(false);
#endif #endif
if( s_currentCursor == cursor )
return;
s_currentCursor = cursor; s_currentCursor = cursor;
host.mouse_visible = visible;
} }
byte GAME_EXPORT VGUI_GetColor( int i, int j) byte GAME_EXPORT VGUI_GetColor( int i, int j)
@ -138,18 +132,6 @@ byte GAME_EXPORT VGUI_GetColor( int i, int j)
} }
// Define and initialize vgui API // Define and initialize vgui API
void GAME_EXPORT VGUI_SetVisible( qboolean state )
{
host.mouse_visible=state;
#ifdef XASH_SDL
SDL_ShowCursor( state );
if( !state )
SDL_GetRelativeMouseState( NULL, NULL );
#endif
Key_EnableTextInput( false, true );
}
int GAME_EXPORT VGUI_UtfProcessChar( int in ) int GAME_EXPORT VGUI_UtfProcessChar( int in )
{ {
if( CVAR_TO_BOOL( vgui_utf8 ) ) if( CVAR_TO_BOOL( vgui_utf8 ) )
@ -175,12 +157,10 @@ vguiapi_t vgui =
NULL, // VGUI_GetTextureSizes, NULL, // VGUI_GetTextureSizes,
NULL, // VGUI_GenerateTexture, NULL, // VGUI_GenerateTexture,
VGUI_EngineMalloc, VGUI_EngineMalloc,
/* VGUI_ShowCursor,
VGUI_HideCursor,*/
VGUI_CursorSelect, VGUI_CursorSelect,
VGUI_GetColor, VGUI_GetColor,
VGUI_IsInGame, VGUI_IsInGame,
VGUI_SetVisible, NULL,
VGUI_GetMousePos, VGUI_GetMousePos,
VGUI_UtfProcessChar, VGUI_UtfProcessChar,
NULL, NULL,

View File

@ -176,11 +176,6 @@ enum VGUI_DefaultCursor
dc_last dc_last
}; };
typedef struct vguiapi_s typedef struct vguiapi_s
{ {
qboolean initialized; qboolean initialized;
@ -201,7 +196,7 @@ typedef struct vguiapi_s
void (*CursorSelect)( enum VGUI_DefaultCursor cursor ); void (*CursorSelect)( enum VGUI_DefaultCursor cursor );
byte (*GetColor)( int i, int j ); byte (*GetColor)( int i, int j );
qboolean (*IsInGame)( void ); qboolean (*IsInGame)( void );
void (*SetVisible)( qboolean state ); void (*Unused)( void );
void (*GetCursorPos)( int *x, int *y ); void (*GetCursorPos)( int *x, int *y );
int (*ProcessUtfChar)( int ch ); int (*ProcessUtfChar)( int ch );
void (*Startup)( int width, int height ); void (*Startup)( int width, int height );

View File

@ -92,7 +92,11 @@ bool CEngineSurface :: hasFocus( void )
void CEngineSurface :: setCursor( Cursor *cursor ) void CEngineSurface :: setCursor( Cursor *cursor )
{ {
_currentCursor = cursor; _currentCursor = cursor;
g_api->CursorSelect( (VGUI_DefaultCursor)cursor->getDefaultCursor() );
if( cursor )
{
g_api->CursorSelect( (VGUI_DefaultCursor)cursor->getDefaultCursor() );
}
} }
void CEngineSurface :: SetupPaintState( const PaintStack *paintState ) void CEngineSurface :: SetupPaintState( const PaintStack *paintState )
@ -428,15 +432,9 @@ void CEngineSurface :: popMakeCurrent( Panel *panel )
bool CEngineSurface :: setFullscreenMode( int wide, int tall, int bpp ) bool CEngineSurface :: setFullscreenMode( int wide, int tall, int bpp )
{ {
// NOTE: Xash3D always working in 32-bit mode
// Skip it now. VGUI cannot change video modes
return false; return false;
} }
void CEngineSurface :: setWindowedMode( void ) void CEngineSurface :: setWindowedMode( void )
{ {
// Skip it now. VGUI cannot change video modes
/*
Cvar_SetFloat( "fullscreen", 0.0f );
*/
} }