-
Notifications
You must be signed in to change notification settings - Fork 0
/
cge.c
71 lines (61 loc) · 1.6 KB
/
cge.c
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
#include "cge.h"
#include <assert.h>
#include <stdlib.h>
#include <math.h>
/*
*
* CGE
*
*/
// DONE
//#
//# Initialization
//#
void cge_init (struct cge_State *s, int w, int h) {
assert(s != NULL);
assert(w > 0);
assert(h > 0);
s->w = w;
s->h = h;
s->cmd = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(s->cmd, &csbi);
s->canvas_front = csbi.dwCursorPosition;
s->canvas_back.X = s->canvas_front.X;
s->canvas_back.Y = s->canvas_front.Y + h + 2;
}
// CHECK
void cge_next_frame (struct cge_State *s) {
assert(s != NULL);
COORD sz = {s->w, s->h};
COORD pos = {0, 0};
CHAR_INFO* char_info = malloc(sizeof(*char_info) * s->w * s->h);
SMALL_RECT rect = {
s->canvas_back.X + 0,
s->canvas_back.Y + 0,
s->canvas_back.X + s->w - 1,
s->canvas_back.Y + s->h - 1
};
ReadConsoleOutput(s->cmd, char_info, sz, pos, &rect);
rect = (SMALL_RECT){
s->canvas_front.X + 0,
s->canvas_front.Y + 0,
s->canvas_front.X + s->w - 1,
s->canvas_front.Y + s->h - 1
};
WriteConsoleOutput(s->cmd, char_info, sz, pos, &rect);
cgeD_rect_wh(s, 0, 0, s->w, s->h, 0.0, ' ', 0);
}
// FIX
//#
//# Retrieve the character at specified X and Y coordinates
//#
CHAR_INFO cge_at (struct cge_State *s, int x, int y) {
assert(s != NULL);
CHAR_INFO c;
COORD sz = {1, 1};
COORD pos = {0, 0};
SMALL_RECT rect = {x, y, x, y};
ReadConsoleOutput(s->cmd, &c, sz, pos, &rect);
return c;
}