-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterface.cpp
More file actions
36 lines (28 loc) · 840 Bytes
/
Interface.cpp
File metadata and controls
36 lines (28 loc) · 840 Bytes
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
#include <windows.h>
#include <windef.h>
#include <wincon.h>
#include <stdexcept>
#include "Interface.h"
using namespace std;
void Interface::AcquireHandles() {
h_out = GetStdHandle(STD_OUTPUT_HANDLE);
h_in = GetStdHandle(STD_INPUT_HANDLE);
if(h_out == INVALID_HANDLE_VALUE || h_in == INVALID_HANDLE_VALUE) {
throw runtime_error("Unable to acquire console handles");
}
}
void Interface::SetPosition(short x, short y) {
if(h_out != NULL && h_out != INVALID_HANDLE_VALUE) {
COORD pos{x, y};
SetConsoleCursorPosition(h_out, pos);
}
}
void Interface::invertColors() {
if(color <= 0xf) {
color *= 0x10;
SetConsoleTextAttribute(h_out, color);
} else {
color /= 0x10;
SetConsoleTextAttribute(h_out, color);
}
}