Rev 9709 | Rev 9926 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1334 | mikedld | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
6035 | pathoswith | 3 | ;; Copyright (C) KolibriOS team 2004-2016. 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: 9911 $ |
||
10 | |||
1391 | mikedld | 11 | button.MAX_BUTTONS = 4095 |
12 | |||
2384 | hidnplayr | 13 | struct SYS_BUTTON |
14 | pslot dw ? |
||
15 | id_lo dw ? |
||
16 | left dw ? |
||
17 | width dw ? |
||
18 | top dw ? |
||
19 | height dw ? |
||
20 | id_hi dw ? |
||
21 | dw ? |
||
22 | ends |
||
6031 | pathoswith | 23 | ;--------------------------------------------------------------- |
9911 | Doczom | 24 | align 4 |
25 | ; @brief system function 17 - Get the identifier of the pressed button |
||
26 | ; @param eax 17 - number function |
||
27 | ; @return eax = 1 - buffer empty, |
||
28 | ; eax = high 24 bits contain button identifier, |
||
29 | ; al = 0 - the button was pressed with left mouse button, |
||
30 | ; al = bit corresponding to used mouse button otherwise |
||
31 | sys_getbutton: |
||
32 | mov ebx, [current_slot_idx] ; TOP OF WINDOW STACK |
||
33 | mov [esp + SYSCALL_STACK.eax], dword 1 |
||
34 | movzx ecx, word [WIN_STACK + ebx * 2] |
||
35 | mov edx, [thread_count] ; less than 256 processes |
||
36 | cmp ecx, edx |
||
37 | jne .exit |
||
38 | movzx eax, byte [BTN_COUNT] |
||
39 | test eax, eax |
||
40 | jz .exit |
||
41 | mov eax, [BTN_BUFF] |
||
42 | and al, 0xFE ; delete left button bit |
||
43 | mov [BTN_COUNT], byte 0 |
||
44 | mov [esp + SYSCALL_STACK.eax], eax |
||
45 | ;-------------------------------------- |
||
46 | align 4 |
||
47 | .exit: |
||
48 | ret |
||
6031 | pathoswith | 49 | ;--------------------------------------------------------------- |
9911 | Doczom | 50 | ; @brief system function 8 - define/delete the button |
51 | ; @param eax = 8 - number function |
||
52 | ; @param ebx = [offset_x]*65536 + [width] |
||
53 | ; @param ecx = [offset_y]*65536 + [height] |
||
54 | ; @param edx = 0xXYnnnnnn, where: |
||
55 | ; nnnnnn = identifier of the button |
||
56 | ; 31 bit - delete button |
||
57 | ; 30 bit - don't draw button |
||
58 | ; 29 bit - don't draw button frame when pressed |
||
59 | ; @param esi = 0x00RRGGBB - button color |
||
60 | ; @return function does not return value |
||
61 | syscall_button: |
||
62 | ;--------------------------------------------------------------- |
||
1362 | mikedld | 63 | ;? Define/undefine GUI button object |
6031 | pathoswith | 64 | ;--------------------------------------------------------------- |
1362 | mikedld | 65 | ;; Define button: |
66 | ;> ebx = pack[16(x), 16(width)] |
||
67 | ;> ecx = pack[16(y), 16(height)] |
||
68 | ;> edx = pack[8(flags), 24(button identifier)] |
||
69 | ;> flags bits: |
||
70 | ;> 7 (31) = 0 |
||
71 | ;> 6 (30) = don't draw button |
||
72 | ;> 5 (29) = don't draw button frame when pressed |
||
73 | ;> esi = button color |
||
6031 | pathoswith | 74 | ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
1362 | mikedld | 75 | ;; Undefine button: |
76 | ;> edx = pack[8(flags), 24(button identifier)] |
||
77 | ;> flags bits: |
||
78 | ;> 7 (31) = 1 |
||
6031 | pathoswith | 79 | ;--------------------------------------------------------------- |
1334 | mikedld | 80 | ; do we actually need to undefine the button? |
81 | test edx, 0x80000000 |
||
82 | jnz .remove_button |
||
83 | |||
84 | ; do we have free button slots available? |
||
85 | mov edi, [BTN_ADDR] |
||
86 | mov eax, [edi] |
||
1391 | mikedld | 87 | cmp eax, button.MAX_BUTTONS |
1334 | mikedld | 88 | jge .exit |
89 | |||
90 | ; does it have positive size? (otherwise it doesn't have sense) |
||
91 | or bx, bx |
||
92 | jle .exit |
||
93 | or cx, cx |
||
94 | jle .exit |
||
95 | |||
96 | ; make coordinates clientbox-relative |
||
97 | push eax |
||
98 | mov eax, [current_slot] |
||
99 | rol ebx, 16 |
||
100 | add bx, word[eax + APPDATA.wnd_clientbox.left] |
||
101 | rol ebx, 16 |
||
102 | rol ecx, 16 |
||
103 | add cx, word[eax + APPDATA.wnd_clientbox.top] |
||
104 | rol ecx, 16 |
||
105 | pop eax |
||
106 | |||
107 | ; basic checks passed, define the button |
||
108 | inc eax |
||
109 | mov [edi], ax |
||
110 | shl eax, 4 |
||
111 | add edi, eax |
||
6031 | pathoswith | 112 | ; NOTE: this code doesn't rely on SYS_BUTTON struct, |
113 | ; please revise it, if you change something. |
||
8869 | rgimad | 114 | mov ax, word [current_slot_idx] |
1334 | mikedld | 115 | stosw |
116 | mov ax, dx |
||
117 | stosw ; button id number: bits 0-15 |
||
118 | mov eax, ebx |
||
119 | rol eax, 16 |
||
120 | stosd ; x start | x size |
||
121 | mov eax, ecx |
||
122 | rol eax, 16 |
||
123 | stosd ; y start | y size |
||
124 | mov eax, edx |
||
125 | shr eax, 16 |
||
126 | stosw ; button id number: bits 16-31 |
||
127 | |||
128 | ; do we also need to draw the button? |
||
129 | test edx, 0x40000000 |
||
130 | jnz .exit |
||
131 | |||
6032 | pathoswith | 132 | and esi, 0xFFFFFF |
6031 | pathoswith | 133 | xor edi, edi |
134 | push ebx ecx esi |
||
6032 | pathoswith | 135 | dec cx |
136 | dec cx |
||
6031 | pathoswith | 137 | cmp [buttontype], 1 |
138 | jnz .draw |
||
6032 | pathoswith | 139 | cmp cx, 65 |
6031 | pathoswith | 140 | jnc .draw |
5185 | mario79 | 141 | |
6031 | pathoswith | 142 | ; calculate gradient data |
143 | mov eax, esi |
||
144 | shl eax, 8 |
||
145 | mov edx, 3 |
||
146 | .calculate: |
||
147 | rol eax, 8 |
||
148 | shl al, 1 |
||
149 | jnc @f |
||
150 | neg al |
||
151 | jnz @f |
||
6032 | pathoswith | 152 | mov al, 64 |
6031 | pathoswith | 153 | @@: |
6032 | pathoswith | 154 | cmp al, 65 |
155 | jc @f |
||
156 | mov al, 64 |
||
6031 | pathoswith | 157 | @@: |
158 | div cl |
||
159 | shl ax, 8 |
||
160 | dec edx |
||
161 | jnz .calculate |
||
162 | mov dl, cl |
||
163 | dec edx |
||
164 | shr edx, 1 |
||
165 | shr eax, 8 |
||
166 | mov edi, eax |
||
167 | mul edx |
||
168 | add esi, eax |
||
5185 | mario79 | 169 | |
6031 | pathoswith | 170 | .draw: ; calculate window-relative coordinates |
171 | movzx ebp, cx |
||
172 | dec ebp |
||
5185 | mario79 | 173 | shr ebx, 16 |
174 | shr ecx, 16 |
||
9709 | Doczom | 175 | mov eax, [current_slot_idx] |
176 | shl eax, BSF sizeof.WDATA |
||
177 | add ebx, [eax + window_data + WDATA.box.left] |
||
178 | add ecx, [eax + window_data + WDATA.box.top] |
||
5185 | mario79 | 179 | mov eax, ebx |
5580 | leency | 180 | inc eax |
6031 | pathoswith | 181 | mov edx, ebx |
182 | add dx, [esp+8] |
||
183 | dec edx |
||
5185 | mario79 | 184 | mov ebx, ecx |
1334 | mikedld | 185 | mov ecx, esi |
6031 | pathoswith | 186 | shr ecx, 1 |
6032 | pathoswith | 187 | and cx, 7F7Fh |
6031 | pathoswith | 188 | push esi |
189 | mov esi, edi |
||
5185 | mario79 | 190 | xor edi, edi |
6031 | pathoswith | 191 | call hline ; top border |
192 | inc ebx |
||
6032 | pathoswith | 193 | or ecx, 808080h |
194 | call hline ; top light line |
||
6031 | pathoswith | 195 | pop ecx |
6032 | pathoswith | 196 | inc ebx |
6031 | pathoswith | 197 | .next_line: |
198 | call hline ; button body |
||
199 | inc ebx |
||
200 | sub ecx, esi |
||
201 | dec ebp |
||
1334 | mikedld | 202 | jnz .next_line |
6032 | pathoswith | 203 | shr ecx, 2 |
204 | and cx, 3F3Fh |
||
205 | mov ebp, ecx |
||
206 | shl ecx, 1 |
||
207 | add ecx, ebp |
||
208 | call hline ; bottom dark line |
||
209 | inc ebx |
||
210 | sub ecx, ebp |
||
6031 | pathoswith | 211 | call hline ; bottom border |
212 | pop ecx |
||
213 | shr ecx, 1 |
||
214 | inc edx |
||
5185 | mario79 | 215 | push edx |
216 | mov edx, ebx |
||
6031 | pathoswith | 217 | sub bx, [esp+4] |
6032 | pathoswith | 218 | dec edx |
219 | inc ebx |
||
220 | cmp [buttontype], 0 |
||
6031 | pathoswith | 221 | jnz @f |
222 | dec edx |
||
6032 | pathoswith | 223 | or ecx, 808080h |
224 | call vline ; left light line |
||
225 | inc edx |
||
6031 | pathoswith | 226 | @@: |
6032 | pathoswith | 227 | and ecx, 7F7F7Fh |
228 | dec eax |
||
6031 | pathoswith | 229 | call vline ; left border |
230 | pop eax |
||
231 | call vline ; right border |
||
6032 | pathoswith | 232 | cmp [buttontype], 0 |
233 | jnz @f |
||
234 | mov ebp, ecx |
||
235 | shr ecx, 1 |
||
236 | and cx, 7F7Fh |
||
237 | add ecx, ebp |
||
238 | dec eax |
||
239 | inc ebx |
||
8926 | leency | 240 | dec edx ; avoid lines overflow |
6032 | pathoswith | 241 | call vline ; right dark line |
242 | @@: |
||
5185 | mario79 | 243 | pop ecx ebx |
6031 | pathoswith | 244 | .exit: |
1334 | mikedld | 245 | ret |
246 | |||
247 | ; FIXME: mutex needed |
||
6031 | pathoswith | 248 | .remove_button: |
1334 | mikedld | 249 | and edx, 0x00ffffff |
250 | mov edi, [BTN_ADDR] |
||
251 | mov ebx, [edi] |
||
252 | inc ebx |
||
2384 | hidnplayr | 253 | imul esi, ebx, sizeof.SYS_BUTTON |
1334 | mikedld | 254 | add esi, edi |
255 | xor ecx, ecx |
||
2384 | hidnplayr | 256 | add ecx, -sizeof.SYS_BUTTON |
257 | add esi, sizeof.SYS_BUTTON |
||
1334 | mikedld | 258 | |
6031 | pathoswith | 259 | .next_button: |
1334 | mikedld | 260 | dec ebx |
261 | jz .exit |
||
262 | |||
2384 | hidnplayr | 263 | add ecx, sizeof.SYS_BUTTON |
264 | add esi, -sizeof.SYS_BUTTON |
||
1334 | mikedld | 265 | |
266 | ; does it belong to our process? |
||
8869 | rgimad | 267 | mov ax, word [current_slot_idx] |
1334 | mikedld | 268 | cmp ax, [esi + SYS_BUTTON.pslot] |
269 | jne .next_button |
||
270 | |||
271 | ; does the identifier match? |
||
272 | mov eax, dword[esi + SYS_BUTTON.id_hi - 2] |
||
273 | mov ax, [esi + SYS_BUTTON.id_lo] |
||
274 | and eax, 0x00ffffff |
||
275 | cmp edx, eax |
||
276 | jne .next_button |
||
277 | |||
278 | ; okay, undefine it |
||
1341 | mikedld | 279 | push ebx |
1334 | mikedld | 280 | mov ebx, esi |
2384 | hidnplayr | 281 | lea eax, [esi + sizeof.SYS_BUTTON] |
1334 | mikedld | 282 | call memmove |
283 | dec dword[edi] |
||
2384 | hidnplayr | 284 | add ecx, -sizeof.SYS_BUTTON |
1341 | mikedld | 285 | pop ebx |
1334 | mikedld | 286 | jmp .next_button |
287 | |||
6031 | pathoswith | 288 | ;--------------------------------------------------------------- |
289 | sys_button_activate_handler: |
||
290 | sys_button_deactivate_handler: |
||
291 | ;--------------------------------------------------------------- |
||
1391 | mikedld | 292 | ;> eax = pack[8(process slot), 24(button id)] |
293 | ;> ebx = pack[16(button x coord), 16(button y coord)] |
||
294 | ;> cl = mouse button mask this system button was pressed with |
||
6031 | pathoswith | 295 | ;--------------------------------------------------------------- |
296 | ; find system button by specified process slot, id and coordinates |
||
1391 | mikedld | 297 | push ecx edx esi edi |
298 | mov edx, eax |
||
299 | shr edx, 24 |
||
300 | and eax, 0x0ffffff |
||
301 | mov edi, [BTN_ADDR] |
||
302 | mov ecx, [edi] |
||
2384 | hidnplayr | 303 | imul esi, ecx, sizeof.SYS_BUTTON |
1391 | mikedld | 304 | add esi, edi |
305 | inc ecx |
||
2384 | hidnplayr | 306 | add esi, sizeof.SYS_BUTTON |
6031 | pathoswith | 307 | .next_button: |
1391 | mikedld | 308 | dec ecx |
6031 | pathoswith | 309 | jz .popexit |
2384 | hidnplayr | 310 | add esi, -sizeof.SYS_BUTTON |
1334 | mikedld | 311 | |
1391 | mikedld | 312 | ; does it belong to our process? |
313 | cmp dx, [esi + SYS_BUTTON.pslot] |
||
314 | jne .next_button |
||
1334 | mikedld | 315 | |
1391 | mikedld | 316 | ; does id match? |
317 | mov edi, dword[esi + SYS_BUTTON.id_hi - 2] |
||
318 | mov di, [esi + SYS_BUTTON.id_lo] |
||
319 | and edi, 0x0ffffff |
||
320 | cmp eax, edi |
||
321 | jne .next_button |
||
1334 | mikedld | 322 | |
1391 | mikedld | 323 | ; does coordinates match? |
324 | mov edi, dword[esi + SYS_BUTTON.left - 2] |
||
325 | mov di, [esi + SYS_BUTTON.top] |
||
326 | cmp ebx, edi |
||
327 | jne .next_button |
||
1334 | mikedld | 328 | |
1391 | mikedld | 329 | mov eax, esi |
330 | pop edi esi edx ecx |
||
6031 | pathoswith | 331 | mov ebx, dword[eax + SYS_BUTTON.id_hi - 2] |
1334 | mikedld | 332 | |
6031 | pathoswith | 333 | ; display button border on press? |
6044 | pathoswith | 334 | bt ebx, 29 |
335 | jc .exit |
||
1334 | mikedld | 336 | |
6031 | pathoswith | 337 | ; invert system button border |
1334 | mikedld | 338 | pushad |
6031 | pathoswith | 339 | mov esi, eax |
6044 | pathoswith | 340 | mov edi, ebx |
1362 | mikedld | 341 | movzx ecx, [esi + SYS_BUTTON.pslot] |
342 | shl ecx, 5 |
||
343 | add ecx, window_data |
||
344 | mov eax, dword[esi + SYS_BUTTON.left] |
||
345 | mov ebx, dword[esi + SYS_BUTTON.top] |
||
346 | add eax, [ecx + WDATA.box.left] |
||
347 | add ebx, [ecx + WDATA.box.top] |
||
6035 | pathoswith | 348 | mov ecx, eax |
349 | mov edx, ebx |
||
6044 | pathoswith | 350 | bt edi, 30 |
351 | jc @f |
||
6035 | pathoswith | 352 | inc ax |
353 | inc bx |
||
6044 | pathoswith | 354 | dec cx |
355 | dec dx |
||
356 | @@: |
||
1362 | mikedld | 357 | rol eax, 16 |
358 | rol ebx, 16 |
||
6035 | pathoswith | 359 | add ax, cx |
360 | add bx, dx |
||
361 | mov esi, 1000000h |
||
362 | call draw_rectangle.forced |
||
1362 | mikedld | 363 | popad |
6031 | pathoswith | 364 | .exit: |
365 | ret |
||
366 | .popexit: |
||
367 | pop edi esi edx ecx |
||
368 | ret |
||
5185 | mario79 | 369 | |
6031 | pathoswith | 370 | ;--------------------------------------------------------------- |
371 | sys_button_perform_handler: |
||
372 | ;--------------------------------------------------------------- |
||
373 | ;> eax = pack[8(process slot), 24(button id)] |
||
374 | ;> ebx = pack[16(button x coord), 16(button y coord)] |
||
375 | ;> cl = mouse button mask this system button was pressed with |
||
376 | ;--------------------------------------------------------------- |
||
377 | shl eax, 8 |
||
378 | mov al, cl |
||
379 | movzx ebx, byte[BTN_COUNT] |
||
380 | mov [BTN_BUFF + ebx * 4], eax |
||
381 | inc bl |
||
382 | mov [BTN_COUNT], bl |
||
1334 | mikedld | 383 | ret |