-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLS_ConsoleInterface.cpp
More file actions
47 lines (41 loc) · 1.44 KB
/
LS_ConsoleInterface.cpp
File metadata and controls
47 lines (41 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "LS_ConsoleInterface.h"
void CLS_ConsoleInterface::clear()
{
// Description: Clears the screen
COORD coordScreen = { 0, 0 };
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
GetConsoleScreenBufferInfo(hConsole, &csbi);
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
GetConsoleScreenBufferInfo(hConsole, &csbi);
FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
SetConsoleCursorPosition(hConsole, coordScreen);
};
void CLS_ConsoleInterface::gotoXY(int x, int y)
{
// Precondition: two non-negative integer parameters for the x and y are provided
// Description: Moves the cursor to x, y in console window, i.e. x=left\right y=top\bottom
// Example: gotoXY(10, 10) moves the cursor to those coordinates
// gotoXY(0, 10) moves the cursor to those coordinates
// gotoXY(-1, 0), gotoXY(0, -1) and gotoXY(-1, -1) throws an exception
if(x<0||y<0)
{
std::cout << "Coordinates cannot be less than zero." << std::endl;
exit(1);
}
else
{
COORD point;
point.X = x;
point.Y = y;
SetConsoleCursorPosition(hConsole, point);
}
};
void CLS_ConsoleInterface::setColour(COLOUR foreground, COLOUR background)
{
int colour = background * 16 + foreground;
SetConsoleTextAttribute(hConsole, colour);
};
HANDLE CLS_ConsoleInterface::hConsole = GetStdHandle(STD_OUTPUT_HANDLE);