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