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