Browse Source

engine: client: extended VGUI API interface

pull/2/head
SNMetamorph 3 years ago committed by a1batross
parent
commit
cfcd58dd78
  1. 93
      engine/client/vgui/vgui_draw.c
  2. 1
      engine/client/vgui/vgui_draw.h
  3. 32
      engine/cursor_type.h
  4. 2
      engine/platform/platform.h
  5. 1
      engine/platform/sdl/events.c
  6. 35
      engine/platform/sdl/in_sdl.c
  7. 33
      engine/vgui_api.h

93
engine/client/vgui/vgui_draw.c

@ -21,10 +21,6 @@ GNU General Public License for more details.
#include "keydefs.h" #include "keydefs.h"
#include "ref_common.h" #include "ref_common.h"
#include "input.h" #include "input.h"
#ifdef XASH_SDL
#include <SDL.h>
static SDL_Cursor* s_pDefaultCursor[20];
#endif
#include "platform/platform.h" #include "platform/platform.h"
static enum VGUI_KeyCode s_pVirtualKeyTrans[256]; static enum VGUI_KeyCode s_pVirtualKeyTrans[256];
@ -32,20 +28,6 @@ static enum VGUI_DefaultCursor s_currentCursor;
static HINSTANCE s_pVGuiSupport; // vgui_support library static HINSTANCE s_pVGuiSupport; // vgui_support library
static convar_t *vgui_utf8 = NULL; static convar_t *vgui_utf8 = NULL;
// Helper functions for vgui backend
/*void VGUI_HideCursor( void )
{
host.mouse_visible = false;
SDL_HideCursor();
}
void VGUI_ShowCursor( void )
{
host.mouse_visible = true;
SDL_ShowCursor();
}*/
void GAME_EXPORT *VGUI_EngineMalloc(size_t size) void GAME_EXPORT *VGUI_EngineMalloc(size_t size)
{ {
return Z_Malloc( size ); return Z_Malloc( size );
@ -66,63 +48,9 @@ void GAME_EXPORT VGUI_GetMousePos( int *_x, int *_y )
*_x = x / xscale, *_y = y / yscale; *_x = x / xscale, *_y = y / yscale;
} }
void VGUI_InitCursors( void )
{
// load up all default cursors
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
s_pDefaultCursor[dc_none] = NULL;
s_pDefaultCursor[dc_arrow] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
s_pDefaultCursor[dc_ibeam] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_IBEAM);
s_pDefaultCursor[dc_hourglass]= SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_WAIT);
s_pDefaultCursor[dc_crosshair]= SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_CROSSHAIR);
s_pDefaultCursor[dc_up] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
s_pDefaultCursor[dc_sizenwse] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENWSE);
s_pDefaultCursor[dc_sizenesw] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENESW);
s_pDefaultCursor[dc_sizewe] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEWE);
s_pDefaultCursor[dc_sizens] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENS);
s_pDefaultCursor[dc_sizeall] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEALL);
s_pDefaultCursor[dc_no] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NO);
s_pDefaultCursor[dc_hand] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND);
#endif
}
void GAME_EXPORT VGUI_CursorSelect( enum VGUI_DefaultCursor cursor ) void GAME_EXPORT VGUI_CursorSelect( enum VGUI_DefaultCursor cursor )
{ {
qboolean visible; Platform_SetCursorType( cursor );
if( cls.key_dest != key_game || cl.paused )
return;
switch( cursor )
{
case dc_user:
case dc_none:
visible = false;
break;
default:
visible = true;
break;
}
host.mouse_visible = visible;
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
/// TODO: platform cursors
if( CVAR_TO_BOOL( touch_emulate ) )
return;
if( host.mouse_visible )
{
SDL_SetCursor( s_pDefaultCursor[cursor] );
SDL_ShowCursor( true );
}
else
{
SDL_ShowCursor( false );
Key_EnableTextInput( false, true );
}
#endif
s_currentCursor = cursor; s_currentCursor = cursor;
} }
@ -134,7 +62,7 @@ byte GAME_EXPORT VGUI_GetColor( int i, int j)
// Define and initialize vgui API // Define and initialize vgui API
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 ))
return Con_UtfProcessCharForce( in ); return Con_UtfProcessCharForce( in );
else else
return in; return in;
@ -163,6 +91,9 @@ vguiapi_t vgui =
NULL, NULL,
VGUI_GetMousePos, VGUI_GetMousePos,
VGUI_UtfProcessChar, VGUI_UtfProcessChar,
Platform_GetClipboardText,
Platform_SetClipboardText,
Platform_GetKeyModifiers,
NULL, NULL,
NULL, NULL,
NULL, NULL,
@ -170,6 +101,7 @@ vguiapi_t vgui =
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL
}; };
qboolean VGui_IsActive( void ) qboolean VGui_IsActive( void )
@ -478,8 +410,9 @@ void VGui_KeyEvent( int key, int down )
switch( key ) switch( key )
{ {
case K_MOUSE1: case K_MOUSE1:
if( down && host.mouse_visible ) if( down && host.mouse_visible ) {
Key_EnableTextInput( true, false ); Key_EnableTextInput(true, false);
}
vgui.Mouse( down ? MA_PRESSED : MA_RELEASED, MOUSE_LEFT ); vgui.Mouse( down ? MA_PRESSED : MA_RELEASED, MOUSE_LEFT );
return; return;
case K_MOUSE2: case K_MOUSE2:
@ -515,7 +448,7 @@ void VGui_MouseMove( int x, int y )
void VGui_Paint( void ) void VGui_Paint( void )
{ {
if(vgui.initialized) if( vgui.initialized )
vgui.Paint(); vgui.Paint();
} }
@ -531,3 +464,9 @@ void *GAME_EXPORT VGui_GetPanel( void )
return vgui.GetPanel(); return vgui.GetPanel();
return NULL; return NULL;
} }
void VGui_ReportTextInput( const char *text )
{
if ( vgui.initialized )
vgui.TextInput( text );
}

