/* =========================================================================== Copyright (C) 1999 - 2005, Id Software, Inc. Copyright (C) 2000 - 2013, Raven Software, Inc. Copyright (C) 2001 - 2013, Activision, Inc. Copyright (C) 2005 - 2015, ioquake3 contributors Copyright (C) 2013 - 2015, OpenJK contributors This file is part of the OpenJK source code. OpenJK is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, see . =========================================================================== */ // console.c #include "server/exe_headers.h" #include "client.h" #include "qcommon/stringed_ingame.h" #include "qcommon/stv_version.h" int g_console_field_width = 78; console_t con; cvar_t *con_conspeed; cvar_t *con_notifytime; cvar_t *con_opacity; // background alpha multiplier cvar_t *con_autoclear; #define DEFAULT_CONSOLE_WIDTH 78 vec4_t console_color = {0.509f, 0.609f, 0.847f, 1.0f}; /* ================ Con_ToggleConsole_f ================ */ void Con_ToggleConsole_f (void) { // closing a full screen console restarts the demo loop if ( cls.state == CA_DISCONNECTED && Key_GetCatcher( ) == KEYCATCH_CONSOLE ) { // CL_StartDemoLoop(); return; } if( con_autoclear->integer ) Field_Clear( &g_consoleField ); g_consoleField.widthInChars = g_console_field_width; Con_ClearNotify (); Key_SetCatcher( Key_GetCatcher( ) ^ KEYCATCH_CONSOLE ); } /* =================== Con_ToggleMenu_f =================== */ void Con_ToggleMenu_f( void ) { CL_KeyEvent( A_ESCAPE, qtrue, Sys_Milliseconds() ); CL_KeyEvent( A_ESCAPE, qfalse, Sys_Milliseconds() ); } /* ================ Con_Clear_f ================ */ void Con_Clear_f (void) { int i; for ( i = 0 ; i < CON_TEXTSIZE ; i++ ) { con.text[i] = (ColorIndex(COLOR_WHITE)<<8) | ' '; } Con_Bottom(); // go to end } /* ================ Con_Dump_f Save the console contents out to a file ================ */ void Con_Dump_f (void) { int l, x, i; short *line; fileHandle_t f; int bufferlen; char *buffer; char filename[MAX_QPATH]; if (Cmd_Argc() != 2) { Com_Printf ("%s\n", SE_GetString("CON_TEXT_DUMP_USAGE")); return; } Q_strncpyz( filename, Cmd_Argv( 1 ), sizeof( filename ) ); COM_DefaultExtension( filename, sizeof( filename ), ".txt" ); if(!COM_CompareExtension(filename, ".txt")) { Com_Printf( "Con_Dump_f: Only the \".txt\" extension is supported by this command!\n" ); return; } f = FS_FOpenFileWrite( filename ); if (!f) { Com_Printf ("ERROR: couldn't open %s.\n", filename); return; } Com_Printf ("Dumped console text to %s.\n", filename ); // skip empty lines for (l = con.current - con.totallines + 1 ; l <= con.current ; l++) { line = con.text + (l%con.totallines)*con.linewidth; for (x=0 ; x=0 ; x--) { if (buffer[x] == ' ') buffer[x] = 0; else break; } #ifdef _WIN32 Q_strcat(buffer, bufferlen, "\r\n"); #else Q_strcat(buffer, bufferlen, "\n"); #endif FS_Write(buffer, strlen(buffer), f); } Z_Free( buffer ); FS_FCloseFile( f ); } /* ================ Con_ClearNotify ================ */ void Con_ClearNotify( void ) { int i; for ( i = 0 ; i < NUM_CON_TIMES ; i++ ) { con.times[i] = 0; } } /* ================ Con_CheckResize If the line width has changed, reformat the buffer. ================ */ void Con_CheckResize (void) { int i, j, width, oldwidth, oldtotallines, numlines, numchars; short tbuf[CON_TEXTSIZE]; //width = (SCREEN_WIDTH / SMALLCHAR_WIDTH) - 2; width = (cls.glconfig.vidWidth / SMALLCHAR_WIDTH) - 2; if (width == con.linewidth) return; if (width < 1) // video hasn't been initialized yet { con.xadjust = 1; con.yadjust = 1; width = DEFAULT_CONSOLE_WIDTH; con.linewidth = width; con.totallines = CON_TEXTSIZE / con.linewidth; for(i=0; i= 0) con.times[con.current % NUM_CON_TIMES] = cls.realtime; con.x = 0; if (con.display == con.current) con.display++; con.current++; for(i=0; iinteger ) { return; } if (!con.initialized) { con.color[0] = con.color[1] = con.color[2] = con.color[3] = 1.0f; con.linewidth = -1; Con_CheckResize (); con.initialized = qtrue; } color = ColorIndex(COLOR_WHITE); while ( (c = (unsigned char )*txt) != 0 ) { if ( Q_IsColorString( (unsigned char*) txt ) ) { color = ColorIndex( *(txt+1) ); txt += 2; continue; } // count word length for (l=0 ; l< con.linewidth ; l++) { if ( txt[l] <= ' ') { break; } } // word wrap if (l != con.linewidth && (con.x + l >= con.linewidth) ) { Con_Linefeed(); } txt++; switch (c) { case '\n': Con_Linefeed (); break; case '\r': con.x = 0; break; default: // display character and advance y = con.current % con.totallines; con.text[y*con.linewidth+con.x] = (color << 8) | c; con.x++; if (con.x >= con.linewidth) { Con_Linefeed(); con.x = 0; } break; } } // mark time for transparent overlay if (con.current >= 0) con.times[con.current % NUM_CON_TIMES] = cls.realtime; } /* ============================================================================== DRAWING ============================================================================== */ /* ================ Con_DrawInput Draw the editline after a ] prompt ================ */ void Con_DrawInput (void) { int y; if ( cls.state != CA_DISCONNECTED && !(Key_GetCatcher( ) & KEYCATCH_CONSOLE ) ) { return; } y = con.vislines - ( SMALLCHAR_HEIGHT * (re.Language_IsAsian() ? 1.5 : 2) ); re.SetColor( con.color ); SCR_DrawSmallChar( con.xadjust + 1 * SMALLCHAR_WIDTH, y, CONSOLE_PROMPT_CHAR ); Field_Draw( &g_consoleField, con.xadjust + 2 * SMALLCHAR_WIDTH, y, SCREEN_WIDTH - 3 * SMALLCHAR_WIDTH, qtrue, qtrue ); } /* ================ Con_DrawNotify Draws the last few lines of output transparently over the game top ================ */ void Con_DrawNotify (void) { int x, v; short *text; int i; int time; int currentColor; currentColor = 7; re.SetColor( g_color_table[currentColor] ); v = 0; for (i= con.current-NUM_CON_TIMES+1 ; i<=con.current ; i++) { if (i < 0) continue; time = con.times[i % NUM_CON_TIMES]; if (time == 0) continue; time = cls.realtime - time; if (time > con_notifytime->value*1000) continue; text = con.text + (i % con.totallines)*con.linewidth; // asian language needs to use the new font system to print glyphs... // // (ignore colours since we're going to print the whole thing as one string) // if (re.Language_IsAsian()) { int iFontIndex = re.RegisterFont("ocr_a"); // this seems naughty const float fFontScale = 0.75f*con.yadjust; const int iPixelHeightToAdvance = 2+(1.3/con.yadjust) * re.Font_HeightPixels(iFontIndex, fFontScale); // for asian spacing, since we don't want glyphs to touch. // concat the text to be printed... // char sTemp[4096]={0}; // ott for (x = 0 ; x < con.linewidth ; x++) { if ( ( (text[x]>>8)&Q_COLOR_BITS ) != currentColor ) { currentColor = (text[x]>>8)&Q_COLOR_BITS; strcat(sTemp,va("^%i", (text[x]>>8)&Q_COLOR_BITS) ); } strcat(sTemp,va("%c",text[x] & 0xFF)); } // // and print... // re.Font_DrawString(con.xadjust*(con.xadjust + (1*SMALLCHAR_WIDTH/*aesthetics*/)), con.yadjust*(v), sTemp, g_color_table[currentColor], iFontIndex, -1, fFontScale); v += iPixelHeightToAdvance; } else { for (x = 0 ; x < con.linewidth ; x++) { if ( ( text[x] & 0xff ) == ' ' ) { continue; } if ( ( (text[x]>>8)&Q_COLOR_BITS ) != currentColor ) { currentColor = (text[x]>>8)&Q_COLOR_BITS; re.SetColor( g_color_table[currentColor] ); } SCR_DrawSmallChar( con.xadjust + (x+1)*SMALLCHAR_WIDTH, v, text[x] & 0xff ); } v += SMALLCHAR_HEIGHT; } } re.SetColor( NULL ); } /* ================ Con_DrawSolidConsole Draws the console with the solid background ================ */ void Con_DrawSolidConsole( float frac ) { int i, x, y; int rows; short *text; int row; int lines; int currentColor; lines = cls.glconfig.vidHeight * frac; if (lines <= 0) return; if (lines > cls.glconfig.vidHeight ) lines = cls.glconfig.vidHeight; // draw the background y = frac * SCREEN_HEIGHT - 2; if ( y < 1 ) { y = 0; } else { // draw the background at full opacity only if fullscreen if (frac < 1.0f) { vec4_t con_color; MAKERGBA(con_color, 1.0f, 1.0f, 1.0f, Com_Clamp(0.0f, 1.0f, con_opacity->value)); re.SetColor(con_color); } else { re.SetColor(NULL); } SCR_DrawPic( 0, 0, SCREEN_WIDTH, y, cls.consoleShader); } // draw the bottom bar and version number re.SetColor( console_color ); re.DrawStretchPic( 0, y, SCREEN_WIDTH, 2, 0, 0, 0, 0, cls.whiteShader ); i = strlen( Q3_VERSION ); for (x=0 ; x= con.totallines) { // past scrollback wrap point continue; } text = con.text + (row % con.totallines)*con.linewidth; // asian language needs to use the new font system to print glyphs... // // (ignore colours since we're going to print the whole thing as one string) // if (re.Language_IsAsian()) { // concat the text to be printed... // char sTemp[4096]={0}; // ott for (x = 0 ; x < con.linewidth ; x++) { if ( ( (text[x]>>8)&Q_COLOR_BITS ) != currentColor ) { currentColor = (text[x]>>8)&Q_COLOR_BITS; strcat(sTemp,va("^%i", (text[x]>>8)&Q_COLOR_BITS) ); } strcat(sTemp,va("%c",text[x] & 0xFF)); } // // and print... // re.Font_DrawString(con.xadjust*(con.xadjust + (1*SMALLCHAR_WIDTH/*(aesthetics)*/)), con.yadjust*(y), sTemp, g_color_table[currentColor], iFontIndexForAsian, -1, fFontScaleForAsian); } else { for (x=0 ; x>8)&Q_COLOR_BITS ) != currentColor ) { currentColor = (text[x]>>8)&Q_COLOR_BITS; re.SetColor( g_color_table[currentColor] ); } SCR_DrawSmallChar( con.xadjust + (x+1)*SMALLCHAR_WIDTH, y, text[x] & 0xff ); } } } // draw the input prompt, user text, and cursor if desired Con_DrawInput (); re.SetColor( NULL ); } /* ================== Con_DrawConsole ================== */ void Con_DrawConsole( void ) { // check for console width changes from a vid mode change Con_CheckResize (); // if disconnected, render console full screen if ( cls.state == CA_DISCONNECTED ) { if ( !( Key_GetCatcher( ) & KEYCATCH_UI) ) { Con_DrawSolidConsole( 1.0 ); return; } } if ( con.displayFrac ) { Con_DrawSolidConsole( con.displayFrac ); } else { // draw notify lines if ( cls.state == CA_ACTIVE ) { Con_DrawNotify (); } } } //================================================================ /* ================== Con_RunConsole Scroll it up or down ================== */ void Con_RunConsole (void) { // decide on the destination height of the console if ( Key_GetCatcher( ) & KEYCATCH_CONSOLE ) con.finalFrac = 0.5; // half screen else con.finalFrac = 0; // none visible // scroll towards the destination height if (con.finalFrac < con.displayFrac) { con.displayFrac -= con_conspeed->value*cls.realFrametime*0.001; if (con.finalFrac > con.displayFrac) con.displayFrac = con.finalFrac; } else if (con.finalFrac > con.displayFrac) { con.displayFrac += con_conspeed->value*cls.realFrametime*0.001; if (con.finalFrac < con.displayFrac) con.displayFrac = con.finalFrac; } } void Con_PageUp( void ) { con.display -= 2; if ( con.current - con.display >= con.totallines ) { con.display = con.current - con.totallines + 1; } } void Con_PageDown( void ) { con.display += 2; if (con.display > con.current) { con.display = con.current; } } void Con_Top( void ) { con.display = con.totallines; if ( con.current - con.display >= con.totallines ) { con.display = con.current - con.totallines + 1; } } void Con_Bottom( void ) { con.display = con.current; } void Con_Close( void ) { Field_Clear( &g_consoleField ); Con_ClearNotify (); Key_SetCatcher( Key_GetCatcher( ) & ~KEYCATCH_CONSOLE ); con.finalFrac = 0; // none visible con.displayFrac = 0; }