-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbge.h
87 lines (68 loc) · 1.57 KB
/
bge.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
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
#include <ncurses.h>
#include <string.h>
unsigned char color;
char lastKey;
int kbhit(void){
struct termios oldt, newt;
int ch;
int oldf;
//Set things up
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO); //Non-canonical input, no echo
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK); //Nonblock = operations not patient
ch = getchar(); //Get our character
//Wrap things up
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
fcntl(STDIN_FILENO, F_SETFL, oldf);
if(ch != EOF){
if(ch == 033){
getchar();
char ch2 = getchar();
lastKey = ch2;
}
ungetc(ch, stdin); //Put character back in stream?
return 1;
}
return 0; //If ch was EOF, then 0 would be returned.
}
void setup(void){
initscr();
start_color();
lastKey = EOF;
}
void chclr(unsigned char c){
attroff(COLOR_PAIR(1));
color = c;
}
void endpr(void){
attroff(COLOR_PAIR(1));
endwin();
}
char getLastKey(void){
return lastKey;
}
void drwbx(int x, int y, int l, int h){
int i, j;
for(i = y; i < (y+h); i++){
//printf("Debug :\t%i\r\n",l);
char c[l+1]; //Contains horizontal slice of box.
for(j = 0; j < l; j++){
//printf("Debug:\t%i\r\n", j);
if((j == 0) || (j == (l-1))){
c[j] = (((i == y) || (i == (y+h-1))) ? '+' : '|');
}else{
c[j] = (((i == y) || (i == (y+h-1))) ? '-' : ' ');
}
}
c[l] = '\0';
//printf("Debug:\t%d\r\n\r\n", (int) strlen(c));
mvprintw(i, x, c);
}
}