-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui_space.c
229 lines (211 loc) · 12.1 KB
/
gui_space.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#include "stdlib.h"
#include "keyboard.h"
#include "platform.h"
#include "core.h"
#include "conf.h"
#include "gui.h"
#include "gui_draw.h"
#include "gui_batt.h"
#include "gui_space.h"
//-------------------------------------------------------------------
static char osd_buf[32];
//-------------------------------------------------------------------
unsigned long get_space_perc() {
return GetFreeCardSpaceKb()*100/GetTotalCardSpaceKb();
}
static void gui_space_draw_spacebar_horizontal() {
coord x;
color cl = conf.space_color;
int perc = get_space_perc(),height = 2;
float size = 0;
if (conf.space_warn_type == 0) {
cl = (perc<=conf.space_perc_warn)?conf.osd_color_warn:(conf.space_color);
}
if (conf.space_warn_type == 1) {
cl = (GetFreeCardSpaceKb()/1024<=conf.space_mb_warn)?conf.osd_color_warn:(conf.space_color);
}
if (conf.space_warn_type == 2) {
cl = conf.space_color;
}
// space icon / bar
height = conf.space_bar_width+1;
if (conf.space_bar_size == 0) {
size = screen_width/4-4;
if (conf.space_hor_pos.x>(screen_width-size)) {
conf.space_hor_pos.x = screen_width-size;
}
}
if (conf.space_bar_size == 1) {
size = screen_width/2-4;
if (conf.space_hor_pos.x>(screen_width-size)) {
conf.space_hor_pos.x = screen_width-size;
}
}
if (conf.space_bar_size == 2) {
size = screen_width-4;
if (conf.space_hor_pos.x>(screen_width-size)) {
conf.space_hor_pos.x = 0;
}
}
if (conf.space_hor_pos.y > (screen_height-height-3)) {
conf.space_hor_pos.y = screen_height-height-3;
}
draw_rect(conf.space_hor_pos.x+1, conf.space_hor_pos.y+1, conf.space_hor_pos.x+1+size+2, conf.space_hor_pos.y+1+height+1, cl);
draw_line(conf.space_hor_pos.x+1-1, conf.space_hor_pos.y+1-1, conf.space_hor_pos.x+1-1, conf.space_hor_pos.y+1+height+2, COLOR_BLACK); // l
draw_line(conf.space_hor_pos.x+1-1, conf.space_hor_pos.y+1-1, conf.space_hor_pos.x+1+size+3, conf.space_hor_pos.y+1-1, COLOR_BLACK); // t
draw_line(conf.space_hor_pos.x+1-1, conf.space_hor_pos.y+1+height+2, conf.space_hor_pos.x+1+size+3, conf.space_hor_pos.y+1+height+2, COLOR_BLACK); // b
draw_line(conf.space_hor_pos.x+1+size+3, conf.space_hor_pos.y+1-1, conf.space_hor_pos.x+1+size+3, conf.space_hor_pos.y+1+height+2, COLOR_BLACK); // r
// space bar fill
x=conf.space_hor_pos.x+size-(perc/(100/size));
if (x<=conf.space_hor_pos.x+1) x=conf.space_hor_pos.x+1;
if (x>conf.space_hor_pos.x+size) x=conf.space_hor_pos.x+size;
draw_filled_rect(conf.space_hor_pos.x+1+1, conf.space_hor_pos.y+1+1, x-1, conf.space_hor_pos.y+1+height, MAKE_COLOR(COLOR_TRANSPARENT, COLOR_BLACK));
draw_filled_rect(x, conf.space_hor_pos.y+1+1, conf.space_hor_pos.x+1+size+2, conf.space_hor_pos.y+1+height, MAKE_COLOR(cl, cl));
}
static void gui_space_draw_spacebar_vertical() {
coord y;
color cl = conf.space_color;
int perc = get_space_perc(), width = 2;
float size = 0;
if (conf.space_warn_type == 0) {
cl = (perc<=conf.space_perc_warn)?conf.osd_color_warn:(conf.space_color);
}
if (conf.space_warn_type == 1) {
cl = (GetFreeCardSpaceKb()/1024<=conf.space_mb_warn)?conf.osd_color_warn:(conf.space_color);
}
if (conf.space_warn_type == 2) {
cl = conf.space_color;
}
// space icon / bar
width = conf.space_bar_width+1;
if (conf.space_bar_size == 0) {
size = screen_height/4-4;
if (conf.space_ver_pos.y>(screen_height-size)) {
conf.space_ver_pos.y = screen_height-size;
}
}
if (conf.space_bar_size == 1) {
size = screen_height/2-4;
if (conf.space_ver_pos.y>(screen_height-size)) {
conf.space_ver_pos.y = screen_height-size;
}
}
if (conf.space_bar_size == 2) {
size = screen_height-4;
if (conf.space_ver_pos.y>(screen_height-size)) {
conf.space_ver_pos.y = 0;
}
}
if (conf.space_ver_pos.x > (screen_width-width-3)) {
conf.space_ver_pos.x = screen_width-width-3;
}
draw_rect(conf.space_ver_pos.x+1, conf.space_ver_pos.y+1, conf.space_ver_pos.x+1+width+1, conf.space_ver_pos.y+1+size+2, cl);
draw_line(conf.space_ver_pos.x+1-1, conf.space_ver_pos.y+1-1, conf.space_ver_pos.x+1-1, conf.space_ver_pos.y+1+5, COLOR_BLACK); // l
draw_line(conf.space_ver_pos.x+1-1, conf.space_ver_pos.y+1-1, conf.space_ver_pos.x+1+width+2, conf.space_ver_pos.y+1-1, COLOR_BLACK); // t
draw_line(conf.space_ver_pos.x+1-1, conf.space_ver_pos.y+1+size+3, conf.space_ver_pos.x+1+width+2, conf.space_ver_pos.y+1+size+3, COLOR_BLACK); // b
draw_line(conf.space_ver_pos.x+1+width+2, conf.space_ver_pos.y+1-1, conf.space_ver_pos.x+1+width+2, conf.space_ver_pos.y+1+size+3, COLOR_BLACK); // r
// space bar fill
y=conf.space_ver_pos.y+size-(perc/(100/size));
if (y<=conf.space_ver_pos.y+1) y=conf.space_ver_pos.y+1;
if (y>conf.space_ver_pos.y+size) y=conf.space_ver_pos.y+size;
draw_filled_rect(conf.space_ver_pos.x+1+1, conf.space_ver_pos.y+1+1, conf.space_ver_pos.x+1+width, y-1, MAKE_COLOR(COLOR_TRANSPARENT, COLOR_BLACK));
draw_filled_rect(conf.space_ver_pos.x+1+1, y, conf.space_ver_pos.x+1+width, conf.space_ver_pos.y+1+size+2, MAKE_COLOR(cl, cl));
}
static void gui_space_draw_icon() {
coord x;
color cl = conf.space_color;
int perc = get_space_perc();
if (conf.space_warn_type == 0) {
cl = (perc<=conf.space_perc_warn)?conf.osd_color_warn:(conf.space_color);
}
if (conf.space_warn_type == 1) {
cl = (GetFreeCardSpaceKb()/1024<=conf.space_mb_warn)?conf.osd_color_warn:(conf.space_color);
}
if (conf.space_warn_type == 2) {
cl = conf.space_color;
}
int i;
int le = 23; // length
int wi = 15; // width
draw_line(conf.space_icon_pos.x+5, conf.space_icon_pos.y, conf.space_icon_pos.x+le, conf.space_icon_pos.y, COLOR_BLACK); // outer top
draw_line(conf.space_icon_pos.x+6, conf.space_icon_pos.y+1, conf.space_icon_pos.x+le-1, conf.space_icon_pos.y+1, MAKE_COLOR(cl, cl)); // inner top
draw_line(conf.space_icon_pos.x, conf.space_icon_pos.y+5, conf.space_icon_pos.x, conf.space_icon_pos.y+wi, COLOR_BLACK); // outer left
draw_line(conf.space_icon_pos.x+1, conf.space_icon_pos.y+6, conf.space_icon_pos.x+1, conf.space_icon_pos.y+wi-1, MAKE_COLOR(cl, cl)); // inner left
draw_line(conf.space_icon_pos.x, conf.space_icon_pos.y+wi, conf.space_icon_pos.x+le, conf.space_icon_pos.y+wi, COLOR_BLACK); // outer bottom
draw_line(conf.space_icon_pos.x+1, conf.space_icon_pos.y+wi-1, conf.space_icon_pos.x+le-1, conf.space_icon_pos.y+wi-1, MAKE_COLOR(cl, cl)); // inner bottom
draw_line(conf.space_icon_pos.x+le, conf.space_icon_pos.y, conf.space_icon_pos.x+le, conf.space_icon_pos.y+wi, COLOR_BLACK); // outer right
draw_line(conf.space_icon_pos.x+le-1, conf.space_icon_pos.y+1, conf.space_icon_pos.x+le-1, conf.space_icon_pos.y+wi-1, MAKE_COLOR(cl, cl)); // inner right
draw_line(conf.space_icon_pos.x+5, conf.space_icon_pos.y, conf.space_icon_pos.x, conf.space_icon_pos.y+5, COLOR_BLACK); // edge
draw_line(conf.space_icon_pos.x+5, conf.space_icon_pos.y+1, conf.space_icon_pos.x+1, conf.space_icon_pos.y+5, MAKE_COLOR(cl, cl)); // edge
draw_line(conf.space_icon_pos.x+6, conf.space_icon_pos.y+1, conf.space_icon_pos.x+1, conf.space_icon_pos.y+6, MAKE_COLOR(cl, cl)); // edge
// memory fill
x=le-(perc*(le-3)/100)-2;
if (x>5) draw_line(conf.space_icon_pos.x+6, conf.space_icon_pos.y+2, conf.space_icon_pos.x+x, conf.space_icon_pos.y+2, COLOR_BLACK);
if (x>2) draw_line(conf.space_icon_pos.x+x+1, conf.space_icon_pos.y+2, conf.space_icon_pos.x+le-2, conf.space_icon_pos.y+2, MAKE_COLOR(cl, cl));
else draw_line(conf.space_icon_pos.x+4, conf.space_icon_pos.y+2, conf.space_icon_pos.x+le-2, conf.space_icon_pos.y+2, MAKE_COLOR(cl, cl));
for(i=3; i<7; i++) { // /--------------|
if (x>7-i) draw_pixel(conf.space_icon_pos.x+8-i, conf.space_icon_pos.y+i, COLOR_BLACK); // / 1st for loop |
if (x>7-i) draw_pixel(conf.space_icon_pos.x+x, conf.space_icon_pos.y+i, COLOR_BLACK); // /__________________|
draw_line(conf.space_icon_pos.x+x+1, conf.space_icon_pos.y+i, conf.space_icon_pos.x+le-2, conf.space_icon_pos.y+i, MAKE_COLOR(cl, cl)); // | |
} // | 2nd for loop |
for(i=7; i<wi-2; i++) { // | |
if (x>1) draw_pixel(conf.space_icon_pos.x+2, conf.space_icon_pos.y+i, COLOR_BLACK); // |-------------------|
if (x>1) draw_pixel(conf.space_icon_pos.x+x, conf.space_icon_pos.y+i, COLOR_BLACK);
draw_line(conf.space_icon_pos.x+x+1, conf.space_icon_pos.y+i, conf.space_icon_pos.x+le-2, conf.space_icon_pos.y+i, MAKE_COLOR(cl, cl));
}
if (x>1) draw_line(conf.space_icon_pos.x+2, conf.space_icon_pos.y+wi-2, conf.space_icon_pos.x+x, conf.space_icon_pos.y+wi-2, COLOR_BLACK);
draw_line(conf.space_icon_pos.x+x+1, conf.space_icon_pos.y+wi-2, conf.space_icon_pos.x+le-2, conf.space_icon_pos.y+wi-2, MAKE_COLOR(cl, cl));
}
//-------------------------------------------------------------------
static void gui_space_draw_percent() {
int perc = get_space_perc();
color cl = conf.space_color;
if (conf.space_warn_type == 0) {
cl = (perc<=conf.space_perc_warn)?conf.osd_color_warn:(conf.space_color);
}
if (conf.space_warn_type == 1) {
cl = (GetFreeCardSpaceKb()/1024<=conf.space_mb_warn)?conf.osd_color_warn:(conf.space_color);
}
if (conf.space_warn_type == 2) {
cl = conf.space_color;
}
sprintf(osd_buf, "%3d%%", get_space_perc());
osd_buf[5]=0;
draw_string(conf.space_txt_pos.x, conf.space_txt_pos.y, osd_buf, cl);
}
//-------------------------------------------------------------------
static void gui_space_draw_mb() {
int perc = get_space_perc();
color cl = conf.space_color;
if (conf.space_warn_type == 0) {
cl = (perc<=conf.space_perc_warn)?conf.osd_color_warn:(conf.space_color);
}
if (conf.space_warn_type == 1) {
cl = (GetFreeCardSpaceKb()/1024<=conf.space_mb_warn)?conf.osd_color_warn:(conf.space_color);
}
if (conf.space_warn_type == 2) {
cl = conf.space_color;
}
unsigned int freemb=GetFreeCardSpaceKb()/1024;
if (freemb < 10000) sprintf(osd_buf, "%3d%M",freemb);
else sprintf(osd_buf, "%3d%G",freemb/1024); // if 10 GiB or more free, print in GiB instead of MiB
osd_buf[5]=0;
draw_string(conf.space_txt_pos.x, conf.space_txt_pos.y, osd_buf, cl);
}
//-------------------------------------------------------------------
void gui_space_draw_osd() {
if (conf.space_icon_show) {
gui_space_draw_icon();
}
if (conf.space_perc_show) {
gui_space_draw_percent();
} else if (conf.space_mb_show) {
gui_space_draw_mb();
}
if (conf.space_bar_show==1) {
gui_space_draw_spacebar_horizontal();
}
if (conf.space_bar_show==2) {
gui_space_draw_spacebar_vertical();
}
}