1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "common/scummsys.h"
24
25 /*
26 * GPH: Device Specific Event Handling.
27 */
28
29 #if defined(GPH_DEVICE)
30
31 #include "backends/events/gph/gph-events.h"
32 #include "backends/graphics/gph/gph-graphics.h"
33 #include "backends/platform/gph/gph-hw.h"
34
35 #include "common/util.h"
36 #include "common/events.h"
37 #include "common/translation.h"
38
39 #define JOY_DEADZONE 2200
40
41 #define JOY_XAXIS 0
42 #define JOY_YAXIS 1
43
44 #if defined(CAANOO)
45
46 /* Caanoo: Main Joystick Button Mappings */
47 /* The Caanoo has an analogue stick so no digital DPAD */
48 enum {
49 /* Joystick Buttons */
50 BUTTON_A = 0,
51 BUTTON_X = 1,
52 BUTTON_B = 2,
53 BUTTON_Y = 3,
54 BUTTON_L = 4,
55 BUTTON_R = 5,
56 BUTTON_HOME = 6, // Home
57 BUTTON_HOLD = 7, // Hold (on Power)
58 BUTTON_HELP = 8, // Help I
59 BUTTON_HELP2 = 9, // Help II
60 BUTTON_CLICK = 10 // Stick Click
61 };
62
63 enum {
64 /* Unused Joystick Buttons on the Caanoo */
65 BUTTON_VOLUP = 51,
66 BUTTON_VOLDOWN = 52,
67 BUTTON_UP = 53,
68 BUTTON_UPLEFT = 54,
69 BUTTON_LEFT = 55,
70 BUTTON_DOWNLEFT = 56,
71 BUTTON_DOWN = 57,
72 BUTTON_DOWNRIGHT = 58,
73 BUTTON_RIGHT = 59,
74 BUTTON_UPRIGHT = 60,
75 BUTTON_MENU = 61,
76 BUTTON_SELECT = 62
77 };
78
79 #elif defined(GP2XWIZ)
80
81 /* Wiz: Main Joystick Mappings */
82 enum {
83 /* DPAD */
84 BUTTON_UP = 0,
85 BUTTON_UPLEFT = 1,
86 BUTTON_LEFT = 2,
87 BUTTON_DOWNLEFT = 3,
88 BUTTON_DOWN = 4,
89 BUTTON_DOWNRIGHT = 5,
90 BUTTON_RIGHT = 6,
91 BUTTON_UPRIGHT = 7,
92 /* Joystick Buttons */
93 BUTTON_MENU = 8,
94 BUTTON_SELECT = 9,
95 BUTTON_L = 10,
96 BUTTON_R = 11,
97 BUTTON_A = 12,
98 BUTTON_B = 13,
99 BUTTON_X = 14,
100 BUTTON_Y = 15,
101 BUTTON_VOLUP = 16,
102 BUTTON_VOLDOWN = 17
103 };
104
105 enum {
106 /* Unused Joystick Buttons on the Wiz */
107 BUTTON_HOME = 51,
108 BUTTON_HOLD = 52,
109 BUTTON_CLICK = 53,
110 BUTTON_HELP = 54,
111 BUTTON_HELP2 = 55
112 };
113
114 #elif defined(GP2X)
115
116 enum {
117 /* DPAD/Stick */
118 BUTTON_UP = 0,
119 BUTTON_UPLEFT = 1,
120 BUTTON_LEFT = 2,
121 BUTTON_DOWNLEFT = 3,
122 BUTTON_DOWN = 4,
123 BUTTON_DOWNRIGHT = 5,
124 BUTTON_RIGHT = 6,
125 BUTTON_UPRIGHT = 7,
126 /* Joystick Buttons */
127 BUTTON_MENU = 8, // Start on F100 GP2X
128 BUTTON_SELECT = 9,
129 BUTTON_L = 10,
130 BUTTON_R = 11,
131 BUTTON_A = 12,
132 BUTTON_B = 13,
133 BUTTON_X = 14,
134 BUTTON_Y = 15,
135 BUTTON_VOLUP = 16,
136 BUTTON_VOLDOWN = 17,
137 BUTTON_CLICK = 18
138 };
139
140 enum {
141 /* Unused Joystick Buttons on the GP2X */
142 BUTTON_HOME = 51,
143 BUTTON_HOLD = 52,
144 BUTTON_HELP = 53,
145 BUTTON_HELP2 = 54
146 };
147
148 #else
149
150 /* Main Joystick Button Mappings */
151 enum {
152 /* Joystick Buttons */
153 BUTTON_A = 0,
154 BUTTON_B = 1,
155 BUTTON_X = 2,
156 BUTTON_Y = 3,
157 BUTTON_L = 4,
158 BUTTON_R = 5,
159 BUTTON_SELECT = 6,
160 BUTTON_MENU = 7,
161 BUTTON_CLICK = 8 // Stick Click
162 };
163
164 enum {
165 /* Unused Joystick Buttons */
166 BUTTON_VOLUP = 51,
167 BUTTON_VOLDOWN = 52,
168 BUTTON_UP = 53,
169 BUTTON_UPLEFT = 54,
170 BUTTON_LEFT = 55,
171 BUTTON_DOWNLEFT = 56,
172 BUTTON_DOWN = 57,
173 BUTTON_DOWNRIGHT = 58,
174 BUTTON_RIGHT = 59,
175 BUTTON_UPRIGHT = 60,
176 BUTTON_HOME = 61, // Home
177 BUTTON_HOLD = 62, // Hold (on Power)
178 BUTTON_HELP = 63, // Help I
179 BUTTON_HELP2 = 64 // Help II
180 };
181
182 #endif
183
184 enum {
185 /* Touchscreen TapMode */
186 TAPMODE_LEFT = 0,
187 TAPMODE_RIGHT = 1,
188 TAPMODE_HOVER = 2
189 };
190
GPHEventSource()191 GPHEventSource::GPHEventSource()
192 : _buttonStateL(false),
193 _tapmodeLevel(TAPMODE_LEFT) {
194 }
195
ToggleTapMode()196 void GPHEventSource::ToggleTapMode() {
197 if (_tapmodeLevel == TAPMODE_LEFT) {
198 _tapmodeLevel = TAPMODE_RIGHT;
199 } else if (_tapmodeLevel == TAPMODE_RIGHT) {
200 _tapmodeLevel = TAPMODE_HOVER;
201 } else if (_tapmodeLevel == TAPMODE_HOVER) {
202 _tapmodeLevel = TAPMODE_LEFT;
203 } else {
204 _tapmodeLevel = TAPMODE_LEFT;
205 }
206 }
207
208 /* Custom handleMouseButtonDown/handleMouseButtonUp to deal with 'Tap Mode' for the touchscreen */
209
handleMouseButtonDown(SDL_Event & ev,Common::Event & event)210 bool GPHEventSource::handleMouseButtonDown(SDL_Event &ev, Common::Event &event) {
211 if (ev.button.button != SDL_BUTTON_LEFT)
212 return SdlEventSource::handleMouseButtonDown(ev, event);
213
214 if (_buttonStateL == true) /* _buttonStateL = Left Trigger Held, force Right Click */
215 event.type = Common::EVENT_RBUTTONDOWN;
216 else if (_tapmodeLevel == TAPMODE_LEFT) /* TAPMODE_LEFT = Left Click Tap Mode */
217 event.type = Common::EVENT_LBUTTONDOWN;
218 else if (_tapmodeLevel == TAPMODE_RIGHT) /* TAPMODE_RIGHT = Right Click Tap Mode */
219 event.type = Common::EVENT_RBUTTONDOWN;
220 else if (_tapmodeLevel == TAPMODE_HOVER) /* TAPMODE_HOVER = Hover (No Click) Tap Mode */
221 event.type = Common::EVENT_MOUSEMOVE;
222 else
223 event.type = Common::EVENT_LBUTTONDOWN; /* For normal mice etc. */
224
225
226 // update KbdMouse
227 _km.x = ev.button.x * MULTIPLIER;
228 _km.y = ev.button.y * MULTIPLIER;
229
230 return processMouseEvent(event, ev.button.x, ev.button.y);
231 }
232
handleMouseButtonUp(SDL_Event & ev,Common::Event & event)233 bool GPHEventSource::handleMouseButtonUp(SDL_Event &ev, Common::Event &event) {
234 if (ev.button.button != SDL_BUTTON_LEFT)
235 return SdlEventSource::handleMouseButtonUp(ev, event);
236
237 if (_buttonStateL == true) /* _buttonStateL = Left Trigger Held, force Right Click */
238 event.type = Common::EVENT_RBUTTONUP;
239 else if (_tapmodeLevel == TAPMODE_LEFT) /* TAPMODE_LEFT = Left Click Tap Mode */
240 event.type = Common::EVENT_LBUTTONUP;
241 else if (_tapmodeLevel == TAPMODE_RIGHT) /* TAPMODE_RIGHT = Right Click Tap Mode */
242 event.type = Common::EVENT_RBUTTONUP;
243 else if (_tapmodeLevel == TAPMODE_HOVER) /* TAPMODE_HOVER = Hover (No Click) Tap Mode */
244 event.type = Common::EVENT_MOUSEMOVE;
245 else
246 event.type = Common::EVENT_LBUTTONUP; /* For normal mice etc. */
247
248
249 // update KbdMouse
250 _km.x = ev.button.x * MULTIPLIER;
251 _km.y = ev.button.y * MULTIPLIER;
252
253 return processMouseEvent(event, ev.button.x, ev.button.y);
254 }
255
256 /* Custom handleJoyButtonDown/handleJoyButtonUp to deal with the joystick buttons on GPH devices */
257
handleJoyButtonDown(SDL_Event & ev,Common::Event & event)258 bool GPHEventSource::handleJoyButtonDown(SDL_Event &ev, Common::Event &event) {
259
260 event.kbd.flags = 0;
261
262 switch (ev.jbutton.button) {
263 case BUTTON_UP:
264 if (_km.y_down_count != 2) {
265 _km.y_vel = -1 * MULTIPLIER;
266 _km.y_down_count = 1;
267 } else {
268 _km.y_vel = -4 * MULTIPLIER;
269 }
270 event.type = Common::EVENT_MOUSEMOVE;
271 processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
272 break;
273 case BUTTON_DOWN:
274 if (_km.y_down_count != 2) {
275 _km.y_vel = 1 * MULTIPLIER;
276 _km.y_down_count = 1;
277 } else {
278 _km.y_vel = 4 * MULTIPLIER;
279 }
280 event.type = Common::EVENT_MOUSEMOVE;
281 processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
282 break;
283 case BUTTON_LEFT:
284 if (_km.x_down_count != 2) {
285 _km.x_vel = -1 * MULTIPLIER;
286 _km.x_down_count = 1;
287 } else {
288 _km.x_vel = -4 * MULTIPLIER;
289 }
290 event.type = Common::EVENT_MOUSEMOVE;
291 processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
292 break;
293 case BUTTON_RIGHT:
294 if (_km.x_down_count != 3) {
295 _km.x_vel = 1 * MULTIPLIER;
296 _km.x_down_count = 1;
297 } else {
298 _km.x_vel = 4 * MULTIPLIER;
299 }
300 event.type = Common::EVENT_MOUSEMOVE;
301 processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
302 break;
303 case BUTTON_UPLEFT:
304 if (_km.x_down_count != 2) {
305 _km.x_vel = -1 * MULTIPLIER;
306 _km.x_down_count = 1;
307 } else {
308 _km.x_vel = -4 * MULTIPLIER;
309 }
310 if (_km.y_down_count != 2) {
311 _km.y_vel = -1 * MULTIPLIER;
312 _km.y_down_count = 1;
313 } else {
314 _km.y_vel = -4 * MULTIPLIER;
315 }
316 event.type = Common::EVENT_MOUSEMOVE;
317 processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
318 break;
319 case BUTTON_UPRIGHT:
320 if (_km.x_down_count != 2) {
321 _km.x_vel = 1 * MULTIPLIER;
322 _km.x_down_count = 1;
323 } else {
324 _km.x_vel = 4 * MULTIPLIER;
325 }
326 if (_km.y_down_count != 2) {
327 _km.y_vel = -1 * MULTIPLIER;
328 _km.y_down_count = 1;
329 } else {
330 _km.y_vel = -4 * MULTIPLIER;
331 }
332 event.type = Common::EVENT_MOUSEMOVE;
333 processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
334 break;
335 case BUTTON_DOWNLEFT:
336 if (_km.x_down_count != 2) {
337 _km.x_vel = -1 * MULTIPLIER;
338 _km.x_down_count = 1;
339 } else {
340 _km.x_vel = -4 * MULTIPLIER;
341 }
342 if (_km.y_down_count != 2) {
343 _km.y_vel = 1 * MULTIPLIER;
344 _km.y_down_count = 1;
345 } else {
346 _km.y_vel = 4 * MULTIPLIER;
347 }
348 event.type = Common::EVENT_MOUSEMOVE;
349 processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
350 break;
351 case BUTTON_DOWNRIGHT:
352 if (_km.x_down_count != 2) {
353 _km.x_vel = 1 * MULTIPLIER;
354 _km.x_down_count = 1;
355 } else {
356 _km.x_vel = 4 * MULTIPLIER;
357 }
358 if (_km.y_down_count != 2) {
359 _km.y_vel = 1 * MULTIPLIER;
360 _km.y_down_count = 1;
361 } else {
362 _km.y_vel = 4 * MULTIPLIER;
363 }
364 event.type = Common::EVENT_MOUSEMOVE;
365 processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
366 break;
367 case BUTTON_B:
368 case BUTTON_CLICK:
369 event.type = Common::EVENT_LBUTTONDOWN;
370 processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
371 break;
372 case BUTTON_X:
373 event.type = Common::EVENT_RBUTTONDOWN;
374 processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
375 break;
376 case BUTTON_L:
377 _buttonStateL = true;
378 break;
379 case BUTTON_R:
380 event.type = Common::EVENT_KEYDOWN;
381 if (_buttonStateL == true) {
382 #ifdef ENABLE_VKEYBD
383 event.type = Common::EVENT_VIRTUAL_KEYBOARD;
384 #else
385 event.kbd.keycode = Common::KEYCODE_0;
386 event.kbd.ascii = mapKey(SDLK_0, ev.key.keysym.mod, 0);
387 #endif
388 } else {
389 event.kbd.keycode = Common::KEYCODE_RETURN;
390 event.kbd.ascii = mapKey(SDLK_RETURN, ev.key.keysym.mod, 0);
391 }
392 break;
393 case BUTTON_SELECT:
394 case BUTTON_HOME:
395 event.type = Common::EVENT_KEYDOWN;
396 if (_buttonStateL == true) {
397 event.type = Common::EVENT_QUIT;
398 } else {
399 event.kbd.keycode = Common::KEYCODE_ESCAPE;
400 event.kbd.ascii = mapKey(SDLK_ESCAPE, ev.key.keysym.mod, 0);
401 }
402 break;
403 case BUTTON_A:
404 event.type = Common::EVENT_KEYDOWN;
405 if (_buttonStateL == true) {
406 event.type = Common::EVENT_PREDICTIVE_DIALOG;
407 } else {
408 event.kbd.keycode = Common::KEYCODE_PERIOD;
409 event.kbd.ascii = mapKey(SDLK_PERIOD, ev.key.keysym.mod, 0);
410 }
411 break;
412 case BUTTON_Y:
413 event.type = Common::EVENT_KEYDOWN;
414 if (_buttonStateL == true) {
415 ToggleTapMode();
416 if (_tapmodeLevel == TAPMODE_LEFT) {
417 g_system->displayMessageOnOSD(_("Touchscreen 'Tap Mode' - Left Click"));
418 } else if (_tapmodeLevel == TAPMODE_RIGHT) {
419 g_system->displayMessageOnOSD(_("Touchscreen 'Tap Mode' - Right Click"));
420 } else if (_tapmodeLevel == TAPMODE_HOVER) {
421 g_system->displayMessageOnOSD(_("Touchscreen 'Tap Mode' - Hover (No Click)"));
422 }
423 } else {
424 event.kbd.keycode = Common::KEYCODE_SPACE;
425 event.kbd.ascii = mapKey(SDLK_SPACE, ev.key.keysym.mod, 0);
426 }
427 break;
428 case BUTTON_MENU:
429 case BUTTON_HELP:
430 event.type = Common::EVENT_KEYDOWN;
431 if (_buttonStateL == true) {
432 event.type = Common::EVENT_MAINMENU;
433 } else {
434 event.kbd.keycode = Common::KEYCODE_F5;
435 event.kbd.ascii = mapKey(SDLK_F5, ev.key.keysym.mod, 0);
436 }
437 break;
438 case BUTTON_VOLUP:
439 WIZ_HW::mixerMoveVolume(2);
440 if (WIZ_HW::volumeLevel == 100) {
441 g_system->displayMessageOnOSD(_("Maximum Volume"));
442 } else {
443 g_system->displayMessageOnOSD(_("Increasing Volume"));
444 }
445 break;
446 case BUTTON_VOLDOWN:
447 WIZ_HW::mixerMoveVolume(1);
448 if (WIZ_HW::volumeLevel == 0) {
449 g_system->displayMessageOnOSD(_("Minimal Volume"));
450 } else {
451 g_system->displayMessageOnOSD(_("Decreasing Volume"));
452 }
453 break;
454 case BUTTON_HOLD:
455 event.type = Common::EVENT_QUIT;
456 break;
457 case BUTTON_HELP2:
458 ToggleTapMode();
459 if (_tapmodeLevel == TAPMODE_LEFT) {
460 g_system->displayMessageOnOSD(_("Touchscreen 'Tap Mode' - Left Click"));
461 } else if (_tapmodeLevel == TAPMODE_RIGHT) {
462 g_system->displayMessageOnOSD(_("Touchscreen 'Tap Mode' - Right Click"));
463 } else if (_tapmodeLevel == TAPMODE_HOVER) {
464 g_system->displayMessageOnOSD(_("Touchscreen 'Tap Mode' - Hover (No Click)"));
465 }
466 break;
467 }
468 return true;
469 }
470
handleJoyButtonUp(SDL_Event & ev,Common::Event & event)471 bool GPHEventSource::handleJoyButtonUp(SDL_Event &ev, Common::Event &event) {
472
473 event.kbd.flags = 0;
474
475 switch (ev.jbutton.button) {
476 case BUTTON_UP:
477 case BUTTON_UPLEFT:
478 case BUTTON_LEFT:
479 case BUTTON_DOWNLEFT:
480 case BUTTON_DOWN:
481 case BUTTON_DOWNRIGHT:
482 case BUTTON_RIGHT:
483 case BUTTON_UPRIGHT:
484 _km.y_vel = 0;
485 _km.y_down_count = 0;
486 _km.x_vel = 0;
487 _km.x_down_count = 0;
488 event.type = Common::EVENT_MOUSEMOVE;
489 processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
490 break;
491 case BUTTON_B:
492 case BUTTON_CLICK:
493 event.type = Common::EVENT_LBUTTONUP;
494 processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
495 break;
496 case BUTTON_X:
497 event.type = Common::EVENT_RBUTTONUP;
498 processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
499 break;
500 case BUTTON_L:
501 _buttonStateL = false;
502 break;
503 case BUTTON_SELECT:
504 case BUTTON_HOME:
505 event.type = Common::EVENT_KEYUP;
506 event.kbd.keycode = Common::KEYCODE_ESCAPE;
507 event.kbd.ascii = mapKey(SDLK_ESCAPE, ev.key.keysym.mod, 0);
508 break;
509 case BUTTON_A:
510 event.type = Common::EVENT_KEYUP;
511 event.kbd.keycode = Common::KEYCODE_PERIOD;
512 event.kbd.ascii = mapKey(SDLK_PERIOD, ev.key.keysym.mod, 0);
513 break;
514 case BUTTON_Y:
515 event.type = Common::EVENT_KEYUP;
516 event.kbd.keycode = Common::KEYCODE_SPACE;
517 event.kbd.ascii = mapKey(SDLK_SPACE, ev.key.keysym.mod, 0);
518 break;
519 case BUTTON_MENU:
520 case BUTTON_HELP:
521 event.type = Common::EVENT_KEYUP;
522 if (_buttonStateL == true) {
523 event.type = Common::EVENT_MAINMENU;
524 } else {
525 event.kbd.keycode = Common::KEYCODE_F5;
526 event.kbd.ascii = mapKey(SDLK_F5, ev.key.keysym.mod, 0);
527 }
528 break;
529 case BUTTON_R:
530 event.type = Common::EVENT_KEYUP;
531 if (_buttonStateL == true) {
532 #ifdef ENABLE_VKEYBD
533 event.kbd.keycode = Common::KEYCODE_F7;
534 event.kbd.ascii = mapKey(SDLK_F7, ev.key.keysym.mod, 0);
535 #else
536 event.kbd.keycode = Common::KEYCODE_0;
537 event.kbd.ascii = mapKey(SDLK_0, ev.key.keysym.mod, 0);
538 #endif
539 } else {
540 event.kbd.keycode = Common::KEYCODE_RETURN;
541 event.kbd.ascii = mapKey(SDLK_RETURN, ev.key.keysym.mod, 0);
542 }
543 break;
544 case BUTTON_VOLUP:
545 break;
546 case BUTTON_VOLDOWN:
547 break;
548 case BUTTON_HOLD:
549 break;
550 case BUTTON_HELP2:
551 break;
552 }
553 return true;
554 }
555
remapKey(SDL_Event & ev,Common::Event & event)556 bool GPHEventSource::remapKey(SDL_Event &ev, Common::Event &event) {
557 return false;
558 }
559
560 #endif
561