Rev 9828 | Rev 9848 | 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: 9831 $ |
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 | |||
62 | ; is there any system button under cursor? |
||
2288 | clevermous | 63 | call mouse._.find_sys_button_under_cursor |
1391 | mikedld | 64 | or eax, eax |
65 | jz .check_buttons_released |
||
66 | |||
67 | ; yes there is, activate it and exit |
||
68 | mov [mouse.active_sys_button.pbid], eax |
||
69 | mov [mouse.active_sys_button.coord], ebx |
||
70 | mov cl, [mouse.state.buttons] |
||
71 | mov [mouse.active_sys_button.buttons], cl |
||
72 | call sys_button_activate_handler |
||
73 | jmp .exit |
||
74 | |||
75 | .check_buttons_released: |
||
76 | cmp [mouse.state.buttons], 0 |
||
77 | jnz .buttons_changed |
||
78 | |||
79 | ; did we press some button earlier? |
||
80 | cmp [mouse.active_sys_button.pbid], 0 |
||
81 | je .buttons_changed |
||
82 | |||
83 | ; yes we did, deactivate it |
||
84 | xor eax, eax |
||
85 | xchg eax, [mouse.active_sys_button.pbid] |
||
86 | mov ebx, [mouse.active_sys_button.coord] |
||
87 | mov cl, [mouse.active_sys_button.buttons] |
||
88 | push eax ebx |
||
89 | call sys_button_deactivate_handler |
||
90 | pop edx ecx |
||
91 | |||
92 | ; is the button under cursor the one we deactivated? |
||
93 | call mouse._.find_sys_button_under_cursor |
||
94 | cmp eax, ecx |
||
95 | jne .exit |
||
96 | cmp ebx, edx |
||
97 | jne .exit |
||
98 | |||
99 | ; yes it is, perform associated action |
||
100 | mov cl, [mouse.active_sys_button.buttons] |
||
101 | call sys_button_perform_handler |
||
102 | jmp .exit |
||
103 | |||
104 | .buttons_changed: |
||
105 | test byte[esp], mouse.LEFT_BUTTON_FLAG |
||
106 | jz @f |
||
107 | mov eax, [esp + 4] |
||
108 | call .call_left_button_handler |
||
109 | |||
2288 | clevermous | 110 | @@: |
111 | test byte[esp], mouse.RIGHT_BUTTON_FLAG |
||
1391 | mikedld | 112 | jz @f |
113 | mov eax, [esp + 4] |
||
114 | call .call_right_button_handler |
||
115 | |||
2288 | clevermous | 116 | @@: |
117 | test byte[esp], mouse.MIDDLE_BUTTON_FLAG |
||
1391 | mikedld | 118 | jz .check_position |
119 | mov eax, [esp + 4] |
||
120 | call .call_middle_button_handler |
||
121 | |||
122 | .check_position: |
||
123 | movzx eax, word[MOUSE_X] |
||
124 | movzx ebx, word[MOUSE_Y] |
||
125 | cmp eax, [mouse.state.pos.x] |
||
126 | jne .position_changed |
||
127 | cmp ebx, [mouse.state.pos.y] |
||
128 | je .exit |
||
129 | |||
130 | .position_changed: |
||
131 | xchg eax, [mouse.state.pos.x] |
||
132 | xchg ebx, [mouse.state.pos.y] |
||
133 | |||
134 | call mouse._.move_handler |
||
135 | |||
136 | .exit: |
||
137 | add esp, 8 |
||
138 | pop ebx eax |
||
139 | ret |
||
140 | |||
141 | .call_left_button_handler: |
||
142 | test eax, mouse.LEFT_BUTTON_FLAG |
||
143 | jnz mouse._.left_button_press_handler |
||
144 | jmp mouse._.left_button_release_handler |
||
145 | |||
146 | .call_right_button_handler: |
||
147 | test eax, mouse.RIGHT_BUTTON_FLAG |
||
148 | jnz mouse._.right_button_press_handler |
||
149 | jmp mouse._.right_button_release_handler |
||
150 | |||
151 | .call_middle_button_handler: |
||
152 | test eax, mouse.MIDDLE_BUTTON_FLAG |
||
153 | jnz mouse._.middle_button_press_handler |
||
154 | jmp mouse._.middle_button_release_handler |
||
155 | |||
5851 | pathoswith | 156 | ;=============================== |
157 | ;////// private functions ////// |
||
158 | ;=============================== |
||
1391 | mikedld | 159 | |
160 | uglobal |
||
161 | mouse.state: |
||
162 | .pos POINT |
||
163 | .buttons db ? |
||
164 | |||
5851 | pathoswith | 165 | ; NOTE: since there's no unique and lifetime-constant button identifiers, |
166 | ; we are using two dwords to identify each of them: |
||
167 | ; * pbid - process slot (high 8 bits) and button id (low 24 bits) pack |
||
168 | ; * coord - left (high 16 bits) and top (low 16 bits) coordinates pack |
||
1391 | mikedld | 169 | align 4 |
170 | mouse.active_sys_button: |
||
171 | .pbid dd ? |
||
172 | .coord dd ? |
||
173 | .buttons db ? |
||
174 | |||
175 | align 4 |
||
176 | mouse.active_sys_window: |
||
177 | .pslot dd ? |
||
178 | .old_box BOX |
||
179 | .new_box BOX |
||
180 | .delta POINT |
||
181 | .last_ticks dd ? |
||
182 | .action db ? |
||
183 | endg |
||
184 | |||
5870 | GerdtR | 185 | iglobal |
186 | fl_moving db 0 |
||
187 | rb 3 |
||
188 | endg |
||
189 | |||
1391 | mikedld | 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 |
5870 | GerdtR | 309 | mov [fl_moving], 0 |
1391 | mikedld | 310 | ret |
311 | |||
5851 | pathoswith | 312 | mouse._.right_button_press_handler: |
313 | bts word [BTN_DOWN], 9 |
||
1391 | mikedld | 314 | test [mouse.state.buttons], not mouse.RIGHT_BUTTON_FLAG |
5851 | pathoswith | 315 | jnz @f |
1391 | mikedld | 316 | call mouse._.find_sys_window_under_cursor |
317 | call mouse._.check_sys_window_actions |
||
318 | test al, mouse.WINDOW_MOVE_FLAG |
||
5851 | pathoswith | 319 | jz @f |
320 | jmp sys_window_rollup_handler |
||
1391 | mikedld | 321 | |
5851 | pathoswith | 322 | mouse._.right_button_release_handler: |
323 | bts dword [BTN_DOWN], 17 |
||
324 | @@: |
||
1391 | mikedld | 325 | ret |
326 | |||
5851 | pathoswith | 327 | mouse._.middle_button_press_handler: |
328 | bts word [BTN_DOWN], 10 |
||
1391 | mikedld | 329 | ret |
330 | |||
5851 | pathoswith | 331 | mouse._.middle_button_release_handler: |
332 | bts dword [BTN_DOWN], 18 |
||
1391 | mikedld | 333 | ret |
334 | |||
335 | align 4 |
||
5851 | pathoswith | 336 | ;----------------------------------------------------------------- |
337 | mouse._.move_handler: |
||
338 | ; Called when cursor has been moved |
||
1391 | mikedld | 339 | ;> eax = old x coord |
340 | ;> ebx = old y coord |
||
341 | cmp [mouse.active_sys_button.pbid], 0 |
||
342 | jnz .exit |
||
343 | |||
344 | mov esi, [mouse.active_sys_window.pslot] |
||
345 | or esi, esi |
||
346 | jz .exit |
||
347 | |||
348 | mov eax, mouse.active_sys_window.new_box |
||
349 | mov ebx, mouse.active_sys_window.old_box |
||
2381 | hidnplayr | 350 | mov ecx, sizeof.BOX |
1391 | mikedld | 351 | call memmove |
352 | |||
353 | mov dl, [mouse.active_sys_window.action] |
||
354 | test dl, mouse.WINDOW_MOVE_FLAG |
||
355 | jz .check_resize_w |
||
356 | |||
357 | mov eax, [mouse.state.pos.x] |
||
358 | sub eax, [mouse.active_sys_window.delta.x] |
||
359 | mov [mouse.active_sys_window.new_box.left], eax |
||
360 | mov eax, [mouse.state.pos.y] |
||
361 | sub eax, [mouse.active_sys_window.delta.y] |
||
362 | mov [mouse.active_sys_window.new_box.top], eax |
||
363 | |||
364 | mov eax, [mouse.active_sys_window.new_box.left] |
||
365 | or eax, eax |
||
366 | jge @f |
||
367 | xor eax, eax |
||
368 | mov [mouse.active_sys_window.new_box.left], eax |
||
2288 | clevermous | 369 | @@: |
370 | add eax, [mouse.active_sys_window.new_box.width] |
||
5350 | serge | 371 | cmp eax, [_display.width] |
1391 | mikedld | 372 | jl @f |
5350 | serge | 373 | sub eax, [_display.width] |
8928 | dunkaist | 374 | inc eax |
1391 | mikedld | 375 | sub [mouse.active_sys_window.new_box.left], eax |
2288 | clevermous | 376 | @@: |
377 | mov eax, [mouse.active_sys_window.new_box.top] |
||
1391 | mikedld | 378 | or eax, eax |
379 | jge @f |
||
380 | xor eax, eax |
||
381 | mov [mouse.active_sys_window.new_box.top], eax |
||
2288 | clevermous | 382 | @@: |
383 | add eax, [mouse.active_sys_window.new_box.height] |
||
5350 | serge | 384 | cmp eax, [_display.height] |
385 | jl .call_window_handler |
||
386 | sub eax, [_display.height] |
||
8928 | dunkaist | 387 | inc eax |
1391 | mikedld | 388 | sub [mouse.active_sys_window.new_box.top], eax |
389 | jmp .call_window_handler |
||
390 | |||
391 | .check_resize_w: |
||
392 | test dl, mouse.WINDOW_RESIZE_W_FLAG |
||
393 | jz .check_resize_s |
||
394 | |||
395 | mov eax, [mouse.state.pos.x] |
||
396 | sub eax, [mouse.active_sys_window.delta.x] |
||
397 | mov [mouse.active_sys_window.new_box.left], eax |
||
398 | sub eax, [mouse.active_sys_window.old_box.left] |
||
399 | sub [mouse.active_sys_window.new_box.width], eax |
||
400 | |||
401 | mov eax, [mouse.active_sys_window.new_box.width] |
||
402 | sub eax, 127 |
||
403 | jge @f |
||
404 | add [mouse.active_sys_window.new_box.left], eax |
||
405 | mov [mouse.active_sys_window.new_box.width], 127 |
||
2288 | clevermous | 406 | @@: |
407 | mov eax, [mouse.active_sys_window.new_box.left] |
||
1391 | mikedld | 408 | or eax, eax |
409 | jge .check_resize_s |
||
410 | add [mouse.active_sys_window.new_box.width], eax |
||
411 | xor eax, eax |
||
412 | mov [mouse.active_sys_window.new_box.left], eax |
||
413 | |||
414 | .check_resize_s: |
||
415 | test dl, mouse.WINDOW_RESIZE_S_FLAG |
||
416 | jz .check_resize_e |
||
417 | |||
418 | mov eax, [mouse.state.pos.y] |
||
419 | add eax, [mouse.active_sys_window.delta.y] |
||
420 | sub eax, [mouse.active_sys_window.old_box.top] |
||
421 | mov [mouse.active_sys_window.new_box.height], eax |
||
422 | |||
423 | push eax |
||
424 | mov edi, esi |
||
425 | shl edi, 5 |
||
426 | add edi, window_data |
||
427 | call window._.get_rolledup_height |
||
428 | mov ecx, eax |
||
429 | pop eax |
||
430 | mov eax, [mouse.active_sys_window.new_box.height] |
||
431 | cmp eax, ecx |
||
432 | jge @f |
||
433 | mov eax, ecx |
||
434 | mov [mouse.active_sys_window.new_box.height], eax |
||
2288 | clevermous | 435 | @@: |
436 | add eax, [mouse.active_sys_window.new_box.top] |
||
5350 | serge | 437 | cmp eax, [_display.height] |
438 | jl .check_resize_e |
||
439 | sub eax, [_display.height] |
||
1391 | mikedld | 440 | neg eax |
441 | add [mouse.active_sys_window.new_box.height], eax |
||
5350 | serge | 442 | mov ecx, [_display.height] |
1391 | mikedld | 443 | cmp ecx, eax |
5350 | serge | 444 | jg .check_resize_e |
1391 | mikedld | 445 | mov [mouse.active_sys_window.new_box.height], ecx |
446 | |||
447 | .check_resize_e: |
||
448 | test dl, mouse.WINDOW_RESIZE_E_FLAG |
||
449 | jz .call_window_handler |
||
450 | |||
451 | mov eax, [mouse.state.pos.x] |
||
452 | add eax, [mouse.active_sys_window.delta.x] |
||
453 | sub eax, [mouse.active_sys_window.old_box.left] |
||
454 | mov [mouse.active_sys_window.new_box.width], eax |
||
455 | |||
456 | mov eax, [mouse.active_sys_window.new_box.width] |
||
457 | cmp eax, 127 |
||
458 | jge @f |
||
459 | mov eax, 127 |
||
460 | mov [mouse.active_sys_window.new_box.width], eax |
||
2288 | clevermous | 461 | @@: |
462 | add eax, [mouse.active_sys_window.new_box.left] |
||
5350 | serge | 463 | cmp eax, [_display.width] |
464 | jl .call_window_handler |
||
465 | sub eax, [_display.width] |
||
1391 | mikedld | 466 | neg eax |
467 | add [mouse.active_sys_window.new_box.width], eax |
||
5350 | serge | 468 | mov ecx, [_display.width] |
1391 | mikedld | 469 | cmp ecx, eax |
5350 | serge | 470 | jg .call_window_handler |
1391 | mikedld | 471 | mov [mouse.active_sys_window.new_box.width], ecx |
472 | |||
473 | .call_window_handler: |
||
474 | mov eax, mouse.active_sys_window.old_box |
||
475 | mov ebx, mouse.active_sys_window.new_box |
||
476 | |||
477 | push esi |
||
478 | mov esi, mouse.active_sys_window.old_box |
||
479 | mov edi, mouse.active_sys_window.new_box |
||
2381 | hidnplayr | 480 | mov ecx, sizeof.BOX / 4 |
1391 | mikedld | 481 | repe |
482 | cmpsd |
||
483 | pop esi |
||
484 | je .exit |
||
485 | |||
5870 | GerdtR | 486 | test [fl_moving], 1 |
487 | jnz @f |
||
488 | |||
489 | mov [fl_moving], 1 |
||
490 | push edi |
||
491 | mov edi, esi |
||
492 | shl edi, 5 |
||
493 | add edi, WDATA.box + window_data |
||
494 | call window._.draw_negative_box |
||
495 | pop edi |
||
496 | @@: |
||
497 | |||
498 | |||
1391 | mikedld | 499 | mov [mouse.active_sys_window.last_ticks], 0 |
500 | call sys_window_moving_handler |
||
501 | |||
502 | .exit: |
||
503 | ret |
||
504 | |||
505 | align 4 |
||
5851 | pathoswith | 506 | ;----------------------------------------------------------------- |
507 | mouse._.find_sys_window_under_cursor: |
||
508 | ; Find system window object which is currently visible on screen |
||
509 | ; and has mouse cursor within its bounds |
||
1391 | mikedld | 510 | ;< esi = process slot |
511 | ;< edi = pointer to WDATA struct |
||
2446 | mario79 | 512 | mov esi, [mouse.state.pos.y] |
513 | mov esi, [d_width_calc_area + esi*4] |
||
514 | |||
5351 | serge | 515 | add esi, [_display.win_map] |
1391 | mikedld | 516 | add esi, [mouse.state.pos.x] |
517 | movzx esi, byte[esi] |
||
518 | mov edi, esi |
||
519 | shl edi, 5 |
||
520 | add edi, window_data |
||
521 | ret |
||
522 | |||
523 | align 4 |
||
5851 | pathoswith | 524 | ;----------------------------------------------------------------- |
525 | mouse._.activate_sys_window_under_cursor: |
||
526 | ; activate and redraw window under cursor (if necessary) |
||
1391 | mikedld | 527 | call mouse._.find_sys_window_under_cursor |
528 | movzx esi, word[WIN_STACK + esi * 2] |
||
529 | lea esi, [WIN_POS + esi * 2] |
||
530 | jmp waredraw |
||
531 | |||
532 | align 4 |
||
5851 | pathoswith | 533 | ;----------------------------------------------------------------- |
534 | mouse._.find_sys_button_under_cursor: |
||
535 | ; Find system button object which is currently visible on screen |
||
536 | ; and has mouse cursor within its bounds |
||
1391 | mikedld | 537 | ;< eax = pack[8(process slot), 24(button id)] or 0 |
538 | ;< ebx = pack[16(button x coord), 16(button y coord)] |
||
539 | push ecx edx esi edi |
||
540 | |||
541 | call mouse._.find_sys_window_under_cursor |
||
542 | mov edx, esi |
||
543 | |||
544 | ; check if any process button contains cursor |
||
545 | mov eax, [BTN_ADDR] |
||
546 | mov ecx, [eax] |
||
2384 | hidnplayr | 547 | imul esi, ecx, sizeof.SYS_BUTTON |
1391 | mikedld | 548 | add esi, eax |
549 | inc ecx |
||
2384 | hidnplayr | 550 | add esi, sizeof.SYS_BUTTON |
1391 | mikedld | 551 | |
552 | .next_button: |
||
553 | dec ecx |
||
554 | jz .not_found |
||
555 | |||
2384 | hidnplayr | 556 | add esi, -sizeof.SYS_BUTTON |
1391 | mikedld | 557 | |
558 | ; does it belong to our process? |
||
559 | cmp dx, [esi + SYS_BUTTON.pslot] |
||
560 | jne .next_button |
||
561 | |||
562 | ; does it contain cursor coordinates? |
||
563 | mov eax, [mouse.state.pos.x] |
||
564 | sub eax, [edi + WDATA.box.left] |
||
565 | sub ax, [esi + SYS_BUTTON.left] |
||
566 | jl .next_button |
||
567 | sub ax, [esi + SYS_BUTTON.width] |
||
568 | jge .next_button |
||
569 | mov eax, [mouse.state.pos.y] |
||
570 | sub eax, [edi + WDATA.box.top] |
||
571 | sub ax, [esi + SYS_BUTTON.top] |
||
572 | jl .next_button |
||
573 | sub ax, [esi + SYS_BUTTON.height] |
||
574 | jge .next_button |
||
575 | |||
576 | ; okay, return it |
||
577 | shl edx, 24 |
||
578 | mov eax, dword[esi + SYS_BUTTON.id_hi - 2] |
||
579 | mov ax, [esi + SYS_BUTTON.id_lo] |
||
580 | and eax, 0x0ffffff |
||
581 | or eax, edx |
||
582 | mov ebx, dword[esi + SYS_BUTTON.left - 2] |
||
583 | mov bx, [esi + SYS_BUTTON.top] |
||
584 | jmp .exit |
||
585 | |||
586 | .not_found: |
||
587 | xor eax, eax |
||
588 | xor ebx, ebx |
||
589 | |||
590 | .exit: |
||
591 | pop edi esi edx ecx |
||
592 | ret |
||
593 | |||
594 | align 4 |
||
5851 | pathoswith | 595 | ;----------------------------------------------------------------- |
596 | mouse._.check_sys_window_actions: |
||
1391 | mikedld | 597 | ;< eax = action flags or 0 |
598 | ; is window movable? |
||
599 | test byte[edi + WDATA.cl_titlebar + 3], 0x01 |
||
600 | jnz .no_action |
||
601 | |||
602 | mov eax, [mouse.state.pos.x] |
||
603 | mov ebx, [mouse.state.pos.y] |
||
604 | sub eax, [edi + WDATA.box.left] |
||
605 | sub ebx, [edi + WDATA.box.top] |
||
606 | |||
607 | ; is there a window titlebar under cursor? |
||
608 | push eax |
||
609 | call window._.get_titlebar_height |
||
610 | cmp ebx, eax |
||
611 | pop eax |
||
612 | jl .move_action |
||
613 | |||
614 | ; no there isn't, can it be resized then? |
||
615 | mov dl, [edi + WDATA.fl_wstyle] |
||
616 | and dl, 0x0f |
||
5851 | pathoswith | 617 | ; NOTE: dangerous optimization, revise if window types changed |
618 | ; this currently implies only types 2 and 3 could be resized |
||
1391 | mikedld | 619 | test dl, 2 |
620 | jz .no_action |
||
621 | |||
622 | mov ecx, [edi + WDATA.box.width] |
||
623 | add ecx, -window.BORDER_SIZE |
||
624 | mov edx, [edi + WDATA.box.height] |
||
625 | add edx, -window.BORDER_SIZE |
||
626 | |||
627 | ; is it rolled up? |
||
628 | test [edi + WDATA.fl_wstate], WSTATE_ROLLEDUP |
||
629 | jnz .resize_w_or_e_action |
||
630 | |||
631 | cmp eax, window.BORDER_SIZE |
||
632 | jl .resize_w_action |
||
633 | cmp eax, ecx |
||
634 | jg .resize_e_action |
||
635 | cmp ebx, edx |
||
636 | jle .no_action |
||
637 | |||
638 | .resize_s_action: |
||
639 | cmp eax, window.BORDER_SIZE + 10 |
||
640 | jl .resize_sw_action |
||
641 | add ecx, -10 |
||
642 | cmp eax, ecx |
||
643 | jge .resize_se_action |
||
644 | mov eax, mouse.WINDOW_RESIZE_S_FLAG |
||
645 | jmp .exit |
||
646 | |||
647 | .resize_w_or_e_action: |
||
648 | cmp eax, window.BORDER_SIZE + 10 |
||
649 | jl .resize_w_action.direct |
||
650 | add ecx, -10 |
||
651 | cmp eax, ecx |
||
652 | jg .resize_e_action.direct |
||
653 | jmp .no_action |
||
654 | |||
655 | .resize_w_action: |
||
656 | add edx, -10 |
||
657 | cmp ebx, edx |
||
658 | jge .resize_sw_action |
||
659 | .resize_w_action.direct: |
||
660 | mov eax, mouse.WINDOW_RESIZE_W_FLAG |
||
661 | jmp .exit |
||
662 | |||
663 | .resize_e_action: |
||
664 | add edx, -10 |
||
665 | cmp ebx, edx |
||
666 | jge .resize_se_action |
||
667 | .resize_e_action.direct: |
||
668 | mov eax, mouse.WINDOW_RESIZE_E_FLAG |
||
669 | jmp .exit |
||
670 | |||
671 | .resize_sw_action: |
||
672 | mov eax, mouse.WINDOW_RESIZE_SW_FLAG |
||
673 | jmp .exit |
||
674 | |||
675 | .resize_se_action: |
||
676 | mov eax, mouse.WINDOW_RESIZE_SE_FLAG |
||
677 | jmp .exit |
||
678 | |||
679 | .move_action: |
||
680 | mov eax, mouse.WINDOW_MOVE_FLAG |
||
681 | jmp .exit |
||
682 | |||
683 | .no_action: |
||
684 | xor eax, eax |
||
685 | |||
686 | .exit: |
||
687 | ret |
||
9514 | rgimad | 688 | ;----------------------------------------------------------------------------- |
689 | |||
690 | align 4 |
||
691 | readmousepos: |
||
692 | ; eax=0 screen relative |
||
693 | ; eax=1 window relative |
||
694 | ; eax=2 buttons pressed |
||
695 | ; eax=3 buttons pressed ext |
||
696 | ; eax=4 load cursor |
||
697 | ; eax=5 set cursor |
||
698 | ; eax=6 delete cursor |
||
699 | ; eax=7 get mouse_z |
||
700 | ; eax=8 load cursor unicode |
||
701 | cmp ebx, 8 |
||
702 | ja @f |
||
703 | jmp dword[.mousefn+ebx*4] |
||
704 | |||
705 | align 4 |
||
706 | .mousefn: |
||
707 | dd .msscreen |
||
708 | dd .mswin |
||
709 | dd .msbutton |
||
710 | dd .msbuttonExt |
||
711 | dd .app_load_cursor |
||
712 | dd .app_set_cursor |
||
713 | dd .app_delete_cursor |
||
714 | dd .msz |
||
715 | dd .loadCursorUni |
||
716 | |||
717 | .msscreen: |
||
718 | mov eax, [MOUSE_X] |
||
719 | shl eax, 16 |
||
720 | mov ax, [MOUSE_Y] |
||
9831 | dunkaist | 721 | mov [esp + SYSCALL_STACK.eax], eax |
9514 | rgimad | 722 | @@: |
723 | ret |
||
724 | |||
725 | .mswin: |
||
726 | mov eax, [MOUSE_X] |
||
727 | shl eax, 16 |
||
728 | mov ax, [MOUSE_Y] |
||
9709 | Doczom | 729 | mov esi, [current_slot_idx] |
730 | shl esi, BSF sizeof.WDATA |
||
731 | mov bx, word [esi + window_data + WDATA.box.left] |
||
9514 | rgimad | 732 | shl ebx, 16 |
9709 | Doczom | 733 | mov bx, word [esi + window_data + WDATA.box.top] |
9514 | rgimad | 734 | sub eax, ebx |
9828 | Doczom | 735 | mov edi, [current_slot] |
736 | sub ax, word[edi + APPDATA.wnd_clientbox.top] |
||
9514 | rgimad | 737 | rol eax, 16 |
9828 | Doczom | 738 | sub ax, word[edi + APPDATA.wnd_clientbox.left] |
9514 | rgimad | 739 | rol eax, 16 |
9831 | dunkaist | 740 | mov [esp + SYSCALL_STACK.eax], eax |
9514 | rgimad | 741 | ret |
742 | |||
743 | .msbutton: |
||
744 | movzx eax, byte [BTN_DOWN] |
||
9831 | dunkaist | 745 | mov [esp + SYSCALL_STACK.eax], eax |
9514 | rgimad | 746 | ret |
747 | |||
748 | .msbuttonExt: |
||
749 | mov eax, [BTN_DOWN] |
||
9831 | dunkaist | 750 | mov [esp + SYSCALL_STACK.eax], eax |
9514 | rgimad | 751 | ret |
752 | |||
753 | .app_load_cursor: |
||
754 | cmp ecx, OS_BASE |
||
755 | jae @f |
||
756 | stdcall load_cursor, ecx, edx |
||
9831 | dunkaist | 757 | mov [esp + SYSCALL_STACK.eax], eax |
9514 | rgimad | 758 | @@: |
759 | ret |
||
760 | |||
761 | .loadCursorUni: |
||
762 | cmp ecx, OS_BASE |
||
763 | jae @b |
||
764 | push ecx edx |
||
765 | stdcall kernel_alloc, maxPathLength |
||
766 | mov edi, eax |
||
767 | pop eax esi |
||
768 | push edi |
||
769 | call getFullPath |
||
770 | pop ebp |
||
771 | test eax, eax |
||
772 | jz @f |
||
773 | stdcall load_cursor, ebp, LOAD_FROM_FILE |
||
9831 | dunkaist | 774 | mov [esp + SYSCALL_STACK.eax], eax |
9514 | rgimad | 775 | @@: |
776 | stdcall kernel_free, ebp |
||
777 | ret |
||
778 | |||
779 | .app_set_cursor: |
||
780 | stdcall set_cursor, ecx |
||
9831 | dunkaist | 781 | mov [esp + SYSCALL_STACK.eax], eax |
9514 | rgimad | 782 | ret |
783 | |||
784 | .app_delete_cursor: |
||
785 | stdcall delete_cursor, ecx |
||
9831 | dunkaist | 786 | mov [esp + SYSCALL_STACK.eax], eax |
9514 | rgimad | 787 | ret |
788 | |||
789 | .msz: |
||
790 | mov edi, [thread_count] |
||
791 | movzx edi, word [WIN_POS + edi*2] |
||
792 | cmp edi, [current_slot_idx] |
||
793 | jne @f |
||
794 | mov ax, [MOUSE_SCROLL_H] |
||
795 | shl eax, 16 |
||
796 | mov ax, [MOUSE_SCROLL_V] |
||
9831 | dunkaist | 797 | mov [esp + SYSCALL_STACK.eax], eax |
9514 | rgimad | 798 | and [MOUSE_SCROLL_H], word 0 |
799 | and [MOUSE_SCROLL_V], word 0 |
||
800 | ret |
||
801 | @@: |
||
9831 | dunkaist | 802 | and [esp + SYSCALL_STACK.eax], dword 0 |
803 | ret>>>>> |