Rev 4429 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4429 | Serge | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; |
||
4 | ;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa ;; |
||
5 | ;; Distributed under terms of the GNU General Public License ;; |
||
6 | ;; ;; |
||
7 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
8 | |||
9 | $Revision: 2455 $ |
||
10 | |||
11 | ;============================================================================== |
||
12 | ;///// public functions /////////////////////////////////////////////////////// |
||
13 | ;============================================================================== |
||
14 | |||
15 | button.MAX_BUTTONS = 4095 |
||
16 | |||
17 | struct SYS_BUTTON |
||
18 | pslot dw ? |
||
19 | id_lo dw ? |
||
20 | left dw ? |
||
21 | width dw ? |
||
22 | top dw ? |
||
23 | height dw ? |
||
24 | id_hi dw ? |
||
25 | dw ? |
||
26 | ends |
||
27 | |||
28 | align 4 |
||
29 | ;------------------------------------------------------------------------------ |
||
30 | syscall_button: ;///// system function 8 ////////////////////////////////////// |
||
31 | ;------------------------------------------------------------------------------ |
||
32 | ;? Define/undefine GUI button object |
||
33 | ;------------------------------------------------------------------------------ |
||
34 | ;; Define button: |
||
35 | ;> ebx = pack[16(x), 16(width)] |
||
36 | ;> ecx = pack[16(y), 16(height)] |
||
37 | ;> edx = pack[8(flags), 24(button identifier)] |
||
38 | ;> flags bits: |
||
39 | ;> 7 (31) = 0 |
||
40 | ;> 6 (30) = don't draw button |
||
41 | ;> 5 (29) = don't draw button frame when pressed |
||
4993 | Serge | 42 | ;> 4 (28) = don't draw button 3d frame |
4429 | Serge | 43 | ;> esi = button color |
44 | ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
||
45 | ;; Undefine button: |
||
46 | ;> edx = pack[8(flags), 24(button identifier)] |
||
47 | ;> flags bits: |
||
48 | ;> 7 (31) = 1 |
||
49 | ;------------------------------------------------------------------------------ |
||
50 | ; do we actually need to undefine the button? |
||
51 | test edx, 0x80000000 |
||
52 | jnz .remove_button |
||
53 | |||
54 | ; do we have free button slots available? |
||
55 | mov edi, [BTN_ADDR] |
||
56 | mov eax, [edi] |
||
57 | cmp eax, button.MAX_BUTTONS |
||
58 | jge .exit |
||
59 | |||
60 | ; does it have positive size? (otherwise it doesn't have sense) |
||
61 | or bx, bx |
||
62 | jle .exit |
||
63 | or cx, cx |
||
64 | jle .exit |
||
65 | |||
66 | ; make coordinates clientbox-relative |
||
67 | push eax |
||
68 | mov eax, [current_slot] |
||
69 | rol ebx, 16 |
||
70 | add bx, word[eax + APPDATA.wnd_clientbox.left] |
||
71 | rol ebx, 16 |
||
72 | rol ecx, 16 |
||
73 | add cx, word[eax + APPDATA.wnd_clientbox.top] |
||
74 | rol ecx, 16 |
||
75 | pop eax |
||
76 | |||
77 | ; basic checks passed, define the button |
||
78 | push ebx ecx edx |
||
79 | inc eax |
||
80 | mov [edi], ax |
||
81 | shl eax, 4 |
||
82 | add edi, eax |
||
83 | ; NOTE: this code doesn't rely on SYS_BUTTON struct, please revise it |
||
84 | ; if you change something |
||
85 | mov ax, [CURRENT_TASK] |
||
86 | stosw |
||
87 | mov ax, dx |
||
88 | stosw ; button id number: bits 0-15 |
||
89 | mov eax, ebx |
||
4993 | Serge | 90 | dec eax |
4429 | Serge | 91 | rol eax, 16 |
92 | stosd ; x start | x size |
||
93 | mov eax, ecx |
||
4993 | Serge | 94 | dec eax |
4429 | Serge | 95 | rol eax, 16 |
96 | stosd ; y start | y size |
||
97 | mov eax, edx |
||
98 | shr eax, 16 |
||
99 | stosw ; button id number: bits 16-31 |
||
100 | pop edx ecx ebx |
||
101 | |||
102 | ; do we also need to draw the button? |
||
103 | test edx, 0x40000000 |
||
104 | jnz .exit |
||
105 | |||
4993 | Serge | 106 | ; DRAW BODY ----------------------------- |
4429 | Serge | 107 | pushad |
4993 | Serge | 108 | call button._.button_calc_relativ |
109 | xor edi, edi ; for __sys_draw_line |
||
110 | ; set color |
||
4429 | Serge | 111 | mov ecx, esi |
4993 | Serge | 112 | ; set coordinate |
113 | inc edx |
||
114 | ; if gradient |
||
4429 | Serge | 115 | cmp [buttontype], 0 |
4993 | Serge | 116 | je .next_line |
117 | call button._.incecx |
||
118 | align 4 |
||
119 | .next_line: |
||
4429 | Serge | 120 | call button._.button_dececx |
121 | call __sys_draw_line |
||
122 | add ebx, 0x00010001 |
||
123 | dec edx |
||
124 | jnz .next_line |
||
4993 | Serge | 125 | popad |
4429 | Serge | 126 | |
4993 | Serge | 127 | ; DRAW FRAME ---------------------------- |
128 | pushad |
||
129 | call button._.button_calc_relativ |
||
130 | mov esi, common_colours |
||
131 | |||
132 | mov edi, dword [esi+104] |
||
133 | call .top_border |
||
134 | mov edi, dword [esi+104] |
||
135 | call .bottom_border |
||
136 | mov edi, dword [esi+104] |
||
137 | call .right_border |
||
138 | mov edi, dword [esi+104] |
||
139 | call .left_border |
||
4429 | Serge | 140 | popad |
141 | |||
4993 | Serge | 142 | ; DRAW 3D SHADOW ------------------------ |
143 | test edx, 0x10000000 |
||
144 | jnz .exit |
||
4429 | Serge | 145 | |
4993 | Serge | 146 | pushad |
147 | mov edi, edx |
||
148 | call button._.button_calc_relativ |
||
149 | ; get color address |
||
150 | mov esi, common_colours |
||
151 | test edi, 0x10000000 |
||
152 | jnz @f |
||
153 | add eax, 0x10000 |
||
154 | dec eax |
||
155 | inc ecx |
||
156 | dec edx |
||
157 | dec edx |
||
158 | align 4 |
||
159 | @@: |
||
160 | mov edi, dword [esi+12] |
||
161 | call .top_border |
||
162 | mov edi, dword [esi+8] |
||
163 | call .bottom_border |
||
164 | mov edi, dword [esi+8] |
||
165 | call .right_border |
||
166 | mov edi, dword [esi+12] |
||
167 | call .left_border |
||
168 | popad |
||
169 | ret |
||
4429 | Serge | 170 | |
4993 | Serge | 171 | align 4 |
172 | .top_border: |
||
4429 | Serge | 173 | mov ebx, ecx |
174 | shl ebx, 16 |
||
4993 | Serge | 175 | mov bx , cx |
176 | mov ecx, edi |
||
4429 | Serge | 177 | xor edi, edi |
178 | call __sys_draw_line |
||
4993 | Serge | 179 | ret |
4429 | Serge | 180 | |
4993 | Serge | 181 | align 4 |
182 | .bottom_border: |
||
183 | add bx , dx |
||
184 | rol ebx, 16 |
||
185 | add bx , dx |
||
186 | mov ecx, edi |
||
187 | xor edi, edi |
||
4429 | Serge | 188 | call __sys_draw_line |
4993 | Serge | 189 | ret |
4429 | Serge | 190 | |
4993 | Serge | 191 | align 4 |
192 | .right_border: |
||
193 | push eax |
||
194 | sub bx, dx |
||
195 | mov cx, ax |
||
196 | shl eax, 16 |
||
197 | mov ax, cx |
||
198 | mov ecx, edi |
||
199 | xor edi, edi |
||
4429 | Serge | 200 | call __sys_draw_line |
4993 | Serge | 201 | pop eax |
202 | ret |
||
4429 | Serge | 203 | |
4993 | Serge | 204 | align 4 |
205 | .left_border: |
||
206 | shr eax, 16 |
||
207 | mov cx, ax |
||
208 | shl eax, 16 |
||
209 | mov ax, cx |
||
210 | mov ecx, edi |
||
211 | xor edi, edi |
||
4429 | Serge | 212 | call __sys_draw_line |
213 | ret |
||
4993 | Serge | 214 | align 4 |
215 | .exit: |
||
216 | ret |
||
4429 | Serge | 217 | |
218 | ; FIXME: mutex needed |
||
219 | syscall_button.remove_button: |
||
220 | and edx, 0x00ffffff |
||
221 | mov edi, [BTN_ADDR] |
||
222 | mov ebx, [edi] |
||
223 | inc ebx |
||
224 | imul esi, ebx, sizeof.SYS_BUTTON |
||
225 | add esi, edi |
||
226 | xor ecx, ecx |
||
227 | add ecx, -sizeof.SYS_BUTTON |
||
228 | add esi, sizeof.SYS_BUTTON |
||
229 | |||
230 | .next_button: |
||
231 | dec ebx |
||
232 | jz .exit |
||
233 | |||
234 | add ecx, sizeof.SYS_BUTTON |
||
235 | add esi, -sizeof.SYS_BUTTON |
||
236 | |||
237 | ; does it belong to our process? |
||
238 | mov ax, [CURRENT_TASK] |
||
239 | cmp ax, [esi + SYS_BUTTON.pslot] |
||
240 | jne .next_button |
||
241 | |||
242 | ; does the identifier match? |
||
243 | mov eax, dword[esi + SYS_BUTTON.id_hi - 2] |
||
244 | mov ax, [esi + SYS_BUTTON.id_lo] |
||
245 | and eax, 0x00ffffff |
||
246 | cmp edx, eax |
||
247 | jne .next_button |
||
248 | |||
249 | ; okay, undefine it |
||
250 | push ebx |
||
251 | mov ebx, esi |
||
252 | lea eax, [esi + sizeof.SYS_BUTTON] |
||
253 | call memmove |
||
254 | dec dword[edi] |
||
255 | add ecx, -sizeof.SYS_BUTTON |
||
256 | pop ebx |
||
257 | jmp .next_button |
||
258 | |||
259 | .exit: |
||
260 | ret |
||
261 | |||
262 | align 4 |
||
263 | ;------------------------------------------------------------------------------ |
||
264 | sys_button_activate_handler: ;///////////////////////////////////////////////// |
||
265 | ;------------------------------------------------------------------------------ |
||
266 | ;? |
||
267 | ;------------------------------------------------------------------------------ |
||
268 | ;> eax = pack[8(process slot), 24(button id)] |
||
269 | ;> ebx = pack[16(button x coord), 16(button y coord)] |
||
270 | ;> cl = mouse button mask this system button was pressed with |
||
271 | ;------------------------------------------------------------------------------ |
||
272 | call button._.find_button |
||
273 | or eax, eax |
||
274 | jz .exit |
||
275 | |||
276 | mov ebx, dword[eax + SYS_BUTTON.id_hi - 2] |
||
4993 | Serge | 277 | push edi ; spam |
278 | xor edi, edi |
||
4429 | Serge | 279 | call button._.negative_button |
4993 | Serge | 280 | pop edi |
4429 | Serge | 281 | .exit: |
282 | ret |
||
283 | |||
284 | align 4 |
||
285 | ;------------------------------------------------------------------------------ |
||
286 | sys_button_deactivate_handler: ;/////////////////////////////////////////////// |
||
287 | ;------------------------------------------------------------------------------ |
||
288 | ;? |
||
289 | ;------------------------------------------------------------------------------ |
||
290 | ;> eax = pack[8(process slot), 24(button id)] |
||
291 | ;> ebx = pack[16(button x coord), 16(button y coord)] |
||
292 | ;> cl = mouse button mask this system button was pressed with |
||
293 | ;------------------------------------------------------------------------------ |
||
294 | call button._.find_button |
||
295 | or eax, eax |
||
296 | jz .exit |
||
297 | |||
298 | mov ebx, dword[eax + SYS_BUTTON.id_hi - 2] |
||
4993 | Serge | 299 | push edi ; spam |
300 | xor edi, edi |
||
301 | inc edi |
||
4429 | Serge | 302 | call button._.negative_button |
4993 | Serge | 303 | pop edi |
4429 | Serge | 304 | .exit: |
305 | ret |
||
306 | |||
307 | align 4 |
||
308 | ;------------------------------------------------------------------------------ |
||
309 | sys_button_perform_handler: ;////////////////////////////////////////////////// |
||
310 | ;------------------------------------------------------------------------------ |
||
311 | ;? |
||
312 | ;------------------------------------------------------------------------------ |
||
313 | ;> eax = pack[8(process slot), 24(button id)] |
||
314 | ;> ebx = pack[16(button x coord), 16(button y coord)] |
||
315 | ;> cl = mouse button mask this system button was pressed with |
||
316 | ;------------------------------------------------------------------------------ |
||
317 | shl eax, 8 |
||
318 | mov al, cl |
||
319 | movzx ebx, byte[BTN_COUNT] |
||
320 | mov [BTN_BUFF + ebx * 4], eax |
||
321 | inc bl |
||
322 | mov [BTN_COUNT], bl |
||
323 | ret |
||
324 | |||
325 | ;============================================================================== |
||
326 | ;///// private functions ////////////////////////////////////////////////////// |
||
327 | ;============================================================================== |
||
328 | |||
329 | ;------------------------------------------------------------------------------ |
||
330 | button._.find_button: ;//////////////////////////////////////////////////////// |
||
331 | ;------------------------------------------------------------------------------ |
||
332 | ;? Find system button by specified process slot, id and coordinates |
||
333 | ;------------------------------------------------------------------------------ |
||
334 | ;> eax = pack[8(process slot), 24(button id)] or 0 |
||
335 | ;> ebx = pack[16(button x coord), 16(button y coord)] |
||
336 | ;------------------------------------------------------------------------------ |
||
337 | ;< eax = pointer to SYS_BUTTON struct or 0 |
||
338 | ;------------------------------------------------------------------------------ |
||
339 | push ecx edx esi edi |
||
340 | |||
341 | mov edx, eax |
||
342 | shr edx, 24 |
||
343 | and eax, 0x0ffffff |
||
344 | |||
345 | mov edi, [BTN_ADDR] |
||
346 | mov ecx, [edi] |
||
347 | imul esi, ecx, sizeof.SYS_BUTTON |
||
348 | add esi, edi |
||
349 | inc ecx |
||
350 | add esi, sizeof.SYS_BUTTON |
||
351 | |||
352 | .next_button: |
||
353 | dec ecx |
||
354 | jz .not_found |
||
355 | |||
356 | add esi, -sizeof.SYS_BUTTON |
||
357 | |||
358 | ; does it belong to our process? |
||
359 | cmp dx, [esi + SYS_BUTTON.pslot] |
||
360 | jne .next_button |
||
361 | |||
362 | ; does id match? |
||
363 | mov edi, dword[esi + SYS_BUTTON.id_hi - 2] |
||
364 | mov di, [esi + SYS_BUTTON.id_lo] |
||
365 | and edi, 0x0ffffff |
||
366 | cmp eax, edi |
||
367 | jne .next_button |
||
368 | |||
369 | ; does coordinates match? |
||
370 | mov edi, dword[esi + SYS_BUTTON.left - 2] |
||
371 | mov di, [esi + SYS_BUTTON.top] |
||
372 | cmp ebx, edi |
||
373 | jne .next_button |
||
374 | |||
375 | ; okay, return it |
||
376 | mov eax, esi |
||
377 | jmp .exit |
||
378 | |||
379 | .not_found: |
||
380 | xor eax, eax |
||
381 | |||
382 | .exit: |
||
383 | pop edi esi edx ecx |
||
384 | ret |
||
385 | |||
386 | ;------------------------------------------------------------------------------ |
||
4993 | Serge | 387 | button._.button_dececx: ;////////////////////////////////////////////////////// |
4429 | Serge | 388 | ;------------------------------------------------------------------------------ |
389 | ;? |
||
390 | ;------------------------------------------------------------------------------ |
||
4993 | Serge | 391 | cmp [buttontype], 1 |
392 | jne .finish |
||
393 | |||
394 | push eax |
||
395 | mov al, 1 |
||
396 | ;cmp edi, 20 |
||
397 | ;jg @f |
||
398 | ;mov al, 2 |
||
399 | |||
400 | @@: |
||
401 | sub cl, al |
||
4429 | Serge | 402 | jnc @f |
403 | xor cl, cl |
||
404 | @@: |
||
4993 | Serge | 405 | sub ch, al |
4429 | Serge | 406 | jnc @f |
407 | xor ch, ch |
||
408 | @@: |
||
409 | rol ecx, 16 |
||
4993 | Serge | 410 | sub cl, al |
4429 | Serge | 411 | jnc @f |
412 | xor cl, cl |
||
413 | @@: |
||
414 | rol ecx, 16 |
||
415 | |||
4993 | Serge | 416 | pop eax |
417 | |||
418 | .finish: |
||
4429 | Serge | 419 | ret |
420 | ;------------------------------------------------------------------------------ |
||
4993 | Serge | 421 | button._.incecx: ;//////////////////////////////////////////////////////////// |
4429 | Serge | 422 | ;------------------------------------------------------------------------------ |
423 | ;? |
||
424 | ;------------------------------------------------------------------------------ |
||
425 | add cl, 0x14 |
||
426 | jnc @f |
||
427 | or cl, -1 |
||
428 | @@: |
||
429 | add ch, 0x14 |
||
430 | jnc @f |
||
431 | or ch, -1 |
||
432 | @@: |
||
433 | rol ecx, 16 |
||
434 | add cl, 0x14 |
||
435 | jnc @f |
||
436 | or cl, -1 |
||
437 | @@: |
||
438 | rol ecx, 16 |
||
439 | ret |
||
440 | ;------------------------------------------------------------------------------ |
||
4993 | Serge | 441 | button._.button_calc_relativ: ; |
4429 | Serge | 442 | ;------------------------------------------------------------------------------ |
443 | ;? |
||
444 | ;------------------------------------------------------------------------------ |
||
4993 | Serge | 445 | movzx edx, cx |
446 | dec edx ; get height |
||
447 | shr ebx, 16 |
||
448 | shr ecx, 16 |
||
449 | mov eax, [TASK_BASE] |
||
450 | add ebx, [eax - twdw + WDATA.box.left] |
||
451 | add ecx, [eax - twdw + WDATA.box.top] |
||
452 | mov eax, ebx |
||
453 | shl eax, 16 |
||
454 | mov ax, bx |
||
455 | add ax, word[esp + 20] |
||
456 | dec eax |
||
457 | mov bx, cx |
||
458 | shl ebx, 16 |
||
459 | mov bx, cx |
||
4429 | Serge | 460 | ret |
461 | |||
462 | ;------------------------------------------------------------------------------ |
||
463 | button._.negative_button: ;//////////////////////////////////////////////////// |
||
464 | ;------------------------------------------------------------------------------ |
||
465 | ;? Invert system button border |
||
4993 | Serge | 466 | ; edi - 0 activate, 1 - deactivate |
4429 | Serge | 467 | ;------------------------------------------------------------------------------ |
468 | ; if requested, do not display button border on press. |
||
469 | test ebx, 0x20000000 |
||
470 | jnz .exit |
||
471 | |||
472 | pushad |
||
4993 | Serge | 473 | push ebx |
4429 | Serge | 474 | xchg esi, eax |
475 | |||
476 | movzx ecx, [esi + SYS_BUTTON.pslot] |
||
477 | shl ecx, 5 |
||
478 | add ecx, window_data |
||
479 | |||
480 | mov eax, dword[esi + SYS_BUTTON.left] |
||
481 | mov ebx, dword[esi + SYS_BUTTON.top] |
||
482 | add eax, [ecx + WDATA.box.left] |
||
483 | add ebx, [ecx + WDATA.box.top] |
||
484 | push eax ebx |
||
485 | pop edx ecx |
||
486 | rol eax, 16 |
||
487 | rol ebx, 16 |
||
488 | add ax, cx |
||
489 | add bx, dx |
||
490 | |||
4993 | Serge | 491 | xor edx, edx |
492 | mov dx, [esi + SYS_BUTTON.id_lo] |
||
493 | |||
494 | cmp dx, 1 |
||
495 | jne .no_close |
||
496 | sub eax, 0x00010001 |
||
497 | dec ebx |
||
4429 | Serge | 498 | mov esi, 0x01000000 |
499 | call draw_rectangle.forced |
||
4993 | Serge | 500 | jmp .fade |
501 | align 4 |
||
502 | .no_close: |
||
503 | cmp dx, 65535 |
||
504 | jne .no_mini |
||
505 | sub eax, 0x00010001 |
||
506 | dec ebx |
||
507 | mov esi, 0x01000000 |
||
508 | call draw_rectangle.forced |
||
509 | jmp .fade |
||
510 | align 4 |
||
511 | .no_mini: |
||
512 | add eax, 0x00010000 |
||
513 | add ebx, 0x00010000 |
||
514 | pop edx |
||
515 | test edx, 0x10000000 |
||
516 | jnz .only_frame |
||
517 | mov edx, common_colours |
||
518 | mov esi, dword [edx+12] |
||
519 | cmp edi, 0 |
||
520 | jne .shadow |
||
521 | mov esi, dword [edx+8] |
||
522 | align 4 |
||
523 | .shadow: |
||
524 | call draw_rectangle.forced |
||
525 | align 4 |
||
526 | .only_frame: |
||
527 | mov edx, common_colours |
||
528 | sub eax, 0x00010000 |
||
529 | sub ebx, 0x00010000 |
||
530 | mov esi, dword [edx+104] |
||
531 | cmp edi, 0 |
||
532 | jne .draw |
||
533 | mov esi, dword [edx+112] |
||
534 | align 4 |
||
535 | .draw: |
||
536 | call draw_rectangle.forced |
||
4429 | Serge | 537 | popad |
538 | ret |
||
4993 | Serge | 539 | align 4 |
540 | .fade: |
||
541 | pop ebx |
||
542 | popad |
||
543 | align 4 |
||
544 | .exit: |
||
545 | ret> |