-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConsoleDraw.cpp
76 lines (63 loc) · 1.8 KB
/
ConsoleDraw.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
#include "console.hpp"
void Console::clear_screen(void) {
memset(buffer, 0, width * height * sizeof(CHAR_INFO));
}
void Console::update_screen(void) {
SMALL_RECT rcRegion = {0, 0, width - 1, height - 1};
COORD dims = {width, height};
COORD orig = {0, 0};
WriteConsoleOutputW(Output, buffer, dims, orig, &rcRegion);
}
void Console::draw_char(int x, int y, wchar_t c, short cc) {
if ((x >= 0 && x < width) && (y >= 0 && y < height)) {
buffer[x + (y * width)].Char.UnicodeChar = c;
buffer[x + (y * width)].Attributes = cc;
}
}
void Console::draw_string(int x, int y, wchar_t *s, short cc) {
int len = wcslen(s);
for (int i=0; i<len; i++) {
draw_char(x + i, y, s[i], cc);
}
}
void Console::draw_rect(int x, int y, int w, int h, short cc) {
for (int yy=y; yy<(y+h); yy++) {
for (int xx=x; xx<(x+w); xx++) {
draw_char(xx, yy, ' ', cc);
}
}
}
void Console::draw_frame(int x, int y, int w, int h, short cc) {
for (int yy=y; yy<(y+h); yy++) {
for (int xx=x; xx<(x+w); xx++) {
if (xx == x || xx == (x+w-1) || yy == y || yy == (y+h-1)) {
draw_char(xx, yy, ' ', cc);
}
}
}
}
void Console::draw_colors(int x, int y, int w, int h, short *cc, int len) {
int i=0;
for (int yy=y; yy<(y+h) && i<len; yy++) {
for (int xx=x; xx<(x+w) && i<len; xx++) {
buffer[xx + (yy * width)].Attributes = cc[i++];
}
}
}
void Console::draw_chars(int x, int y, int w, int h, wchar_t *s) {
int i=0;
int len = wcslen(s);
for (int yy=y; yy<(y+h) && i<len; yy++) {
for (int xx=x; xx<(x+w) && i<len; xx++) {
buffer[xx + (yy * width)].Char.UnicodeChar = s[i++];
}
}
}
void Console::draw_substr(int x, int y, wchar_t *s, short cc, int start, int count) {
int slen = wcslen(s);
if (start < slen) {
for (int i=start, xx=0; i<start+count && i<slen; i++, xx++) {
draw_char(x + xx, y, s[i], cc);
}
}
}