-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathio.cpp
More file actions
69 lines (60 loc) · 1.64 KB
/
io.cpp
File metadata and controls
69 lines (60 loc) · 1.64 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "io.h"
#include <Windows.h>
#include <conio.h>
using namespace std;
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
SMALL_RECT src;
CHAR_INFO* buffer = (CHAR_INFO*)malloc(sizeof(CHAR_INFO));
CONSOLE_FONT_INFOEX fontInfo;
COORD xy;
COORD x0y0;
void SetSymbol(short x, short y, wchar_t c, short background, short text) {
buffer[x + y * xy.X].Char.UnicodeChar = c;
buffer[x + y * xy.X].Attributes = (WORD)((background << 4) | text);
}
void Clear() {
for (int i = 0; i < xy.X * xy.Y; i++) {
buffer[i].Char.UnicodeChar = ' ';
buffer[i].Attributes = (WORD)0;
}
}
void Init(wstring name) {
srand((int)time(0));
fontInfo.cbSize = sizeof(fontInfo);
fontInfo.FontFamily = FF_DONTCARE;
fontInfo.FontWeight = 400;
wcscpy_s(fontInfo.FaceName, L"Lucida Console");
SetCurrentConsoleFontEx(hStdOut, FALSE, &fontInfo);
SetConsoleTitleW(name.c_str());
CONSOLE_CURSOR_INFO cur = { 1, false };
SetConsoleCursorInfo(hStdOut, &cur);
src.Left = 0;
src.Top = 0;
x0y0.X = 0;
x0y0.Y = 0;
}
void SetWindow(short x, short y, short fontSize) {
fontInfo.dwFontSize.Y = fontSize;
SetCurrentConsoleFontEx(hStdOut, FALSE, &fontInfo);
src.Right = x;
src.Bottom = y;
xy.X = src.Right + 1;
xy.Y = src.Bottom + 1;
SetConsoleScreenBufferSize(hStdOut, xy);
SetConsoleWindowInfo(hStdOut, true, &src);
SetConsoleScreenBufferSize(hStdOut, xy);
SetConsoleWindowInfo(hStdOut, true, &src);
free(buffer);
buffer = (CHAR_INFO*)malloc(xy.X * xy.Y * sizeof(CHAR_INFO));
Clear();
}
short ReadKey() {
return _getch();
}
void Render() {
WriteConsoleOutputW(hStdOut, buffer, xy, x0y0, &src);
Clear();
}
wstring to_wstring(int i) {
return to_wstring((long double)i);
}