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