Mercurial > sdl-ios-xcode
comparison src/video/nanox/SDL_nxevents.c @ 30:57bf11a5efd7
Added initial support for Nano-X (thanks Hsieh-Fu!)
author | Sam Lantinga <slouken@lokigames.com> |
---|---|
date | Fri, 11 May 2001 01:13:35 +0000 |
parents | |
children | e8157fcb3114 |
comparison
equal
deleted
inserted
replaced
29:a8360daed17d | 30:57bf11a5efd7 |
---|---|
1 /* | |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga | |
4 Copyright (C) 2001 Hsieh-Fu Tsai | |
5 | |
6 This library is free software; you can redistribute it and/or | |
7 modify it under the terms of the GNU Library General Public | |
8 License as published by the Free Software Foundation; either | |
9 version 2 of the License, or (at your option) any later version. | |
10 | |
11 This library is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 Library General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU Library General Public | |
17 License along with this library; if not, write to the Free | |
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 | |
20 Sam Lantinga | |
21 slouken@devolution.com | |
22 | |
23 Hsieh-Fu Tsai | |
24 clare@setabox.com | |
25 */ | |
26 | |
27 #include "SDL_keysym.h" | |
28 #include "SDL_events_c.h" | |
29 | |
30 #include "SDL_nxevents_c.h" | |
31 #include "SDL_nximage_c.h" | |
32 | |
33 // The translation tables from a nanox keysym to a SDL keysym | |
34 static SDLKey NX_NONASCII_keymap [MWKEY_LAST + 1] ; | |
35 | |
36 void NX_InitOSKeymap (_THIS) | |
37 { | |
38 int i ; | |
39 | |
40 Dprintf ("enter NX_InitOSKeymap\n") ; | |
41 | |
42 // Map the nanox scancodes to SDL keysyms | |
43 for (i = 0; i < SDL_TABLESIZE (NX_NONASCII_keymap); ++ i) | |
44 NX_NONASCII_keymap [i] = SDLK_UNKNOWN ; | |
45 | |
46 NX_NONASCII_keymap [MWKEY_LEFT & 0xFF] = SDLK_LEFT ; | |
47 NX_NONASCII_keymap [MWKEY_RIGHT & 0xFF] = SDLK_RIGHT ; | |
48 NX_NONASCII_keymap [MWKEY_UP & 0xFF] = SDLK_UP ; | |
49 NX_NONASCII_keymap [MWKEY_DOWN & 0xFF] = SDLK_DOWN ; | |
50 NX_NONASCII_keymap [MWKEY_INSERT & 0xFF] = SDLK_INSERT ; | |
51 NX_NONASCII_keymap [MWKEY_DELETE & 0xFF] = SDLK_DELETE ; | |
52 NX_NONASCII_keymap [MWKEY_HOME & 0xFF] = SDLK_HOME ; | |
53 NX_NONASCII_keymap [MWKEY_END & 0xFF] = SDLK_END ; | |
54 NX_NONASCII_keymap [MWKEY_PAGEUP & 0xFF] = SDLK_PAGEUP ; | |
55 NX_NONASCII_keymap [MWKEY_PAGEDOWN & 0xFF] = SDLK_PAGEDOWN ; | |
56 | |
57 NX_NONASCII_keymap [MWKEY_KP0 & 0xFF] = SDLK_KP0 ; | |
58 NX_NONASCII_keymap [MWKEY_KP1 & 0xFF] = SDLK_KP1 ; | |
59 NX_NONASCII_keymap [MWKEY_KP2 & 0xFF] = SDLK_KP2 ; | |
60 NX_NONASCII_keymap [MWKEY_KP3 & 0xFF] = SDLK_KP3 ; | |
61 NX_NONASCII_keymap [MWKEY_KP4 & 0xFF] = SDLK_KP4 ; | |
62 NX_NONASCII_keymap [MWKEY_KP5 & 0xFF] = SDLK_KP5 ; | |
63 NX_NONASCII_keymap [MWKEY_KP6 & 0xFF] = SDLK_KP6 ; | |
64 NX_NONASCII_keymap [MWKEY_KP7 & 0xFF] = SDLK_KP7 ; | |
65 NX_NONASCII_keymap [MWKEY_KP8 & 0xFF] = SDLK_KP8 ; | |
66 NX_NONASCII_keymap [MWKEY_KP9 & 0xFF] = SDLK_KP9 ; | |
67 NX_NONASCII_keymap [MWKEY_KP_PERIOD & 0xFF] = SDLK_KP_PERIOD ; | |
68 NX_NONASCII_keymap [MWKEY_KP_DIVIDE & 0xFF] = SDLK_KP_DIVIDE ; | |
69 NX_NONASCII_keymap [MWKEY_KP_MULTIPLY & 0xFF] = SDLK_KP_MULTIPLY ; | |
70 NX_NONASCII_keymap [MWKEY_KP_MINUS & 0xFF] = SDLK_KP_MINUS ; | |
71 NX_NONASCII_keymap [MWKEY_KP_PLUS & 0xFF] = SDLK_KP_PLUS ; | |
72 NX_NONASCII_keymap [MWKEY_KP_ENTER & 0xFF] = SDLK_KP_ENTER ; | |
73 NX_NONASCII_keymap [MWKEY_KP_EQUALS & 0xFF] = SDLK_KP_EQUALS ; | |
74 | |
75 NX_NONASCII_keymap [MWKEY_F1 & 0xFF] = SDLK_F1 ; | |
76 NX_NONASCII_keymap [MWKEY_F2 & 0xFF] = SDLK_F2 ; | |
77 NX_NONASCII_keymap [MWKEY_F3 & 0xFF] = SDLK_F3 ; | |
78 NX_NONASCII_keymap [MWKEY_F4 & 0xFF] = SDLK_F4 ; | |
79 NX_NONASCII_keymap [MWKEY_F5 & 0xFF] = SDLK_F5 ; | |
80 NX_NONASCII_keymap [MWKEY_F6 & 0xFF] = SDLK_F6 ; | |
81 NX_NONASCII_keymap [MWKEY_F7 & 0xFF] = SDLK_F7 ; | |
82 NX_NONASCII_keymap [MWKEY_F8 & 0xFF] = SDLK_F8 ; | |
83 NX_NONASCII_keymap [MWKEY_F9 & 0xFF] = SDLK_F9 ; | |
84 NX_NONASCII_keymap [MWKEY_F10 & 0xFF] = SDLK_F10 ; | |
85 NX_NONASCII_keymap [MWKEY_F11 & 0xFF] = SDLK_F11 ; | |
86 NX_NONASCII_keymap [MWKEY_F12 & 0xFF] = SDLK_F12 ; | |
87 | |
88 NX_NONASCII_keymap [MWKEY_NUMLOCK & 0xFF] = SDLK_NUMLOCK ; | |
89 NX_NONASCII_keymap [MWKEY_CAPSLOCK & 0xFF] = SDLK_CAPSLOCK ; | |
90 NX_NONASCII_keymap [MWKEY_SCROLLOCK & 0xFF] = SDLK_SCROLLOCK ; | |
91 NX_NONASCII_keymap [MWKEY_LSHIFT & 0xFF] = SDLK_LSHIFT ; | |
92 NX_NONASCII_keymap [MWKEY_RSHIFT & 0xFF] = SDLK_RSHIFT ; | |
93 NX_NONASCII_keymap [MWKEY_LCTRL & 0xFF] = SDLK_LCTRL ; | |
94 NX_NONASCII_keymap [MWKEY_RCTRL & 0xFF] = SDLK_RCTRL ; | |
95 NX_NONASCII_keymap [MWKEY_LALT & 0xFF] = SDLK_LALT ; | |
96 NX_NONASCII_keymap [MWKEY_RALT & 0xFF] = SDLK_RALT ; | |
97 NX_NONASCII_keymap [MWKEY_LMETA & 0xFF] = SDLK_LMETA ; | |
98 NX_NONASCII_keymap [MWKEY_RMETA & 0xFF] = SDLK_RMETA ; | |
99 NX_NONASCII_keymap [MWKEY_ALTGR & 0xFF] = SDLK_MODE ; | |
100 | |
101 NX_NONASCII_keymap [MWKEY_PRINT & 0xFF] = SDLK_PRINT ; | |
102 NX_NONASCII_keymap [MWKEY_SYSREQ & 0xFF] = SDLK_SYSREQ ; | |
103 NX_NONASCII_keymap [MWKEY_PAUSE & 0xFF] = SDLK_PAUSE ; | |
104 NX_NONASCII_keymap [MWKEY_BREAK & 0xFF] = SDLK_BREAK ; | |
105 NX_NONASCII_keymap [MWKEY_MENU & 0xFF] = SDLK_MENU ; | |
106 | |
107 Dprintf ("leave NX_InitOSKeymap\n") ; | |
108 } | |
109 | |
110 SDL_keysym * NX_TranslateKey (GR_EVENT_KEYSTROKE * keystroke, SDL_keysym * keysym) | |
111 { | |
112 GR_KEY ch = keystroke -> ch ; | |
113 | |
114 Dprintf ("enter NX_TranslateKey\n") ; | |
115 | |
116 keysym -> scancode = keystroke -> scancode ; | |
117 keysym -> sym = SDLK_UNKNOWN ; | |
118 | |
119 if (ch & MWKEY_NONASCII_MASK) { | |
120 keysym -> sym = NX_NONASCII_keymap [ch & 0xFF] ; | |
121 } else { | |
122 keysym -> sym = ch & 0x7F ; | |
123 } | |
124 | |
125 keysym -> mod = KMOD_NONE ; | |
126 | |
127 #if 1 // Retrieve more mode information | |
128 { | |
129 GR_KEYMOD mod = keystroke -> modifiers ; | |
130 | |
131 if (mod & MWKMOD_LSHIFT) | |
132 keysym -> mod |= KMOD_LSHIFT ; | |
133 if (mod & MWKMOD_RSHIFT) | |
134 keysym -> mod |= KMOD_RSHIFT ; | |
135 if (mod & MWKMOD_LCTRL) | |
136 keysym -> mod |= KMOD_LCTRL ; | |
137 if (mod & MWKMOD_RCTRL) | |
138 keysym -> mod |= KMOD_RCTRL ; | |
139 if (mod & MWKMOD_LALT) | |
140 keysym -> mod |= KMOD_LALT ; | |
141 if (mod & MWKMOD_RALT) | |
142 keysym -> mod |= KMOD_RALT ; | |
143 if (mod & MWKMOD_LMETA) | |
144 keysym -> mod |= KMOD_LMETA ; | |
145 if (mod & MWKMOD_RMETA) | |
146 keysym -> mod |= KMOD_RMETA ; | |
147 if (mod & MWKMOD_NUM) | |
148 keysym -> mod |= KMOD_NUM ; | |
149 if (mod & MWKMOD_CAPS) | |
150 keysym -> mod |= KMOD_CAPS ; | |
151 if (mod & MWKMOD_ALTGR) | |
152 keysym -> mod |= KMOD_MODE ; | |
153 } | |
154 #endif | |
155 | |
156 keysym -> unicode = ch ; | |
157 | |
158 Dprintf ("leave NX_TranslateKey\n") ; | |
159 return keysym ; | |
160 } | |
161 | |
162 static int check_boundary (_THIS, int x, int y) | |
163 { | |
164 if (x < OffsetX || y < OffsetY || x > OffsetX + this -> screen -> w || | |
165 y > OffsetY + this -> screen -> h) | |
166 return 0 ; | |
167 | |
168 return 1 ; | |
169 } | |
170 | |
171 void NX_PumpEvents (_THIS) | |
172 { | |
173 GR_EVENT event ; | |
174 static GR_BUTTON last_button_down = 0 ; | |
175 | |
176 GrCheckNextEvent (& event) ; | |
177 while (event.type != GR_EVENT_TYPE_NONE) { | |
178 | |
179 // dispatch event | |
180 switch (event.type) { | |
181 case GR_EVENT_TYPE_MOUSE_ENTER : | |
182 { | |
183 Dprintf ("mouse enter\n") ; | |
184 SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS) ; | |
185 break ; | |
186 } | |
187 | |
188 case GR_EVENT_TYPE_MOUSE_EXIT : | |
189 { | |
190 Dprintf ("mouse exit\n") ; | |
191 SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS) ; | |
192 break ; | |
193 } | |
194 | |
195 case GR_EVENT_TYPE_FOCUS_IN : | |
196 { | |
197 Dprintf ("focus in\n") ; | |
198 SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS) ; | |
199 break ; | |
200 } | |
201 | |
202 case GR_EVENT_TYPE_FOCUS_OUT : | |
203 { | |
204 Dprintf ("focus out\n") ; | |
205 SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS) ; | |
206 break ; | |
207 } | |
208 | |
209 case GR_EVENT_TYPE_MOUSE_MOTION : | |
210 { | |
211 Dprintf ("mouse motion\n") ; | |
212 | |
213 if (SDL_VideoSurface) { | |
214 if (currently_fullscreen) { | |
215 if (check_boundary (this, event.button.x, event.button.y)) { | |
216 SDL_PrivateMouseMotion (0, 0, event.button.x - OffsetX, | |
217 event.button.y - OffsetY) ; | |
218 } | |
219 } else { | |
220 SDL_PrivateMouseMotion (0, 0, event.button.x, event.button.y) ; | |
221 } | |
222 } | |
223 break ; | |
224 } | |
225 | |
226 case GR_EVENT_TYPE_BUTTON_DOWN : | |
227 { | |
228 int button = event.button.buttons ; | |
229 | |
230 Dprintf ("button down\n") ; | |
231 | |
232 switch (button) { | |
233 case MWBUTTON_L : | |
234 button = 1 ; | |
235 break ; | |
236 case MWBUTTON_M : | |
237 button = 2 ; | |
238 break ; | |
239 case MWBUTTON_R : | |
240 button = 3 ; | |
241 break ; | |
242 default : | |
243 button = 0 ; | |
244 } | |
245 last_button_down = button ; | |
246 | |
247 if (currently_fullscreen) { | |
248 if (check_boundary (this, event.button.x, event.button.y)) { | |
249 SDL_PrivateMouseButton (SDL_PRESSED, button, | |
250 event.button.x - OffsetX, event.button.y - OffsetY) ; | |
251 } | |
252 } else { | |
253 SDL_PrivateMouseButton (SDL_PRESSED, button, | |
254 event.button.x, event.button.y) ; | |
255 } | |
256 break ; | |
257 } | |
258 | |
259 // do not konw which button is released | |
260 case GR_EVENT_TYPE_BUTTON_UP : | |
261 { | |
262 Dprintf ("button up\n") ; | |
263 | |
264 if (currently_fullscreen) { | |
265 if (check_boundary (this, event.button.x, event.button.y)) { | |
266 SDL_PrivateMouseButton (SDL_RELEASED, last_button_down, | |
267 event.button.x - OffsetX, event.button.y - OffsetY) ; | |
268 } | |
269 } else { | |
270 SDL_PrivateMouseButton (SDL_RELEASED, last_button_down, | |
271 event.button.x, event.button.y) ; | |
272 } | |
273 last_button_down = 0 ; | |
274 break ; | |
275 } | |
276 | |
277 case GR_EVENT_TYPE_KEY_DOWN : | |
278 { | |
279 SDL_keysym keysym ; | |
280 | |
281 Dprintf ("key down\n") ; | |
282 SDL_PrivateKeyboard (SDL_PRESSED, | |
283 NX_TranslateKey (& event.keystroke, & keysym)) ; | |
284 break ; | |
285 } | |
286 | |
287 case GR_EVENT_TYPE_KEY_UP : | |
288 { | |
289 SDL_keysym keysym ; | |
290 | |
291 Dprintf ("key up\n") ; | |
292 SDL_PrivateKeyboard (SDL_RELEASED, | |
293 NX_TranslateKey (& event.keystroke, & keysym)) ; | |
294 break ; | |
295 } | |
296 | |
297 case GR_EVENT_TYPE_CLOSE_REQ : | |
298 { | |
299 Dprintf ("close require\n") ; | |
300 SDL_PrivateQuit () ; | |
301 break ; | |
302 } | |
303 | |
304 case GR_EVENT_TYPE_EXPOSURE : | |
305 { | |
306 Dprintf ("event_type_exposure\n") ; | |
307 if (SDL_VideoSurface) { | |
308 NX_RefreshDisplay (this) ;//, & event.exposure) ; | |
309 } | |
310 break ; | |
311 } | |
312 | |
313 case GR_EVENT_TYPE_UPDATE : | |
314 { | |
315 switch (event.update.utype) { | |
316 case GR_UPDATE_MAP : | |
317 { | |
318 Dprintf ("GR_UPDATE_MAP\n") ; | |
319 // If we're not active, make ourselves active | |
320 if (!(SDL_GetAppState () & SDL_APPACTIVE)) { | |
321 // Send an internal activate event | |
322 SDL_PrivateAppActive (1, SDL_APPACTIVE) ; | |
323 } | |
324 if (SDL_VideoSurface) { | |
325 NX_RefreshDisplay (this) ; | |
326 } | |
327 break ; | |
328 } | |
329 | |
330 case GR_UPDATE_UNMAP : | |
331 case GR_UPDATE_UNMAPTEMP : | |
332 { | |
333 Dprintf ("GR_UPDATE_UNMAP or GR_UPDATE_UNMAPTEMP\n") ; | |
334 // If we're active, make ourselves inactive | |
335 if (SDL_GetAppState () & SDL_APPACTIVE) { | |
336 // Send an internal deactivate event | |
337 SDL_PrivateAppActive (0, SDL_APPACTIVE | SDL_APPINPUTFOCUS) ; | |
338 } | |
339 break ; | |
340 } | |
341 | |
342 case GR_UPDATE_SIZE : | |
343 { | |
344 Dprintf ("GR_UPDATE_SIZE\n") ; | |
345 SDL_PrivateResize (event.update.width, event.update.height) ; | |
346 break ; | |
347 } | |
348 | |
349 default : | |
350 Dprintf ("unknown GR_EVENT_TYPE_UPDATE\n") ; | |
351 break ; | |
352 } | |
353 break ; | |
354 } | |
355 | |
356 default : | |
357 { | |
358 Dprintf ("pump event default\n") ; | |
359 } | |
360 } | |
361 | |
362 GrCheckNextEvent (& event) ; | |
363 } | |
364 } |