1
engine/client/vgui/vgui_draw.h

@ -33,6 +33,7 @@ void VGui_KeyEvent( int key, int down );
void VGui_MouseMove( int x, int y ); void VGui_MouseMove( int x, int y );
qboolean VGui_IsActive( void ); qboolean VGui_IsActive( void );
void *VGui_GetPanel( void ); void *VGui_GetPanel( void );
void VGui_ReportTextInput( const char *text );
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

32
engine/cursor_type.h

@ -19,21 +19,21 @@ GNU General Public License for more details.
typedef enum typedef enum
{ {
CursorType_User, dc_user,
CursorType_None, dc_none,
CursorType_Arrow, dc_arrow,
CursorType_Ibeam, dc_ibeam,
CursorType_Wait, dc_hourglass,
CursorType_Crosshair, dc_crosshair,
CursorType_Up, dc_up,
CursorType_SizeNwSe, dc_sizenwse,
CursorType_SizeNeSw, dc_sizenesw,
CursorType_SizeWe, dc_sizewe,
CursorType_SizeNs, dc_sizens,
CursorType_SizeAll, dc_sizeall,
CursorType_No, dc_no,
CursorType_Hand, dc_hand,
CursorType_Last dc_last
} cursor_type_t; } VGUI_DefaultCursor;
#endif #endif

2
engine/platform/platform.h

@ -82,7 +82,7 @@ void Platform_GetMousePos( int *x, int *y );
void Platform_SetMousePos( int x, int y ); void Platform_SetMousePos( int x, int y );
void Platform_PreCreateMove( void ); void Platform_PreCreateMove( void );
void Platform_MouseMove( float *x, float *y ); void Platform_MouseMove( float *x, float *y );
void Platform_SetCursorType( cursor_type_t type ); void Platform_SetCursorType( VGUI_DefaultCursor type );
// Clipboard // Clipboard
int Platform_GetClipboardText( char *buffer, size_t size ); int Platform_GetClipboardText( char *buffer, size_t size );
void Platform_SetClipboardText( const char *buffer ); void Platform_SetClipboardText( const char *buffer );

1
engine/platform/sdl/events.c

