r1172 - trunk/code/sys

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Sun Sep 9 03:20:13 EDT 2007


Author: tjw
Date: 2007-09-09 03:20:12 -0400 (Sun, 09 Sep 2007)
New Revision: 1172

Modified:
   trunk/code/sys/con_win32.c
Log:
* 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().


Modified: trunk/code/sys/con_win32.c
===================================================================
--- trunk/code/sys/con_win32.c	2007-09-07 21:27:01 UTC (rev 1171)
+++ trunk/code/sys/con_win32.c	2007-09-09 07:20:12 UTC (rev 1172)
@@ -24,8 +24,6 @@
 #include "../qcommon/qcommon.h"
 #include "windows.h"
 
-#define QCONSOLE_WIDTH 80
-#define QCONSOLE_HEIGHT 30
 
 #define QCONSOLE_THEME FOREGROUND_RED | \
                        BACKGROUND_RED | \
@@ -34,8 +32,12 @@
 
 #define QCONSOLE_INPUT_RECORDS 1024
 
+// used to track key input
 static int qconsole_chars = 0;
 
+// used to restore original color theme 
+static int qconsole_orig_attrib;
+
 /*
 ==================
 CON_Hide
@@ -61,6 +63,15 @@
 */
 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 @@
 */
 void CON_Init( void )
 {
-  SMALL_RECT win = { 0, 0, QCONSOLE_WIDTH-1, QCONSOLE_HEIGHT-1 };
   HANDLE hout;
   COORD screen = { 0, 0 };
-  DWORD written;
+  DWORD written, read;
   CONSOLE_SCREEN_BUFFER_INFO binfo;
   SMALL_RECT rect;
+  WORD oldattrib;
 
+  hout = GetStdHandle( STD_OUTPUT_HANDLE );
+
+  // remember original color theme
+  ReadConsoleOutputAttribute( hout, &oldattrib, 1, screen, &read );
+  qconsole_orig_attrib = oldattrib;
+  
   SetConsoleTitle("ioquake3 Dedicated Server Console");
 
-  hout = GetStdHandle( STD_OUTPUT_HANDLE );
-
-  SetConsoleWindowInfo( hout, TRUE, &win );
   SetConsoleTextAttribute( hout, QCONSOLE_THEME );
   FillConsoleOutputAttribute( hout, QCONSOLE_THEME, 63999, screen, &written ); 
   
@@ -111,7 +125,7 @@
   static char input[ 1024 ] = { "" };
   int inputlen;
   int newlinepos = -1;
-  CHAR_INFO line[ QCONSOLE_WIDTH ];
+  CHAR_INFO line[ QCONSOLE_INPUT_RECORDS ];
   int linelen = 0;
 
   inputlen = 0;
@@ -136,8 +150,7 @@
 
   for( i = 0; i < count; i++ )
   {
-    if( buff[ i ].EventType == KEY_EVENT &&
-        buff[ i ].Event.KeyEvent.bKeyDown )
+    if( buff[ i ].EventType == KEY_EVENT && buff[ i ].Event.KeyEvent.bKeyDown ) 
     {
       if( buff[ i ].Event.KeyEvent.wVirtualKeyCode == VK_RETURN )
       {
@@ -145,7 +158,7 @@
         break;
       }
 
-      if( linelen < QCONSOLE_WIDTH &&
+      if( linelen < QCONSOLE_INPUT_RECORDS &&
           buff[ i ].Event.KeyEvent.uChar.AsciiChar )
       {
         if( buff[ i ].Event.KeyEvent.wVirtualKeyCode == VK_BACK )
@@ -168,7 +181,7 @@
   if( linelen != qconsole_chars )
   {
     CONSOLE_SCREEN_BUFFER_INFO binfo;
-    COORD writeSize = { QCONSOLE_WIDTH, 1 };
+    COORD writeSize = { QCONSOLE_INPUT_RECORDS, 1 };
     COORD writePos = { 0, 0 };
     SMALL_RECT writeArea = { 0, 0, 0, 0 };
     int i;
@@ -198,16 +211,24 @@
     writeArea.Left = 0;
     writeArea.Top = binfo.srWindow.Bottom; 
     writeArea.Bottom = binfo.srWindow.Bottom; 
-    writeArea.Right = QCONSOLE_WIDTH;
+    writeArea.Right = QCONSOLE_INPUT_RECORDS;
 
     // 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 ].Attributes =  QCONSOLE_THEME;
     }
 
-    WriteConsoleOutput( hout, line, writeSize, writePos, &writeArea );
+    if( linelen > binfo.srWindow.Right )
+    {
+      WriteConsoleOutput( hout, line + (linelen - binfo.srWindow.Right ),
+                          writeSize, writePos, &writeArea );
+    }
+    else
+    {
+      WriteConsoleOutput( hout, line, writeSize, writePos, &writeArea );
+    }
 
     if( binfo.dwCursorPosition.X != linelen )
     {
@@ -241,8 +262,7 @@
 
   for( i = 0; i < count; i++ )
   {
-    if( buff[ i ].EventType == KEY_EVENT &&
-        buff[ i ].Event.KeyEvent.bKeyDown )
+    if( buff[ i ].EventType == KEY_EVENT && buff[ i ].Event.KeyEvent.bKeyDown ) 
     {
       if( buff[ i ].Event.KeyEvent.wVirtualKeyCode == VK_BACK )
       {




More information about the quake3-commits mailing list