-
Notifications
You must be signed in to change notification settings - Fork 1
/
GUI.cpp
274 lines (258 loc) · 6.89 KB
/
GUI.cpp
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
//
// Created by Штирманн on 03.07.2022.
//
#include <conio.h>
#include <fstream>
#include <iostream>
#include <string>
#include <utility>
#include <windows.h>
#include "GUI.h"
void GUI::ClearRow(int16_t row, uint16_t sym_amo) {
HANDLE h_std_out = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coord = {0, static_cast<int16_t>(row - 1)};
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(h_std_out, &csbi);
DWORD dwNumWritten;
FillConsoleOutputCharacter(h_std_out, ' ', sym_amo, coord, &dwNumWritten);
SetConsoleCursorPosition(h_std_out, csbi.dwCursorPosition);
}
void GUI::WindowMax() {
HWND h_wnd = GetForegroundWindow();
ShowWindow(h_wnd, SW_MAXIMIZE);
COORD position = {0, 0};
HANDLE h_console = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(h_console, position);
}
void GUI::SetColor(uint16_t text, uint16_t bg) {
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hStdOut, (WORD) ((bg << 4) | text));
}
int16_t GUI::Menu(std::string a[], uint32_t n) {
system("cls");
FilePrint(a[0]);
int32_t i = 0;
while (true) {
WindowMax();
uint32_t code = getch();
if (code == 80 || code == 75) {
system("cls");
i++;
if (i == n) {
i = 0;
}
if (i == 0) {
i = 1;
}
FilePrint(a[i]);
} else if (code == 72 || code == 77) {
system("cls");
i--;
if (i < 0) {
i = n - 1;
}
FilePrint(a[i]);
} else if (code == 13) {
system("cls");
return i;
} else if (code == 27) {
exit(0);
}
}
}
void GUI::FontSize(uint16_t font_size) {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_FONT_INFOEX fontInfo;
fontInfo.cbSize = sizeof(fontInfo);
GetCurrentConsoleFontEx(hConsole, TRUE, &fontInfo);
wcscpy(fontInfo.FaceName, L"Consolas");
fontInfo.dwFontSize.Y = font_size;
SetCurrentConsoleFontEx(hConsole, TRUE, &fontInfo);
}
void GUI::PreString(std::string a) {
for (int i = 0; i < 111 - a.size(); ++i) {
std::cout << ' ';
}
std::cout << a;
for (int i = 0; i < 111 - a.size(); ++i) {
std::cout << ' ';
}
std::cout << '\n';
}
void GUI::WinString(uint16_t font_size, uint16_t text_color) {
system("cls");
FontSize(font_size);
SetColor(text_color, 0);
std::cout << " You won! Congratulations! Press Enter. \n";
uint16_t button = getch();
while (button != 13) {
button = getch();
}
FontSize();
SetColor();
}
void GUI::LoseString(uint16_t font_size, uint16_t text_color) {
system("cls");
FontSize(font_size);
SetColor(text_color, 0);
std::cout << " You lost! Good luck next time! Press Enter. \n";
uint16_t button = getch();
while (button != 13) {
button = getch();
}
FontSize();
SetColor();
}
void GUI::Loading(uint32_t sec) {
FontSize(60);
for (uint16_t i = 0; i < 53; ++i) {
std::cout << '\n';
}
for (uint32_t i = 0; i < sec; ++i) {
for (int i = 0; i < 2; ++i) {
std::cout << '\n';
}
for (int i = 0; i < 3; ++i) {
std::cout << ' ';
}
std::cout << '|';
Sleep(125);
system("cls");
for (int i = 0; i < 2; ++i) {
std::cout << '\n';
}
for (int i = 0; i < 3; ++i) {
std::cout << ' ';
}
std::cout << '\\';
Sleep(125);
SemiCls();
for (int i = 0; i < 2; ++i) {
std::cout << '\n';
}
for (int i = 0; i < 3; ++i) {
std::cout << ' ';
}
std::cout << '-';
Sleep(125);
SemiCls();
for (int i = 0; i < 2; ++i) {
std::cout << '\n';
}
for (int i = 0; i < 3; ++i) {
std::cout << ' ';
}
std::cout << '/';
Sleep(125);
SemiCls();
for (int i = 0; i < 2; ++i) {
std::cout << '\n';
}
for (int i = 0; i < 3; ++i) {
std::cout << ' ';
}
std::cout << '|';
Sleep(125);
SemiCls();
for (int i = 0; i < 2; ++i) {
std::cout << '\n';
}
for (int i = 0; i < 3; ++i) {
std::cout << ' ';
}
std::cout << '\\';
Sleep(125);
SemiCls();
for (int i = 0; i < 2; ++i) {
std::cout << '\n';
}
for (int i = 0; i < 3; ++i) {
std::cout << ' ';
}
std::cout << '-';
Sleep(125);
SemiCls();
for (int i = 0; i < 2; ++i) {
std::cout << '\n';
}
for (int i = 0; i < 3; ++i) {
std::cout << ' ';
}
std::cout << '/';
Sleep(125);
SemiCls();
}
FontSize();
}
void GUI::FilePrint(std::string file_name) {
std::ifstream file(file_name);
std::string str;
while (getline(file, str)) {
std::cout << str << '\n';
}
file.close();
}
void GUI::SetCursorPosition(int x, int y) {
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void GUI::SemiCls() {
SetCursorPosition(0, 0);
}
void GUI::Cls() {
char Arr[4096];
HANDLE hCon = (HANDLE) GetStdHandle(STD_OUTPUT_HANDLE);
int x = 0;
for (uint32_t i1 = 0; i1 < 4096; ++i1) {
memset(Arr, ' ', sizeof(Arr));
DWORD w;
WriteConsoleOutputCharacter(hCon, Arr, 4096, COORD{0, 0}, &w);
}
SetCursorPosition(0, 0);
}
void GUI::FancyFrame(std::string x, uint32_t spaces) {
for (uint32_t i = 0; i < spaces; ++i) {
std::cout << ' ';
}
std::cout << ".-";
for (uint32_t i = 0; i < x.size(); ++i) {
std::cout << '-';
}
std::cout << "-.\n";
for (uint32_t i = 0; i < spaces; ++i) {
std::cout << ' ';
}
std::cout << " " << x << " \n";
for (uint32_t i = 0; i < spaces; ++i) {
std::cout << ' ';
}
std::cout << "\'-";
for (uint32_t i = 0; i < x.size(); ++i) {
std::cout << '-';
}
std::cout << "-\'";
}
std::pair<int16_t, int16_t> GUI::ClickCoord() {
HANDLE hin = GetStdHandle(STD_INPUT_HANDLE);
INPUT_RECORD InputRecord;
DWORD Events;
COORD coord;
DWORD prev_mode;
GetConsoleMode(hin, &prev_mode);
SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), ENABLE_EXTENDED_FLAGS | (prev_mode & ~ENABLE_QUICK_EDIT_MODE));
SetConsoleMode(hin, ENABLE_MOUSE_INPUT);
while (true) {
ReadConsoleInput(hin, &InputRecord, 1, &Events);
if (InputRecord.Event.MouseEvent.dwButtonState == RIGHTMOST_BUTTON_PRESSED) {
coord.X = InputRecord.Event.MouseEvent.dwMousePosition.X;
coord.Y = InputRecord.Event.MouseEvent.dwMousePosition.Y;
return (std::make_pair(static_cast<int16_t>(-1 * (coord.X + 1)), static_cast<int16_t>(-1 * (coord.Y + 1))));
} else if (InputRecord.Event.MouseEvent.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED) {
coord.X = InputRecord.Event.MouseEvent.dwMousePosition.X;
coord.Y = InputRecord.Event.MouseEvent.dwMousePosition.Y;
return (std::make_pair(static_cast<int16_t>(coord.X + 1), static_cast<int16_t>(coord.Y + 1)));
}
}
}