TGE: change text color in the WinConsole
by Thomas Bang · 10/01/2010 (9:38 am) · 1 comments
The changes in the source code are very simple:
In winConsole.cc (after the includes) add this line.
At the end of winConsole.cc add this console function.
Also in winConsole.cc, in WinConsole::printf(.....) after...
add this.
OK, that's all we need in the engine.
Example in TorqueScript:
Look into WinCon.cc (line 144) for the flags like FOREGROUND_RED and so on.

In winConsole.cc (after the includes) add this line.
WORD WinConsoleTextColor = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY; //white
At the end of winConsole.cc add this console function.
ConsoleFunction(setWinConsoleTextColor,void,2,2,"setWinConsoleTextColor(int color);")
{
int textColor = atoi(argv[1]);
switch (textColor)
{
case 0: WinConsoleTextColor = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY; //white
break;
case 1: WinConsoleTextColor = FOREGROUND_RED | FOREGROUND_INTENSITY; // red
break;
case 2: WinConsoleTextColor = FOREGROUND_GREEN | FOREGROUND_INTENSITY; // green
break;
case 3: WinConsoleTextColor = FOREGROUND_BLUE | FOREGROUND_INTENSITY; // blue
break;
default: WinConsoleTextColor = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY; //white
}
}Also in winConsole.cc, in WinConsole::printf(.....) after...
Con::stripColorChars(buffer);
add this.
// set the TextColor SetConsoleTextAttribute(stdOut,WinConsoleTextColor);
OK, that's all we need in the engine.
Example in TorqueScript:
enableWinConsole(true);
setWinConsoleTextColor(0); // white text
echo("Dedicated Server");
setWinConsoleTextColor(1); // red text
echo("I am red text");Look into WinCon.cc (line 144) for the flags like FOREGROUND_RED and so on.

About the author

Associate Konrad Kiss
Bitgap Games