diff options
author | Andrey Nazarov <skuller@skuller.net> | 2007-12-14 23:30:31 +0000 |
---|---|---|
committer | Andrey Nazarov <skuller@skuller.net> | 2007-12-14 23:30:31 +0000 |
commit | a21868632c585f33742f7e295aafad36a436cdd9 (patch) | |
tree | 91d01192835662109845c2f9fd4d840d842e2b47 | |
parent | 0ec5f1b7a5689865d6cd10daa17883201766dc6a (diff) |
Distinguish left and right SHIFT, CTRL, ALT modifiers.
Take SHIFT modifier into account when executing key bindings.
Added `text' command which just stuffs its arguments into the
command buffer for further macro expansion.
Made sure $$ escaping works.
-rw-r--r-- | source/cl_console.c | 76 | ||||
-rw-r--r-- | source/cl_input.c | 1 | ||||
-rw-r--r-- | source/cl_keys.c | 48 | ||||
-rw-r--r-- | source/cl_local.h | 4 | ||||
-rw-r--r-- | source/cl_ref.c | 1 | ||||
-rw-r--r-- | source/cmd.c | 37 | ||||
-rw-r--r-- | source/common.c | 5 | ||||
-rw-r--r-- | source/key_public.h | 7 | ||||
-rw-r--r-- | source/vid_sdl.c | 23 |
9 files changed, 134 insertions, 68 deletions
diff --git a/source/cl_console.c b/source/cl_console.c index 478a37a..f138a7f 100644 --- a/source/cl_console.c +++ b/source/cl_console.c @@ -28,11 +28,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define CON_TOTALLINES 1024 // total lines in console scrollback #define CON_TOTALLINES_MASK ( CON_TOTALLINES - 1 ) -/* max chars in a single line. - * this should be large enough to hold (maxscreenwidth / charwidth) chars, - * plus some extra color escape codes - */ -#define CON_LINEWIDTH 512 +#define CON_LINEWIDTH 100 // fixed width, do not need more typedef struct console_s { qboolean initialized; @@ -138,10 +134,25 @@ void Con_ToggleConsole_f( void ) { Con_ToggleChat_f ================ */ -void Con_ToggleChat_f( void ) { +static void Con_ToggleChat_f( void ) { Con_ToggleConsole_f(); if( ( cls.key_dest & KEY_CONSOLE ) && cls.state == ca_active ) { + con.chatTeam = qfalse; + con.chatMode = qtrue; + } +} + +/* +================ +Con_ToggleChat2_f +================ +*/ +static void Con_ToggleChat2_f( void ) { + Con_ToggleConsole_f(); + + if( ( cls.key_dest & KEY_CONSOLE ) && cls.state == ca_active ) { + con.chatTeam = qtrue; con.chatMode = qtrue; } } @@ -151,7 +162,7 @@ void Con_ToggleChat_f( void ) { Con_Clear_f ================ */ -void Con_Clear_f( void ) { +static void Con_Clear_f( void ) { memset( con.text, 0, sizeof( con.text ) ); con.display = con.current; } @@ -167,7 +178,7 @@ Con_Dump_f Save the console contents out to a file ================ */ -void Con_Dump_f( void ) { +static void Con_Dump_f( void ) { int l; char *line; fileHandle_t f; @@ -227,7 +238,7 @@ void Con_ClearNotify_f( void ) { Con_MessageMode_f ================ */ -void Con_MessageMode_f( void ) { +static void Con_MessageMode_f( void ) { con.chatTeam = qfalse; if( Cmd_Argc() > 1 ) { IF_Replace( &con.chatPrompt.inputLine, Cmd_RawArgs() ); @@ -240,7 +251,7 @@ void Con_MessageMode_f( void ) { Con_MessageMode2_f ================ */ -void Con_MessageMode2_f( void ) { +static void Con_MessageMode2_f( void ) { con.chatTeam = qtrue; if( Cmd_Argc() > 1 ) { IF_Replace( &con.chatPrompt.inputLine, Cmd_RawArgs() ); @@ -255,7 +266,7 @@ Con_CheckResize If the line width has changed, reformat the buffer. ================ */ -void Con_CheckResize( void ) { +static void Con_CheckResize( void ) { int width; con.vidWidth = scr_glconfig.vidWidth * con.scale; @@ -272,6 +283,23 @@ void Con_CheckResize( void ) { con.chatPrompt.inputLine.visibleChars = con.linewidth; } +/* +================ +Con_CheckTop + +Make sure at least one line is visible if console is backscrolled. +================ +*/ +static void Con_CheckTop( void ) { + int top = con.current - CON_TOTALLINES + 1; + + if( top < 1 ) { + top = 1; + } + if( con.display < top ) { + con.display = top; + } +} static void con_param_changed( cvar_t *self ) { if( con.initialized && cls.ref_initialized ) { @@ -282,6 +310,7 @@ static void con_param_changed( cvar_t *self ) { static const cmdreg_t c_console[] = { { "toggleconsole", Con_ToggleConsole_f }, { "togglechat", Con_ToggleChat_f }, + { "togglechat2", Con_ToggleChat2_f }, { "messagemode", Con_MessageMode_f }, { "messagemode2", Con_MessageMode2_f }, { "clear", Con_Clear_f }, @@ -352,7 +381,6 @@ void Con_Shutdown( void ) { Prompt_Clear( &con.prompt ); } - /* =============== Con_Linefeed @@ -369,6 +397,8 @@ void Con_Linefeed( void ) { if( con_scroll->integer & 2 ) { con.display = con.current; + } else { + Con_CheckTop(); } } @@ -830,6 +860,12 @@ void Con_DrawConsole( void ) { ============================================================================== */ +static void Con_Say( char *msg ) { + Cbuf_AddText( con.chatTeam ? "say_team \"" : "say \"" ); + Cbuf_AddText( msg ); + Cbuf_AddText( "\"\n" ); +} + static void Con_Action( void ) { char *cmd = Prompt_Action( &con.prompt ); @@ -841,14 +877,15 @@ static void Con_Action( void ) { // backslash text are commands, else chat if( cmd[0] == '\\' || cmd[0] == '/' ) { Cbuf_AddText( cmd + 1 ); // skip slash + Cbuf_AddText( "\n" ); } else { if( cls.state == ca_active && con.chatMode ) { - Cbuf_AddText( va( "cmd say \"%s\"", cmd ) ); + Con_Say( cmd ); } else { Cbuf_AddText( cmd ); + Cbuf_AddText( "\n" ); } } - Cbuf_AddText( "\n" ); Con_Printf( "]%s\n", cmd ); @@ -928,10 +965,7 @@ void Key_Console( int key ) { } else { con.display -= 2; } - - if( con.display < 1 ) { - con.display = 1; - } + Con_CheckTop(); return; } @@ -949,6 +983,7 @@ void Key_Console( int key ) { if( key == K_HOME && Key_IsDown( K_CTRL ) ) { con.display = 1; + Con_CheckTop(); return; } @@ -981,16 +1016,15 @@ void Key_Message( int key ) { } if( key == K_ENTER || key == K_KP_ENTER ) { - char *cmd; + char *cmd = Prompt_Action( &con.chatPrompt ); - if( ( cmd = Prompt_Action( &con.chatPrompt ) ) ) { + if( cmd ) { Cbuf_AddText( con.chatTeam ? "say_team \"" : "say \"" ); Cbuf_AddText( cmd ); Cbuf_AddText( "\"\n" ); } Key_SetDest( cls.key_dest & ~KEY_MESSAGE ); - //IF_Clear( &con.chatPrompt.inputField ); return; } diff --git a/source/cl_input.c b/source/cl_input.c index 237607c..b186c40 100644 --- a/source/cl_input.c +++ b/source/cl_input.c @@ -20,7 +20,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // cl.input.c -- builds an intended movement command to send to the server #include "cl_local.h" -#include "vid_public.h" #include "vid_local.h" static cvar_t *cl_nodelta; diff --git a/source/cl_keys.c b/source/cl_keys.c index e243fde..4546489 100644 --- a/source/cl_keys.c +++ b/source/cl_keys.c @@ -70,8 +70,14 @@ static keyname_t keynames[] = {"RIGHTARROW", K_RIGHTARROW}, {"ALT", K_ALT}, + {"LALT", K_LALT}, + {"RALT", K_RALT}, {"CTRL", K_CTRL}, + {"LCTRL", K_LCTRL}, + {"RCTRL", K_RCTRL}, {"SHIFT", K_SHIFT}, + {"LSHIFT", K_LSHIFT}, + {"RSHIFT", K_RSHIFT}, {"F1", K_F1}, {"F2", K_F2}, @@ -276,7 +282,7 @@ int Key_StringToKeynum( const char *str ) { if( !str[1] ) return str[0]; - for( kn=keynames ; kn->name ; kn++ ) { + for( kn = keynames; kn->name; kn++ ) { if( !Q_stricmp( str, kn->name ) ) return kn->keynum; } @@ -322,7 +328,7 @@ Returns the name of the first key found. char *Key_GetBinding( const char *binding ) { int key; - for( key=0 ; key<256 ; key++ ) { + for( key = 0; key < 256; key++ ) { if( keybindings[key] ) { if( !Q_stricmp( keybindings[key], binding ) ) { return Key_KeynumToString( key ); @@ -422,7 +428,7 @@ Key_Unbindall_f static void Key_Unbindall_f( void ) { int i; - for( i=0 ; i<256 ; i++ ) + for( i = 0; i < 256; i++ ) if( keybindings[i] ) Key_SetBinding( i, NULL ); } @@ -470,7 +476,7 @@ Writes lines containing "bind key value" void Key_WriteBindings( fileHandle_t f ) { int i; - for( i=0 ; i<256 ; i++ ) { + for( i = 0; i < 256; i++ ) { if( keybindings[i] && keybindings[i][0] ) { FS_FPrintf( f, "bind %s \"%s\"\n", Key_KeynumToString( i ), keybindings[i] ); @@ -488,7 +494,7 @@ Key_Bindlist_f static void Key_Bindlist_f( void ) { int i; - for( i=0 ; i<256 ; i++ ) { + for( i = 0; i < 256; i++ ) { if( keybindings[i] && keybindings[i][0] ) { Com_Printf( "%s \"%s\"\n", Key_KeynumToString( i ), keybindings[i] ); @@ -671,9 +677,11 @@ void Key_Event( uint32 key, qboolean down, uint32 time ) { // Alt+Enter is hardcoded for all systems if( keydown[K_ALT] && key == K_ENTER ) { if( down ) { - Cvar_SetInteger( "vid_fullscreen", - !Cvar_VariableInteger( "vid_fullscreen" ) ); - Cbuf_AddText( "vid_restart\n" ); + if( scr_glconfig.flags & QVF_FULLSCREEN ) { + Cbuf_AddText( "set vid_fullscreen 0\n" ); + } else { + Cbuf_AddText( "set vid_fullscreen 1\n" ); + } } return; } @@ -736,16 +744,19 @@ void Key_Event( uint32 key, qboolean down, uint32 time ) { anykeydown = 0; } +// +// if not a consolekey, send to the interpreter no matter what mode is +// if( ( cls.key_dest == KEY_GAME ) || ( ( cls.key_dest & KEY_CONSOLE ) && !consolekeys[key] ) || ( ( cls.key_dest & KEY_MENU ) && menubound[key] ) ) { // -// key up events only generate commands if the game key binding is +// Key up events only generate commands if the game key binding is // a button command (leading + sign). // Button commands include the kenum as a parameter, so multiple -// downs can be matched with ups +// downs can be matched with ups. // if( !down ) { kb = keybindings[key]; @@ -763,17 +774,20 @@ void Key_Event( uint32 key, qboolean down, uint32 time ) { Cbuf_InsertText( cmd ); } } -#endif +#endif // USE_CHAR_EVENTS return; } -// -// if not a consolekey, send to the interpreter no matter what mode is -// if( key_repeats[key] > 1 ) { return; } +#ifndef USE_CHAR_EVENTS + if( keydown[K_SHIFT] && keyshift[key] != key && keybindings[keyshift[key]] ) { + key = keyshift[key]; + } +#endif // USE_CHAR_EVENTS + kb = keybindings[key]; if( kb ) { if( kb[0] == '+' ) { @@ -853,7 +867,7 @@ void Key_Event( uint32 key, qboolean down, uint32 time ) { break; } - /* if key is printable, generate char events */ + // if key is printable, generate char events if( key < 32 || key >= 127 ) { return; } @@ -870,7 +884,7 @@ void Key_Event( uint32 key, qboolean down, uint32 time ) { Char_Message( key ); } -#endif /* !USE_CHAR_EVENTS */ +#endif // !USE_CHAR_EVENTS } @@ -895,7 +909,7 @@ void Key_CharEvent( int key ) { } } -#endif /* USE_CHAR_EVENTS */ +#endif // USE_CHAR_EVENTS /* =================== diff --git a/source/cl_local.h b/source/cl_local.h index 886065b..8b5ae93 100644 --- a/source/cl_local.h +++ b/source/cl_local.h @@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "q_list.h" #include "q_field.h" #include "q_uis.h" +#include "vid_public.h" #include "ref_public.h" #include "key_public.h" #include "snd_public.h" @@ -616,7 +617,6 @@ void Con_Shutdown( void ); void Con_DrawConsole( void ); void Con_RunConsole( void ); void Con_Print( const char *txt ); -void Con_Clear_f( void ); void Con_ClearNotify_f( void ); void Con_ToggleConsole_f (void); void Con_Close( void ); @@ -634,8 +634,6 @@ void Char_Message( int key ); void CL_InitRefresh( void ); void CL_ShutdownRefresh( void ); -extern cvar_t *vid_autorestart; - // // cl_ui.c // diff --git a/source/cl_ref.c b/source/cl_ref.c index 0d5467a..7a82e51 100644 --- a/source/cl_ref.c +++ b/source/cl_ref.c @@ -24,7 +24,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "cl_local.h" -#include "vid_public.h" #include "vid_local.h" // Structure containing functions exported from refresh DLL diff --git a/source/cmd.c b/source/cmd.c index d04aae6..9f5971f 100644 --- a/source/cmd.c +++ b/source/cmd.c @@ -729,8 +729,7 @@ char *Cmd_MacroExpandString( const char *text, qboolean aliasHack ) { return NULL; } - strcpy( expanded, text ); - scan = expanded; + scan = memcpy( expanded, text, len + 1 ); inquote = qfalse; count = 0; @@ -743,27 +742,26 @@ char *Cmd_MacroExpandString( const char *text, qboolean aliasHack ) { inquote ^= 1; } if( inquote ) { - continue; /* don't expand inside quotes */ + continue; // don't expand inside quotes } if( scan[i] != '$' ) { continue; } - /* scan out the complete macro */ + // scan out the complete macro start = scan + i + 1; - if( !start[0] ) { - break; /* end of string */ + if( *start == 0 ) { + break; // end of string } - /* allow escape syntax */ - if( i && scan[i-1] == '\\' ) { - memmove( scan + i - 1, scan + i, len - i + 1 ); - i--; + // allow $$ escape syntax + if( *start == '$' ) { + memmove( scan + i, start, len - i ); continue; } - /* fix from jitspoe - skip leading spaces */ + // skip leading spaces while( *start && *start <= 32 ) { start++; } @@ -771,9 +769,9 @@ char *Cmd_MacroExpandString( const char *text, qboolean aliasHack ) { token = temporary; if( *start == '{' ) { - /* allow ${variable} syntax */ + // allow ${variable} syntax start++; - if( *start == '$' ) { + if( *start == '$' ) { // allow ${$varibale} syntax start++; } while( *start ) { @@ -784,7 +782,7 @@ char *Cmd_MacroExpandString( const char *text, qboolean aliasHack ) { *token++ = *start++; } } else { - /* parse single word */ + // parse single word while( *start > 32 ) { *token++ = *start++; } @@ -799,7 +797,7 @@ char *Cmd_MacroExpandString( const char *text, qboolean aliasHack ) { rescan = qfalse; if( aliasHack ) { - /* expand positional parameters only */ + // expand positional parameters only if( temporary[1] ) { continue; } @@ -811,12 +809,13 @@ char *Cmd_MacroExpandString( const char *text, qboolean aliasHack ) { continue; } } else { - /* check for macros first */ + // check for macros first macro = Cmd_FindMacro( temporary ); if( macro ) { macro->function( buffer, sizeof( buffer ) ); token = buffer; } else { + // than variables var = Cvar_FindVar( temporary ); if( var && !( var->flags & CVAR_PRIVATE ) ) { token = var->string; @@ -1361,6 +1360,11 @@ static void Cmd_MacroList_f( void ) { Com_Printf( "%i of %i macros\n", i, total ); } +static void Cmd_Text_f( void ) { + Cbuf_AddText( Cmd_Args() ); + Cbuf_AddText( "\n" ); +} + /* ============ Cmd_FillAPI @@ -1389,6 +1393,7 @@ static const cmdreg_t c_cmd[] = { { "alias", Cmd_Alias_f, Cmd_Alias_g, Cmd_Mixed_g }, { "unalias", Cmd_UnAlias_f, Cmd_Alias_g }, { "wait", Cmd_Wait_f }, + { "text", Cmd_Text_f }, { NULL } }; diff --git a/source/common.c b/source/common.c index 84022e7..7e545b6 100644 --- a/source/common.c +++ b/source/common.c @@ -1097,6 +1097,10 @@ int Com_Uptime_m( char *buffer, int size ) { return Com_sprintf( buffer, size, "%02d.%02d", min, sec ); } +int Com_Random_m( char *buffer, int size ) { + return Com_sprintf( buffer, size, "%d", rand() % 10 ); +} + static void Com_LastError_f( void ) { if( com_errorMsg[0] ) { Com_Printf( "%s\n", com_errorMsg ); @@ -1451,6 +1455,7 @@ void Qcommon_Init( int argc, char **argv ) { Cmd_AddMacro( "com_date", Com_Date_m ); Cmd_AddMacro( "com_time", Com_Time_m ); Cmd_AddMacro( "com_uptime", Com_Uptime_m ); + Cmd_AddMacro( "random", Com_Random_m ); // add any system-wide configuration files Sys_AddDefaultConfig(); diff --git a/source/key_public.h b/source/key_public.h index 992f9b7..e308b6c 100644 --- a/source/key_public.h +++ b/source/key_public.h @@ -81,6 +81,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define K_KP_PLUS 174 #define K_KP_MULTIPLY 175 +#define K_LALT 180 +#define K_RALT 181 +#define K_LCTRL 182 +#define K_RCTRL 183 +#define K_LSHIFT 184 +#define K_RSHIFT 185 + // // joystick buttons diff --git a/source/vid_sdl.c b/source/vid_sdl.c index c11041b..dcccc80 100644 --- a/source/vid_sdl.c +++ b/source/vid_sdl.c @@ -196,7 +196,7 @@ static void QSDL_UpdateGamma( const byte *table ) { } static void QSDL_KeyEvent( SDL_keysym *keysym, qboolean down ) { - uint32 key; + uint32 key1, key2 = 0; if( keysym->sym <= 127 ) { // ASCII chars are mapped directly @@ -204,7 +204,8 @@ static void QSDL_KeyEvent( SDL_keysym *keysym, qboolean down ) { return; } -#define K( s, d ) case SDLK_ ## s: key = K_ ## d; break; +#define K( s, d ) case SDLK_ ## s: key1 = K_ ## d; break; +#define KK( s, d1, d2 ) case SDLK_ ## s: key1 = K_ ## d1; key2 = K_ ## d2; break; switch( keysym->sym ) { K( KP0, KP_INS ) @@ -254,21 +255,25 @@ static void QSDL_KeyEvent( SDL_keysym *keysym, qboolean down ) { K( RSUPER, RWINKEY ) K( MENU, MENU ) - K( RSHIFT, SHIFT ) - K( LSHIFT, SHIFT ) - K( RCTRL, CTRL ) - K( LCTRL, CTRL ) - K( RALT, ALT ) - K( LALT, ALT ) + KK( RSHIFT, SHIFT, RSHIFT ) + KK( LSHIFT, SHIFT, LSHIFT ) + KK( RCTRL, CTRL, RCTRL ) + KK( LCTRL, CTRL, LCTRL ) + KK( RALT, ALT, RALT ) + KK( LALT, ALT, LALT ) #undef K +#undef KK default: Com_DPrintf( "%s: unknown keysym %d\n", __func__, keysym->sym ); return; } - Key_Event( key, down, com_eventTime ); + Key_Event( key1, down, com_eventTime ); + if( key2 ) { + Key_Event( key2, down, com_eventTime ); + } } static void QSDL_MouseButtonEvent( int button, qboolean down ) { |