Rev 1531 | Go to most recent revision | Details | 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 | |||
8 | $Revision: -1 $ |
||
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:< |