@ -318,6 +318,7 @@ SDLash_InputEvent
static void SDLash_InputEvent( SDL_TextInputEvent input ) static void SDLash_InputEvent( SDL_TextInputEvent input )
{ {
char *text; char *text;
VGui_ReportTextInput( input.text );
for( text = input.text; *text; text++ ) for( text = input.text; *text; text++ )
{ {
int ch; int ch;

35
engine/platform/sdl/in_sdl.c

@ -25,9 +25,10 @@ GNU General Public License for more details.
#include "vid_common.h" #include "vid_common.h"
SDL_Joystick *g_joy = NULL; SDL_Joystick *g_joy = NULL;
static SDL_Cursor *g_pDefaultCursor[CursorType_Last];
#if !SDL_VERSION_ATLEAST( 2, 0, 0 ) #if !SDL_VERSION_ATLEAST( 2, 0, 0 )
#define SDL_WarpMouseInWindow( win, x, y ) SDL_WarpMouse( ( x ), ( y ) ) #define SDL_WarpMouseInWindow( win, x, y ) SDL_WarpMouse( ( x ), ( y ) )
#else
static SDL_Cursor *g_pDefaultCursor[dc_last];
#endif #endif
/* /*
@ -260,19 +261,19 @@ static void SDLash_InitCursors( void )
{ {
// load up all default cursors // load up all default cursors
#if SDL_VERSION_ATLEAST( 2, 0, 0 ) #if SDL_VERSION_ATLEAST( 2, 0, 0 )
g_pDefaultCursor[CursorType_None] = NULL; g_pDefaultCursor[dc_none] = NULL;
g_pDefaultCursor[CursorType_Arrow] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW); g_pDefaultCursor[dc_arrow] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
g_pDefaultCursor[CursorType_Ibeam] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_IBEAM); g_pDefaultCursor[dc_ibeam] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_IBEAM);
g_pDefaultCursor[CursorType_Wait] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_WAIT); g_pDefaultCursor[dc_hourglass] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_WAIT);
g_pDefaultCursor[CursorType_Crosshair] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_CROSSHAIR); g_pDefaultCursor[dc_crosshair] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_CROSSHAIR);
g_pDefaultCursor[CursorType_Up] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW); g_pDefaultCursor[dc_up] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
g_pDefaultCursor[CursorType_SizeNwSe] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENWSE); g_pDefaultCursor[dc_sizenwse] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENWSE);
g_pDefaultCursor[CursorType_SizeNeSw] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENESW); g_pDefaultCursor[dc_sizenesw] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENESW);
g_pDefaultCursor[CursorType_SizeWe] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEWE); g_pDefaultCursor[dc_sizewe] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEWE);
g_pDefaultCursor[CursorType_SizeNs] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENS); g_pDefaultCursor[dc_sizens] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENS);
g_pDefaultCursor[CursorType_SizeAll] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEALL); g_pDefaultCursor[dc_sizeall] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEALL);
g_pDefaultCursor[CursorType_No] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NO); g_pDefaultCursor[dc_no] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NO);
g_pDefaultCursor[CursorType_Hand] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND); g_pDefaultCursor[dc_hand] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND);
#endif #endif
initialized = true; initialized = true;
} }
@ -284,7 +285,7 @@ Platform_SetCursorType
======================== ========================
*/ */
void Platform_SetCursorType( cursor_type_t type ) void Platform_SetCursorType( VGUI_DefaultCursor type )
{ {
qboolean visible; qboolean visible;
@ -295,8 +296,8 @@ void Platform_SetCursorType( cursor_type_t type )
switch( type ) switch( type )
{ {
case CursorType_User: case dc_user:
case CursorType_None: case dc_none:
visible = false; visible = false;
break; break;
default: default:

33
engine/vgui_api.h

@ -16,6 +16,8 @@ GNU General Public License for more details.
#define VGUI_API_H #define VGUI_API_H
#include "xash3d_types.h" #include "xash3d_types.h"
#include "key_modifiers.h"
#include "cursor_type.h"
// VGUI generic vertex // VGUI generic vertex
@ -157,28 +159,10 @@ enum VGUI_MouseAction
MA_WHEEL MA_WHEEL
}; };
enum VGUI_DefaultCursor
{
dc_user,
dc_none,
dc_arrow,
dc_ibeam,
dc_hourglass,
dc_crosshair,
dc_up,
dc_sizenwse,
dc_sizenesw,
dc_sizewe,
dc_sizens,
dc_sizeall,
dc_no,
dc_hand,
dc_last
};
typedef struct vguiapi_s typedef struct vguiapi_s
{ {
qboolean initialized; qboolean initialized;
// called from vgui_support
void (*DrawInit)( void ); void (*DrawInit)( void );
void (*DrawShutdown)( void ); void (*DrawShutdown)( void );
void (*SetupDrawingText)( int *pColor ); void (*SetupDrawingText)( int *pColor );
@ -193,18 +177,23 @@ typedef struct vguiapi_s
void (*GetTextureSizes)( int *width, int *height ); void (*GetTextureSizes)( int *width, int *height );
int (*GenerateTexture)( void ); int (*GenerateTexture)( void );
void *(*EngineMalloc)( size_t size ); void *(*EngineMalloc)( size_t size );
void (*CursorSelect)( enum VGUI_DefaultCursor cursor ); void (*CursorSelect)( VGUI_DefaultCursor cursor );
byte (*GetColor)( int i, int j ); byte (*GetColor)( int i, int j );
qboolean (*IsInGame)( void ); qboolean (*IsInGame)( void );
void (*Unused)( void ); void (*Unused)( void );
void (*GetCursorPos)( int *x, int *y ); void (*GetCursorPos)( int *x, int *y );
int (*ProcessUtfChar)( int ch ); int (*ProcessUtfChar)( int ch );
int (*GetClipboardText)( char *buffer, size_t bufferSize );
void (*SetClipboardText)( const char *text );
key_modifier_t (*GetKeyModifiers)( void );
// called from engine side
void (*Startup)( int width, int height ); void (*Startup)( int width, int height );
void (*Shutdown)( void ); void (*Shutdown)( void );
void *(*GetPanel)( void ); void *(*GetPanel)( void );
void (*Paint)( void ); void (*Paint)( void );
void (*Mouse)(enum VGUI_MouseAction action, int code ); void (*Mouse)( enum VGUI_MouseAction action, int code );
void (*Key)(enum VGUI_KeyAction action,enum VGUI_KeyCode code ); void (*Key)( enum VGUI_KeyAction action, enum VGUI_KeyCode code );
void (*MouseMove)( int x, int y ); void (*MouseMove)( int x, int y );
void (*TextInput)( const char *text );
} vguiapi_t; } vguiapi_t;
#endif // VGUI_API_H #endif // VGUI_API_H

Loading…
Cancel
Save