// backend
void R_ClearScreen(void);
+// color tag printing
+static vec4_t _draw_colors[] =
+{
+ // Quake3 colors
+ // LordHavoc: why on earth is cyan before magenta in Quake3?
+ // LordHavoc: note: Doom3 uses white for [0] and [7]
+ {0.0, 0.0, 0.0, 1.0}, // black
+ {1.0, 0.0, 0.0, 1.0}, // red
+ {0.0, 1.0, 0.0, 1.0}, // green
+ {1.0, 1.0, 0.0, 1.0}, // yellow
+ {0.0, 0.0, 1.0, 1.0}, // blue
+ {0.0, 1.0, 1.0, 1.0}, // cyan
+ {1.0, 0.0, 1.0, 1.0}, // magenta
+ {1.0, 1.0, 1.0, 1.0} // white
+ // Black's color table
+ //{1.0, 1.0, 1.0, 1.0},
+ //{1.0, 0.0, 0.0, 1.0},
+ //{0.0, 1.0, 0.0, 1.0},
+ //{0.0, 0.0, 1.0, 1.0},
+ //{1.0, 1.0, 0.0, 1.0},
+ //{0.0, 1.0, 1.0, 1.0},
+ //{1.0, 0.0, 1.0, 1.0},
+ //{0.1, 0.1, 0.1, 1.0}
+};
+
+#define _draw_colors_count (sizeof(_draw_colors) / sizeof(vec4_t))
+#define _draw_color_tag '^'
+#define _draw_color_default 7
+
+// color is read and changed in the end
+void DrawQ_ColoredString( float x, float y, const char *text, int maxlen, float scalex, float scaley, float basered, float basegreen, float baseblue, float basealpha, int flags, int *outcolor )
+{
+ vec_t *color;
+ const char *first, *last;
+ int len;
+ int colorindex;
+
+ if( !outcolor || *outcolor == -1 ) {
+ colorindex = _draw_color_default;
+ } else {
+ colorindex = *outcolor;
+ }
+
+ color = _draw_colors[colorindex];
+
+ if( maxlen < 1)
+ len = strlen( text );
+ else
+ len = min( maxlen, (signed) strlen( text ) );
+
+ first = last = text;
+ while( len ) {
+ // iterate until we get the next color tag or reach the end of the text part to draw
+ for( ; len && *last != _draw_color_tag ; len--, last++ )
+ ;
+ // only draw the partial string if we have read anything
+ if( last != first ) {
+ // draw the string
+ DrawQ_String( x, y, first, last - first, scalex, scaley, basered * color[0], basegreen * color[1], baseblue * color[2], basealpha * color[3], flags );
+ // update x to be at the new start position
+ x += (last - first) * scalex;
+ // if we have reached the end, we have finished
+ if( !len )
+ break;
+ }
+ first = last;
+ // jump over the tag
+ last++;
+ len--;
+ if( len && '0' <= *last && *last <= '9' ) {
+ colorindex = 0;
+ while( '0' <= *last && *last <= '9' && len ) {
+ colorindex = colorindex * 10 + *last - '0';
+ if( colorindex < _draw_colors_count ) {
+ last++;
+ len--;
+ } else {
+ colorindex /= 10;
+ break;
+ }
+ }
+
+ color = _draw_colors[colorindex];
+ // we dont want to display the color tag and the color index
+ first = last;
+ }
+ }
+
+ if( outcolor ) {
+ *outcolor = colorindex;
+ }
+}
+
/*
===============================================================================
DrawQ_String_Real(x,y,string,maxlen,scalex,scaley,red,green,blue,alpha,flags);
}
+
+
void DrawQ_Fill (float x, float y, float w, float h, float red, float green, float blue, float alpha, int flags)
{
DrawQ_SuperPic(x,y,NULL,w,h,0,0,red,green,blue,alpha,1,0,red,green,blue,alpha,0,1,red,green,blue,alpha,1,1,red,green,blue,alpha,flags);
void DrawQ_Pic(float x, float y, const char *picname, float width, float height, float red, float green, float blue, float alpha, int flags);
// draw a text string
void DrawQ_String(float x, float y, const char *string, int maxlen, float scalex, float scaley, float red, float green, float blue, float alpha, int flags);
+// draw a text string that supports color tags (colorindex can either be NULL, -1 to make it choose the default color or valid index to start with)
+void DrawQ_ColoredString( float x, float y, const char *text, int maxlen, float scalex, float scaley, float basered, float basegreen, float baseblue, float basealpha, int flags, int *outcolor );
// draw a filled rectangle
void DrawQ_Fill(float x, float y, float w, float h, float red, float green, float blue, float alpha, int flags);
// draw a very fancy pic (per corner texcoord/color control), the order is tl, tr, bl, br
{
// if this is the beginning of a new line, print timestamp
char *timestamp = timestamps.integer ? Sys_TimeString(timeformat.string) : "";
+ // reset the color
+ // FIXME: 1. perhaps we should use a terminal system 2. use a constant instead of 7!
+ line[index++] = '^';
+ line[index++] = '7';
// special color codes for chat messages must always come first
// for Con_PrintToHistory to work properly
if (*msg <= 2)
==============================================================================
*/
-static vec4_t _con_colors[] =
-{
- // Quake3 colors
- // LordHavoc: why on earth is cyan before magenta in Quake3?
- // LordHavoc: note: Doom3 uses white for [0] and [7]
- {0.0, 0.0, 0.0, 1.0}, // black
- {1.0, 0.0, 0.0, 1.0}, // red
- {0.0, 1.0, 0.0, 1.0}, // green
- {1.0, 1.0, 0.0, 1.0}, // yellow
- {0.0, 0.0, 1.0, 1.0}, // blue
- {0.0, 1.0, 1.0, 1.0}, // cyan
- {1.0, 0.0, 1.0, 1.0}, // magenta
- {1.0, 1.0, 1.0, 1.0} // white
- // Black's color table
- //{1.0, 1.0, 1.0, 1.0},
- //{1.0, 0.0, 0.0, 1.0},
- //{0.0, 1.0, 0.0, 1.0},
- //{0.0, 0.0, 1.0, 1.0},
- //{1.0, 1.0, 0.0, 1.0},
- //{0.0, 1.0, 1.0, 1.0},
- //{1.0, 0.0, 1.0, 1.0},
- //{0.1, 0.1, 0.1, 1.0}
-};
-
-#define _con_colors_count (sizeof(_con_colors) / sizeof(vec3_t))
-#define _con_color_tag '^'
-
-// color is read and changed in the end
-static void _Con_DrawString( float x, float y, const char *text, int maxlen, float scalex, float scaley, int flags )
-{
- vec_t *color;
- const char *first, *last;
- int len;
-
- color = _con_colors[7];
- if( maxlen < 1)
- len = strlen( text );
- else
- len = min( maxlen, (signed) strlen( text ));
-
- first = last = text;
- while( 1 ) {
- // iterate until we get the next color tag or reach the end of the text part to draw
- for( ; len && *last != _con_color_tag ; len--, last++ )
- ;
- // only draw the partial string if we have read anything
- if( last != first ) {
- // draw the string
- DrawQ_String( x, y, first, last - first, scalex, scaley, color[0], color[1], color[2], color[3], flags );
- // update x to be at the new start position
- x += (last - first) * scalex;
- // if we have reached the end, we have finished
- if( !len )
- break;
- }
- first = last;
- // jump over the tag
- last++;
- len--;
- if( len && '0' <= *last && *last <= '9' ) {
- int index = 0;
-
- while( '0' <= *last && *last <= '9' && len ) {
- index = index * 10 + *last - '0';
- if( index < _con_colors_count ) {
- last++;
- len--;
- } else {
- index /= 10;
- break;
- }
- }
-
- color = _con_colors[index];
- // we dont want to display the color tag and the color index
- first = last;
- }
- }
-}
-
/*
================
Con_DrawInput
text += 1 + key_linepos - con_linewidth;
// draw it
- _Con_DrawString(0, con_vislines - 16, text, con_linewidth, 8, 8, 0);
+ DrawQ_ColoredString(0, con_vislines - 16, text, con_linewidth, 8, 8, 1.0, 1.0, 1.0, 1.0, 0, NULL );
// remove cursor
// key_lines[edit_line][key_linepos] = 0;
float time;
extern char chat_buffer[];
char temptext[256];
+ int colorindex = -1; //-1 for default
if (con_notify.integer < 0)
Cvar_SetValueQuick(&con_notify, 0);
v = 0;
for (i= con_current-con_notify.integer+1 ; i<=con_current ; i++)
{
+
if (i < 0)
continue;
time = con_times[i % con_notify.integer];
} else
x = 0;
- _Con_DrawString(x, v, text, con_linewidth, 8, 8, 0);
-
+ DrawQ_ColoredString( x, v, text, con_linewidth, 8, 8, 1.0, 1.0, 1.0, 1.0, 0, &colorindex );
+
v += 8;
}
if (key_dest == key_message)
{
+ int colorindex = -1;
+
x = 0;
// LordHavoc: speedup, and other improvements
sprintf(temptext, "say:%s%c", chat_buffer, (int) 10+((int)(realtime*con_cursorspeed)&1));
while (strlen(temptext) >= (size_t) con_linewidth)
{
- _Con_DrawString (0, v, temptext, con_linewidth, 8, 8, 0);
+ DrawQ_ColoredString( 0, v, temptext, con_linewidth, 8, 8, 1.0, 1.0, 1.0, 1.0, 0, &colorindex );
strcpy(temptext, &temptext[con_linewidth]);
v += 8;
}
if (strlen(temptext) > 0)
{
- _Con_DrawString (0, v, temptext, 0, 8, 8, 0);
+ DrawQ_ColoredString( 0, v, temptext, 0, 8, 8, 1.0, 1.0, 1.0, 1.0, 0, &colorindex );
v += 8;
}
}
{
int i, y, rows, j;
char *text;
+ int colorindex = -1;
if (lines <= 0)
return;
j = max(i - con_backscroll, 0);
text = con_text + (j % con_totallines)*con_linewidth;
- _Con_DrawString(0, y, text, con_linewidth, 8, 8, 0);
+ DrawQ_ColoredString( 0, y, text, con_linewidth, 8, 8, 1.0, 1.0, 1.0, 1.0, 0, &colorindex );
}
// draw the input prompt, user text, and cursor if desired
consolekeys[K_KP_MINUS] = true;
consolekeys[K_KP_DIVIDE] = true;
consolekeys[K_KP_MULTIPLY] = true;
- consolekeys['`'] = false;
- consolekeys['~'] = false;
+ consolekeys['`'] = true;
+ consolekeys['~'] = true;
menubound[K_ESCAPE] = true;
for (i = 0; i < 12; i++)
void
Key_Event (int key, char ascii, qboolean down)
{
+#if 1
+#define USERPLAYING() ( !key_consoleactive && key_dest == key_game && (cls.state == ca_connected && cls.signon == SIGNONS) )
+//#define CONSOLEKEY() (key_consoleactive && !consolekeys[key])
+#define CONSOLEKEY() ( key_dest == key_console)
+ const char *bind;
+
+ // get key binding
+ bind = keybindings[ key_bmap ][ key ];
+ if( !bind ) {
+ bind = keybindings[ key_bmap2 ][ key ];
+ }
+
+ // set key state
+ keydown[ key ] = down;
+
+ // update key repeats
+ if( down ) {
+ key_repeats[ key ]++;
+ if( key_repeats[ key ] > 1 ) {
+ if( (key_consoleactive && !consolekeys[key]) || USERPLAYING() )
+ return; // ignore most autorepeats
+ }
+ } else {
+ key_repeats[ key ] = 0;
+ }
+
+ if( key == K_CTRL ) {
+ ctrl_down = down;
+ }
+
+ if( !down ) {
+ if( bind && bind[ 0 ] == '+') {
+ Cbuf_AddText( va( "-%s %i\n", bind + 1, key) );
+ }
+ } else {
+ // handle ESCAPE specially, so unbinding wont help
+ if( key == K_ESCAPE ) {
+ // ctrl-escape is a safety measure for users who cant toggle the console otherwise
+ if( ctrl_down ) {
+ Con_ToggleConsole_f();
+ return;
+ }
+ switch( key_dest ) {
+ case key_message:
+ Key_Message( key, ascii );
+ break;
+ case key_menu:
+ MR_Keydown( key, ascii );
+ break;
+ case key_game:
+ MR_ToggleMenu_f();
+ break;
+ default:
+ Sys_Error( "Bad key_dest" );
+ }
+ return;
+ }
+
+ if (bind && !strncmp( bind, "toggleconsole", strlen( "toggleconsole" ) ) )
+ {
+ Cbuf_AddText( bind );
+ Cbuf_AddText( "\n" );
+ } else {
+ // during demo playback, all keys ingame bring up the main menu
+ if( cls.demoplayback && !key_consoleactive && key_dest == key_game ) {
+ MR_ToggleMenu_f ();
+ return;
+ }
+
+ // menu bind/function keys or normal binds
+ if( (key_dest == key_menu && menubound[key]) || USERPLAYING() ) {
+ if( bind ) {
+ if( bind[0] == '+' ) { // button commands add keynum as a parm
+ Cbuf_AddText( va( "%s %i\n", bind, key ) );
+ } else {
+ Cbuf_AddText( bind );
+ Cbuf_AddText( "\n" );
+ }
+ }
+ return;
+ }
+ }
+
+ // either console or game state key functions
+ if( key_consoleactive ) {
+ Key_Console( key, ascii );
+ } else {
+ switch (key_dest) {
+ case key_message:
+ Key_Message( key, ascii );
+ break;
+ case key_menu:
+ MR_Keydown( key, ascii );
+ break;
+ case key_game:
+ // unbound key
+ break;
+ default:
+ Sys_Error( "Bad key_dest" );
+ }
+ }
+ }
+#else
const char *kb;
char cmd[1024];
Sys_Error ("Bad key_dest");
}
}
+#endif
}
/*
c = (qbyte *)&palette_complete[((s->colors & 15)<<4) + 8];
DrawQ_Fill(x + 8, y+4, 32, 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f) * sbar_alpha_fg.value, 0);
// print the text
- DrawQ_String(x, y, va("%c%4i %s", (s - cl.scores) == cl.playerentity - 1 ? 13 : ' ', (int) s->frags, s->name), 0, 8, 8, 1, 1, 1, 1 * sbar_alpha_fg.value, 0);
+ //DrawQ_String(x, y, va("%c%4i %s", (s - cl.scores) == cl.playerentity - 1 ? 13 : ' ', (int) s->frags, s->name), 0, 8, 8, 1, 1, 1, 1 * sbar_alpha_fg.value, 0);
+ // FIXME: use a constant for this color tag instead
+ DrawQ_ColoredString(x, y, va("%c%4i %s^7", (s - cl.scores) == cl.playerentity - 1 ? 13 : ' ', (int) s->frags, s->name), 0, 8, 8, 1, 1, 1, 1 * sbar_alpha_fg.value, 0, NULL );
return 8;
}
char state[256];
char asciichar[4];
int vkey;
+ int charlength;
qboolean down = false;
if ( uMsg == uiWheelMessage )
GetKeyboardState (state);
// alt/ctrl/shift tend to produce funky ToAscii values,
// and if it's not a single character we don't know care about it
- if (vkey == K_ALT || vkey == K_CTRL || vkey == K_SHIFT || ToAscii (wParam, lParam >> 16, state, (unsigned short *)asciichar, 0) != 1)
+ charlength = ToAscii (wParam, lParam >> 16, state, (unsigned short *)asciichar, 0);
+ if (vkey == K_ALT || vkey == K_CTRL || vkey == K_SHIFT || charlength == 0)
asciichar[0] = 0;
+ else if( charlength == 2 ) {
+ asciichar[0] = asciichar[1];
+ }
Key_Event (vkey, asciichar[0], down);
break;