-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathterminal_gl.c
87 lines (67 loc) · 1.83 KB
/
terminal_gl.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
char* color_data;
#define SSH_MODE 1
#define DEFAULT 0
struct flag* flags;
char flag_inc = 0;
int ms_sleep = 1000 / 60;
void add_flag(char flagC, int value){
flag_inc++;
struct flag* new_flag = (struct flag*)malloc((flag_inc+1)*sizeof(struct flag));
memcpy(new_flag, flags, (flag_inc - 1) * sizeof(struct flag));
free(flags);
flags = new_flag;
flags[flag_inc - 1].command = flagC;
flags[flag_inc - 1].number = value;
}
void scan_flags(){
int inc = 0;
while(inc < flag_inc){
if(flags[inc].command == SSH_MODE){
ms_sleep = 1000 / 4;
}
inc++;
}
}
void init_window(const char* name){
backend_init();
get_terminal_size(&window_size_y, &window_size_x);
scan_flags();
window_buffer = (char*)allocate_memory(window_size_x*window_size_y);
color_data = (char*)allocate_memory(window_size_x*window_size_y);
if (!window_buffer) {
//printtf("faled to allocate memory\n");
//exit(1);
}
set_process_name(name);
}
void update(){
clear();
draw_buffer(window_buffer, window_size_x, window_size_y, color_data);
}
void fill_screen(char chare, char color){
int i = 0;
int final = window_size_x*window_size_y;
while(i < final){
window_buffer[i] = chare;
color_data[i] = color;
i++;
}
}
void draw_char(char c, int x, int y, char color){
if(x < window_size_x && x > 0){
if(y < window_size_y && y > 0){
window_buffer[window_size_x*y+x] = c;
color_data[window_size_x*y+x] = color;
}
}
}
void draw_text(const char* text, int x, int y, char color){
int inx = x;
int charinc = 0;
int max = x + (x - window_size_x);
while(text[charinc] != '\0'){
draw_char(text[charinc], inx, y, color);
inx++;
charinc++;
}
}