-
Notifications
You must be signed in to change notification settings - Fork 0
/
display.h
105 lines (85 loc) · 2.14 KB
/
display.h
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
#ifndef _DISPLAY_H_INCLUDED_
#define _DISPLAY_H_INCLUDED_
const int COLOR_BLUE_BLACK = 1;
const int COLOR_CYAN_BLACK = 2;
const int COLOR_GREEN_BLACK = 3;
const int COLOR_YELLOW_BLACK = 4;
const int COLOR_RED_BLACK = 5;
const int COLOR_WHITE_BLACK = 6;
const int COLOR_BLACK_BLUE = 7;
const int COLOR_BLACK_CYAN = 8;
const int COLOR_BLACK_GREEN = 9;
const int COLOR_BLACK_YELLOW = 10;
const int COLOR_BLACK_RED = 11;
const int COLOR_BLACK_WHITE = 12;
const int COLOR_RED_WHITE = 13;
#include <ncurses.h>
class Display
{
public:
// get coordinates
int xmax,ymax;
int vertical_quad_width;
int vertical_quad_height;
int vertical_quad_top = 2;
MEVENT event;
bool has_mouse_event = false;
int mouse_x, mouse_y;
int c;
void start() {
WINDOW *win = initscr();
cbreak();
noecho();
curs_set(0);
nodelay(win, true);
keypad(win, true);
getmaxyx(win, ymax, xmax);
ymax = ymax - 1;
xmax = xmax - 1;
vertical_quad_width = ((xmax+4) / 4) - 1;
vertical_quad_height = ymax - 6;
start_color();
// black text color background
init_pair(1, COLOR_BLACK, COLOR_BLUE);
init_pair(2, COLOR_BLACK, COLOR_CYAN);
init_pair(3, COLOR_BLACK, COLOR_GREEN);
init_pair(4, COLOR_BLACK, COLOR_YELLOW);
init_pair(5, COLOR_BLACK, COLOR_RED);
init_pair(6, COLOR_BLACK, COLOR_WHITE);
// color text black background
init_pair(7, COLOR_BLUE, COLOR_BLACK);
init_pair(8, COLOR_CYAN, COLOR_BLACK);
init_pair(9, COLOR_GREEN, COLOR_BLACK);
init_pair(10, COLOR_YELLOW, COLOR_BLACK);
init_pair(11, COLOR_RED, COLOR_BLACK);
init_pair(12, COLOR_WHITE, COLOR_BLACK);
// color text color background
init_pair(13, COLOR_WHITE, COLOR_RED);
mousemask(ALL_MOUSE_EVENTS, NULL);
}
void checkInput() {
c = getch();
switch(c) {
case KEY_MOUSE:
if(getmouse(&event) == OK)
{
if(event.bstate & BUTTON1_RELEASED)
{
mouse_x = event.x;
mouse_y = event.y;
has_mouse_event = true;
}
}
}
}
void onLoopStart() {
erase();
}
void onLoopEnd() {
refresh();
}
void end() {
endwin();
}
};
#endif