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