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