Rev 7491 | Rev 7658 | Go to most recent revision | 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" |
||
7450 | leency | 30 | |
31 | #ifndef INCLUDE_MENU_H |
||
7447 | leency | 32 | #include "../lib/gui/menu.h" |
7450 | leency | 33 | #endif |
7225 | leency | 34 | |
7244 | leency | 35 | :int last_free_button_id = 1000; |
7243 | leency | 36 | :int GetFreeButtonId() |
37 | { |
||
38 | last_free_button_id++; |
||
39 | return last_free_button_id; |
||
40 | } |
||
41 | |||
4005 | leency | 42 | :void DrawRectangle(dword x,y,w,h,color1) |
3067 | leency | 43 | { |
3225 | leency | 44 | DrawBar(x,y,w,1,color1); |
45 | DrawBar(x,y+h,w,1,color1); |
||
46 | DrawBar(x,y,1,h,color1); |
||
47 | DrawBar(x+w,y,1,h+1,color1); |
||
3067 | leency | 48 | } |
49 | |||
5738 | leency | 50 | :void DrawWideRectangle(dword x,y,w,h,boder,color1) |
51 | { |
||
52 | DrawBar(x, y, w, boder, color1); |
||
53 | DrawBar(x, y+h-boder, w, boder, color1); |
||
54 | DrawBar(x, y+boder, boder, h-boder-boder, color1); |
||
55 | DrawBar(x+w-boder, y+boder, boder, h-boder-boder, color1); |
||
56 | } |
||
57 | |||
4005 | leency | 58 | :void DrawRectangle3D(dword x,y,w,h,color1,color2) |
3067 | leency | 59 | { |
3225 | leency | 60 | DrawBar(x,y,w+1,1,color1); |
61 | DrawBar(x,y+1,1,h-1,color1); |
||
62 | DrawBar(x+w,y+1,1,h,color2); |
||
63 | DrawBar(x,y+h,w,1,color2); |
||
3067 | leency | 64 | } |
65 | |||
4005 | leency | 66 | :void DrawCaptButton(dword x,y,w,h,id,color_b, color_t,text) |
3067 | leency | 67 | { |
6209 | leency | 68 | dword tx = -strlen(text)*8+w/2+x; |
69 | dword ty = h/2-7+y; |
||
70 | |||
4846 | leency | 71 | if (id>0) DefineButton(x,y,w,h,id,color_b); |
7647 | leency | 72 | WriteText(tx+1,ty+1,0x90,LightenDarkenColor(color_b, -40),text); |
6198 | leency | 73 | WriteText(tx,ty,0x90,color_t,text); |
3067 | leency | 74 | } |
75 | |||
7031 | leency | 76 | :int active_button_id = 0; |
6631 | leency | 77 | :int DrawStandartCaptButton(dword x, y, id, text) |
6567 | leency | 78 | { |
7219 | leency | 79 | #define padding_v 5 |
80 | #define padding_h 15 |
||
81 | #define right_margin 12 |
||
82 | #define h padding_v + padding_v + 16 //16 font height |
||
6567 | leency | 83 | int tx = x + padding_h; |
6678 | leency | 84 | int ty = y + padding_v+1; |
7031 | leency | 85 | int tw = strlen(text)*8; |
86 | int w = tw + padding_h + padding_h; |
||
7647 | leency | 87 | unsigned darker_color = LightenDarkenColor(system.color.work_button, -40); |
6567 | leency | 88 | |
7031 | leency | 89 | |
6631 | leency | 90 | if (id>0) DefineButton(x,y,w,h,id,system.color.work_button); |
7031 | leency | 91 | |
7647 | leency | 92 | WriteText(tx+1,ty+1,0x90,darker_color,text); |
6631 | leency | 93 | WriteText(tx,ty,0x90,system.color.work_button_text,text); |
7031 | leency | 94 | |
95 | if (active_button_id==id) { |
||
7647 | leency | 96 | DrawBar(tx,ty+15,tw,1, darker_color); |
7031 | leency | 97 | DrawBar(tx,ty+14,tw,1, system.color.work_button_text); |
98 | } |
||
99 | |||
6567 | leency | 100 | return w + right_margin; |
101 | } |
||
102 | |||
7647 | leency | 103 | :unsigned LightenDarkenColor(dword color, amt) { |
104 | dword r = color >> 16 + amt << 16; |
||
105 | dword b = color >> 8 & 0x00FF + amt << 8; |
||
106 | dword g = color & 0x0000FF + amt; |
||
107 | return g | b | r ; |
||
108 | } |
||
109 | |||
7031 | leency | 110 | :void ActiveButtonSwitch(int min, max) |
111 | { |
||
112 | active_button_id++; |
||
113 | if (active_button_id>max) || (active_button_id |
||
114 | } |
||
115 | |||
4846 | leency | 116 | :void WriteTextCenter(dword x,y,w,color_t,text) |
117 | { |
||
118 | WriteText(-strlen(text)*6+w/2+x+1,y,0x80,color_t,text); |
||
119 | } |
||
120 | |||
5519 | leency | 121 | :void DrawCircle(int x, y, r, color) |
3067 | leency | 122 | { |
123 | int i; |
||
124 | float px=0, py=r, ii = r * 3.1415926 * 2; |
||
125 | FOR (i = 0; i < ii; i++) |
||
126 | { |
||
5519 | leency | 127 | PutPixel(px + x, y - py, color); |
3067 | leency | 128 | px = py / r + px; |
129 | py = -px / r + py; |
||
130 | } |
||
3076 | leency | 131 | } |
3106 | leency | 132 | |
6278 | leency | 133 | :void DrawEditBox(dword edit_box_pointer) |
6193 | leency | 134 | { |
7245 | leency | 135 | dword x,y,w,h,bg,t; |
6193 | leency | 136 | ESI = edit_box_pointer; |
137 | x = ESI.edit_box.left; |
||
138 | y = ESI.edit_box.top; |
||
139 | w = ESI.edit_box.width+1; |
||
7245 | leency | 140 | h = 22; |
6278 | leency | 141 | if (ESI.edit_box.flags & 100000000000b) bg = 0xCACACA; else bg = 0xFFFfff; |
6678 | leency | 142 | edit_box_draw stdcall (edit_box_pointer); |
7218 | leency | 143 | DrawRectangle3D(x-1, y-1, w+1, h+1, 0xE7E7E7, bg); |
144 | DrawRectangle(x-2, y-2, w+3, h+3, system.color.work_graph); |
||
145 | DrawRectangle3D(x-3, y-3, w+5, h+5, system.color.work_dark, system.color.work_light); |
||
6193 | leency | 146 | } |
147 | |||
7245 | leency | 148 | :void DrawEditBoxPos(dword x,y, edit_box_pointer) |
149 | { |
||
150 | ESI = edit_box_pointer; |
||
151 | ESI.edit_box.left = x; |
||
152 | ESI.edit_box.top = y; |
||
153 | DrawEditBox(dword edit_box_pointer); |
||
154 | } |
||
155 | |||
4686 | leency | 156 | :void DrawProgressBar(dword st_x, st_y, st_w, st_h, col_fon, col_border, col_fill, col_text, progress_percent) |
3114 | leency | 157 | { |
3225 | leency | 158 | int progress_w; |
3114 | leency | 159 | static int fill_old; |
160 | |||
3363 | leency | 161 | //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;} |
162 | if (progress_percent<=0) || (progress_percent>=100) return; |
||
3114 | leency | 163 | |
164 | DrawRectangle(st_x, st_y, st_w,st_h, col_border); |
||
165 | DrawRectangle3D(st_x+1, st_y+1, st_w-2,st_h-2, 0xFFFfff, 0xFFFfff); |
||
3225 | leency | 166 | |
167 | if (progress_percent>0) && (progress_percent<=100) |
||
168 | { |
||
169 | progress_w = st_w - 3 * progress_percent / 100; |
||
170 | DrawBar(st_x+2, st_y+2, progress_w, st_h-3, col_fill); |
||
171 | DrawBar(st_x+2+progress_w, st_y+2, st_w-progress_w-3, st_h-3, 0xFFFfff); |
||
172 | } |
||
3363 | leency | 173 | } |
174 | |||
175 | :void DrawLink(dword x,y,font_type,btn_id, inscription) |
||
176 | { |
||
177 | int w; |
||
178 | WriteText(x,y,font_type,0x4E00E7,inscription); |
||
7031 | leency | 179 | if (font_type==0x80) w = strlen(inscription)*6; else w = strlen(inscription)*8; |
3363 | leency | 180 | DefineButton(x-1,y-1,w,10,btn_id+BT_HIDE,0); |
181 | DrawBar(x,y+8,w,1,0x4E00E7); |
||
182 | } |
||
183 | |||
3991 | leency | 184 | :void PutShadow(dword x,y,w,h,skinned,strength) |
3363 | leency | 185 | { |
186 | proc_info wForm; |
||
187 | dword shadow_buf, skin_height; |
||
188 | shadow_buf = mem_Alloc(w*h*3); |
||
189 | GetProcessInfo(#wForm, SelfInfo); |
||
3991 | leency | 190 | CopyScreen(shadow_buf, 5*skinned+x+wForm.left, GetSkinHeight()*skinned+y+wForm.top, w, h); |
3363 | leency | 191 | ShadowImage(shadow_buf, w, h, strength); |
192 | _PutImage(x,y,w,h,shadow_buf); |
||
193 | mem_Free(shadow_buf); |
||
194 | } |
||
195 | |||
3991 | leency | 196 | :void DrawPopup(dword x,y,w,h,skinned, col_work,col_border) |
197 | { |
||
198 | DrawRectangle(x,y,w,h,col_border); |
||
3992 | leency | 199 | DrawBar(x+1,y+1,w-1,1,0xFFFfff); |
4029 | leency | 200 | DrawBar(x+1,y+2,1,h-2,0xFFFfff); |
3992 | leency | 201 | if (col_work!=-1) DrawBar(x+2,y+2,w-2,h-2,col_work); |
3991 | leency | 202 | DrawPopupShadow(x,y,w,h-1,skinned); |
203 | } |
||
204 | |||
5499 | leency | 205 | :void DrawPopupShadow(dword x,y,w,h,skinned) |
206 | { |
||
207 | PutShadow(w+x+1,y,1,h+2,skinned,2); |
||
208 | PutShadow(w+x+2,y+1,1,h+2,skinned,1); |
||
209 | PutShadow(x,y+h+2,w+2,1,skinned,2); |
||
210 | PutShadow(x+1,y+h+3,w+1,1,skinned,1); |
||
211 | } |
||
212 | |||
7422 | leency | 213 | :dword GrayScaleImage(dword color_image, w, h) |
3363 | leency | 214 | { |
5761 | leency | 215 | dword i,gray,to,rr,gg,bb; |
216 | to = w*h*3 + color_image; |
||
217 | for (i = color_image; i < to; i+=3) |
||
3363 | leency | 218 | { |
5761 | leency | 219 | rr = DSBYTE[i]; |
220 | gg = DSBYTE[i+1]; |
||
221 | bb = DSBYTE[i+2]; |
||
3363 | leency | 222 | gray = rr*rr; |
223 | gray += gg*gg; |
||
224 | gray += bb*bb; |
||
225 | gray = sqrt(gray) / 3; |
||
5761 | leency | 226 | DSBYTE[i] = DSBYTE[i+1] = DSBYTE[i+2] = gray; |
3363 | leency | 227 | } |
7422 | leency | 228 | return gray; |
3363 | leency | 229 | } |
230 | |||
231 | :void ShadowImage(dword color_image, w, h, strength) |
||
232 | { |
||
233 | dword col, to; |
||
234 | strength = 10 - strength; |
||
235 | to = w*h*3 + color_image; |
||
236 | for ( ; color_image < to; color_image++) |
||
237 | { |
||
238 | col = strength * DSBYTE[color_image] / 10; |
||
239 | DSBYTE[color_image] = col; |
||
240 | } |
||
5598 | pavelyakov | 241 | } |
242 | |||
5962 | leency | 243 | :void WriteTextLines(dword x,y,byte fontType, dword color, text_pointer, line_h) |
244 | { |
||
245 | dword next_word_pointer = strchr(text_pointer, '\n'); |
||
246 | if (next_word_pointer) WriteTextLines(dword x, y+line_h, byte fontType, dword color, next_word_pointer+2, line_h); |
||
247 | ESBYTE[next_word_pointer] = NULL; |
||
248 | WriteText(dword x, y, byte fontType, dword color, text_pointer); |
||
249 | ESBYTE[next_word_pointer] = '\n'; |
||
250 | } |
||
251 | |||
6197 | leency | 252 | //this function increase falue and return it |
253 | //useful for list of controls which goes one after one |
||
7160 | leency | 254 | :struct incn |
6197 | leency | 255 | { |
256 | dword n; |
||
257 | dword inc(dword _addition); |
||
258 | }; |
||
259 | |||
7160 | leency | 260 | :dword incn::inc(dword _addition) |
6197 | leency | 261 | { |
262 | n+=_addition; |
||
263 | return n; |
||
264 | } |
||
265 | |||
7227 | leency | 266 | //block with hover |
267 | struct block { |
||
268 | int x,y,w,h; |
||
269 | bool hovered(); |
||
270 | void set_size(); |
||
271 | }; |
||
6264 | leency | 272 | |
7227 | leency | 273 | :bool block::hovered() { |
7444 | leency | 274 | if ((mouse.x>=x) && (mouse.y>=y) |
275 | && (mouse.y<=y+h) && (mouse.x<=x+w)) |
||
7227 | leency | 276 | return true; |
277 | return false; |
||
278 | } |
||
6264 | leency | 279 | |
7227 | leency | 280 | :void block::set_size(dword _x, _y, _w, _h) |
281 | { |
||
282 | x=_x; |
||
283 | y=_y; |
||
284 | w=_w; |
||
285 | h=_h; |
||
286 | } |
||
6264 | leency | 287 | |
288 | |||
7227 | leency | 289 | |
290 | |||
291 | |||
5598 | pavelyakov | 292 | #endif=x+w))>=y+h)>>>=100) |