comparison src/video/gem/SDL_gemevents.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents 2405517b5eab
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
34 34
35 #include "../../events/SDL_sysevents.h" 35 #include "../../events/SDL_sysevents.h"
36 #include "../../events/SDL_events_c.h" 36 #include "../../events/SDL_events_c.h"
37 #include "SDL_gemvideo.h" 37 #include "SDL_gemvideo.h"
38 #include "SDL_gemevents_c.h" 38 #include "SDL_gemevents_c.h"
39 #include "../ataricommon/SDL_atarikeys.h" /* for keyboard scancodes */ 39 #include "../ataricommon/SDL_atarikeys.h" /* for keyboard scancodes */
40 #include "../ataricommon/SDL_atarievents_c.h" 40 #include "../ataricommon/SDL_atarievents_c.h"
41 #include "../ataricommon/SDL_xbiosevents_c.h" 41 #include "../ataricommon/SDL_xbiosevents_c.h"
42 #include "../ataricommon/SDL_ataridevmouse_c.h" 42 #include "../ataricommon/SDL_ataridevmouse_c.h"
43 43
44 /* Defines */ 44 /* Defines */
54 /* The translation tables from a console scancode to a SDL keysym */ 54 /* The translation tables from a console scancode to a SDL keysym */
55 static SDLKey keymap[ATARIBIOS_MAXKEYS]; 55 static SDLKey keymap[ATARIBIOS_MAXKEYS];
56 56
57 /* Functions prototypes */ 57 /* Functions prototypes */
58 58
59 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym, 59 static SDL_keysym *TranslateKey (int scancode, int asciicode,
60 SDL_bool pressed); 60 SDL_keysym * keysym, SDL_bool pressed);
61 static int do_messages(_THIS, short *message); 61 static int do_messages (_THIS, short *message);
62 static void do_keyboard(short kc, short ks); 62 static void do_keyboard (short kc, short ks);
63 static void do_mouse(_THIS, short mx, short my, short mb, short ks); 63 static void do_mouse (_THIS, short mx, short my, short mb, short ks);
64 64
65 /* Functions */ 65 /* Functions */
66 66
67 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym, 67 static SDL_keysym *
68 SDL_bool pressed) 68 TranslateKey (int scancode, int asciicode, SDL_keysym * keysym,
69 { 69 SDL_bool pressed)
70 /* Set the keysym information */ 70 {
71 keysym->scancode = scancode; 71 /* Set the keysym information */
72 72 keysym->scancode = scancode;
73 if (asciicode) 73
74 keysym->sym = asciicode; 74 if (asciicode)
75 else 75 keysym->sym = asciicode;
76 keysym->sym = keymap[scancode]; 76 else
77 77 keysym->sym = keymap[scancode];
78 keysym->mod = KMOD_NONE; 78
79 keysym->unicode = 0; 79 keysym->mod = KMOD_NONE;
80 if (SDL_TranslateUNICODE && pressed) { 80 keysym->unicode = 0;
81 keysym->unicode = SDL_AtariToUnicodeTable[asciicode]; 81 if (SDL_TranslateUNICODE && pressed) {
82 } 82 keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
83 83 }
84 return(keysym); 84
85 } 85 return (keysym);
86 86 }
87 void GEM_InitOSKeymap(_THIS) 87
88 { 88 void
89 int i; 89 GEM_InitOSKeymap (_THIS)
90 90 {
91 SDL_memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard)); 91 int i;
92 SDL_memset(gem_previouskeyboard, 0, sizeof(gem_previouskeyboard)); 92
93 SDL_memset(gem_currentascii, 0, sizeof(gem_currentascii)); 93 SDL_memset (gem_currentkeyboard, 0, sizeof (gem_currentkeyboard));
94 94 SDL_memset (gem_previouskeyboard, 0, sizeof (gem_previouskeyboard));
95 /* Initialize keymap */ 95 SDL_memset (gem_currentascii, 0, sizeof (gem_currentascii));
96 for ( i=0; i<sizeof(keymap); i++ ) 96
97 keymap[i] = SDLK_UNKNOWN; 97 /* Initialize keymap */
98 98 for (i = 0; i < sizeof (keymap); i++)
99 /* Functions keys */ 99 keymap[i] = SDLK_UNKNOWN;
100 for ( i = 0; i<10; i++ ) 100
101 keymap[SCANCODE_F1 + i] = SDLK_F1+i; 101 /* Functions keys */
102 102 for (i = 0; i < 10; i++)
103 /* Cursor keypad */ 103 keymap[SCANCODE_F1 + i] = SDLK_F1 + i;
104 keymap[SCANCODE_HELP] = SDLK_HELP; 104
105 keymap[SCANCODE_UNDO] = SDLK_UNDO; 105 /* Cursor keypad */
106 keymap[SCANCODE_INSERT] = SDLK_INSERT; 106 keymap[SCANCODE_HELP] = SDLK_HELP;
107 keymap[SCANCODE_CLRHOME] = SDLK_HOME; 107 keymap[SCANCODE_UNDO] = SDLK_UNDO;
108 keymap[SCANCODE_UP] = SDLK_UP; 108 keymap[SCANCODE_INSERT] = SDLK_INSERT;
109 keymap[SCANCODE_DOWN] = SDLK_DOWN; 109 keymap[SCANCODE_CLRHOME] = SDLK_HOME;
110 keymap[SCANCODE_RIGHT] = SDLK_RIGHT; 110 keymap[SCANCODE_UP] = SDLK_UP;
111 keymap[SCANCODE_LEFT] = SDLK_LEFT; 111 keymap[SCANCODE_DOWN] = SDLK_DOWN;
112 112 keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
113 /* Special keys */ 113 keymap[SCANCODE_LEFT] = SDLK_LEFT;
114 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE; 114
115 keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE; 115 /* Special keys */
116 keymap[SCANCODE_TAB] = SDLK_TAB; 116 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
117 keymap[SCANCODE_ENTER] = SDLK_RETURN; 117 keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
118 keymap[SCANCODE_DELETE] = SDLK_DELETE; 118 keymap[SCANCODE_TAB] = SDLK_TAB;
119 keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL; 119 keymap[SCANCODE_ENTER] = SDLK_RETURN;
120 keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT; 120 keymap[SCANCODE_DELETE] = SDLK_DELETE;
121 keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT; 121 keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
122 keymap[SCANCODE_LEFTALT] = SDLK_LALT; 122 keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
123 keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK; 123 keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
124 124 keymap[SCANCODE_LEFTALT] = SDLK_LALT;
125 /* Mouse init */ 125 keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
126 GEM_mouse_relative = SDL_FALSE; 126
127 } 127 /* Mouse init */
128 128 GEM_mouse_relative = SDL_FALSE;
129 void GEM_PumpEvents(_THIS) 129 }
130 { 130
131 short mousex, mousey, mouseb, dummy; 131 void
132 short kstate, prevkc, prevks; 132 GEM_PumpEvents (_THIS)
133 int i; 133 {
134 SDL_keysym keysym; 134 short mousex, mousey, mouseb, dummy;
135 135 short kstate, prevkc, prevks;
136 SDL_memset(gem_currentkeyboard,0,sizeof(gem_currentkeyboard)); 136 int i;
137 prevkc = prevks = 0; 137 SDL_keysym keysym;
138 138
139 for (;;) 139 SDL_memset (gem_currentkeyboard, 0, sizeof (gem_currentkeyboard));
140 { 140 prevkc = prevks = 0;
141 int quit, resultat, event_mask, mouse_event; 141
142 short buffer[8], kc; 142 for (;;) {
143 short x2,y2,w2,h2; 143 int quit, resultat, event_mask, mouse_event;
144 144 short buffer[8], kc;
145 quit = 145 short x2, y2, w2, h2;
146 mouse_event = 146
147 x2=y2=w2=h2 = 0; 147 quit = mouse_event = x2 = y2 = w2 = h2 = 0;
148 148
149 event_mask = MU_MESAG|MU_TIMER|MU_KEYBD; 149 event_mask = MU_MESAG | MU_TIMER | MU_KEYBD;
150 if (!GEM_fullscreen && (GEM_handle>=0)) { 150 if (!GEM_fullscreen && (GEM_handle >= 0)) {
151 wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2); 151 wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
152 event_mask |= MU_M1; 152 event_mask |= MU_M1;
153 if ( (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) { 153 if ((SDL_GetAppState () & SDL_APPMOUSEFOCUS)) {
154 mouse_event = MO_LEAVE; 154 mouse_event = MO_LEAVE;
155 } else { 155 } else {
156 mouse_event = MO_ENTER; 156 mouse_event = MO_ENTER;
157 } 157 }
158 } 158 }
159 159
160 resultat = evnt_multi( 160 resultat = evnt_multi (event_mask,
161 event_mask, 161 0, 0, 0,
162 0,0,0, 162 mouse_event, x2, y2, w2, h2,
163 mouse_event,x2,y2,w2,h2, 163 0, 0, 0, 0, 0,
164 0,0,0,0,0, 164 buffer,
165 buffer, 165 10,
166 10, 166 &dummy, &dummy, &dummy, &kstate, &kc, &dummy);
167 &dummy,&dummy,&dummy,&kstate,&kc,&dummy 167
168 ); 168 /* Message event ? */
169 169 if (resultat & MU_MESAG)
170 /* Message event ? */ 170 quit = do_messages (this, buffer);
171 if (resultat & MU_MESAG) 171
172 quit = do_messages(this, buffer); 172 /* Keyboard event ? */
173 173 if (resultat & MU_KEYBD) {
174 /* Keyboard event ? */ 174 if ((prevkc != kc) || (prevks != kstate)) {
175 if (resultat & MU_KEYBD) { 175 do_keyboard (kc, kstate);
176 if ((prevkc != kc) || (prevks != kstate)) { 176 } else {
177 do_keyboard(kc,kstate); 177 /* Avoid looping, if repeating same key */
178 } else { 178 break;
179 /* Avoid looping, if repeating same key */ 179 }
180 break; 180 }
181 } 181
182 } 182 /* Mouse entering/leaving window */
183 183 if (resultat & MU_M1) {
184 /* Mouse entering/leaving window */ 184 if (this->input_grab == SDL_GRAB_OFF) {
185 if (resultat & MU_M1) { 185 if (SDL_GetAppState () & SDL_APPMOUSEFOCUS) {
186 if (this->input_grab == SDL_GRAB_OFF) { 186 SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS);
187 if (SDL_GetAppState() & SDL_APPMOUSEFOCUS) { 187 } else {
188 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); 188 SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS);
189 } else { 189 }
190 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); 190 }
191 } 191 }
192 } 192
193 } 193 /* Timer event ? */
194 194 if ((resultat & MU_TIMER) || quit)
195 /* Timer event ? */ 195 break;
196 if ((resultat & MU_TIMER) || quit) 196 }
197 break; 197
198 } 198 /* Update mouse */
199 199 graf_mkstate (&mousex, &mousey, &mouseb, &kstate);
200 /* Update mouse */ 200 do_mouse (this, mousex, mousey, mouseb, kstate);
201 graf_mkstate(&mousex, &mousey, &mouseb, &kstate); 201
202 do_mouse(this, mousex, mousey, mouseb, kstate); 202 /* Now generate keyboard events */
203 203 for (i = 0; i < ATARIBIOS_MAXKEYS; i++) {
204 /* Now generate keyboard events */ 204 /* Key pressed ? */
205 for (i=0; i<ATARIBIOS_MAXKEYS; i++) { 205 if (gem_currentkeyboard[i] && !gem_previouskeyboard[i])
206 /* Key pressed ? */ 206 SDL_PrivateKeyboard (SDL_PRESSED,
207 if (gem_currentkeyboard[i] && !gem_previouskeyboard[i]) 207 TranslateKey (i, gem_currentascii[i],
208 SDL_PrivateKeyboard(SDL_PRESSED, 208 &keysym, SDL_TRUE));
209 TranslateKey(i, gem_currentascii[i], &keysym, SDL_TRUE)); 209
210 210 /* Key unpressed ? */
211 /* Key unpressed ? */ 211 if (gem_previouskeyboard[i] && !gem_currentkeyboard[i])
212 if (gem_previouskeyboard[i] && !gem_currentkeyboard[i]) 212 SDL_PrivateKeyboard (SDL_RELEASED,
213 SDL_PrivateKeyboard(SDL_RELEASED, 213 TranslateKey (i, gem_currentascii[i],
214 TranslateKey(i, gem_currentascii[i], &keysym, SDL_FALSE)); 214 &keysym, SDL_FALSE));
215 } 215 }
216 216
217 SDL_memcpy(gem_previouskeyboard,gem_currentkeyboard,sizeof(gem_previouskeyboard)); 217 SDL_memcpy (gem_previouskeyboard, gem_currentkeyboard,
218 218 sizeof (gem_previouskeyboard));
219 /* Refresh window name ? */ 219
220 if (GEM_refresh_name) { 220 /* Refresh window name ? */
221 if ( SDL_GetAppState() & SDL_APPACTIVE ) { 221 if (GEM_refresh_name) {
222 /* Fullscreen/windowed */ 222 if (SDL_GetAppState () & SDL_APPACTIVE) {
223 if (GEM_title_name) { 223 /* Fullscreen/windowed */
224 wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0); 224 if (GEM_title_name) {
225 } 225 wind_set (GEM_handle, WF_NAME,
226 } else { 226 (short) (((unsigned long) GEM_title_name) >>
227 /* Iconified */ 227 16),
228 if (GEM_icon_name) { 228 (short) (((unsigned long) GEM_title_name) &
229 wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_icon_name)>>16),(short)(((unsigned long)GEM_icon_name) & 0xffff),0,0); 229 0xffff), 0, 0);
230 } 230 }
231 } 231 } else {
232 GEM_refresh_name = SDL_FALSE; 232 /* Iconified */
233 } 233 if (GEM_icon_name) {
234 } 234 wind_set (GEM_handle, WF_NAME,
235 235 (short) (((unsigned long) GEM_icon_name) >>
236 static int do_messages(_THIS, short *message) 236 16),
237 { 237 (short) (((unsigned long) GEM_icon_name) &
238 int quit, posted; 238 0xffff), 0, 0);
239 short x2,y2,w2,h2; 239 }
240 240 }
241 quit=0; 241 GEM_refresh_name = SDL_FALSE;
242 switch (message[0]) { 242 }
243 case WM_CLOSED: 243 }
244 case AP_TERM: 244
245 posted = SDL_PrivateQuit(); 245 static int
246 quit=1; 246 do_messages (_THIS, short *message)
247 break; 247 {
248 case WM_MOVED: 248 int quit, posted;
249 wind_set(message[3],WF_CURRXYWH,message[4],message[5],message[6],message[7]); 249 short x2, y2, w2, h2;
250 break; 250
251 case WM_TOPPED: 251 quit = 0;
252 wind_set(message[3],WF_TOP,message[4],0,0,0); 252 switch (message[0]) {
253 /* Continue with TOP event processing */ 253 case WM_CLOSED:
254 case WM_ONTOP: 254 case AP_TERM:
255 SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS); 255 posted = SDL_PrivateQuit ();
256 if (VDI_setpalette) { 256 quit = 1;
257 VDI_setpalette(this, VDI_curpalette); 257 break;
258 } 258 case WM_MOVED:
259 break; 259 wind_set (message[3], WF_CURRXYWH, message[4], message[5],
260 case WM_REDRAW: 260 message[6], message[7]);
261 if (!GEM_lock_redraw) { 261 break;
262 GEM_wind_redraw(this, message[3],&message[4]); 262 case WM_TOPPED:
263 } 263 wind_set (message[3], WF_TOP, message[4], 0, 0, 0);
264 break; 264 /* Continue with TOP event processing */
265 case WM_ICONIFY: 265 case WM_ONTOP:
266 case WM_ALLICONIFY: 266 SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS);
267 wind_set(message[3],WF_ICONIFY,message[4],message[5],message[6],message[7]); 267 if (VDI_setpalette) {
268 /* If we're active, make ourselves inactive */ 268 VDI_setpalette (this, VDI_curpalette);
269 if ( SDL_GetAppState() & SDL_APPACTIVE ) { 269 }
270 /* Send an internal deactivate event */ 270 break;
271 SDL_PrivateAppActive(0, SDL_APPACTIVE); 271 case WM_REDRAW:
272 } 272 if (!GEM_lock_redraw) {
273 /* Update window title */ 273 GEM_wind_redraw (this, message[3], &message[4]);
274 if (GEM_refresh_name && GEM_icon_name) { 274 }
275 wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_icon_name)>>16),(short)(((unsigned long)GEM_icon_name) & 0xffff),0,0); 275 break;
276 GEM_refresh_name = SDL_FALSE; 276 case WM_ICONIFY:
277 } 277 case WM_ALLICONIFY:
278 break; 278 wind_set (message[3], WF_ICONIFY, message[4], message[5],
279 case WM_UNICONIFY: 279 message[6], message[7]);
280 wind_set(message[3],WF_UNICONIFY,message[4],message[5],message[6],message[7]); 280 /* If we're active, make ourselves inactive */
281 /* If we're not active, make ourselves active */ 281 if (SDL_GetAppState () & SDL_APPACTIVE) {
282 if ( !(SDL_GetAppState() & SDL_APPACTIVE) ) { 282 /* Send an internal deactivate event */
283 /* Send an internal activate event */ 283 SDL_PrivateAppActive (0, SDL_APPACTIVE);
284 SDL_PrivateAppActive(1, SDL_APPACTIVE); 284 }
285 } 285 /* Update window title */
286 if (GEM_refresh_name && GEM_title_name) { 286 if (GEM_refresh_name && GEM_icon_name) {
287 wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0); 287 wind_set (GEM_handle, WF_NAME,
288 GEM_refresh_name = SDL_FALSE; 288 (short) (((unsigned long) GEM_icon_name) >> 16),
289 } 289 (short) (((unsigned long) GEM_icon_name) & 0xffff),
290 break; 290 0, 0);
291 case WM_SIZED: 291 GEM_refresh_name = SDL_FALSE;
292 wind_set (message[3], WF_CURRXYWH, message[4], message[5], message[6], message[7]); 292 }
293 wind_get (message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2); 293 break;
294 GEM_win_fulled = SDL_FALSE; /* Cancel maximized flag */ 294 case WM_UNICONIFY:
295 GEM_lock_redraw = SDL_TRUE; /* Prevent redraw till buffers resized */ 295 wind_set (message[3], WF_UNICONIFY, message[4], message[5],
296 SDL_PrivateResize(w2, h2); 296 message[6], message[7]);
297 break; 297 /* If we're not active, make ourselves active */
298 case WM_FULLED: 298 if (!(SDL_GetAppState () & SDL_APPACTIVE)) {
299 { 299 /* Send an internal activate event */
300 short x,y,w,h; 300 SDL_PrivateAppActive (1, SDL_APPACTIVE);
301 301 }
302 if (GEM_win_fulled) { 302 if (GEM_refresh_name && GEM_title_name) {
303 wind_get (message[3], WF_PREVXYWH, &x, &y, &w, &h); 303 wind_set (GEM_handle, WF_NAME,
304 GEM_win_fulled = SDL_FALSE; 304 (short) (((unsigned long) GEM_title_name) >> 16),
305 } else { 305 (short) (((unsigned long) GEM_title_name) & 0xffff),
306 x = GEM_desk_x; 306 0, 0);
307 y = GEM_desk_y; 307 GEM_refresh_name = SDL_FALSE;
308 w = GEM_desk_w; 308 }
309 h = GEM_desk_h; 309 break;
310 GEM_win_fulled = SDL_TRUE; 310 case WM_SIZED:
311 } 311 wind_set (message[3], WF_CURRXYWH, message[4], message[5],
312 wind_set (message[3], WF_CURRXYWH, x, y, w, h); 312 message[6], message[7]);
313 wind_get (message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2); 313 wind_get (message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2);
314 GEM_lock_redraw = SDL_TRUE; /* Prevent redraw till buffers resized */ 314 GEM_win_fulled = SDL_FALSE; /* Cancel maximized flag */
315 SDL_PrivateResize(w2, h2); 315 GEM_lock_redraw = SDL_TRUE; /* Prevent redraw till buffers resized */
316 } 316 SDL_PrivateResize (w2, h2);
317 break; 317 break;
318 case WM_BOTTOMED: 318 case WM_FULLED:
319 wind_set(message[3],WF_BOTTOM,0,0,0,0); 319 {
320 /* Continue with BOTTOM event processing */ 320 short x, y, w, h;
321 case WM_UNTOPPED: 321
322 SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS); 322 if (GEM_win_fulled) {
323 if (VDI_setpalette) { 323 wind_get (message[3], WF_PREVXYWH, &x, &y, &w, &h);
324 VDI_setpalette(this, VDI_oldpalette); 324 GEM_win_fulled = SDL_FALSE;
325 } 325 } else {
326 break; 326 x = GEM_desk_x;
327 } 327 y = GEM_desk_y;
328 328 w = GEM_desk_w;
329 return quit; 329 h = GEM_desk_h;
330 } 330 GEM_win_fulled = SDL_TRUE;
331 331 }
332 static void do_keyboard(short kc, short ks) 332 wind_set (message[3], WF_CURRXYWH, x, y, w, h);
333 { 333 wind_get (message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2);
334 int scancode, asciicode; 334 GEM_lock_redraw = SDL_TRUE; /* Prevent redraw till buffers resized */
335 335 SDL_PrivateResize (w2, h2);
336 if (kc) { 336 }
337 scancode=(kc>>8) & 127; 337 break;
338 asciicode=kc & 255; 338 case WM_BOTTOMED:
339 339 wind_set (message[3], WF_BOTTOM, 0, 0, 0, 0);
340 gem_currentkeyboard[scancode]=0xFF; 340 /* Continue with BOTTOM event processing */
341 gem_currentascii[scancode]=asciicode; 341 case WM_UNTOPPED:
342 } 342 SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS);
343 343 if (VDI_setpalette) {
344 /* Read special keys */ 344 VDI_setpalette (this, VDI_oldpalette);
345 if (ks & K_RSHIFT) 345 }
346 gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF; 346 break;
347 if (ks & K_LSHIFT) 347 }
348 gem_currentkeyboard[SCANCODE_LEFTSHIFT]=0xFF; 348
349 if (ks & K_CTRL) 349 return quit;
350 gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF; 350 }
351 if (ks & K_ALT) 351
352 gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF; 352 static void
353 } 353 do_keyboard (short kc, short ks)
354 354 {
355 static void do_mouse(_THIS, short mx, short my, short mb, short ks) 355 int scancode, asciicode;
356 { 356
357 static short prevmousex=0, prevmousey=0, prevmouseb=0; 357 if (kc) {
358 short x2, y2, w2, h2; 358 scancode = (kc >> 8) & 127;
359 359 asciicode = kc & 255;
360 /* Don't return mouse events if out of window */ 360
361 if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS)==0) { 361 gem_currentkeyboard[scancode] = 0xFF;
362 return; 362 gem_currentascii[scancode] = asciicode;
363 } 363 }
364 364
365 /* Retrieve window coords, and generate mouse events accordingly */ 365 /* Read special keys */
366 x2 = y2 = 0; 366 if (ks & K_RSHIFT)
367 w2 = VDI_w; 367 gem_currentkeyboard[SCANCODE_RIGHTSHIFT] = 0xFF;
368 h2 = VDI_h; 368 if (ks & K_LSHIFT)
369 if ((!GEM_fullscreen) && (GEM_handle>=0)) { 369 gem_currentkeyboard[SCANCODE_LEFTSHIFT] = 0xFF;
370 wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2); 370 if (ks & K_CTRL)
371 371 gem_currentkeyboard[SCANCODE_LEFTCONTROL] = 0xFF;
372 /* Do not generate mouse button event if out of window working area */ 372 if (ks & K_ALT)
373 if ((mx<x2) || (mx>=x2+w2) || (my<y2) || (my>=y2+h2)) { 373 gem_currentkeyboard[SCANCODE_LEFTALT] = 0xFF;
374 mb=prevmouseb; 374 }
375 } 375
376 } 376 static void
377 377 do_mouse (_THIS, short mx, short my, short mb, short ks)
378 /* Mouse motion ? */ 378 {
379 if (GEM_mouse_relative) { 379 static short prevmousex = 0, prevmousey = 0, prevmouseb = 0;
380 if (GEM_usedevmouse) { 380 short x2, y2, w2, h2;
381 SDL_AtariDevMouse_PostMouseEvents(this, SDL_FALSE); 381
382 } else { 382 /* Don't return mouse events if out of window */
383 SDL_AtariXbios_PostMouseEvents(this, SDL_FALSE); 383 if ((SDL_GetAppState () & SDL_APPMOUSEFOCUS) == 0) {
384 } 384 return;
385 } else { 385 }
386 if ((prevmousex!=mx) || (prevmousey!=my)) { 386
387 int posx, posy; 387 /* Retrieve window coords, and generate mouse events accordingly */
388 388 x2 = y2 = 0;
389 /* Give mouse position relative to window position */ 389 w2 = VDI_w;
390 posx = mx - x2; 390 h2 = VDI_h;
391 if (posx<0) posx = 0; 391 if ((!GEM_fullscreen) && (GEM_handle >= 0)) {
392 if (posx>w2) posx = w2-1; 392 wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
393 posy = my - y2; 393
394 if (posy<0) posy = 0; 394 /* Do not generate mouse button event if out of window working area */
395 if (posy>h2) posy = h2-1; 395 if ((mx < x2) || (mx >= x2 + w2) || (my < y2) || (my >= y2 + h2)) {
396 396 mb = prevmouseb;
397 SDL_PrivateMouseMotion(0, 0, posx, posy); 397 }
398 } 398 }
399 prevmousex = mx; 399
400 prevmousey = my; 400 /* Mouse motion ? */
401 } 401 if (GEM_mouse_relative) {
402 402 if (GEM_usedevmouse) {
403 /* Mouse button ? */ 403 SDL_AtariDevMouse_PostMouseEvents (this, SDL_FALSE);
404 if (prevmouseb!=mb) { 404 } else {
405 int i; 405 SDL_AtariXbios_PostMouseEvents (this, SDL_FALSE);
406 406 }
407 for (i=0;i<2;i++) { 407 } else {
408 int curbutton, prevbutton; 408 if ((prevmousex != mx) || (prevmousey != my)) {
409 409 int posx, posy;
410 curbutton = mb & (1<<i); 410
411 prevbutton = prevmouseb & (1<<i); 411 /* Give mouse position relative to window position */
412 412 posx = mx - x2;
413 if (curbutton && !prevbutton) { 413 if (posx < 0)
414 SDL_PrivateMouseButton(SDL_PRESSED, i+1, 0, 0); 414 posx = 0;
415 } 415 if (posx > w2)
416 if (!curbutton && prevbutton) { 416 posx = w2 - 1;
417 SDL_PrivateMouseButton(SDL_RELEASED, i+1, 0, 0); 417 posy = my - y2;
418 } 418 if (posy < 0)
419 } 419 posy = 0;
420 prevmouseb = mb; 420 if (posy > h2)
421 } 421 posy = h2 - 1;
422 422
423 /* Read special keys */ 423 SDL_PrivateMouseMotion (0, 0, posx, posy);
424 if (ks & K_RSHIFT) 424 }
425 gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF; 425 prevmousex = mx;
426 if (ks & K_LSHIFT) 426 prevmousey = my;
427 gem_currentkeyboard[SCANCODE_LEFTSHIFT]=0xFF; 427 }
428 if (ks & K_CTRL) 428
429 gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF; 429 /* Mouse button ? */
430 if (ks & K_ALT) 430 if (prevmouseb != mb) {
431 gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF; 431 int i;
432 } 432
433 for (i = 0; i < 2; i++) {
434 int curbutton, prevbutton;
435
436 curbutton = mb & (1 << i);
437 prevbutton = prevmouseb & (1 << i);
438
439 if (curbutton && !prevbutton) {
440 SDL_PrivateMouseButton (SDL_PRESSED, i + 1, 0, 0);
441 }
442 if (!curbutton && prevbutton) {
443 SDL_PrivateMouseButton (SDL_RELEASED, i + 1, 0, 0);
444 }
445 }
446 prevmouseb = mb;
447 }
448
449 /* Read special keys */
450 if (ks & K_RSHIFT)
451 gem_currentkeyboard[SCANCODE_RIGHTSHIFT] = 0xFF;
452 if (ks & K_LSHIFT)
453 gem_currentkeyboard[SCANCODE_LEFTSHIFT] = 0xFF;
454 if (ks & K_CTRL)
455 gem_currentkeyboard[SCANCODE_LEFTCONTROL] = 0xFF;
456 if (ks & K_ALT)
457 gem_currentkeyboard[SCANCODE_LEFTALT] = 0xFF;
458 }
459
460 /* vi: set ts=4 sw=4 expandtab: */