|
#include "Utilities.h"
|
|
|
|
#define FOREGROUND_WHITE FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY
|
|
#define FOREGROUND_YELLOW FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY
|
|
#define BACKGROUND_WHITE BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY
|
|
|
|
Utilities::Utilities()
|
|
{
|
|
hConsole = GetStdHandle( STD_OUTPUT_HANDLE );
|
|
}
|
|
|
|
|
|
|
|
int Utilities::nonblockingGetch()
|
|
{
|
|
int ch = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(kbhit())
|
|
ch = getch();
|
|
return ch;
|
|
}
|
|
|
|
|
|
|
|
int Utilities::checkKey()
|
|
{
|
|
|
|
int ch = nonblockingGetch();
|
|
return ch;
|
|
}
|
|
|
|
void Utilities::getWindowSize(Size& s)
|
|
{
|
|
_CONSOLE_SCREEN_BUFFER_INFO info;
|
|
GetConsoleScreenBufferInfo(hConsole, &info);
|
|
s.setWidth(info.dwMaximumWindowSize.X-1);
|
|
s.setHeight(info.dwMaximumWindowSize.Y-1);
|
|
}
|
|
|
|
|
|
void Utilities::clearConsole()
|
|
{
|
|
COORD coordinate = {0,0};
|
|
DWORD count;
|
|
CONSOLE_SCREEN_BUFFER_INFO info;
|
|
if(GetConsoleScreenBufferInfo(hConsole,&info))
|
|
{
|
|
FillConsoleOutputCharacter(hConsole, (TCHAR) 32, info.dwSize.X * info.dwSize.Y, coordinate, &count);
|
|
FillConsoleOutputAttribute(hConsole, info.wAttributes, info.dwSize.X * info.dwSize.Y, coordinate, &count);
|
|
SetConsoleCursorPosition(hConsole, coordinate);
|
|
}
|
|
}
|
|
|
|
|
|
void Utilities::gotoXY(int x, int y)
|
|
{
|
|
COORD coordinate = {x,y};
|
|
SetConsoleCursorPosition(hConsole, coordinate);
|
|
}
|
|
|
|
|
|
void Utilities::changeColour(WORD colour)
|
|
{
|
|
SetConsoleTextAttribute(hConsole,colour);
|
|
} |