Skip to content

Commit

Permalink
Refactoring: use single CL_CharEvent, instead of direct call of CharE…
Browse files Browse the repository at this point in the history
…vent-s of different subsystems. Fixes #259
  • Loading branch information
a1batross committed Feb 27, 2018
1 parent 1f71a58 commit 624ee47
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
14 changes: 9 additions & 5 deletions engine/client/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ CL_CharEvent
Normal keyboard characters, already shifted / capslocked / etc
===================
*/
void CL_CharEvent( int key )
void CL_CharEvent( int ch )
{
// the console key should never be used as a char
#ifdef _WIN32
Expand All @@ -861,13 +861,17 @@ void CL_CharEvent( int key )
#endif
#endif
// distribute the key down event to the apropriate handler
if( cls.key_dest == key_console || cls.key_dest == key_message )

Con_CharEvent( ch ); // a1ba: no need for checks, as Con_CharEvent already it does

if( cls.key_dest == key_menu )
{
Con_CharEvent( key );
UI_CharEvent( ch );
}
else if( cls.key_dest == key_menu )
else if( cls.key_dest == key_game ) // typing support for VGUI
{
UI_CharEvent( key );
VGui_KeyEvent( ch, 2 );
}

}
#endif
2 changes: 1 addition & 1 deletion engine/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ qboolean CL_IsIntermission( void );
void CL_WarnLostSplitPacket( void );
float CL_GetServerTime( void );
float CL_GetLerpFrac( void );
void CL_CharEvent( int key );
void CL_CharEvent( int ch );
qboolean CL_DisableVisibility( void );
int CL_PointContents( const vec3_t point );
char *COM_ParseFile( char *data, char *token );
Expand Down
4 changes: 1 addition & 3 deletions engine/platform/android/android_nosdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,7 @@ void Android_RunEvents()
}

// otherwise just push it by char, text render will decode unicode strings
Con_CharEvent( ch );
if( cls.key_dest == key_menu )
UI_CharEvent ( ch );
CL_CharEvent( ch );
}
events.inputtext[0] = 0; // no more text

Expand Down
37 changes: 20 additions & 17 deletions engine/platform/sdl/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ static SDL_Joystick *joy;
static SDL_GameController *gamecontroller;

void R_ChangeDisplaySettingsFast( int w, int h );
void SDLash_SendCharEvent( int ch );

#define DECLARE_KEY_RANGE( min, max, repl ) if( keynum >= (min) && keynum <= (max) ) { keynum = keynum - (min) + (repl); }

void SDLash_KeyEvent( SDL_KeyboardEvent key, int down )
{
Expand All @@ -49,16 +47,24 @@ void SDLash_KeyEvent( SDL_KeyboardEvent key, int down )
if( keynum >= SDL_SCANCODE_A && keynum <= SDL_SCANCODE_Z )
{
keynum = keynum - SDL_SCANCODE_A + 1;
SDLash_SendCharEvent( keynum );
CL_CharEvent( keynum );
}

return;
}
}

#define DECLARE_KEY_RANGE( min, max, repl ) \
if( keynum >= (min) && keynum <= (max) ) \
{ \
keynum = keynum - (min) + (repl); \
}

DECLARE_KEY_RANGE( SDL_SCANCODE_A, SDL_SCANCODE_Z, 'a' )
else DECLARE_KEY_RANGE( SDL_SCANCODE_1, SDL_SCANCODE_9, '1' )
else DECLARE_KEY_RANGE( SDL_SCANCODE_F1, SDL_SCANCODE_F12, K_F1 )

#undef DECLARE_KEY_RANGE
else
{
switch( keynum )
Expand Down Expand Up @@ -123,6 +129,13 @@ void SDLash_KeyEvent( SDL_KeyboardEvent key, int down )
host.force_draw_version_time = host.realtime + FORCE_DRAW_VERSION_TIME;
break;
}
// don't console spam on known functional buttons, but not used in engine
case SDL_SCANCODE_MUTE:
case SDL_SCANCODE_VOLUMEUP:
case SDL_SCANCODE_VOLUMEDOWN:
case SDL_SCANCODE_BRIGHTNESSDOWN:
case SDL_SCANCODE_BRIGHTNESSUP:
break;
case SDL_SCANCODE_UNKNOWN:
{
if( down ) MsgDev( D_INFO, "SDLash_KeyEvent: Unknown scancode\n" );
Expand All @@ -137,7 +150,7 @@ void SDLash_KeyEvent( SDL_KeyboardEvent key, int down )
Key_Event( keynum, down );
}

void SDLash_MouseEvent(SDL_MouseButtonEvent button)
void SDLash_MouseEvent( SDL_MouseButtonEvent button )
{
int down = button.type == SDL_MOUSEBUTTONDOWN ? 1 : 0;
if( in_mouseinitialized && !m_ignore->integer && button.which != SDL_TOUCH_MOUSEID )
Expand All @@ -146,13 +159,13 @@ void SDLash_MouseEvent(SDL_MouseButtonEvent button)
}
}

void SDLash_WheelEvent(SDL_MouseWheelEvent wheel)
void SDLash_WheelEvent( SDL_MouseWheelEvent wheel )
{
wheelbutton = wheel.y < 0 ? K_MWHEELDOWN : K_MWHEELUP;
Key_Event( wheelbutton, true );
}

void SDLash_InputEvent(SDL_TextInputEvent input)
void SDLash_InputEvent( SDL_TextInputEvent input )
{
int i;

Expand All @@ -169,19 +182,10 @@ void SDLash_InputEvent(SDL_TextInputEvent input)
if( !ch )
continue;

SDLash_SendCharEvent( ch );
CL_CharEvent( ch );
}
}

void SDLash_SendCharEvent( int ch )
{
Con_CharEvent( ch );
if( cls.key_dest == key_menu )
UI_CharEvent ( ch );
if( cls.key_dest == key_game )
VGui_KeyEvent( ch, 2 );
}

void SDLash_EnableTextInput( int enable, qboolean force )
{
if( force )
Expand Down Expand Up @@ -383,7 +387,6 @@ void SDLash_EventFilter( void *ev )
};

// TODO: Use joyinput funcs, for future multiple gamepads support

if( Joy_IsActive() )
Key_Event( sdlControllerButtonToEngine[event->cbutton.button], event->cbutton.state );
break;
Expand Down

0 comments on commit 624ee47

Please sign in to comment.