Rev 5363 | Rev 5870 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1391 | mikedld | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
5363 | yogev_ezra | 3 | ;; Copyright (C) KolibriOS team 2010-2015. All rights reserved. ;; |
1391 | mikedld | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
7 | |||
1531 | diamond | 8 | $Revision: 5851 $ |
1391 | mikedld | 9 | |
10 | include 'mousepointer.inc' |
||
11 | |||
5851 | pathoswith | 12 | ;================================ |
13 | ;/////// public functions /////// |
||
14 | ;================================ |
||
1391 | mikedld | 15 | |
16 | mouse.LEFT_BUTTON_FLAG = 0001b |
||
17 | mouse.RIGHT_BUTTON_FLAG = 0010b |
||
18 | mouse.MIDDLE_BUTTON_FLAG = 0100b |
||
19 | |||
20 | mouse.BUTTONS_MASK = \ |
||
21 | mouse.LEFT_BUTTON_FLAG or \ |
||
22 | mouse.RIGHT_BUTTON_FLAG or \ |
||
23 | mouse.MIDDLE_BUTTON_FLAG |
||
24 | |||
25 | mouse.WINDOW_RESIZE_N_FLAG = 000001b |
||
26 | mouse.WINDOW_RESIZE_W_FLAG = 000010b |
||
27 | mouse.WINDOW_RESIZE_S_FLAG = 000100b |
||
28 | mouse.WINDOW_RESIZE_E_FLAG = 001000b |
||
29 | mouse.WINDOW_MOVE_FLAG = 010000b |
||
30 | |||
31 | mouse.WINDOW_RESIZE_SW_FLAG = \ |
||
32 | mouse.WINDOW_RESIZE_S_FLAG or \ |
||
33 | mouse.WINDOW_RESIZE_W_FLAG |
||
34 | mouse.WINDOW_RESIZE_SE_FLAG = \ |
||
35 | mouse.WINDOW_RESIZE_S_FLAG or \ |
||
36 | mouse.WINDOW_RESIZE_E_FLAG |
||
37 | |||
38 | align 4 |
||
5851 | pathoswith | 39 | ;----------------------------------------------------------------- |
40 | mouse_check_events: |
||
41 | ; Check if mouse buttons state or cursor position has changed |
||
1391 | mikedld | 42 | push eax ebx |
43 | mov al, [BTN_DOWN] |
||
44 | mov bl, [mouse.state.buttons] |
||
45 | and al, mouse.BUTTONS_MASK |
||
46 | mov cl, al |
||
47 | xchg cl, [mouse.state.buttons] |
||
48 | xor bl, al |
||
49 | push eax ebx |
||
50 | |||
51 | ; did any mouse button changed its state? |
||
52 | or bl, bl |
||
53 | jz .check_position |
||
54 | |||
55 | ; yes it did, is that the first button of all pressed down? |
||
56 | or cl, cl |
||
57 | jnz .check_buttons_released |
||
58 | |||
59 | ; yes it is, activate window user is pointing at, if needed |
||
60 | call mouse._.activate_sys_window_under_cursor |
||
61 | |||
5851 | pathoswith | 62 | ; NOTE: this code wouldn't be necessary if we knew |
63 | ; that window did already redraw itself after call above |
||
1391 | mikedld | 64 | or eax, eax |
3536 | clevermous | 65 | jnz .exit |
1391 | mikedld | 66 | |
67 | ; is there any system button under cursor? |
||
2288 | clevermous | 68 | call mouse._.find_sys_button_under_cursor |
1391 | mikedld | 69 | or eax, eax |
70 | jz .check_buttons_released |
||
71 | |||
72 | ; yes there is, activate it and exit |
||
73 | mov [mouse.active_sys_button.pbid], eax |
||
74 | mov [mouse.active_sys_button.coord], ebx |
||
75 | mov cl, [mouse.state.buttons] |
||
76 | mov [mouse.active_sys_button.buttons], cl |
||
77 | call sys_button_activate_handler |
||
78 | jmp .exit |
||
79 | |||
80 | .check_buttons_released: |
||
81 | cmp [mouse.state.buttons], 0 |
||
82 | jnz .buttons_changed |
||
83 | |||
84 | ; did we press some button earlier? |
||
85 | cmp [mouse.active_sys_button.pbid], 0 |
||
86 | je .buttons_changed |
||
87 | |||
88 | ; yes we did, deactivate it |
||
89 | xor eax, eax |
||
90 | xchg eax, [mouse.active_sys_button.pbid] |
||
91 | mov ebx, [mouse.active_sys_button.coord] |
||
92 | mov cl, [mouse.active_sys_button.buttons] |
||
93 | push eax ebx |
||
94 | call sys_button_deactivate_handler |
||
95 | pop edx ecx |
||
96 | |||
97 | ; is the button under cursor the one we deactivated? |
||
98 | call mouse._.find_sys_button_under_cursor |
||
99 | cmp eax, ecx |
||
100 | jne .exit |
||
101 | cmp ebx, edx |
||
102 | jne .exit |
||
103 | |||
104 | ; yes it is, perform associated action |
||
105 | mov cl, [mouse.active_sys_button.buttons] |
||
106 | call sys_button_perform_handler |
||
107 | jmp .exit |
||
108 | |||
109 | .buttons_changed: |
||
110 | test byte[esp], mouse.LEFT_BUTTON_FLAG |
||
111 | jz @f |
||
112 | mov eax, [esp + 4] |
||
113 | call .call_left_button_handler |
||
114 | |||
2288 | clevermous | 115 | @@: |
116 | test byte[esp], mouse.RIGHT_BUTTON_FLAG |
||
1391 | mikedld | 117 | jz @f |
118 | mov eax, [esp + 4] |
||
119 | call .call_right_button_handler |
||
120 | |||
2288 | clevermous | 121 | @@: |
122 | test byte[esp], mouse.MIDDLE_BUTTON_FLAG |
||
1391 | mikedld | 123 | jz .check_position |
124 | mov eax, [esp + 4] |
||
125 | call .call_middle_button_handler |
||
126 | |||
127 | .check_position: |
||
128 | movzx eax, word[MOUSE_X] |
||
129 | movzx ebx, word[MOUSE_Y] |
||
130 | cmp eax, [mouse.state.pos.x] |
||
131 | jne .position_changed |
||
132 | cmp ebx, [mouse.state.pos.y] |
||
133 | je .exit |
||
134 | |||
135 | .position_changed: |
||
136 | xchg eax, [mouse.state.pos.x] |
||
137 | xchg ebx, [mouse.state.pos.y] |
||
138 | |||
139 | call mouse._.move_handler |
||
140 | |||
141 | .exit: |
||
142 | add esp, 8 |
||
143 | pop ebx eax |
||
144 | ret |
||
145 | |||
146 | .call_left_button_handler: |
||
147 | test eax, mouse.LEFT_BUTTON_FLAG |
||
148 | jnz mouse._.left_button_press_handler |
||
149 | jmp mouse._.left_button_release_handler |
||
150 | |||
151 | .call_right_button_handler: |
||
152 | test eax, mouse.RIGHT_BUTTON_FLAG |
||
153 | jnz mouse._.right_button_press_handler |
||
154 | jmp mouse._.right_button_release_handler |
||
155 | |||
156 | .call_middle_button_handler: |
||
157 | test eax, mouse.MIDDLE_BUTTON_FLAG |
||
158 | jnz mouse._.middle_button_press_handler |
||
159 | jmp mouse._.middle_button_release_handler |
||
160 | |||
5851 | pathoswith | 161 | ;=============================== |
162 | ;////// private functions ////// |
||
163 | ;=============================== |
||
1391 | mikedld | 164 | |
165 | uglobal |
||
166 | mouse.state: |
||
167 | .pos POINT |
||
168 | .buttons db ? |
||
169 | |||
5851 | pathoswith | 170 | ; NOTE: since there's no unique and lifetime-constant button identifiers, |
171 | ; we are using two dwords to identify each of them: |
||
172 | ; * pbid - process slot (high 8 bits) and button id (low 24 bits) pack |
||
173 | ; * coord - left (high 16 bits) and top (low 16 bits) coordinates pack |
||
1391 | mikedld | 174 | align 4 |
175 | mouse.active_sys_button: |
||
176 | .pbid dd ? |
||
177 | .coord dd ? |
||
178 | .buttons db ? |
||
179 | |||
180 | align 4 |
||
181 | mouse.active_sys_window: |
||
182 | .pslot dd ? |
||
183 | .old_box BOX |
||
184 | .new_box BOX |
||
185 | .delta POINT |
||
186 | .last_ticks dd ? |
||
187 | .action db ? |
||
188 | endg |
||
189 | |||
190 | align 4 |
||
5851 | pathoswith | 191 | ;----------------------------------------------------------------- |
192 | mouse._.left_button_press_handler: |
||
193 | ; Called when left mouse button has been pressed down |
||
194 | bts word [BTN_DOWN], 8 |
||
195 | mov eax, [timer_ticks] |
||
196 | mov ebx, eax |
||
197 | xchg ebx, [mouse.active_sys_window.last_ticks] |
||
198 | sub eax, ebx |
||
199 | movzx ebx, [mouse_doubleclick_delay] |
||
200 | cmp eax, ebx |
||
201 | jg @f |
||
202 | bts dword [BTN_DOWN], 24 |
||
203 | @@: |
||
1391 | mikedld | 204 | test [mouse.state.buttons], not mouse.LEFT_BUTTON_FLAG |
205 | jnz .exit |
||
206 | |||
207 | call mouse._.find_sys_window_under_cursor |
||
208 | call mouse._.check_sys_window_actions |
||
209 | mov [mouse.active_sys_window.action], al |
||
210 | or eax, eax |
||
211 | jz .exit |
||
212 | |||
213 | xchg eax, edx |
||
214 | test dl, mouse.WINDOW_MOVE_FLAG |
||
215 | jz @f |
||
216 | |||
5851 | pathoswith | 217 | bt dword [BTN_DOWN], 24 |
218 | jnc @f |
||
1391 | mikedld | 219 | |
220 | mov [mouse.active_sys_window.last_ticks], 0 |
||
221 | call sys_window_maximize_handler |
||
222 | jmp .exit |
||
223 | |||
2288 | clevermous | 224 | @@: |
225 | test [edi + WDATA.fl_wstate], WSTATE_MAXIMIZED |
||
1391 | mikedld | 226 | jnz .exit |
227 | mov [mouse.active_sys_window.pslot], esi |
||
228 | lea eax, [edi + WDATA.box] |
||
229 | mov ebx, mouse.active_sys_window.old_box |
||
2381 | hidnplayr | 230 | mov ecx, sizeof.BOX |
1391 | mikedld | 231 | call memmove |
232 | mov ebx, mouse.active_sys_window.new_box |
||
233 | call memmove |
||
234 | test edx, mouse.WINDOW_MOVE_FLAG |
||
235 | jz @f |
||
236 | |||
237 | call .calculate_n_delta |
||
238 | call .calculate_w_delta |
||
239 | jmp .call_window_handler |
||
240 | |||
2288 | clevermous | 241 | @@: |
242 | test dl, mouse.WINDOW_RESIZE_W_FLAG |
||
1391 | mikedld | 243 | jz @f |
244 | call .calculate_w_delta |
||
245 | |||
2288 | clevermous | 246 | @@: |
247 | test dl, mouse.WINDOW_RESIZE_S_FLAG |
||
1391 | mikedld | 248 | jz @f |
249 | call .calculate_s_delta |
||
250 | |||
2288 | clevermous | 251 | @@: |
252 | test dl, mouse.WINDOW_RESIZE_E_FLAG |
||
1391 | mikedld | 253 | jz .call_window_handler |
254 | call .calculate_e_delta |
||
255 | |||
256 | .call_window_handler: |
||
257 | .exit: |
||
258 | ret |
||
259 | |||
260 | .calculate_n_delta: |
||
261 | mov eax, [mouse.state.pos.y] |
||
262 | sub eax, [mouse.active_sys_window.old_box.top] |
||
263 | mov [mouse.active_sys_window.delta.y], eax |
||
264 | ret |
||
265 | |||
266 | .calculate_w_delta: |
||
267 | mov eax, [mouse.state.pos.x] |
||
268 | sub eax, [mouse.active_sys_window.old_box.left] |
||
269 | mov [mouse.active_sys_window.delta.x], eax |
||
270 | ret |
||
271 | |||
272 | .calculate_s_delta: |
||
273 | mov eax, [mouse.active_sys_window.old_box.top] |
||
274 | add eax, [mouse.active_sys_window.old_box.height] |
||
275 | sub eax, [mouse.state.pos.y] |
||
276 | mov [mouse.active_sys_window.delta.y], eax |
||
277 | ret |
||
278 | |||
279 | .calculate_e_delta: |
||
280 | mov eax, [mouse.active_sys_window.old_box.left] |
||
281 | add eax, [mouse.active_sys_window.old_box.width] |
||
282 | sub eax, [mouse.state.pos.x] |
||
283 | mov [mouse.active_sys_window.delta.x], eax |
||
284 | ret |
||
285 | |||
286 | align 4 |
||
5851 | pathoswith | 287 | ;----------------------------------------------------------------- |
288 | mouse._.left_button_release_handler: |
||
289 | ; Called when left mouse button has been released |
||
290 | bts dword [BTN_DOWN], 16 |
||
1391 | mikedld | 291 | xor esi, esi |
292 | xchg esi, [mouse.active_sys_window.pslot] |
||
293 | or esi, esi |
||
294 | jz .exit |
||
295 | |||
296 | mov eax, esi |
||
297 | shl eax, 5 |
||
298 | add eax, window_data + WDATA.box |
||
299 | mov ebx, mouse.active_sys_window.old_box |
||
2381 | hidnplayr | 300 | mov ecx, sizeof.BOX |
1391 | mikedld | 301 | call memmove |
302 | |||
303 | mov eax, mouse.active_sys_window.old_box |
||
304 | mov ebx, mouse.active_sys_window.new_box |
||
305 | call sys_window_end_moving_handler |
||
306 | |||
307 | .exit: |
||
2011 | mikedld | 308 | and [mouse.active_sys_window.action], 0 |
1391 | mikedld | 309 | ret |
310 | |||
5851 | pathoswith | 311 | mouse._.right_button_press_handler: |
312 | bts word [BTN_DOWN], 9 |
||
1391 | mikedld | 313 | test [mouse.state.buttons], not mouse.RIGHT_BUTTON_FLAG |
5851 | pathoswith | 314 | jnz @f |
1391 | mikedld | 315 | call mouse._.find_sys_window_under_cursor |
316 | call mouse._.check_sys_window_actions |
||
317 | test al, mouse.WINDOW_MOVE_FLAG |
||
5851 | pathoswith | 318 | jz @f |
319 | jmp sys_window_rollup_handler |
||
1391 | mikedld | 320 | |
5851 | pathoswith | 321 | mouse._.right_button_release_handler: |
322 | bts dword [BTN_DOWN], 17 |
||
323 | @@: |
||
1391 | mikedld | 324 | ret |
325 | |||
5851 | pathoswith | 326 | mouse._.middle_button_press_handler: |
327 | bts word [BTN_DOWN], 10 |
||
1391 | mikedld | 328 | ret |
329 | |||
5851 | pathoswith | 330 | mouse._.middle_button_release_handler: |
331 | bts dword [BTN_DOWN], 18 |
||
1391 | mikedld | 332 | ret |
333 | |||
334 | align 4 |
||
5851 | pathoswith | 335 | ;----------------------------------------------------------------- |
336 | mouse._.move_handler: |
||
337 | ; Called when cursor has been moved |
||
1391 | mikedld | 338 | ;> eax = old x coord |
339 | ;> ebx = old y coord |
||
340 | cmp [mouse.active_sys_button.pbid], 0 |
||
341 | jnz .exit |
||
342 | |||
343 | mov esi, [mouse.active_sys_window.pslot] |
||
344 | or esi, esi |
||
345 | jz .exit |
||
346 | |||
347 | mov eax, mouse.active_sys_window.new_box |
||
348 | mov ebx, mouse.active_sys_window.old_box |
||
2381 | hidnplayr | 349 | mov ecx, sizeof.BOX |
1391 | mikedld | 350 | call memmove |
351 | |||
352 | mov dl, [mouse.active_sys_window.action] |
||
353 | test dl, mouse.WINDOW_MOVE_FLAG |
||
354 | jz .check_resize_w |
||
355 | |||
356 | mov eax, [mouse.state.pos.x] |
||
357 | sub eax, [mouse.active_sys_window.delta.x] |
||
358 | mov [mouse.active_sys_window.new_box.left], eax |
||
359 | mov eax, [mouse.state.pos.y] |
||
360 | sub eax, [mouse.active_sys_window.delta.y] |
||
361 | mov [mouse.active_sys_window.new_box.top], eax |
||
362 | |||
363 | mov eax, [mouse.active_sys_window.new_box.left] |
||
364 | or eax, eax |
||
365 | jge @f |
||
366 | xor eax, eax |
||
367 | mov [mouse.active_sys_window.new_box.left], eax |
||
2288 | clevermous | 368 | @@: |
369 | add eax, [mouse.active_sys_window.new_box.width] |
||
5350 | serge | 370 | cmp eax, [_display.width] |
1391 | mikedld | 371 | jl @f |
5350 | serge | 372 | sub eax, [_display.width] |
1391 | mikedld | 373 | sub [mouse.active_sys_window.new_box.left], eax |
2288 | clevermous | 374 | @@: |
375 | mov eax, [mouse.active_sys_window.new_box.top] |
||
1391 | mikedld | 376 | or eax, eax |
377 | jge @f |
||
378 | xor eax, eax |
||
379 | mov [mouse.active_sys_window.new_box.top], eax |
||
2288 | clevermous | 380 | @@: |
381 | add eax, [mouse.active_sys_window.new_box.height] |
||
5350 | serge | 382 | cmp eax, [_display.height] |
383 | jl .call_window_handler |
||
384 | sub eax, [_display.height] |
||
1391 | mikedld | 385 | sub [mouse.active_sys_window.new_box.top], eax |
386 | jmp .call_window_handler |
||
387 | |||
388 | .check_resize_w: |
||
389 | test dl, mouse.WINDOW_RESIZE_W_FLAG |
||
390 | jz .check_resize_s |
||
391 | |||
392 | mov eax, [mouse.state.pos.x] |
||
393 | sub eax, [mouse.active_sys_window.delta.x] |
||
394 | mov [mouse.active_sys_window.new_box.left], eax |
||
395 | sub eax, [mouse.active_sys_window.old_box.left] |
||
396 | sub [mouse.active_sys_window.new_box.width], eax |
||
397 | |||
398 | mov eax, [mouse.active_sys_window.new_box.width] |
||
399 | sub eax, 127 |
||
400 | jge @f |
||
401 | add [mouse.active_sys_window.new_box.left], eax |
||
402 | mov [mouse.active_sys_window.new_box.width], 127 |
||
2288 | clevermous | 403 | @@: |
404 | mov eax, [mouse.active_sys_window.new_box.left] |
||
1391 | mikedld | 405 | or eax, eax |
406 | jge .check_resize_s |
||
407 | add [mouse.active_sys_window.new_box.width], eax |
||
408 | xor eax, eax |
||
409 | mov [mouse.active_sys_window.new_box.left], eax |
||
410 | |||
411 | .check_resize_s: |
||
412 | test dl, mouse.WINDOW_RESIZE_S_FLAG |
||
413 | jz .check_resize_e |
||
414 | |||
415 | mov eax, [mouse.state.pos.y] |
||
416 | add eax, [mouse.active_sys_window.delta.y] |
||
417 | sub eax, [mouse.active_sys_window.old_box.top] |
||
418 | mov [mouse.active_sys_window.new_box.height], eax |
||
419 | |||
420 | push eax |
||
421 | mov edi, esi |
||
422 | shl edi, 5 |
||
423 | add edi, window_data |
||
424 | call window._.get_rolledup_height |
||
425 | mov ecx, eax |
||
426 | pop eax |
||
427 | mov eax, [mouse.active_sys_window.new_box.height] |
||
428 | cmp eax, ecx |
||
429 | jge @f |
||
430 | mov eax, ecx |
||
431 | mov [mouse.active_sys_window.new_box.height], eax |
||
2288 | clevermous | 432 | @@: |
433 | add eax, [mouse.active_sys_window.new_box.top] |
||
5350 | serge | 434 | cmp eax, [_display.height] |
435 | jl .check_resize_e |
||
436 | sub eax, [_display.height] |
||
1391 | mikedld | 437 | neg eax |
438 | add [mouse.active_sys_window.new_box.height], eax |
||
5350 | serge | 439 | mov ecx, [_display.height] |
1391 | mikedld | 440 | cmp ecx, eax |
5350 | serge | 441 | jg .check_resize_e |
1391 | mikedld | 442 | mov [mouse.active_sys_window.new_box.height], ecx |
443 | |||
444 | .check_resize_e: |
||
445 | test dl, mouse.WINDOW_RESIZE_E_FLAG |
||
446 | jz .call_window_handler |
||
447 | |||
448 | mov eax, [mouse.state.pos.x] |
||
449 | add eax, [mouse.active_sys_window.delta.x] |
||
450 | sub eax, [mouse.active_sys_window.old_box.left] |
||
451 | mov [mouse.active_sys_window.new_box.width], eax |
||
452 | |||
453 | mov eax, [mouse.active_sys_window.new_box.width] |
||
454 | cmp eax, 127 |
||
455 | jge @f |
||
456 | mov eax, 127 |
||
457 | mov [mouse.active_sys_window.new_box.width], eax |
||
2288 | clevermous | 458 | @@: |
459 | add eax, [mouse.active_sys_window.new_box.left] |
||
5350 | serge | 460 | cmp eax, [_display.width] |
461 | jl .call_window_handler |
||
462 | sub eax, [_display.width] |
||
1391 | mikedld | 463 | neg eax |
464 | add [mouse.active_sys_window.new_box.width], eax |
||
5350 | serge | 465 | mov ecx, [_display.width] |
1391 | mikedld | 466 | cmp ecx, eax |
5350 | serge | 467 | jg .call_window_handler |
1391 | mikedld | 468 | mov [mouse.active_sys_window.new_box.width], ecx |
469 | |||
470 | .call_window_handler: |
||
471 | mov eax, mouse.active_sys_window.old_box |
||
472 | mov ebx, mouse.active_sys_window.new_box |
||
473 | |||
474 | push esi |
||
475 | mov esi, mouse.active_sys_window.old_box |
||
476 | mov edi, mouse.active_sys_window.new_box |
||
2381 | hidnplayr | 477 | mov ecx, sizeof.BOX / 4 |
1391 | mikedld | 478 | repe |
479 | cmpsd |
||
480 | pop esi |
||
481 | je .exit |
||
482 | |||
483 | mov [mouse.active_sys_window.last_ticks], 0 |
||
484 | call sys_window_moving_handler |
||
485 | |||
486 | .exit: |
||
487 | ret |
||
488 | |||
489 | align 4 |
||
5851 | pathoswith | 490 | ;----------------------------------------------------------------- |
491 | mouse._.find_sys_window_under_cursor: |
||
492 | ; Find system window object which is currently visible on screen |
||
493 | ; and has mouse cursor within its bounds |
||
1391 | mikedld | 494 | ;< esi = process slot |
495 | ;< edi = pointer to WDATA struct |
||
2446 | mario79 | 496 | mov esi, [mouse.state.pos.y] |
497 | mov esi, [d_width_calc_area + esi*4] |
||
498 | |||
5351 | serge | 499 | add esi, [_display.win_map] |
1391 | mikedld | 500 | add esi, [mouse.state.pos.x] |
501 | movzx esi, byte[esi] |
||
502 | mov edi, esi |
||
503 | shl edi, 5 |
||
504 | add edi, window_data |
||
505 | ret |
||
506 | |||
507 | align 4 |
||
5851 | pathoswith | 508 | ;----------------------------------------------------------------- |
509 | mouse._.activate_sys_window_under_cursor: |
||
510 | ; activate and redraw window under cursor (if necessary) |
||
1391 | mikedld | 511 | call mouse._.find_sys_window_under_cursor |
512 | movzx esi, word[WIN_STACK + esi * 2] |
||
513 | lea esi, [WIN_POS + esi * 2] |
||
514 | jmp waredraw |
||
515 | |||
516 | align 4 |
||
5851 | pathoswith | 517 | ;----------------------------------------------------------------- |
518 | mouse._.find_sys_button_under_cursor: |
||
519 | ; Find system button object which is currently visible on screen |
||
520 | ; and has mouse cursor within its bounds |
||
1391 | mikedld | 521 | ;< eax = pack[8(process slot), 24(button id)] or 0 |
522 | ;< ebx = pack[16(button x coord), 16(button y coord)] |
||
523 | push ecx edx esi edi |
||
524 | |||
525 | call mouse._.find_sys_window_under_cursor |
||
526 | mov edx, esi |
||
527 | |||
528 | ; check if any process button contains cursor |
||
529 | mov eax, [BTN_ADDR] |
||
530 | mov ecx, [eax] |
||
2384 | hidnplayr | 531 | imul esi, ecx, sizeof.SYS_BUTTON |
1391 | mikedld | 532 | add esi, eax |
533 | inc ecx |
||
2384 | hidnplayr | 534 | add esi, sizeof.SYS_BUTTON |
1391 | mikedld | 535 | |
536 | .next_button: |
||
537 | dec ecx |
||
538 | jz .not_found |
||
539 | |||
2384 | hidnplayr | 540 | add esi, -sizeof.SYS_BUTTON |
1391 | mikedld | 541 | |
542 | ; does it belong to our process? |
||
543 | cmp dx, [esi + SYS_BUTTON.pslot] |
||
544 | jne .next_button |
||
545 | |||
546 | ; does it contain cursor coordinates? |
||
547 | mov eax, [mouse.state.pos.x] |
||
548 | sub eax, [edi + WDATA.box.left] |
||
549 | sub ax, [esi + SYS_BUTTON.left] |
||
550 | jl .next_button |
||
551 | sub ax, [esi + SYS_BUTTON.width] |
||
552 | jge .next_button |
||
553 | mov eax, [mouse.state.pos.y] |
||
554 | sub eax, [edi + WDATA.box.top] |
||
555 | sub ax, [esi + SYS_BUTTON.top] |
||
556 | jl .next_button |
||
557 | sub ax, [esi + SYS_BUTTON.height] |
||
558 | jge .next_button |
||
559 | |||
560 | ; okay, return it |
||
561 | shl edx, 24 |
||
562 | mov eax, dword[esi + SYS_BUTTON.id_hi - 2] |
||
563 | mov ax, [esi + SYS_BUTTON.id_lo] |
||
564 | and eax, 0x0ffffff |
||
565 | or eax, edx |
||
566 | mov ebx, dword[esi + SYS_BUTTON.left - 2] |
||
567 | mov bx, [esi + SYS_BUTTON.top] |
||
568 | jmp .exit |
||
569 | |||
570 | .not_found: |
||
571 | xor eax, eax |
||
572 | xor ebx, ebx |
||
573 | |||
574 | .exit: |
||
575 | pop edi esi edx ecx |
||
576 | ret |
||
577 | |||
578 | align 4 |
||
5851 | pathoswith | 579 | ;----------------------------------------------------------------- |
580 | mouse._.check_sys_window_actions: |
||
1391 | mikedld | 581 | ;< eax = action flags or 0 |
582 | ; is window movable? |
||
583 | test byte[edi + WDATA.cl_titlebar + 3], 0x01 |
||
584 | jnz .no_action |
||
585 | |||
586 | mov eax, [mouse.state.pos.x] |
||
587 | mov ebx, [mouse.state.pos.y] |
||
588 | sub eax, [edi + WDATA.box.left] |
||
589 | sub ebx, [edi + WDATA.box.top] |
||
590 | |||
591 | ; is there a window titlebar under cursor? |
||
592 | push eax |
||
593 | call window._.get_titlebar_height |
||
594 | cmp ebx, eax |
||
595 | pop eax |
||
596 | jl .move_action |
||
597 | |||
598 | ; no there isn't, can it be resized then? |
||
599 | mov dl, [edi + WDATA.fl_wstyle] |
||
600 | and dl, 0x0f |
||
5851 | pathoswith | 601 | ; NOTE: dangerous optimization, revise if window types changed |
602 | ; this currently implies only types 2 and 3 could be resized |
||
1391 | mikedld | 603 | test dl, 2 |
604 | jz .no_action |
||
605 | |||
606 | mov ecx, [edi + WDATA.box.width] |
||
607 | add ecx, -window.BORDER_SIZE |
||
608 | mov edx, [edi + WDATA.box.height] |
||
609 | add edx, -window.BORDER_SIZE |
||
610 | |||
611 | ; is it rolled up? |
||
612 | test [edi + WDATA.fl_wstate], WSTATE_ROLLEDUP |
||
613 | jnz .resize_w_or_e_action |
||
614 | |||
615 | cmp eax, window.BORDER_SIZE |
||
616 | jl .resize_w_action |
||
617 | cmp eax, ecx |
||
618 | jg .resize_e_action |
||
619 | cmp ebx, edx |
||
620 | jle .no_action |
||
621 | |||
622 | .resize_s_action: |
||
623 | cmp eax, window.BORDER_SIZE + 10 |
||
624 | jl .resize_sw_action |
||
625 | add ecx, -10 |
||
626 | cmp eax, ecx |
||
627 | jge .resize_se_action |
||
628 | mov eax, mouse.WINDOW_RESIZE_S_FLAG |
||
629 | jmp .exit |
||
630 | |||
631 | .resize_w_or_e_action: |
||
632 | cmp eax, window.BORDER_SIZE + 10 |
||
633 | jl .resize_w_action.direct |
||
634 | add ecx, -10 |
||
635 | cmp eax, ecx |
||
636 | jg .resize_e_action.direct |
||
637 | jmp .no_action |
||
638 | |||
639 | .resize_w_action: |
||
640 | add edx, -10 |
||
641 | cmp ebx, edx |
||
642 | jge .resize_sw_action |
||
643 | .resize_w_action.direct: |
||
644 | mov eax, mouse.WINDOW_RESIZE_W_FLAG |
||
645 | jmp .exit |
||
646 | |||
647 | .resize_e_action: |
||
648 | add edx, -10 |
||
649 | cmp ebx, edx |
||
650 | jge .resize_se_action |
||
651 | .resize_e_action.direct: |
||
652 | mov eax, mouse.WINDOW_RESIZE_E_FLAG |
||
653 | jmp .exit |
||
654 | |||
655 | .resize_sw_action: |
||
656 | mov eax, mouse.WINDOW_RESIZE_SW_FLAG |
||
657 | jmp .exit |
||
658 | |||
659 | .resize_se_action: |
||
660 | mov eax, mouse.WINDOW_RESIZE_SE_FLAG |
||
661 | jmp .exit |
||
662 | |||
663 | .move_action: |
||
664 | mov eax, mouse.WINDOW_MOVE_FLAG |
||
665 | jmp .exit |
||
666 | |||
667 | .no_action: |
||
668 | xor eax, eax |
||
669 | |||
670 | .exit: |
||
671 | ret>>>>> |