Rev 9576 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7450 | leency | 1 | #ifndef INCLUDE_GUI_H |
5598 | pavelyakov | 2 | #define INCLUDE_GUI_H |
3107 | leency | 3 | |
5598 | pavelyakov | 4 | #ifndef INCLUDE_KOLIBRI_H |
5 | #include "../lib/kolibri.h" |
||
6 | #endif |
||
7 | |||
8 | #ifndef INCLUDE_STRING_H |
||
9 | #include "../lib/strings.h" |
||
10 | #endif |
||
11 | |||
6176 | leency | 12 | #ifndef INCLUDE_RGB_H |
13 | #include "../lib/patterns/rgb.h" |
||
14 | #endif |
||
15 | |||
7086 | leency | 16 | #ifndef INCLUDE_MATH_H |
17 | #include "../lib/math.h" |
||
18 | #endif |
||
19 | |||
7225 | leency | 20 | #include "../lib/gui/tabs.h" |
7491 | leency | 21 | #include "../lib/gui/sensor.h" |
7225 | leency | 22 | #include "../lib/gui/more_less_box.h" |
7450 | leency | 23 | |
24 | #ifndef INCLUDE_CHECKBOX |
||
7243 | leency | 25 | #include "../lib/gui/checkbox.h" |
7450 | leency | 26 | #endif |
27 | |||
7274 | leency | 28 | #include "../lib/gui/child_window.h" |
29 | #include "../lib/gui/text_view_area.h" |
||
9439 | leency | 30 | #include "../lib/gui/reshare.h" |
7450 | leency | 31 | |
32 | #ifndef INCLUDE_MENU_H |
||
7447 | leency | 33 | #include "../lib/gui/menu.h" |
7450 | leency | 34 | #endif |
7225 | leency | 35 | |
7244 | leency | 36 | :int last_free_button_id = 1000; |
7243 | leency | 37 | :int GetFreeButtonId() |
38 | { |
||
39 | last_free_button_id++; |
||
40 | return last_free_button_id; |
||
41 | } |
||
42 | |||
4005 | leency | 43 | :void DrawRectangle(dword x,y,w,h,color1) |
3067 | leency | 44 | { |
7661 | leency | 45 | DrawRectangle3D(x,y,w,h,color1,color1); |
46 | /* |
||
3225 | leency | 47 | DrawBar(x,y,w,1,color1); |
48 | DrawBar(x,y+h,w,1,color1); |
||
49 | DrawBar(x,y,1,h,color1); |
||
50 | DrawBar(x+w,y,1,h+1,color1); |
||
7661 | leency | 51 | */ |
3067 | leency | 52 | } |
53 | |||
5738 | leency | 54 | :void DrawWideRectangle(dword x,y,w,h,boder,color1) |
55 | { |
||
56 | DrawBar(x, y, w, boder, color1); |
||
8949 | leency | 57 | DrawBar(x, y+h-boder, w, boder, EDX); |
58 | DrawBar(x, y+boder, boder, h-boder-boder, EDX); |
||
59 | DrawBar(x+w-boder, y+boder, boder, h-boder-boder, EDX); |
||
5738 | leency | 60 | } |
61 | |||
4005 | leency | 62 | :void DrawRectangle3D(dword x,y,w,h,color1,color2) |
3067 | leency | 63 | { |
3225 | leency | 64 | DrawBar(x,y,w+1,1,color1); |
8949 | leency | 65 | DrawBar(x,y+1,1,h-1,EDX); |
3225 | leency | 66 | DrawBar(x+w,y+1,1,h,color2); |
8949 | leency | 67 | DrawBar(x,y+h,w,1,EDX); |
3067 | leency | 68 | } |
69 | |||
4005 | leency | 70 | :void DrawCaptButton(dword x,y,w,h,id,color_b, color_t,text) |
3067 | leency | 71 | { |
6209 | leency | 72 | dword tx = -strlen(text)*8+w/2+x; |
73 | dword ty = h/2-7+y; |
||
8944 | leency | 74 | DefineButton(x,y,w,h,id,color_b); |
7660 | leency | 75 | WriteText(tx+1,ty+1,0x90,MixColors(color_b,0,230),text); |
6198 | leency | 76 | WriteText(tx,ty,0x90,color_t,text); |
3067 | leency | 77 | } |
78 | |||
7031 | leency | 79 | :int active_button_id = 0; |
6631 | leency | 80 | :int DrawStandartCaptButton(dword x, y, id, text) |
6567 | leency | 81 | { |
7219 | leency | 82 | #define padding_v 5 |
83 | #define padding_h 15 |
||
84 | #define right_margin 12 |
||
85 | #define h padding_v + padding_v + 16 //16 font height |
||
7031 | leency | 86 | int tw = strlen(text)*8; |
87 | int w = tw + padding_h + padding_h; |
||
7806 | leency | 88 | unsigned darker_color = MixColors(sc.button,0,230); |
6567 | leency | 89 | |
8944 | leency | 90 | DefineButton(x,y,w,h,id,sc.button); |
7031 | leency | 91 | |
9576 | leency | 92 | x += padding_h; |
93 | y += padding_v+1; |
||
7031 | leency | 94 | |
9576 | leency | 95 | WriteText(x+1,y+1,0x90,darker_color,text); |
96 | WriteText(x,y,0x90,sc.button_text,text); |
||
97 | |||
7031 | leency | 98 | if (active_button_id==id) { |
9576 | leency | 99 | |
100 | DrawBar(x,y+15,tw,1, darker_color); |
||
101 | DrawBar(x,y+14,tw,1, sc.button_text); |
||
7031 | leency | 102 | } |
103 | |||
6567 | leency | 104 | return w + right_margin; |
105 | } |
||
106 | |||
7660 | leency | 107 | /* UNSTABLE |
7647 | leency | 108 | :unsigned LightenDarkenColor(dword color, amt) { |
109 | dword r = color >> 16 + amt << 16; |
||
110 | dword b = color >> 8 & 0x00FF + amt << 8; |
||
111 | dword g = color & 0x0000FF + amt; |
||
112 | return g | b | r ; |
||
113 | } |
||
7660 | leency | 114 | */ |
7647 | leency | 115 | |
7031 | leency | 116 | :void ActiveButtonSwitch(int min, max) |
117 | { |
||
118 | active_button_id++; |
||
119 | if (active_button_id>max) || (active_button_id |
||
120 | } |
||
121 | |||
4846 | leency | 122 | :void WriteTextCenter(dword x,y,w,color_t,text) |
123 | { |
||
124 | WriteText(-strlen(text)*6+w/2+x+1,y,0x80,color_t,text); |
||
125 | } |
||
126 | |||
5519 | leency | 127 | :void DrawCircle(int x, y, r, color) |
3067 | leency | 128 | { |
129 | int i; |
||
130 | float px=0, py=r, ii = r * 3.1415926 * 2; |
||
131 | FOR (i = 0; i < ii; i++) |
||
132 | { |
||
5519 | leency | 133 | PutPixel(px + x, y - py, color); |
3067 | leency | 134 | px = py / r + px; |
135 | py = -px / r + py; |
||
136 | } |
||
3076 | leency | 137 | } |
3106 | leency | 138 | |
6278 | leency | 139 | :void DrawEditBox(dword edit_box_pointer) |
6193 | leency | 140 | { |
8868 | leency | 141 | dword x,y,w,h,bg; |
6193 | leency | 142 | ESI = edit_box_pointer; |
143 | x = ESI.edit_box.left; |
||
144 | y = ESI.edit_box.top; |
||
145 | w = ESI.edit_box.width+1; |
||
7245 | leency | 146 | h = 22; |
6278 | leency | 147 | if (ESI.edit_box.flags & 100000000000b) bg = 0xCACACA; else bg = 0xFFFfff; |
6678 | leency | 148 | edit_box_draw stdcall (edit_box_pointer); |
7218 | leency | 149 | DrawRectangle3D(x-1, y-1, w+1, h+1, 0xE7E7E7, bg); |
9602 | leency | 150 | DrawRectangle(x-2, y-2, w+3, h+3, sc.line); |
151 | DrawRectangle3D(x-3, y-3, w+5, h+5, sc.dark, sc.light); |
||
6193 | leency | 152 | } |
153 | |||
7658 | leency | 154 | #define DOT_W 37 |
155 | :void DrawFileBox(dword edit_box_pointer, title, btn) |
||
156 | { |
||
9576 | leency | 157 | dword x,y,w,bg,t; |
7658 | leency | 158 | ESI = edit_box_pointer; |
159 | x = ESI.edit_box.left; |
||
160 | y = ESI.edit_box.top; |
||
161 | w = ESI.edit_box.width+1; |
||
9576 | leency | 162 | #define box_h 22 |
7658 | leency | 163 | |
164 | if (ESI.edit_box.flags & 100000000000b) bg = 0xCACACA; else bg = 0xFFFfff; |
||
165 | edit_box_draw stdcall (edit_box_pointer); |
||
9576 | leency | 166 | DrawRectangle3D(x-1, y-1, w+1, box_h+1, 0xE7E7E7, bg); |
9602 | leency | 167 | DrawRectangle(x-2, y-2, w+3, box_h+3, sc.line); |
168 | DrawRectangle3D(x-3, y-3, w+DOT_W+5, box_h+5, sc.dark, sc.light); |
||
7658 | leency | 169 | |
7806 | leency | 170 | WriteText(x-2, y-19, 0x90, sc.work_text, title); |
9576 | leency | 171 | DrawCaptButton(x+w+1, y-2, DOT_W, box_h+3, btn, sc.button, sc.button_text, "..."); |
7658 | leency | 172 | } |
173 | |||
7245 | leency | 174 | :void DrawEditBoxPos(dword x,y, edit_box_pointer) |
175 | { |
||
176 | ESI = edit_box_pointer; |
||
177 | ESI.edit_box.left = x; |
||
178 | ESI.edit_box.top = y; |
||
179 | DrawEditBox(dword edit_box_pointer); |
||
180 | } |
||
181 | |||
8305 | leency | 182 | :void DrawProgressBar(dword st_x, st_y, st_w, st_h, col_fon, col_border, col_fill, progress_percent) |
3114 | leency | 183 | { |
3225 | leency | 184 | int progress_w; |
3114 | leency | 185 | static int fill_old; |
186 | |||
3363 | leency | 187 | //if (progress_percent<=0) {DrawBar(st_x,st_y, st_x + st_w + fill_old + 15,st_h+1, col_fon); fill_old=0; return;} |
188 | if (progress_percent<=0) || (progress_percent>=100) return; |
||
3114 | leency | 189 | |
190 | DrawRectangle(st_x, st_y, st_w,st_h, col_border); |
||
191 | DrawRectangle3D(st_x+1, st_y+1, st_w-2,st_h-2, 0xFFFfff, 0xFFFfff); |
||
3225 | leency | 192 | |
193 | if (progress_percent>0) && (progress_percent<=100) |
||
194 | { |
||
195 | progress_w = st_w - 3 * progress_percent / 100; |
||
196 | DrawBar(st_x+2, st_y+2, progress_w, st_h-3, col_fill); |
||
197 | DrawBar(st_x+2+progress_w, st_y+2, st_w-progress_w-3, st_h-3, 0xFFFfff); |
||
198 | } |
||
3363 | leency | 199 | } |
200 | |||
201 | :void DrawLink(dword x,y,font_type,btn_id, inscription) |
||
202 | { |
||
203 | int w; |
||
204 | WriteText(x,y,font_type,0x4E00E7,inscription); |
||
7031 | leency | 205 | if (font_type==0x80) w = strlen(inscription)*6; else w = strlen(inscription)*8; |
3363 | leency | 206 | DefineButton(x-1,y-1,w,10,btn_id+BT_HIDE,0); |
207 | DrawBar(x,y+8,w,1,0x4E00E7); |
||
208 | } |
||
209 | |||
7998 | leency | 210 | :void PutShadow(dword x,y,w,h,skinned, signed strength) |
3363 | leency | 211 | { |
212 | proc_info wForm; |
||
7910 | leency | 213 | dword shadow_buf = mem_Alloc(w*h*3); |
3363 | leency | 214 | GetProcessInfo(#wForm, SelfInfo); |
3991 | leency | 215 | CopyScreen(shadow_buf, 5*skinned+x+wForm.left, GetSkinHeight()*skinned+y+wForm.top, w, h); |
3363 | leency | 216 | ShadowImage(shadow_buf, w, h, strength); |
9602 | leency | 217 | PutImage(x,y,w,h,shadow_buf); |
3363 | leency | 218 | mem_Free(shadow_buf); |
219 | } |
||
220 | |||
3991 | leency | 221 | :void DrawPopup(dword x,y,w,h,skinned, col_work,col_border) |
222 | { |
||
223 | DrawRectangle(x,y,w,h,col_border); |
||
3992 | leency | 224 | DrawBar(x+1,y+1,w-1,1,0xFFFfff); |
8949 | leency | 225 | DrawBar(x+1,y+2,1,h-2,EDX); |
3992 | leency | 226 | if (col_work!=-1) DrawBar(x+2,y+2,w-2,h-2,col_work); |
3991 | leency | 227 | DrawPopupShadow(x,y,w,h-1,skinned); |
228 | } |
||
229 | |||
7773 | leency | 230 | :void Draw3DPopup(dword x,y,w,h) |
231 | { |
||
9602 | leency | 232 | DrawRectangle3D(x,y,w,h, sc.dark, sc.line); |
233 | DrawBar(x+1,y+1,w-1,1,sc.light); |
||
234 | DrawBar(x+1,y+2,1,h-2,sc.light); |
||
7773 | leency | 235 | DrawPopupShadow(x,y,w,h-1,0); |
236 | } |
||
237 | |||
5499 | leency | 238 | :void DrawPopupShadow(dword x,y,w,h,skinned) |
239 | { |
||
240 | PutShadow(w+x+1,y,1,h+2,skinned,2); |
||
241 | PutShadow(w+x+2,y+1,1,h+2,skinned,1); |
||
242 | PutShadow(x,y+h+2,w+2,1,skinned,2); |
||
243 | PutShadow(x+1,y+h+3,w+1,1,skinned,1); |
||
244 | } |
||
245 | |||
7422 | leency | 246 | :dword GrayScaleImage(dword color_image, w, h) |
3363 | leency | 247 | { |
5761 | leency | 248 | dword i,gray,to,rr,gg,bb; |
249 | to = w*h*3 + color_image; |
||
250 | for (i = color_image; i < to; i+=3) |
||
3363 | leency | 251 | { |
5761 | leency | 252 | rr = DSBYTE[i]; |
253 | gg = DSBYTE[i+1]; |
||
254 | bb = DSBYTE[i+2]; |
||
3363 | leency | 255 | gray = rr*rr; |
256 | gray += gg*gg; |
||
257 | gray += bb*bb; |
||
258 | gray = sqrt(gray) / 3; |
||
5761 | leency | 259 | DSBYTE[i] = DSBYTE[i+1] = DSBYTE[i+2] = gray; |
3363 | leency | 260 | } |
7422 | leency | 261 | return gray; |
3363 | leency | 262 | } |
263 | |||
7998 | leency | 264 | :void ShadowImage(dword color_image, w, h, signed strength) |
3363 | leency | 265 | { |
7998 | leency | 266 | byte col; |
267 | dword to; |
||
3363 | leency | 268 | strength = 10 - strength; |
269 | to = w*h*3 + color_image; |
||
270 | for ( ; color_image < to; color_image++) |
||
271 | { |
||
7998 | leency | 272 | col = math.min(strength * DSBYTE[color_image] / 10, 255); |
3363 | leency | 273 | DSBYTE[color_image] = col; |
274 | } |
||
5598 | pavelyakov | 275 | } |
276 | |||
5962 | leency | 277 | :void WriteTextLines(dword x,y,byte fontType, dword color, text_pointer, line_h) |
278 | { |
||
279 | dword next_word_pointer = strchr(text_pointer, '\n'); |
||
280 | if (next_word_pointer) WriteTextLines(dword x, y+line_h, byte fontType, dword color, next_word_pointer+2, line_h); |
||
281 | ESBYTE[next_word_pointer] = NULL; |
||
282 | WriteText(dword x, y, byte fontType, dword color, text_pointer); |
||
283 | ESBYTE[next_word_pointer] = '\n'; |
||
284 | } |
||
285 | |||
7759 | leency | 286 | :void DrawOvalBorder(dword x,y,w,h, light,dark,right,dots) |
287 | { |
||
288 | DrawBar(x+1, y, w, 1, light); |
||
289 | DrawBar(x+1, y+h+1, w, 1, dark); |
||
290 | DrawBar(x, y+1, 1, h-1, light); |
||
291 | DrawBar(x+w+1, y+2, 1, h-2, right); |
||
292 | |||
293 | PutPixel(x, y, dots); |
||
8949 | leency | 294 | PutPixel(x+w+1, y+h+1, EDX); |
295 | PutPixel(x, y+h+1, EDX); |
||
296 | PutPixel(x+w+1, y, EDX); |
||
7759 | leency | 297 | |
298 | PutPixel(x, y+h, dark); |
||
299 | PutPixel(x+w+1, y+1, light); |
||
300 | PutPixel(x+w+1, y+h, dark); |
||
301 | } |
||
302 | |||
7780 | leency | 303 | :bool skin_is_dark() |
7773 | leency | 304 | { |
8949 | leency | 305 | ESI = #sc.work; |
7780 | leency | 306 | |
8949 | leency | 307 | EDI = DSBYTE[ESI]*DSBYTE[ESI]; |
308 | EDI += DSBYTE[ESI+1]*DSBYTE[ESI+1]; |
||
309 | EDI += DSBYTE[ESI+2]*DSBYTE[ESI+2]; |
||
7780 | leency | 310 | |
8949 | leency | 311 | if (sqrt(EDI) / 3 < 65) { |
7773 | leency | 312 | return true; |
313 | } else { |
||
314 | return false; |
||
315 | } |
||
316 | } |
||
317 | |||
6197 | leency | 318 | //this function increase falue and return it |
319 | //useful for list of controls which goes one after one |
||
7160 | leency | 320 | :struct incn |
6197 | leency | 321 | { |
322 | dword n; |
||
323 | dword inc(dword _addition); |
||
7863 | leency | 324 | dword set(dword _new_val); |
6197 | leency | 325 | }; |
326 | |||
7160 | leency | 327 | :dword incn::inc(dword _addition) |
6197 | leency | 328 | { |
7863 | leency | 329 | n += _addition; |
6197 | leency | 330 | return n; |
331 | } |
||
332 | |||
7863 | leency | 333 | :dword incn::set(dword _new_val) |
334 | { |
||
335 | n =_new_val; |
||
336 | return n; |
||
337 | } |
||
338 | |||
7227 | leency | 339 | //block with hover |
340 | struct block { |
||
341 | int x,y,w,h; |
||
342 | bool hovered(); |
||
343 | void set_size(); |
||
344 | }; |
||
6264 | leency | 345 | |
7227 | leency | 346 | :bool block::hovered() { |
7444 | leency | 347 | if ((mouse.x>=x) && (mouse.y>=y) |
348 | && (mouse.y<=y+h) && (mouse.x<=x+w)) |
||
7227 | leency | 349 | return true; |
350 | return false; |
||
351 | } |
||
6264 | leency | 352 | |
7227 | leency | 353 | :void block::set_size(dword _x, _y, _w, _h) |
354 | { |
||
355 | x=_x; |
||
356 | y=_y; |
||
357 | w=_w; |
||
358 | h=_h; |
||
359 | } |
||
6264 | leency | 360 | |
361 | |||
5598 | pavelyakov | 362 | #endif=x+w))>=y+h)>>>>=100) |