* win32 dedicated console cleanup: drop silly predifined height and width,

scroll the command buffer to the right when typing long lines, restore
  the original color theme on CON_Shutdown().
This commit is contained in:
Tony J. White = 2007-09-09 07:20:12 +00:00
parent e75c19b45d
commit 687b744166

View file

@ -24,8 +24,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "../qcommon/qcommon.h" #include "../qcommon/qcommon.h"
#include "windows.h" #include "windows.h"
#define QCONSOLE_WIDTH 80
#define QCONSOLE_HEIGHT 30
#define QCONSOLE_THEME FOREGROUND_RED | \ #define QCONSOLE_THEME FOREGROUND_RED | \
BACKGROUND_RED | \ BACKGROUND_RED | \
@ -34,8 +32,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#define QCONSOLE_INPUT_RECORDS 1024 #define QCONSOLE_INPUT_RECORDS 1024
// used to track key input
static int qconsole_chars = 0; static int qconsole_chars = 0;
// used to restore original color theme
static int qconsole_orig_attrib;
/* /*
================== ==================
CON_Hide CON_Hide
@ -61,6 +63,15 @@ CON_Shutdown
*/ */
void CON_Shutdown( void ) void CON_Shutdown( void )
{ {
HANDLE hout;
COORD screen = { 0, 0 };
DWORD written;
hout = GetStdHandle( STD_OUTPUT_HANDLE );
SetConsoleTextAttribute( hout, qconsole_orig_attrib );
FillConsoleOutputAttribute( hout, qconsole_orig_attrib, 63999,
screen, &written );
} }
/* /*
@ -70,18 +81,21 @@ CON_Init
*/ */
void CON_Init( void ) void CON_Init( void )
{ {
SMALL_RECT win = { 0, 0, QCONSOLE_WIDTH-1, QCONSOLE_HEIGHT-1 };
HANDLE hout; HANDLE hout;
COORD screen = { 0, 0 }; COORD screen = { 0, 0 };
DWORD written; DWORD written, read;
CONSOLE_SCREEN_BUFFER_INFO binfo; CONSOLE_SCREEN_BUFFER_INFO binfo;
SMALL_RECT rect; SMALL_RECT rect;
WORD oldattrib;
SetConsoleTitle("ioquake3 Dedicated Server Console");
hout = GetStdHandle( STD_OUTPUT_HANDLE ); hout = GetStdHandle( STD_OUTPUT_HANDLE );
SetConsoleWindowInfo( hout, TRUE, &win ); // remember original color theme
ReadConsoleOutputAttribute( hout, &oldattrib, 1, screen, &read );
qconsole_orig_attrib = oldattrib;
SetConsoleTitle("ioquake3 Dedicated Server Console");
SetConsoleTextAttribute( hout, QCONSOLE_THEME ); SetConsoleTextAttribute( hout, QCONSOLE_THEME );
FillConsoleOutputAttribute( hout, QCONSOLE_THEME, 63999, screen, &written ); FillConsoleOutputAttribute( hout, QCONSOLE_THEME, 63999, screen, &written );
@ -111,7 +125,7 @@ char *CON_ConsoleInput( void )
static char input[ 1024 ] = { "" }; static char input[ 1024 ] = { "" };
int inputlen; int inputlen;
int newlinepos = -1; int newlinepos = -1;
CHAR_INFO line[ QCONSOLE_WIDTH ]; CHAR_INFO line[ QCONSOLE_INPUT_RECORDS ];
int linelen = 0; int linelen = 0;
inputlen = 0; inputlen = 0;
@ -136,8 +150,7 @@ char *CON_ConsoleInput( void )
for( i = 0; i < count; i++ ) for( i = 0; i < count; i++ )
{ {
if( buff[ i ].EventType == KEY_EVENT && if( buff[ i ].EventType == KEY_EVENT && buff[ i ].Event.KeyEvent.bKeyDown )
buff[ i ].Event.KeyEvent.bKeyDown )
{ {
if( buff[ i ].Event.KeyEvent.wVirtualKeyCode == VK_RETURN ) if( buff[ i ].Event.KeyEvent.wVirtualKeyCode == VK_RETURN )
{ {
@ -145,7 +158,7 @@ char *CON_ConsoleInput( void )
break; break;
} }
if( linelen < QCONSOLE_WIDTH && if( linelen < QCONSOLE_INPUT_RECORDS &&
buff[ i ].Event.KeyEvent.uChar.AsciiChar ) buff[ i ].Event.KeyEvent.uChar.AsciiChar )
{ {
if( buff[ i ].Event.KeyEvent.wVirtualKeyCode == VK_BACK ) if( buff[ i ].Event.KeyEvent.wVirtualKeyCode == VK_BACK )
@ -168,7 +181,7 @@ char *CON_ConsoleInput( void )
if( linelen != qconsole_chars ) if( linelen != qconsole_chars )
{ {
CONSOLE_SCREEN_BUFFER_INFO binfo; CONSOLE_SCREEN_BUFFER_INFO binfo;
COORD writeSize = { QCONSOLE_WIDTH, 1 }; COORD writeSize = { QCONSOLE_INPUT_RECORDS, 1 };
COORD writePos = { 0, 0 }; COORD writePos = { 0, 0 };
SMALL_RECT writeArea = { 0, 0, 0, 0 }; SMALL_RECT writeArea = { 0, 0, 0, 0 };
int i; int i;
@ -198,16 +211,24 @@ char *CON_ConsoleInput( void )
writeArea.Left = 0; writeArea.Left = 0;
writeArea.Top = binfo.srWindow.Bottom; writeArea.Top = binfo.srWindow.Bottom;
writeArea.Bottom = binfo.srWindow.Bottom; writeArea.Bottom = binfo.srWindow.Bottom;
writeArea.Right = QCONSOLE_WIDTH; writeArea.Right = QCONSOLE_INPUT_RECORDS;
// pad line with ' ' to handle VK_BACK // pad line with ' ' to handle VK_BACK
for( i = linelen; i < QCONSOLE_WIDTH; i++ ) for( i = linelen; i < QCONSOLE_INPUT_RECORDS; i++ )
{ {
line[ i ].Char.AsciiChar = ' '; line[ i ].Char.AsciiChar = ' ';
line[ i ].Attributes = QCONSOLE_THEME; line[ i ].Attributes = QCONSOLE_THEME;
} }
if( linelen > binfo.srWindow.Right )
{
WriteConsoleOutput( hout, line + (linelen - binfo.srWindow.Right ),
writeSize, writePos, &writeArea );
}
else
{
WriteConsoleOutput( hout, line, writeSize, writePos, &writeArea ); WriteConsoleOutput( hout, line, writeSize, writePos, &writeArea );
}
if( binfo.dwCursorPosition.X != linelen ) if( binfo.dwCursorPosition.X != linelen )
{ {
@ -241,8 +262,7 @@ char *CON_ConsoleInput( void )
for( i = 0; i < count; i++ ) for( i = 0; i < count; i++ )
{ {
if( buff[ i ].EventType == KEY_EVENT && if( buff[ i ].EventType == KEY_EVENT && buff[ i ].Event.KeyEvent.bKeyDown )
buff[ i ].Event.KeyEvent.bKeyDown )
{ {
if( buff[ i ].Event.KeyEvent.wVirtualKeyCode == VK_BACK ) if( buff[ i ].Event.KeyEvent.wVirtualKeyCode == VK_BACK )
{ {