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 #if defined(DINGUX)
26
27 #include "backends/events/dinguxsdl/dinguxsdl-events.h"
28
29 #ifndef GCW0
30 #define PAD_UP SDLK_UP
31 #define PAD_DOWN SDLK_DOWN
32 #define PAD_LEFT SDLK_LEFT
33 #define PAD_RIGHT SDLK_RIGHT
34 #define BUT_A SDLK_LCTRL
35 #define BUT_B SDLK_LALT
36 #define BUT_X SDLK_SPACE // BUT_Y in GCW0
37 #define BUT_Y SDLK_LSHIFT // BUT_X in GCW0
38 #define BUT_SELECT SDLK_ESCAPE
39 #define BUT_START SDLK_RETURN
40 #define TRIG_L SDLK_TAB
41 #define TRIG_R SDLK_BACKSPACE
42 #else // GCW0
43
44 /******
45 * GCW0 keymap
46 * Dingoo button
47 * A -> Left Button BUT_Y
48 * B -> right button BUT_B
49 * X -> ' ' BUT_A '0'
50 * Y -> '.' BUT_X
51 * Select -> ESC TRIG_R
52 * Start -> F5 TRIG_L
53 * L -> Shift BUT_START
54 * R -> VK BUT_SELECT
55 */
56
57 #define PAD_UP SDLK_UP
58 #define PAD_DOWN SDLK_DOWN
59 #define PAD_LEFT SDLK_LEFT
60 #define PAD_RIGHT SDLK_RIGHT
61 #define BUT_A SDLK_LSHIFT
62 #define BUT_B SDLK_LALT
63 #define BUT_X SDLK_SPACE
64 #define BUT_Y SDLK_LCTRL
65 #define BUT_SELECT SDLK_BACKSPACE
66 #define BUT_START SDLK_TAB
67 #define TRIG_L SDLK_RETURN
68 #define TRIG_R SDLK_ESCAPE
69
70 #endif
71
remapKey(SDL_Event & ev,Common::Event & event)72 bool DINGUXSdlEventSource::remapKey(SDL_Event &ev, Common::Event &event) {
73 if (ev.key.keysym.sym == PAD_UP) {
74 if (ev.type == SDL_KEYDOWN) {
75 _km.y_vel = -1 * MULTIPLIER;
76 _km.y_down_count = 1;
77 } else {
78 _km.y_vel = 0 * MULTIPLIER;
79 _km.y_down_count = 0;
80 }
81
82 event.type = Common::EVENT_MOUSEMOVE;
83 processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
84
85 return true;
86 } else if (ev.key.keysym.sym == PAD_DOWN) {
87 if (ev.type == SDL_KEYDOWN) {
88 _km.y_vel = 1 * MULTIPLIER;
89 _km.y_down_count = 1;
90 } else {
91 _km.y_vel = 0 * MULTIPLIER;
92 _km.y_down_count = 0;
93 }
94
95 event.type = Common::EVENT_MOUSEMOVE;
96 processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
97
98 return true;
99 } else if (ev.key.keysym.sym == PAD_LEFT) {
100 if (ev.type == SDL_KEYDOWN) {
101 _km.x_vel = -1 * MULTIPLIER;
102 _km.x_down_count = 1;
103 } else {
104 _km.x_vel = 0 * MULTIPLIER;
105 _km.x_down_count = 0;
106 }
107
108 event.type = Common::EVENT_MOUSEMOVE;
109 processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
110
111 return true;
112 } else if (ev.key.keysym.sym == PAD_RIGHT) {
113 if (ev.type == SDL_KEYDOWN) {
114 _km.x_vel = 1 * MULTIPLIER;
115 _km.x_down_count = 1;
116 } else {
117 _km.x_vel = 0 * MULTIPLIER;
118 _km.x_down_count = 0;
119 }
120
121 event.type = Common::EVENT_MOUSEMOVE;
122 processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
123
124 return true;
125 } else if (ev.key.keysym.sym == BUT_Y) { // left mouse button
126 if (ev.type == SDL_KEYDOWN) {
127 event.type = Common::EVENT_LBUTTONDOWN;
128 } else {
129 event.type = Common::EVENT_LBUTTONUP;
130 }
131
132 processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
133
134 return true;
135 } else if (ev.key.keysym.sym == BUT_B) { // right mouse button
136 if (ev.type == SDL_KEYDOWN) {
137 event.type = Common::EVENT_RBUTTONDOWN;
138 } else {
139 event.type = Common::EVENT_RBUTTONUP;
140 }
141
142 processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
143
144 return true;
145 } else if (ev.key.keysym.sym == BUT_X) { // '.' skip dialogue
146 ev.key.keysym.sym = SDLK_PERIOD;
147 ev.key.keysym.mod = (SDLMod)0;
148 ev.key.keysym.unicode = '.';
149 } else if (ev.key.keysym.sym == TRIG_L) { // global menu
150 ev.key.keysym.sym = SDLK_F5;
151 event.kbd.keycode = Common::KEYCODE_F5;
152 event.kbd.ascii = Common::ASCII_F5;
153 event.kbd.flags = Common::KBD_CTRL;
154
155 if (ev.type == SDL_KEYDOWN) {
156 event.type = Common::EVENT_KEYDOWN;
157 } else {
158 event.type = Common::EVENT_KEYUP;
159 }
160
161 return true;
162 } else if (ev.key.keysym.sym == BUT_A) { // key '0'
163 ev.key.keysym.sym = SDLK_0;
164
165 event.kbd.keycode = Common::KEYCODE_0;
166 event.kbd.ascii = '0';
167 event.kbd.flags = 0;
168
169 if (ev.type == SDL_KEYDOWN) {
170 event.type = Common::EVENT_KEYDOWN;
171 } else {
172 event.type = Common::EVENT_KEYUP;
173 }
174
175 return true;
176 } else if (ev.key.keysym.sym == BUT_SELECT) { // virtual keyboard
177 #ifdef ENABLE_VKEYBD
178 if (ev.type == SDL_KEYDOWN)
179 event.type = Common::EVENT_VIRTUAL_KEYBOARD;
180
181 return true;
182 #endif
183 } else if (ev.key.keysym.sym == BUT_START) { // F5, menu in some games
184 ev.key.keysym.sym = SDLK_F5;
185
186 } else if (ev.key.keysym.sym == TRIG_R) { // ESC
187 ev.key.keysym.sym = SDLK_ESCAPE;
188 } else {
189 event.kbd.keycode = (Common::KeyCode)ev.key.keysym.sym;
190 event.kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod, ev.key.keysym.unicode);
191 }
192
193 return false;
194 }
195
196 #endif /* DINGUX */
197