Debian Codegraph @

ddio/lnxmouse.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/ddio_lnx/lnxmouse.cpp $
21 * $Revision: 1.10 $
22 * $Date: 2000/07/07 03:47:19 $
23 * $Author: hercules $
24 *
25 * Linux mouse routines
26 *
27 * $Log: lnxmouse.cpp,v $
28 * Revision 1.10 2000/07/07 03:47:19 hercules
29 * Scale the ball values to mouse range (64000 -> 640)
30 *
31 * Revision 1.9 2000/07/04 00:30:04 icculus
32 * Again.
33 *
34 * Revision 1.8 2000/07/04 00:29:00 icculus
35 * Cleanups. Removed chunks of commented-out, abandoned attempts, and some
36 * no-longer used global variables.
37 *
38 * Revision 1.7 2000/06/29 10:38:45 hercules
39 * Don't warp the mouse during mouse reset
40 *
41 * Revision 1.6 2000/06/29 09:51:53 hercules
42 * Added support for wheel mouse
43 *
44 * Revision 1.5 2000/06/29 06:41:23 icculus
45 * mad commits.
46 *
47 * Revision 1.4 2000/06/24 01:15:15 icculus
48 * patched to compile.
49 *
50 * Revision 1.3 2000/04/28 20:13:42 icculus
51 * Took out some mprintfs
52 *
53 * Revision 1.2 2000/04/27 11:36:29 icculus
54 * Rewritten to use SDL.
55 *
56 * Revision 1.1.1.1 2000/04/18 00:00:33 icculus
57 * initial checkin
58 *
59 *
60 * 17 9/09/99 4:36p Jeff
61 * use DGA extension for much better mouse control
62 *
63 * 16 9/07/99 4:35p Jeff
64 * added a call to XSync() to attempt to better the mouse performance...
65 *
66 * 15 8/22/99 10:00p Jeff
67 * attempt to better the mouse motion...but it's not working...XWindows
68 * seems to buffer up motion motion events when the mouse moves very
69 * small. Added support for up to 5 mouse buttons
70 *
71 * 14 8/19/99 2:24p Jeff
72 * mouse resets to center of the screen
73 *
74 * 13 7/14/99 9:06p Jeff
75 * added comment header
76 *
77 * $NoKeywords: $
78 */
79
80 // ----------------------------------------------------------------------------
81 // Mouse Interface
82 // ----------------------------------------------------------------------------
83
84 #include <cstring>
85 #include <SDL.h>
86
87 #include "pserror.h"cxx . . $ `<file>/misc/pserror.h`/
88 #include "psclass.h"cxx . . $ `<file>/lib/psclass.h`/
89 #include "ddio.h"cxx . . $ `<file>/ddio/ddio.h`/
90 #include "ddio_lnx.h"cxx . . $ `<file>/ddio/ddio_lnx.h`/
91
92 bool ddio_mouseGrabbedcxx . . $ ddio_mouseGrabbed. = false;
93 static bool DDIO_mouse_initcxx . . $ DDIO_mouse_init. = false;
94
95 static struct mses_statecxx . . $ mses_state# {
96 int fdcxx . . $ mses_state#fd.; // file descriptor of mouse
97 int tcxx . . $ mses_state#t., lcxx . . $ mses_state#l., bcxx . . $ mses_state#b., rcxx . . $ mses_state#r.; // limit rectangle of absolute mouse coords
98 int xcxx . . $ mses_state#x., ycxx . . $ mses_state#y., dxcxx . . $ mses_state#dx., dycxx . . $ mses_state#dy., cxcxx . . $ mses_state#cx., cycxx . . $ mses_state#cy.; // current x,y,z in absolute mouse coords
99 int btn_maskcxx . . $ mses_state#btn_mask.;
100 } DDIO_mouse_statecxx . . $ DDIO_mouse_state.;
101
102 struct t_mse_button_infocxx . . $ t_mse_button_info# {
103 bool is_downcxx . . $ t_mse_button_info#is_down.[N_MSEBTNScxx . . $ `ddio/ddio.h:252:9`!];
104 uint8_tcxx . . $ uint8_t# down_countcxx . . $ t_mse_button_info#down_count.[N_MSEBTNScxx . . $ `ddio/ddio.h:252:9`!];
105 uint8_tcxx . . $ uint8_t# up_countcxx . . $ t_mse_button_info#up_count.[N_MSEBTNScxx . . $ `ddio/ddio.h:252:9`!];
106 float time_downcxx . . $ t_mse_button_info#time_down.[N_MSEBTNScxx . . $ `ddio/ddio.h:252:9`!];
107 float time_upcxx . . $ t_mse_button_info#time_up.[N_MSEBTNScxx . . $ `ddio/ddio.h:252:9`!];
108 };
109
110 struct t_mse_eventcxx . . $ t_mse_event# {
111 int16_t btncxx . . $ t_mse_event#btn.;
112 int16_t statecxx . . $ t_mse_event#state.;
113 };
114
115 static t_mse_button_infocxx . . $ t_mse_button_info# DIM_buttonscxx . . $ DIM_buttons.;
116 static tQueuecxx . . $ tQueue#<t_mse_eventcxx . . $ t_mse_event#, 16> MB_queuecxx . . $ MB_queue.;
117 static int Mouse_modecxx . . $ Mouse_mode. = MOUSE_STANDARD_MODEcxx . . $ `ddio/ddio.h:262:9`!;
118
119 // ---------------------------------------------------------------------------
120 // Initialization Functions
121
122 bool ddio_MouseInitcxx . . $ ddio_MouseInit(c9857a73d68e59ba).(void) {
123 DDIO_mouse_initcxx . . $ DDIO_mouse_init. = true;
124 ddio_MouseResetcxx . . $ ddio_MouseReset(49f6e7a06ebc5aa8).();
125 return true;
126 }
127
128 int ddio_MouseGetCapscxx . . $ ddio_MouseGetCaps(aa23d0250da59a45).(int *buttons, int *axes) {
129 *buttons = 6;
130 *axes = 2;
131 return MOUSE_LBcxx . . $ `ddio/ddio.h:243:9`! | MOUSE_CBcxx . . $ `ddio/ddio.h:245:9`! | MOUSE_RBcxx . . $ `ddio/ddio.h:244:9`!;
132 }
133
134 void ddio_MouseClosecxx . . $ ddio_MouseClose(49f6e7a06ebc5aa8).() { DDIO_mouse_initcxx . . $ DDIO_mouse_init. = false; }
135
136 void ddio_MouseSetLimitscxx . . $ ddio_MouseSetLimits(4df37d5d0c1dcce).(int left, int top, int right, int bottom, int zmin, int zmax) {
137 DDIO_mouse_statecxx . . $ DDIO_mouse_state..lcxx . . $ mses_state#l. = left;
138 DDIO_mouse_statecxx . . $ DDIO_mouse_state..tcxx . . $ mses_state#t. = top;
139 DDIO_mouse_statecxx . . $ DDIO_mouse_state..rcxx . . $ mses_state#r. = right;
140 DDIO_mouse_statecxx . . $ DDIO_mouse_state..bcxx . . $ mses_state#b. = bottom;
141 }
142
143 void ddio_MouseGetLimitscxx . . $ ddio_MouseGetLimits(883f425df92af248).(int *left, int *top, int *right, int *bottom, int *zmin, int *zmax) {
144 *left = DDIO_mouse_statecxx . . $ DDIO_mouse_state..lcxx . . $ mses_state#l.;
145 *top = DDIO_mouse_statecxx . . $ DDIO_mouse_state..tcxx . . $ mses_state#t.;
146 *right = DDIO_mouse_statecxx . . $ DDIO_mouse_state..rcxx . . $ mses_state#r.;
147 *bottom = DDIO_mouse_statecxx . . $ DDIO_mouse_state..bcxx . . $ mses_state#b.;
148
149 if (zmin)
150 *zmin = 0;
151 if (zmax)
152 *zmax = 10;
153 }
154
155 void ddio_MouseResetcxx . . $ ddio_MouseReset(49f6e7a06ebc5aa8).() {
156 ddio_MouseSetLimitscxx . . $ ddio_MouseSetLimits(4df37d5d0c1dcce).(0, 0, Lnx_app_objcxx . . $ Lnx_app_obj.->m_Wcxx . . $ oeLnxApplication#m_W., Lnx_app_objcxx . . $ Lnx_app_obj.->m_Hcxx . . $ oeLnxApplication#m_H.);
157 DDIO_mouse_statecxx . . $ DDIO_mouse_state..btn_maskcxx . . $ mses_state#btn_mask. = 0;
158
159 // reset button states
160 ddio_MouseQueueFlushcxx . . $ ddio_MouseQueueFlush(49f6e7a06ebc5aa8).();
161
162 /*
163 if(Mouse_mode==MOUSE_STANDARD_MODE)
164 return;
165 bool use_dga = false;
166
167 if(Lnx_app_obj && Lnx_app_obj->m_Flags&APPFLAG_DGAMOUSE)
168 use_dga = true;
169
170 // warp the mouse.
171 if(!use_dga)
172 {
173 XWarpPointer(Lnx_app_obj->m_Display, None, Lnx_app_obj->m_Window,
174 0,0,0,0, Lnx_app_obj->m_W/2, Lnx_app_obj->m_H/2);
175 }
176 */
177
178 DDIO_mouse_statecxx . . $ DDIO_mouse_state..xcxx . . $ mses_state#x. = DDIO_mouse_statecxx . . $ DDIO_mouse_state..cxcxx . . $ mses_state#cx. = Lnx_app_objcxx . . $ Lnx_app_obj.->m_Wcxx . . $ oeLnxApplication#m_W. / 2;
179 DDIO_mouse_statecxx . . $ DDIO_mouse_state..ycxx . . $ mses_state#y. = DDIO_mouse_statecxx . . $ DDIO_mouse_state..cycxx . . $ mses_state#cy. = Lnx_app_objcxx . . $ Lnx_app_obj.->m_Hcxx . . $ oeLnxApplication#m_H. / 2;
180 DDIO_mouse_statecxx . . $ DDIO_mouse_state..dycxx . . $ mses_state#dy. = DDIO_mouse_statecxx . . $ DDIO_mouse_state..dxcxx . . $ mses_state#dx. = 0;
181 }
182
183 // displays the mouse pointer. Each Hide call = Show call.
184
185 static int Mouse_countercxx . . $ Mouse_counter. = 0;
186
187 void ddio_MouseShowcxx . . $ ddio_MouseShow(49f6e7a06ebc5aa8).() { Mouse_countercxx . . $ Mouse_counter.++; }
188
189 void ddio_MouseHidecxx . . $ ddio_MouseHide(49f6e7a06ebc5aa8).() { Mouse_countercxx . . $ Mouse_counter.--; }
190
191 void ddio_InternalMouseSuspendcxx . . $ ddio_InternalMouseSuspend(49f6e7a06ebc5aa8).(void) {}
192
193 void ddio_InternalMouseResumecxx . . $ ddio_InternalMouseResume(49f6e7a06ebc5aa8).(void) {}
194
195 void ddio_MouseModecxx . . $ ddio_MouseMode(d4f767463ce0a6b3).(int mode) { Mouse_modecxx . . $ Mouse_mode. = mode; }
196
197 // virtual coordinate system for mouse (match to video resolution set for optimal mouse usage.
198 void ddio_MouseSetVCoordscxx . . $ ddio_MouseSetVCoords(3e454b8ccf442868).(int width, int height) { ddio_MouseSetLimitscxx . . $ ddio_MouseSetLimits(4df37d5d0c1dcce).(0, 0, width, height); }
199
200 int sdlMouseButtonDownFiltercxx . . $ sdlMouseButtonDownFilter(5d4fa56947397a26).(SDL_Event const *event) {
201 ASSERTcxx . . $ `misc/pserror.h:246:9`!(event->type == SDL_MOUSEBUTTONDOWN);
202
203 const SDL_MouseButtonEvent *ev = &event->button;
204 t_mse_eventcxx . . $ t_mse_event# mevt;
205
206 if (ev->button == 1) {
207 DDIO_mouse_statecxx . . $ DDIO_mouse_state..btn_maskcxx . . $ mses_state#btn_mask. |= MOUSE_LBcxx . . $ `ddio/ddio.h:243:9`!;
208 DIM_buttonscxx . . $ DIM_buttons..down_countcxx . . $ t_mse_button_info#down_count.[0]++;
209 DIM_buttonscxx . . $ DIM_buttons..time_downcxx . . $ t_mse_button_info#time_down.[0] = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
210 DIM_buttonscxx . . $ DIM_buttons..is_downcxx . . $ t_mse_button_info#is_down.[0] = true;
211 mevt.btncxx . . $ t_mse_event#btn. = 0;
212 mevt.statecxx . . $ t_mse_event#state. = true;
213 MB_queuecxx . . $ MB_queue..sendcxx . . $ tQueue#send(8e935d9c2e576e3a).(mevt);
214 // mprintf(0, "MOUSE Button 0: Down\n");
215 } else if (ev->button == 2) {
216 DDIO_mouse_statecxx . . $ DDIO_mouse_state..btn_maskcxx . . $ mses_state#btn_mask. |= MOUSE_RBcxx . . $ `ddio/ddio.h:244:9`!;
217 DIM_buttonscxx . . $ DIM_buttons..down_countcxx . . $ t_mse_button_info#down_count.[1]++;
218 DIM_buttonscxx . . $ DIM_buttons..time_downcxx . . $ t_mse_button_info#time_down.[1] = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
219 DIM_buttonscxx . . $ DIM_buttons..is_downcxx . . $ t_mse_button_info#is_down.[1] = true;
220 mevt.btncxx . . $ t_mse_event#btn. = 1;
221 mevt.statecxx . . $ t_mse_event#state. = true;
222 MB_queuecxx . . $ MB_queue..sendcxx . . $ tQueue#send(8e935d9c2e576e3a).(mevt);
223 // mprintf(0, "MOUSE Button 1: Down\n");
224 }
225 else if (ev->button == 3) {
226 DDIO_mouse_statecxx . . $ DDIO_mouse_state..btn_maskcxx . . $ mses_state#btn_mask. |= MOUSE_CBcxx . . $ `ddio/ddio.h:245:9`!;
227 DIM_buttonscxx . . $ DIM_buttons..down_countcxx . . $ t_mse_button_info#down_count.[2]++;
228 DIM_buttonscxx . . $ DIM_buttons..time_downcxx . . $ t_mse_button_info#time_down.[2] = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
229 DIM_buttonscxx . . $ DIM_buttons..is_downcxx . . $ t_mse_button_info#is_down.[2] = true;
230 mevt.btncxx . . $ t_mse_event#btn. = 2;
231 mevt.statecxx . . $ t_mse_event#state. = true;
232 MB_queuecxx . . $ MB_queue..sendcxx . . $ tQueue#send(8e935d9c2e576e3a).(mevt);
233 // mprintf(0, "MOUSE Button 2: Down\n");
234 }
235
236 // buttons 4 and 5 are reserved for the mouse wheel...that's how the engine works...adjust in here.
237
238 else if (ev->button == 4) {
239 DDIO_mouse_statecxx . . $ DDIO_mouse_state..btn_maskcxx . . $ mses_state#btn_mask. |= MOUSE_B6cxx . . $ `ddio/ddio.h:248:9`!;
240 DIM_buttonscxx . . $ DIM_buttons..down_countcxx . . $ t_mse_button_info#down_count.[5]++;
241 DIM_buttonscxx . . $ DIM_buttons..time_downcxx . . $ t_mse_button_info#time_down.[5] = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
242 DIM_buttonscxx . . $ DIM_buttons..is_downcxx . . $ t_mse_button_info#is_down.[5] = true;
243 mevt.btncxx . . $ t_mse_event#btn. = 5;
244 mevt.statecxx . . $ t_mse_event#state. = true;
245 MB_queuecxx . . $ MB_queue..sendcxx . . $ tQueue#send(8e935d9c2e576e3a).(mevt);
246 // mprintf(0, "MOUSE Button 5: Down\n");
247 }
248 else if (ev->button == 5) {
249 DDIO_mouse_statecxx . . $ DDIO_mouse_state..btn_maskcxx . . $ mses_state#btn_mask. |= MOUSE_B7cxx . . $ `ddio/ddio.h:249:9`!;
250 DIM_buttonscxx . . $ DIM_buttons..down_countcxx . . $ t_mse_button_info#down_count.[6]++;
251 DIM_buttonscxx . . $ DIM_buttons..time_downcxx . . $ t_mse_button_info#time_down.[6] = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
252 DIM_buttonscxx . . $ DIM_buttons..is_downcxx . . $ t_mse_button_info#is_down.[6] = true;
253 mevt.btncxx . . $ t_mse_event#btn. = 6;
254 mevt.statecxx . . $ t_mse_event#state. = true;
255 MB_queuecxx . . $ MB_queue..sendcxx . . $ tQueue#send(8e935d9c2e576e3a).(mevt);
256 // mprintf(0, "MOUSE Button 6: Down\n");
257 }
258 else if (ev->button == 6) {
259 DDIO_mouse_statecxx . . $ DDIO_mouse_state..btn_maskcxx . . $ mses_state#btn_mask. |= MOUSE_B8cxx . . $ `ddio/ddio.h:250:9`!;
260 DIM_buttonscxx . . $ DIM_buttons..down_countcxx . . $ t_mse_button_info#down_count.[7]++;
261 DIM_buttonscxx . . $ DIM_buttons..time_downcxx . . $ t_mse_button_info#time_down.[7] = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
262 DIM_buttonscxx . . $ DIM_buttons..is_downcxx . . $ t_mse_button_info#is_down.[7] = true;
263 mevt.btncxx . . $ t_mse_event#btn. = 7;
264 mevt.statecxx . . $ t_mse_event#state. = true;
265 MB_queuecxx . . $ MB_queue..sendcxx . . $ tQueue#send(8e935d9c2e576e3a).(mevt);
266 // mprintf(0, "MOUSE Button 7: Down\n");
267 }
268
269 return (0);
270 }
271
272 int sdlMouseButtonUpFiltercxx . . $ sdlMouseButtonUpFilter(5d4fa56947397a26).(SDL_Event const *event) {
273 ASSERTcxx . . $ `misc/pserror.h:246:9`!(event->type == SDL_MOUSEBUTTONUP);
274
275 const SDL_MouseButtonEvent *ev = &event->button;
276 t_mse_eventcxx . . $ t_mse_event# mevt;
277
278 if (ev->button == 1) {
279 DDIO_mouse_statecxx . . $ DDIO_mouse_state..btn_maskcxx . . $ mses_state#btn_mask. &= (~MOUSE_LBcxx . . $ `ddio/ddio.h:243:9`!);
280 DIM_buttonscxx . . $ DIM_buttons..up_countcxx . . $ t_mse_button_info#up_count.[0]++;
281 DIM_buttonscxx . . $ DIM_buttons..is_downcxx . . $ t_mse_button_info#is_down.[0] = false;
282 DIM_buttonscxx . . $ DIM_buttons..time_upcxx . . $ t_mse_button_info#time_up.[0] = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
283 mevt.btncxx . . $ t_mse_event#btn. = 0;
284 mevt.statecxx . . $ t_mse_event#state. = false;
285 MB_queuecxx . . $ MB_queue..sendcxx . . $ tQueue#send(8e935d9c2e576e3a).(mevt);
286 // mprintf(0, "MOUSE Button 0: Up\n");
287 }
288 else if (ev->button == 2) {
289 DDIO_mouse_statecxx . . $ DDIO_mouse_state..btn_maskcxx . . $ mses_state#btn_mask. &= (~MOUSE_RBcxx . . $ `ddio/ddio.h:244:9`!);
290 DIM_buttonscxx . . $ DIM_buttons..up_countcxx . . $ t_mse_button_info#up_count.[1]++;
291 DIM_buttonscxx . . $ DIM_buttons..is_downcxx . . $ t_mse_button_info#is_down.[1] = false;
292 DIM_buttonscxx . . $ DIM_buttons..time_upcxx . . $ t_mse_button_info#time_up.[1] = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
293 mevt.btncxx . . $ t_mse_event#btn. = 1;
294 mevt.statecxx . . $ t_mse_event#state. = false;
295 MB_queuecxx . . $ MB_queue..sendcxx . . $ tQueue#send(8e935d9c2e576e3a).(mevt);
296 // mprintf(0, "MOUSE Button 1: Up\n");
297 }
298 else if (ev->button == 3) {
299 DDIO_mouse_statecxx . . $ DDIO_mouse_state..btn_maskcxx . . $ mses_state#btn_mask. &= (~MOUSE_CBcxx . . $ `ddio/ddio.h:245:9`!);
300 DIM_buttonscxx . . $ DIM_buttons..up_countcxx . . $ t_mse_button_info#up_count.[2]++;
301 DIM_buttonscxx . . $ DIM_buttons..is_downcxx . . $ t_mse_button_info#is_down.[2] = false;
302 DIM_buttonscxx . . $ DIM_buttons..time_upcxx . . $ t_mse_button_info#time_up.[2] = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
303 mevt.btncxx . . $ t_mse_event#btn. = 2;
304 mevt.statecxx . . $ t_mse_event#state. = false;
305 MB_queuecxx . . $ MB_queue..sendcxx . . $ tQueue#send(8e935d9c2e576e3a).(mevt);
306 // mprintf(0, "MOUSE Button 2: Up\n");
307
308 }
309
310 // buttons 4 and 5 are reserved for the mouse wheel...that's how the engine works...adjust in here.
311
312 else if (ev->button == 4) {
313 DDIO_mouse_statecxx . . $ DDIO_mouse_state..btn_maskcxx . . $ mses_state#btn_mask. &= (~MOUSE_B6cxx . . $ `ddio/ddio.h:248:9`!);
314 DIM_buttonscxx . . $ DIM_buttons..up_countcxx . . $ t_mse_button_info#up_count.[5]++;
315 DIM_buttonscxx . . $ DIM_buttons..is_downcxx . . $ t_mse_button_info#is_down.[5] = false;
316 DIM_buttonscxx . . $ DIM_buttons..time_upcxx . . $ t_mse_button_info#time_up.[5] = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
317 mevt.btncxx . . $ t_mse_event#btn. = 5;
318 mevt.statecxx . . $ t_mse_event#state. = false;
319 MB_queuecxx . . $ MB_queue..sendcxx . . $ tQueue#send(8e935d9c2e576e3a).(mevt);
320 // mprintf(0, "MOUSE Button 5: Up\n");
321 }
322 else if (ev->button == 5) {
323 DDIO_mouse_statecxx . . $ DDIO_mouse_state..btn_maskcxx . . $ mses_state#btn_mask. &= (~MOUSE_B7cxx . . $ `ddio/ddio.h:249:9`!);
324 DIM_buttonscxx . . $ DIM_buttons..up_countcxx . . $ t_mse_button_info#up_count.[6]++;
325 DIM_buttonscxx . . $ DIM_buttons..is_downcxx . . $ t_mse_button_info#is_down.[6] = false;
326 DIM_buttonscxx . . $ DIM_buttons..time_upcxx . . $ t_mse_button_info#time_up.[6] = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
327 mevt.btncxx . . $ t_mse_event#btn. = 6;
328 mevt.statecxx . . $ t_mse_event#state. = false;
329 MB_queuecxx . . $ MB_queue..sendcxx . . $ tQueue#send(8e935d9c2e576e3a).(mevt);
330 // mprintf(0, "MOUSE Button 6: Up\n");
331 }
332 else if (ev->button == 6) {
333 DDIO_mouse_statecxx . . $ DDIO_mouse_state..btn_maskcxx . . $ mses_state#btn_mask. &= (~MOUSE_B8cxx . . $ `ddio/ddio.h:250:9`!);
334 DIM_buttonscxx . . $ DIM_buttons..up_countcxx . . $ t_mse_button_info#up_count.[7]++;
335 DIM_buttonscxx . . $ DIM_buttons..is_downcxx . . $ t_mse_button_info#is_down.[7] = false;
336 DIM_buttonscxx . . $ DIM_buttons..time_upcxx . . $ t_mse_button_info#time_up.[7] = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
337 mevt.btncxx . . $ t_mse_event#btn. = 7;
338 mevt.statecxx . . $ t_mse_event#state. = false;
339 MB_queuecxx . . $ MB_queue..sendcxx . . $ tQueue#send(8e935d9c2e576e3a).(mevt);
340 // mprintf(0, "MOUSE Button 7: Up\n");
341 }
342
343 return (0);
344 }
345
346 int sdlMouseWheelFiltercxx . . $ sdlMouseWheelFilter(5d4fa56947397a26).(SDL_Event const *event) {
347 ASSERTcxx . . $ `misc/pserror.h:246:9`!(event->type == SDL_MOUSEWHEEL);
348
349 const SDL_MouseWheelEvent *ev = &event->wheel;
350 t_mse_eventcxx . . $ t_mse_event# mevt;
351
352 // !!! FIXME: this ignores horizontal wheels for now, since Descent3 doesn't currently have a concept of them
353 // !!! FIXME: (vertical mouse wheels are represented as mouse buttons 4 and 5, incorrectly, on all platforms).
354 // !!! FIXME: this will require improvements to the engine before this changes here, though.
355
356 if (ev->y > 0) { /* Mouse scroll up */
357 DDIO_mouse_statecxx . . $ DDIO_mouse_state..btn_maskcxx . . $ mses_state#btn_mask. |= MOUSE_B5cxx . . $ `ddio/ddio.h:247:9`!;
358 DIM_buttonscxx . . $ DIM_buttons..down_countcxx . . $ t_mse_button_info#down_count.[4]++;
359 DIM_buttonscxx . . $ DIM_buttons..time_downcxx . . $ t_mse_button_info#time_down.[4] = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
360 DIM_buttonscxx . . $ DIM_buttons..is_downcxx . . $ t_mse_button_info#is_down.[4] = true;
361 mevt.btncxx . . $ t_mse_event#btn. = 4;
362 mevt.statecxx . . $ t_mse_event#state. = true;
363 MB_queuecxx . . $ MB_queue..sendcxx . . $ tQueue#send(8e935d9c2e576e3a).(mevt);
364
365 // send an immediate release event, as if the "button" was clicked. !!! FIXME: this also needs improvements in the engine.
366 // don't remove from btn_mask
367 DIM_buttonscxx . . $ DIM_buttons..up_countcxx . . $ t_mse_button_info#up_count.[4]++;
368 DIM_buttonscxx . . $ DIM_buttons..is_downcxx . . $ t_mse_button_info#is_down.[4] = false;
369 DIM_buttonscxx . . $ DIM_buttons..time_upcxx . . $ t_mse_button_info#time_up.[4] = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
370 mevt.btncxx . . $ t_mse_event#btn. = 4;
371 mevt.statecxx . . $ t_mse_event#state. = false;
372 MB_queuecxx . . $ MB_queue..sendcxx . . $ tQueue#send(8e935d9c2e576e3a).(mevt);
373 // mprintf(0, "MOUSE Scrollwheel: Rolled Up\n");
374 } else if (ev->y < 0) { /* Mouse scroll down */
375 DDIO_mouse_statecxx . . $ DDIO_mouse_state..btn_maskcxx . . $ mses_state#btn_mask. |= MOUSE_B6cxx . . $ `ddio/ddio.h:248:9`!;
376 DIM_buttonscxx . . $ DIM_buttons..down_countcxx . . $ t_mse_button_info#down_count.[5]++;
377 DIM_buttonscxx . . $ DIM_buttons..time_downcxx . . $ t_mse_button_info#time_down.[5] = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
378 DIM_buttonscxx . . $ DIM_buttons..is_downcxx . . $ t_mse_button_info#is_down.[5] = true;
379 mevt.btncxx . . $ t_mse_event#btn. = 5;
380 mevt.statecxx . . $ t_mse_event#state. = true;
381 MB_queuecxx . . $ MB_queue..sendcxx . . $ tQueue#send(8e935d9c2e576e3a).(mevt);
382
383 // send an immediate release event, as if the "button" was clicked. !!! FIXME: this also needs improvements in the engine.
384 // don't remove from btn_mask
385 DIM_buttonscxx . . $ DIM_buttons..up_countcxx . . $ t_mse_button_info#up_count.[5]++;
386 DIM_buttonscxx . . $ DIM_buttons..is_downcxx . . $ t_mse_button_info#is_down.[5] = false;
387 DIM_buttonscxx . . $ DIM_buttons..time_upcxx . . $ t_mse_button_info#time_up.[5] = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
388 mevt.btncxx . . $ t_mse_event#btn. = 5;
389 mevt.statecxx . . $ t_mse_event#state. = false;
390 MB_queuecxx . . $ MB_queue..sendcxx . . $ tQueue#send(8e935d9c2e576e3a).(mevt);
391 // mprintf(0, "MOUSE Scrollwheel: Rolled Down\n");
392 }
393
394 return 0;
395 }
396
397 int sdlMouseMotionFiltercxx . . $ sdlMouseMotionFilter(5d4fa56947397a26).(SDL_Event const *event) {
398 /*
399 int oldmx, oldmy;
400 int deltamx,deltamy;
401 oldmx = DDIO_mouse_state.cx;
402 oldmy = DDIO_mouse_state.cy;
403 deltamx = deltamy = 0;
404
405 bool use_dga = false;
406
407 if(Lnx_app_obj->m_Flags&APPFLAG_DGAMOUSE)
408 use_dga = true;
409
410 if(Mouse_mode==MOUSE_STANDARD_MODE)
411 return;
412
413 while (XCheckMaskEvent(Lnx_app_obj->m_Display, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, &evt))
414 {
415 switch (evt.type)
416 {
417 case MotionNotify:
418 if(use_dga)
419 {
420
421 deltamx += event->motion.x; //evt.xmotion.x_root;
422 deltamy += event->motion.y; //evt.xmotion.y_root;
423
424 }else
425 {
426 if ((evt.xmotion.x != DDIO_mouse_state.cx) && (evt.xmotion.y != DDIO_mouse_state.cy)) {
427 deltamx += (evt.xmotion.x - oldmx);
428 deltamy += (evt.xmotion.y - oldmy);
429 oldmx = evt.xmotion.x;
430 oldmy = evt.xmotion.y;
431 }
432 }
433 break;
434 case ButtonPress:
435 case ButtonRelease:
436 break;
437 }
438 }
439
440 if( (deltamx) || (deltamy) )
441 {
442 DDIO_mouse_state.dx = deltamx;
443 DDIO_mouse_state.dy = deltamy;
444 DDIO_mouse_state.x += deltamx;
445 DDIO_mouse_state.y += deltamy;
446 if (DDIO_mouse_state.x < DDIO_mouse_state.l) DDIO_mouse_state.x = DDIO_mouse_state.l;
447 if (DDIO_mouse_state.x >= DDIO_mouse_state.r) DDIO_mouse_state.x = DDIO_mouse_state.r-1;
448 if (DDIO_mouse_state.y < DDIO_mouse_state.t) DDIO_mouse_state.y = DDIO_mouse_state.t;
449 if (DDIO_mouse_state.y >= DDIO_mouse_state.b) DDIO_mouse_state.y = DDIO_mouse_state.b-1;
450
451 // warp the mouse.
452 if(!use_dga)
453 {
454 XWarpPointer(Lnx_app_obj->m_Display, None, Lnx_app_obj->m_Window,
455 0,0,0,0, Lnx_app_obj->m_W/2, Lnx_app_obj->m_H/2);
456 }
457 }
458 */
459
460 if (event->type == SDL_JOYBALLMOTION) {
461 DDIO_mouse_statecxx . . $ DDIO_mouse_state..dxcxx . . $ mses_state#dx. = event->jball.xrel / 100;
462 DDIO_mouse_statecxx . . $ DDIO_mouse_state..dycxx . . $ mses_state#dy. = event->jball.yrel / 100;
463 DDIO_mouse_statecxx . . $ DDIO_mouse_state..xcxx . . $ mses_state#x. += DDIO_mouse_statecxx . . $ DDIO_mouse_state..dxcxx . . $ mses_state#dx.;
464 DDIO_mouse_statecxx . . $ DDIO_mouse_state..ycxx . . $ mses_state#y. += DDIO_mouse_statecxx . . $ DDIO_mouse_state..dycxx . . $ mses_state#dy.;
465 } // if
466 else {
467 if (ddio_mouseGrabbedcxx . . $ ddio_mouseGrabbed.) {
468 DDIO_mouse_statecxx . . $ DDIO_mouse_state..dxcxx . . $ mses_state#dx. = event->motion.xrel;
469 DDIO_mouse_statecxx . . $ DDIO_mouse_state..dycxx . . $ mses_state#dy. = event->motion.yrel;
470 DDIO_mouse_statecxx . . $ DDIO_mouse_state..xcxx . . $ mses_state#x. += DDIO_mouse_statecxx . . $ DDIO_mouse_state..dxcxx . . $ mses_state#dx.;
471 DDIO_mouse_statecxx . . $ DDIO_mouse_state..ycxx . . $ mses_state#y. += DDIO_mouse_statecxx . . $ DDIO_mouse_state..dycxx . . $ mses_state#dy.;
472 } // if
473 else {
474 DDIO_mouse_statecxx . . $ DDIO_mouse_state..dxcxx . . $ mses_state#dx. = event->motion.x - DDIO_mouse_statecxx . . $ DDIO_mouse_state..xcxx . . $ mses_state#x.;
475 DDIO_mouse_statecxx . . $ DDIO_mouse_state..dycxx . . $ mses_state#dy. = event->motion.y - DDIO_mouse_statecxx . . $ DDIO_mouse_state..ycxx . . $ mses_state#y.;
476 DDIO_mouse_statecxx . . $ DDIO_mouse_state..xcxx . . $ mses_state#x. = event->motion.x;
477 DDIO_mouse_statecxx . . $ DDIO_mouse_state..ycxx . . $ mses_state#y. = event->motion.y;
478 } // else
479 } // else
480
481 if (DDIO_mouse_statecxx . . $ DDIO_mouse_state..xcxx . . $ mses_state#x. < DDIO_mouse_statecxx . . $ DDIO_mouse_state..lcxx . . $ mses_state#l.)
482 DDIO_mouse_statecxx . . $ DDIO_mouse_state..xcxx . . $ mses_state#x. = DDIO_mouse_statecxx . . $ DDIO_mouse_state..lcxx . . $ mses_state#l.;
483 if (DDIO_mouse_statecxx . . $ DDIO_mouse_state..xcxx . . $ mses_state#x. >= DDIO_mouse_statecxx . . $ DDIO_mouse_state..rcxx . . $ mses_state#r.)
484 DDIO_mouse_statecxx . . $ DDIO_mouse_state..xcxx . . $ mses_state#x. = DDIO_mouse_statecxx . . $ DDIO_mouse_state..rcxx . . $ mses_state#r. - 1;
485 if (DDIO_mouse_statecxx . . $ DDIO_mouse_state..ycxx . . $ mses_state#y. < DDIO_mouse_statecxx . . $ DDIO_mouse_state..tcxx . . $ mses_state#t.)
486 DDIO_mouse_statecxx . . $ DDIO_mouse_state..ycxx . . $ mses_state#y. = DDIO_mouse_statecxx . . $ DDIO_mouse_state..tcxx . . $ mses_state#t.;
487 if (DDIO_mouse_statecxx . . $ DDIO_mouse_state..ycxx . . $ mses_state#y. >= DDIO_mouse_statecxx . . $ DDIO_mouse_state..bcxx . . $ mses_state#b.)
488 DDIO_mouse_statecxx . . $ DDIO_mouse_state..ycxx . . $ mses_state#y. = DDIO_mouse_statecxx . . $ DDIO_mouse_state..bcxx . . $ mses_state#b. - 1;
489
490 return (0);
491 }
492
493 // This function will handle all mouse events.
494 void ddio_InternalMouseFramecxx . . $ ddio_InternalMouseFrame(49f6e7a06ebc5aa8).(void) {
495 static unsigned frame_count = 0;
496 SDL_PumpEvents();
497 frame_count++;
498 }
499
500 /* x, y = absolute mouse position
501 dx, dy = mouse deltas since last call
502 return value is mouse button mask
503 */
504 int ddio_MouseGetStatecxx . . $ ddio_MouseGetState(150f8a26046a094b).(int *x, int *y, int *dx, int *dy, int *z, int *dz) {
505 // update mouse timer.
506 int btn_mask = DDIO_mouse_statecxx . . $ DDIO_mouse_state..btn_maskcxx . . $ mses_state#btn_mask.;
507
508 // get return values.
509 if (x)
510 *x = DDIO_mouse_statecxx . . $ DDIO_mouse_state..xcxx . . $ mses_state#x.;
511 if (y)
512 *y = DDIO_mouse_statecxx . . $ DDIO_mouse_state..ycxx . . $ mses_state#y.;
513 if (z)
514 *z = 0;
515 if (dx)
516 *dx = DDIO_mouse_statecxx . . $ DDIO_mouse_state..dxcxx . . $ mses_state#dx.;
517 if (dy)
518 *dy = DDIO_mouse_statecxx . . $ DDIO_mouse_state..dycxx . . $ mses_state#dy.;
519 if (dz)
520 *dz = 0;
521
522 DDIO_mouse_statecxx . . $ DDIO_mouse_state..dxcxx . . $ mses_state#dx. = 0;
523 DDIO_mouse_statecxx . . $ DDIO_mouse_state..dycxx . . $ mses_state#dy. = 0;
524
525 // unset the mouse wheel "button" once it's been retrieved.
526 DDIO_mouse_statecxx . . $ DDIO_mouse_state..btn_maskcxx . . $ mses_state#btn_mask. &= ~(MOUSE_B5cxx . . $ `ddio/ddio.h:247:9`!|MOUSE_B6cxx . . $ `ddio/ddio.h:248:9`!);
527
528 return btn_mask;
529 }
530
531 // resets mouse queue and button info only.
532 void ddio_MouseQueueFlushcxx . . $ ddio_MouseQueueFlush(49f6e7a06ebc5aa8).() {
533 memset(&DIM_buttonscxx . . $ DIM_buttons., 0, sizeof(DIM_buttonscxx . . $ DIM_buttons.));
534 MB_queuecxx . . $ MB_queue..flushcxx . . $ tQueue#flush(49f6e7a06ebc5aa8).();
535 }
536
537 // gets a mouse button event, returns false if none.
538 bool ddio_MouseGetEventcxx . . $ ddio_MouseGetEvent(ee4fd70245e09a47).(int *btn, bool *state) {
539 t_mse_eventcxx . . $ t_mse_event# evt;
540
541 if (MB_queuecxx . . $ MB_queue..recvcxx . . $ tQueue#recv(4a2ab88644057ef5).(&evt)) {
542 *btn = (int)evt.btncxx . . $ t_mse_event#btn.;
543 *state = evt.statecxx . . $ t_mse_event#state. ? true : false;
544 return true;
545 }
546
547 return false;
548 }
549
550 // return mouse button down time.
551 float ddio_MouseBtnDownTimecxx . . $ ddio_MouseBtnDownTime(5cde91ea12d43f46).(int btn) {
552 float dtime, curtime = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
553
554 ASSERTcxx . . $ `misc/pserror.h:246:9`!(btn >= 0 && btn < N_MSEBTNScxx . . $ `ddio/ddio.h:252:9`!);
555
556 if (DIM_buttonscxx . . $ DIM_buttons..is_downcxx . . $ t_mse_button_info#is_down.[btn]) {
557 dtime = curtime - DIM_buttonscxx . . $ DIM_buttons..time_downcxx . . $ t_mse_button_info#time_down.[btn];
558 DIM_buttonscxx . . $ DIM_buttons..time_downcxx . . $ t_mse_button_info#time_down.[btn] = curtime;
559 } else {
560 dtime = DIM_buttonscxx . . $ DIM_buttons..time_upcxx . . $ t_mse_button_info#time_up.[btn] - DIM_buttonscxx . . $ DIM_buttons..time_downcxx . . $ t_mse_button_info#time_down.[btn];
561 DIM_buttonscxx . . $ DIM_buttons..time_downcxx . . $ t_mse_button_info#time_down.[btn] = 0;
562 DIM_buttonscxx . . $ DIM_buttons..time_upcxx . . $ t_mse_button_info#time_up.[btn] = 0;
563 }
564
565 return dtime;
566 }
567
568 // return mouse button down time
569 int ddio_MouseBtnDownCountcxx . . $ ddio_MouseBtnDownCount(7864480464b09eea).(int btn) {
570 if (btn < 0 || btn >= N_MSEBTNScxx . . $ `ddio/ddio.h:252:9`!)
571 return 0;
572 int n_downs = DIM_buttonscxx . . $ DIM_buttons..down_countcxx . . $ t_mse_button_info#down_count.[btn];
573
574 if (n_downs) {
575 DIM_buttonscxx . . $ DIM_buttons..down_countcxx . . $ t_mse_button_info#down_count.[btn] = 0;
576 }
577
578 return n_downs;
579 }
580
581 // return mouse button up count
582 int ddio_MouseBtnUpCountcxx . . $ ddio_MouseBtnUpCount(7864480464b09eea).(int btn) {
583 if (btn < 0 || btn >= N_MSEBTNScxx . . $ `ddio/ddio.h:252:9`!)
584 return 0;
585 int n_ups = DIM_buttonscxx . . $ DIM_buttons..up_countcxx . . $ t_mse_button_info#up_count.[btn];
586 DIM_buttonscxx . . $ DIM_buttons..up_countcxx . . $ t_mse_button_info#up_count.[btn] = 0;
587 return n_ups;
588 }
589
590 char Ctltext_MseBtnBindingscxx . . $ Ctltext_MseBtnBindings.[N_MSEBTNScxx . . $ `ddio/ddio.h:252:9`!][32] = {"mse-1\0\0\0\0\0\0\0\0\0\0\0\0",
591 "mse-2\0\0\0\0\0\0\0\0\0\0\0\0",
592 "mse-3\0\0\0\0\0\0\0\0\0\0\0\0",
593 "mse-4\0\0\0\0\0\0\0\0\0\0\0",
594 "msew-u\0\0\0\0\0\0\0\0\0\0\0",
595 "msew-d\0\0\0\0\0\0\0\0\0\0\0",
596 "",
597 ""};
598
599 char Ctltext_MseAxisBindingscxx . . $ Ctltext_MseAxisBindings.[][32] = {"mse-X\0\0\0\0\0\0\0\0\0\0\0\0", "mse-Y\0\0\0\0\0\0\0\0\0\0\0\0",
600 "msewheel\0\0\0\0\0\0\0\0\0\0"};
601
602 // returns string to binding.
603 const char *ddio_MouseGetBtnTextcxx . . $ ddio_MouseGetBtnText(f7ae7e56280f18ae).(int btn) {
604 if (btn >= N_MSEBTNScxx . . $ `ddio/ddio.h:252:9`! || btn < 0)
605 return ("");
606 return Ctltext_MseBtnBindingscxx . . $ Ctltext_MseBtnBindings.[btn];
607 }
608
609 const char *ddio_MouseGetAxisTextcxx . . $ ddio_MouseGetAxisText(f7ae7e56280f18ae).(int axis) {
610 if (axis >= (sizeof(Ctltext_MseAxisBindingscxx . . $ Ctltext_MseAxisBindings.) / sizeof(char *)) || axis < 0)
611 return ("");
612 return Ctltext_MseAxisBindingscxx . . $ Ctltext_MseAxisBindings.[axis];
613 }