Mercurial > sdl-ios-xcode
comparison src/video/gem/SDL_gemevents.c @ 319:189a6a3416c7
*** empty log message ***
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 26 Mar 2002 17:37:31 +0000 |
parents | f6ffac90895c |
children | 028e03e273c8 |
comparison
equal
deleted
inserted
replaced
318:0910a3034576 | 319:189a6a3416c7 |
---|---|
41 #include "SDL.h" | 41 #include "SDL.h" |
42 #include "SDL_sysevents.h" | 42 #include "SDL_sysevents.h" |
43 #include "SDL_events_c.h" | 43 #include "SDL_events_c.h" |
44 #include "SDL_gemvideo.h" | 44 #include "SDL_gemvideo.h" |
45 #include "SDL_gemevents_c.h" | 45 #include "SDL_gemevents_c.h" |
46 #include "../ataricommon/SDL_atarikeys.h" /* for keyboard scancodes */ | 46 #include "SDL_atarikeys.h" /* for keyboard scancodes */ |
47 #include "SDL_xbiosinterrupt_s.h" | |
47 | 48 |
48 /* Defines */ | 49 /* Defines */ |
49 | 50 |
50 #define ATARIBIOS_MAXKEYS 128 | 51 #define ATARIBIOS_MAXKEYS 128 |
51 | 52 |
53 | 54 |
54 static unsigned char gem_currentkeyboard[ATARIBIOS_MAXKEYS]; | 55 static unsigned char gem_currentkeyboard[ATARIBIOS_MAXKEYS]; |
55 static unsigned char gem_previouskeyboard[ATARIBIOS_MAXKEYS]; | 56 static unsigned char gem_previouskeyboard[ATARIBIOS_MAXKEYS]; |
56 static unsigned char gem_currentascii[ATARIBIOS_MAXKEYS]; | 57 static unsigned char gem_currentascii[ATARIBIOS_MAXKEYS]; |
57 | 58 |
58 static short prevmousex, prevmousey, prevmouseb; | |
59 | |
60 /* The translation tables from a console scancode to a SDL keysym */ | 59 /* The translation tables from a console scancode to a SDL keysym */ |
61 static SDLKey keymap[ATARIBIOS_MAXKEYS]; | 60 static SDLKey keymap[ATARIBIOS_MAXKEYS]; |
62 | 61 |
63 /* Functions prototypes */ | 62 /* Functions prototypes */ |
64 | 63 |
65 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym); | 64 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym); |
66 static int do_messages(_THIS, short *message); | 65 static int do_messages(_THIS, short *message); |
67 static void do_keyboard(short kc, short ks); | 66 static void do_keyboard(short kc, short ks); |
68 static void do_mouse(_THIS, short mx, short my, short mb); | 67 static void do_mouse(_THIS, short mx, short my, short mb, short ks); |
69 | 68 |
70 /* Functions */ | 69 /* Functions */ |
71 | 70 |
72 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym) | 71 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym) |
73 { | 72 { |
122 keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT; | 121 keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT; |
123 keymap[SCANCODE_LEFTALT] = SDLK_LALT; | 122 keymap[SCANCODE_LEFTALT] = SDLK_LALT; |
124 keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK; | 123 keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK; |
125 | 124 |
126 /* Mouse init */ | 125 /* Mouse init */ |
127 prevmousex = prevmousey = prevmouseb = 0; | |
128 GEM_mouse_relative = SDL_FALSE; | 126 GEM_mouse_relative = SDL_FALSE; |
129 } | 127 } |
130 | 128 |
131 void GEM_PumpEvents(_THIS) | 129 void GEM_PumpEvents(_THIS) |
132 { | 130 { |
133 short mx, my, mb, dummy; | 131 short mousex, mousey, mouseb, dummy; |
132 short kstate, prevkc, prevks; | |
134 int i; | 133 int i; |
135 SDL_keysym keysym; | 134 SDL_keysym keysym; |
136 | 135 |
137 memset(gem_currentkeyboard,0,sizeof(gem_currentkeyboard)); | 136 memset(gem_currentkeyboard,0,sizeof(gem_currentkeyboard)); |
137 prevkc = prevks = 0; | |
138 | 138 |
139 for (;;) | 139 for (;;) |
140 { | 140 { |
141 int quit, resultat; | 141 int quit, resultat; |
142 short buffer[8], kc, ks; | 142 short buffer[8], kc; |
143 | 143 |
144 quit = 0; | 144 quit = 0; |
145 | 145 |
146 resultat = evnt_multi( | 146 resultat = evnt_multi( |
147 MU_MESAG|MU_TIMER|MU_KEYBD, | 147 MU_MESAG|MU_TIMER|MU_KEYBD, |
148 0,0,0, | 148 0,0,0, |
149 0,0,0,0,0, | 149 0,0,0,0,0, |
150 0,0,0,0,0, | 150 0,0,0,0,0, |
151 buffer, | 151 buffer, |
152 10, | 152 10, |
153 &dummy,&dummy,&dummy,&ks,&kc,&dummy | 153 &dummy,&dummy,&dummy,&kstate,&kc,&dummy |
154 ); | 154 ); |
155 | 155 |
156 /* Message event ? */ | 156 /* Message event ? */ |
157 if (resultat & MU_MESAG) | 157 if (resultat & MU_MESAG) |
158 quit = do_messages(this, buffer); | 158 quit = do_messages(this, buffer); |
159 | 159 |
160 /* Keyboard event ? */ | 160 /* Keyboard event ? */ |
161 if (resultat & MU_KEYBD) | 161 if (resultat & MU_KEYBD) { |
162 do_keyboard(kc,ks); | 162 if ((prevkc != kc) || (prevks != kstate)) { |
163 else | 163 do_keyboard(kc,kstate); |
164 do_keyboard(0,0); | 164 } else { |
165 /* Avoid looping, if repeating same key */ | |
166 break; | |
167 } | |
168 } | |
165 | 169 |
166 /* Timer event ? */ | 170 /* Timer event ? */ |
167 if ((resultat & MU_TIMER) || quit) | 171 if ((resultat & MU_TIMER) || quit) |
168 break; | 172 break; |
169 } | 173 } |
170 | 174 |
171 /* Update mouse */ | 175 /* Update mouse */ |
172 graf_mkstate(&mx, &my, &mb, &dummy); | 176 graf_mkstate(&mousex, &mousey, &mouseb, &kstate); |
173 do_mouse(this, mx, my, mb); | 177 do_mouse(this, mousex, mousey, mouseb, kstate); |
174 | 178 |
175 /* Now generates keyboard events */ | 179 /* Now generate keyboard events */ |
176 for (i=0; i<ATARIBIOS_MAXKEYS; i++) { | 180 for (i=0; i<ATARIBIOS_MAXKEYS; i++) { |
177 /* Key pressed ? */ | 181 /* Key pressed ? */ |
178 if (gem_currentkeyboard[i] && !gem_previouskeyboard[i]) | 182 if (gem_currentkeyboard[i] && !gem_previouskeyboard[i]) |
179 SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(i, gem_currentascii[i], &keysym)); | 183 SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(i, gem_currentascii[i], &keysym)); |
180 | 184 |
257 } | 261 } |
258 | 262 |
259 static void do_keyboard(short kc, short ks) | 263 static void do_keyboard(short kc, short ks) |
260 { | 264 { |
261 int scancode, asciicode; | 265 int scancode, asciicode; |
262 short dummy; | |
263 | 266 |
264 if (kc) { | 267 if (kc) { |
265 scancode=(kc>>8) & 127; | 268 scancode=(kc>>8) & 127; |
266 asciicode=kc & 255; | 269 asciicode=kc & 255; |
267 | 270 |
268 gem_currentkeyboard[scancode]=0xFF; | 271 gem_currentkeyboard[scancode]=0xFF; |
269 gem_currentascii[scancode]=asciicode; | 272 gem_currentascii[scancode]=asciicode; |
270 } | 273 } |
271 | |
272 if (!ks) | |
273 graf_mkstate(&dummy, &dummy, &dummy, &ks); | |
274 | 274 |
275 /* Read special keys */ | 275 /* Read special keys */ |
276 if (ks & K_RSHIFT) | 276 if (ks & K_RSHIFT) |
277 gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF; | 277 gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF; |
278 if (ks & K_LSHIFT) | 278 if (ks & K_LSHIFT) |
281 gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF; | 281 gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF; |
282 if (ks & K_ALT) | 282 if (ks & K_ALT) |
283 gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF; | 283 gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF; |
284 } | 284 } |
285 | 285 |
286 static void do_mouse(_THIS, short mx, short my, short mb) | 286 static void do_mouse(_THIS, short mx, short my, short mb, short ks) |
287 { | 287 { |
288 static short prevmousex=0, prevmousey=0, prevmouseb=0; | |
289 | |
288 /* Mouse motion ? */ | 290 /* Mouse motion ? */ |
289 if ((prevmousex!=mx) || (prevmousey!=my)) { | 291 if ((prevmousex!=mx) || (prevmousey!=my)) { |
290 if (GEM_mouse_relative) { | 292 if (GEM_mouse_relative) { |
291 short wind_pxy[8]; | 293 SDL_PrivateMouseMotion(0, 1, SDL_AtariXbios_mousex, SDL_AtariXbios_mousey); |
292 | 294 SDL_AtariXbios_mousex = SDL_AtariXbios_mousey = 0; |
293 wind_get(GEM_handle, WF_WORKXYWH, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2], &wind_pxy[3]); | |
294 | |
295 SDL_PrivateMouseMotion(0, 1, mx-wind_pxy[0], my-wind_pxy[1]); | |
296 } else { | 295 } else { |
297 SDL_PrivateMouseMotion(0, 1, mx, my); | 296 SDL_PrivateMouseMotion(0, 1, mx, my); |
298 } | 297 } |
299 prevmousex = mx; | 298 prevmousex = mx; |
300 prevmousey = my; | 299 prevmousey = my; |
302 | 301 |
303 /* Mouse button ? */ | 302 /* Mouse button ? */ |
304 if (prevmouseb!=mb) { | 303 if (prevmouseb!=mb) { |
305 int i; | 304 int i; |
306 | 305 |
307 for (i=0;i<3;i++) { | 306 for (i=0;i<2;i++) { |
308 int curbutton, prevbutton; | 307 int curbutton, prevbutton; |
309 | 308 |
310 curbutton = mb & (1<<i); | 309 curbutton = mb & (1<<i); |
311 prevbutton = prevmouseb & (1<<i); | 310 prevbutton = prevmouseb & (1<<i); |
312 | 311 |
313 if (curbutton & !prevbutton) { | 312 if (curbutton && !prevbutton) { |
314 SDL_PrivateMouseButton(SDL_PRESSED, i, 0, 0); | 313 SDL_PrivateMouseButton(SDL_PRESSED, i+1, 0, 0); |
315 } | 314 } |
316 if (!curbutton & prevbutton) { | 315 if (!curbutton && prevbutton) { |
317 SDL_PrivateMouseButton(SDL_RELEASED, i, 0, 0); | 316 SDL_PrivateMouseButton(SDL_RELEASED, i+1, 0, 0); |
318 } | 317 } |
319 } | 318 } |
320 prevmouseb = mb; | 319 prevmouseb = mb; |
321 } | 320 } |
322 } | 321 |
322 /* Read special keys */ | |
323 if (ks & K_RSHIFT) | |
324 gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF; | |
325 if (ks & K_LSHIFT) | |
326 gem_currentkeyboard[SCANCODE_LEFTSHIFT]=0xFF; | |
327 if (ks & K_CTRL) | |
328 gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF; | |
329 if (ks & K_ALT) | |
330 gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF; | |
331 } |