Skip to content

Latest commit

 

History

History
432 lines (371 loc) · 11.5 KB

SDL_gemevents.c

File metadata and controls

432 lines (371 loc) · 11.5 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Feb 1, 2006
Feb 1, 2006
3
Copyright (C) 1997-2006 Sam Lantinga
4
5
This library is free software; you can redistribute it and/or
Feb 1, 2006
Feb 1, 2006
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
Feb 1, 2006
Feb 1, 2006
8
version 2.1 of the License, or (at your option) any later version.
9
10
11
12
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Feb 1, 2006
Feb 1, 2006
13
Lesser General Public License for more details.
Feb 1, 2006
Feb 1, 2006
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19
20
21
Sam Lantinga
slouken@libsdl.org
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
23
24
25
26
27
28
29
30
31
32
33
34
/*
* GEM SDL video driver implementation
* inspired from the Dummy SDL driver
*
* Patrice Mandin
* and work from
* Olivier Landemarre, Johan Klockars, Xavier Joubert, Claude Attard
*/
#include <gem.h>
Feb 16, 2006
Feb 16, 2006
35
36
#include "../../events/SDL_sysevents.h"
#include "../../events/SDL_events_c.h"
37
38
#include "SDL_gemvideo.h"
#include "SDL_gemevents_c.h"
Feb 21, 2006
Feb 21, 2006
39
40
41
#include "../ataricommon/SDL_atarikeys.h" /* for keyboard scancodes */
#include "../ataricommon/SDL_atarievents_c.h"
#include "../ataricommon/SDL_xbiosevents_c.h"
Feb 23, 2006
Feb 23, 2006
42
#include "../ataricommon/SDL_ataridevmouse_c.h"
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* Defines */
#define ATARIBIOS_MAXKEYS 128
/* Variables */
static unsigned char gem_currentkeyboard[ATARIBIOS_MAXKEYS];
static unsigned char gem_previouskeyboard[ATARIBIOS_MAXKEYS];
static unsigned char gem_currentascii[ATARIBIOS_MAXKEYS];
/* The translation tables from a console scancode to a SDL keysym */
static SDLKey keymap[ATARIBIOS_MAXKEYS];
/* Functions prototypes */
Jan 1, 2006
Jan 1, 2006
59
60
static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym,
SDL_bool pressed);
61
62
static int do_messages(_THIS, short *message);
static void do_keyboard(short kc, short ks);
Mar 26, 2002
Mar 26, 2002
63
static void do_mouse(_THIS, short mx, short my, short mb, short ks);
64
65
66
/* Functions */
Jan 1, 2006
Jan 1, 2006
67
68
static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym,
SDL_bool pressed)
69
70
71
72
73
74
75
76
77
78
79
{
/* Set the keysym information */
keysym->scancode = scancode;
if (asciicode)
keysym->sym = asciicode;
else
keysym->sym = keymap[scancode];
keysym->mod = KMOD_NONE;
keysym->unicode = 0;
Jan 2, 2006
Jan 2, 2006
80
81
if (SDL_TranslateUNICODE && pressed) {
keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
Jan 1, 2006
Jan 1, 2006
82
}
83
84
85
86
87
88
89
90
return(keysym);
}
void GEM_InitOSKeymap(_THIS)
{
int i;
Feb 7, 2006
Feb 7, 2006
91
92
93
SDL_memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard));
SDL_memset(gem_previouskeyboard, 0, sizeof(gem_previouskeyboard));
SDL_memset(gem_currentascii, 0, sizeof(gem_currentascii));
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* Initialize keymap */
for ( i=0; i<sizeof(keymap); i++ )
keymap[i] = SDLK_UNKNOWN;
/* Functions keys */
for ( i = 0; i<10; i++ )
keymap[SCANCODE_F1 + i] = SDLK_F1+i;
/* Cursor keypad */
keymap[SCANCODE_HELP] = SDLK_HELP;
keymap[SCANCODE_UNDO] = SDLK_UNDO;
keymap[SCANCODE_INSERT] = SDLK_INSERT;
keymap[SCANCODE_CLRHOME] = SDLK_HOME;
keymap[SCANCODE_UP] = SDLK_UP;
keymap[SCANCODE_DOWN] = SDLK_DOWN;
keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
keymap[SCANCODE_LEFT] = SDLK_LEFT;
/* Special keys */
keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
keymap[SCANCODE_TAB] = SDLK_TAB;
keymap[SCANCODE_ENTER] = SDLK_RETURN;
keymap[SCANCODE_DELETE] = SDLK_DELETE;
keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
keymap[SCANCODE_LEFTALT] = SDLK_LALT;
keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
/* Mouse init */
GEM_mouse_relative = SDL_FALSE;
}
void GEM_PumpEvents(_THIS)
{
Mar 26, 2002
Mar 26, 2002
131
132
short mousex, mousey, mouseb, dummy;
short kstate, prevkc, prevks;
133
134
135
int i;
SDL_keysym keysym;
Feb 7, 2006
Feb 7, 2006
136
SDL_memset(gem_currentkeyboard,0,sizeof(gem_currentkeyboard));
Mar 26, 2002
Mar 26, 2002
137
prevkc = prevks = 0;
138
139
140
for (;;)
{
Jul 7, 2005
Jul 7, 2005
141
int quit, resultat, event_mask, mouse_event;
Mar 26, 2002
Mar 26, 2002
142
short buffer[8], kc;
Jun 3, 2005
Jun 3, 2005
143
short x2,y2,w2,h2;
Jul 7, 2005
Jul 7, 2005
145
146
147
quit =
mouse_event =
x2=y2=w2=h2 = 0;
Jun 3, 2005
Jun 3, 2005
149
150
151
event_mask = MU_MESAG|MU_TIMER|MU_KEYBD;
if (!GEM_fullscreen && (GEM_handle>=0)) {
wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
Jul 7, 2005
Jul 7, 2005
152
153
154
155
156
157
event_mask |= MU_M1;
if ( (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
mouse_event = MO_LEAVE;
} else {
mouse_event = MO_ENTER;
}
Jun 3, 2005
Jun 3, 2005
158
159
}
160
resultat = evnt_multi(
Jun 3, 2005
Jun 3, 2005
161
event_mask,
162
0,0,0,
Jul 7, 2005
Jul 7, 2005
163
164
mouse_event,x2,y2,w2,h2,
0,0,0,0,0,
165
166
buffer,
10,
Mar 26, 2002
Mar 26, 2002
167
&dummy,&dummy,&dummy,&kstate,&kc,&dummy
168
169
170
171
172
173
174
);
/* Message event ? */
if (resultat & MU_MESAG)
quit = do_messages(this, buffer);
/* Keyboard event ? */
Mar 26, 2002
Mar 26, 2002
175
176
177
178
179
180
181
182
if (resultat & MU_KEYBD) {
if ((prevkc != kc) || (prevks != kstate)) {
do_keyboard(kc,kstate);
} else {
/* Avoid looping, if repeating same key */
break;
}
}
Jun 3, 2005
Jun 3, 2005
184
185
186
/* Mouse entering/leaving window */
if (resultat & MU_M1) {
if (this->input_grab == SDL_GRAB_OFF) {
Jul 7, 2005
Jul 7, 2005
187
188
189
if (SDL_GetAppState() & SDL_APPMOUSEFOCUS) {
SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
} else {
Jul 7, 2005
Jul 7, 2005
190
191
SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
}
Jun 3, 2005
Jun 3, 2005
192
193
194
}
}
195
196
197
198
199
200
/* Timer event ? */
if ((resultat & MU_TIMER) || quit)
break;
}
/* Update mouse */
Mar 26, 2002
Mar 26, 2002
201
202
graf_mkstate(&mousex, &mousey, &mouseb, &kstate);
do_mouse(this, mousex, mousey, mouseb, kstate);
Mar 26, 2002
Mar 26, 2002
204
/* Now generate keyboard events */
205
206
207
for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
/* Key pressed ? */
if (gem_currentkeyboard[i] && !gem_previouskeyboard[i])
Jan 1, 2006
Jan 1, 2006
208
209
SDL_PrivateKeyboard(SDL_PRESSED,
TranslateKey(i, gem_currentascii[i], &keysym, SDL_TRUE));
210
211
212
/* Key unpressed ? */
if (gem_previouskeyboard[i] && !gem_currentkeyboard[i])
Jan 1, 2006
Jan 1, 2006
213
214
SDL_PrivateKeyboard(SDL_RELEASED,
TranslateKey(i, gem_currentascii[i], &keysym, SDL_FALSE));
215
216
}
Feb 7, 2006
Feb 7, 2006
217
SDL_memcpy(gem_previouskeyboard,gem_currentkeyboard,sizeof(gem_previouskeyboard));
Nov 30, 2004
Nov 30, 2004
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/* Refresh window name ? */
if (GEM_refresh_name) {
if ( SDL_GetAppState() & SDL_APPACTIVE ) {
/* Fullscreen/windowed */
if (GEM_title_name) {
wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0);
}
} else {
/* Iconified */
if (GEM_icon_name) {
wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_icon_name)>>16),(short)(((unsigned long)GEM_icon_name) & 0xffff),0,0);
}
}
GEM_refresh_name = SDL_FALSE;
}
234
235
236
237
238
}
static int do_messages(_THIS, short *message)
{
int quit, posted;
Aug 5, 2004
Aug 5, 2004
239
short x2,y2,w2,h2;
240
241
242
243
244
245
246
247
248
249
250
251
252
quit=0;
switch (message[0]) {
case WM_CLOSED:
case AP_TERM:
posted = SDL_PrivateQuit();
quit=1;
break;
case WM_MOVED:
wind_set(message[3],WF_CURRXYWH,message[4],message[5],message[6],message[7]);
break;
case WM_TOPPED:
wind_set(message[3],WF_TOP,message[4],0,0,0);
Jul 7, 2005
Jul 7, 2005
253
254
/* Continue with TOP event processing */
case WM_ONTOP:
255
SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
Jun 7, 2005
Jun 7, 2005
256
257
258
if (VDI_setpalette) {
VDI_setpalette(this, VDI_curpalette);
}
259
260
break;
case WM_REDRAW:
Nov 6, 2004
Nov 6, 2004
261
262
263
if (!GEM_lock_redraw) {
GEM_wind_redraw(this, message[3],&message[4]);
}
264
265
266
267
268
269
270
break;
case WM_ICONIFY:
case WM_ALLICONIFY:
wind_set(message[3],WF_ICONIFY,message[4],message[5],message[6],message[7]);
/* If we're active, make ourselves inactive */
if ( SDL_GetAppState() & SDL_APPACTIVE ) {
/* Send an internal deactivate event */
Jul 7, 2005
Jul 7, 2005
271
SDL_PrivateAppActive(0, SDL_APPACTIVE);
Nov 12, 2003
Nov 12, 2003
273
274
275
276
277
/* Update window title */
if (GEM_refresh_name && GEM_icon_name) {
wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_icon_name)>>16),(short)(((unsigned long)GEM_icon_name) & 0xffff),0,0);
GEM_refresh_name = SDL_FALSE;
}
278
279
280
281
282
283
284
285
break;
case WM_UNICONIFY:
wind_set(message[3],WF_UNICONIFY,message[4],message[5],message[6],message[7]);
/* If we're not active, make ourselves active */
if ( !(SDL_GetAppState() & SDL_APPACTIVE) ) {
/* Send an internal activate event */
SDL_PrivateAppActive(1, SDL_APPACTIVE);
}
Nov 12, 2003
Nov 12, 2003
286
287
288
289
if (GEM_refresh_name && GEM_title_name) {
wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0);
GEM_refresh_name = SDL_FALSE;
}
290
291
292
break;
case WM_SIZED:
wind_set (message[3], WF_CURRXYWH, message[4], message[5], message[6], message[7]);
Aug 5, 2004
Aug 5, 2004
293
wind_get (message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2);
Nov 6, 2004
Nov 6, 2004
294
295
GEM_win_fulled = SDL_FALSE; /* Cancel maximized flag */
GEM_lock_redraw = SDL_TRUE; /* Prevent redraw till buffers resized */
Aug 5, 2004
Aug 5, 2004
296
SDL_PrivateResize(w2, h2);
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
break;
case WM_FULLED:
{
short x,y,w,h;
if (GEM_win_fulled) {
wind_get (message[3], WF_PREVXYWH, &x, &y, &w, &h);
GEM_win_fulled = SDL_FALSE;
} else {
x = GEM_desk_x;
y = GEM_desk_y;
w = GEM_desk_w;
h = GEM_desk_h;
GEM_win_fulled = SDL_TRUE;
}
wind_set (message[3], WF_CURRXYWH, x, y, w, h);
Aug 5, 2004
Aug 5, 2004
313
wind_get (message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2);
Nov 6, 2004
Nov 6, 2004
314
GEM_lock_redraw = SDL_TRUE; /* Prevent redraw till buffers resized */
Aug 5, 2004
Aug 5, 2004
315
SDL_PrivateResize(w2, h2);
316
317
318
}
break;
case WM_BOTTOMED:
Jul 7, 2005
Jul 7, 2005
319
320
wind_set(message[3],WF_BOTTOM,0,0,0,0);
/* Continue with BOTTOM event processing */
321
322
case WM_UNTOPPED:
SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
Jun 7, 2005
Jun 7, 2005
323
324
325
if (VDI_setpalette) {
VDI_setpalette(this, VDI_oldpalette);
}
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
break;
}
return quit;
}
static void do_keyboard(short kc, short ks)
{
int scancode, asciicode;
if (kc) {
scancode=(kc>>8) & 127;
asciicode=kc & 255;
gem_currentkeyboard[scancode]=0xFF;
gem_currentascii[scancode]=asciicode;
}
/* Read special keys */
if (ks & K_RSHIFT)
gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF;
if (ks & K_LSHIFT)
gem_currentkeyboard[SCANCODE_LEFTSHIFT]=0xFF;
if (ks & K_CTRL)
gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF;
if (ks & K_ALT)
gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF;
}
Mar 26, 2002
Mar 26, 2002
355
static void do_mouse(_THIS, short mx, short my, short mb, short ks)
Mar 26, 2002
Mar 26, 2002
357
static short prevmousex=0, prevmousey=0, prevmouseb=0;
Aug 10, 2004
Aug 10, 2004
358
359
short x2, y2, w2, h2;
Jun 3, 2005
Jun 3, 2005
360
361
362
363
364
/* Don't return mouse events if out of window */
if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS)==0) {
return;
}
Aug 10, 2004
Aug 10, 2004
365
366
/* Retrieve window coords, and generate mouse events accordingly */
x2 = y2 = 0;
Aug 10, 2004
Aug 10, 2004
367
368
w2 = VDI_w;
h2 = VDI_h;
Aug 10, 2004
Aug 10, 2004
369
370
371
372
373
374
375
376
if ((!GEM_fullscreen) && (GEM_handle>=0)) {
wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
/* Do not generate mouse button event if out of window working area */
if ((mx<x2) || (mx>=x2+w2) || (my<y2) || (my>=y2+h2)) {
mb=prevmouseb;
}
}
Mar 26, 2002
Mar 26, 2002
377
378
/* Mouse motion ? */
Jan 25, 2006
Jan 25, 2006
379
if (GEM_mouse_relative) {
Feb 23, 2006
Feb 23, 2006
380
381
382
383
384
if (GEM_usedevmouse) {
SDL_AtariDevMouse_PostMouseEvents(this, SDL_FALSE);
} else {
SDL_AtariXbios_PostMouseEvents(this, SDL_FALSE);
}
Jan 25, 2006
Jan 25, 2006
385
386
} else {
if ((prevmousex!=mx) || (prevmousey!=my)) {
Aug 10, 2004
Aug 10, 2004
387
388
389
390
int posx, posy;
/* Give mouse position relative to window position */
posx = mx - x2;
Aug 10, 2004
Aug 10, 2004
391
if (posx<0) posx = 0;
Aug 10, 2004
Aug 10, 2004
392
393
if (posx>w2) posx = w2-1;
posy = my - y2;
Aug 10, 2004
Aug 10, 2004
394
if (posy<0) posy = 0;
Aug 10, 2004
Aug 10, 2004
395
396
397
if (posy>h2) posy = h2-1;
SDL_PrivateMouseMotion(0, 0, posx, posy);
398
399
400
401
402
403
404
405
406
}
prevmousex = mx;
prevmousey = my;
}
/* Mouse button ? */
if (prevmouseb!=mb) {
int i;
Mar 26, 2002
Mar 26, 2002
407
for (i=0;i<2;i++) {
408
409
410
411
412
int curbutton, prevbutton;
curbutton = mb & (1<<i);
prevbutton = prevmouseb & (1<<i);
Mar 26, 2002
Mar 26, 2002
413
414
if (curbutton && !prevbutton) {
SDL_PrivateMouseButton(SDL_PRESSED, i+1, 0, 0);
Mar 26, 2002
Mar 26, 2002
416
417
if (!curbutton && prevbutton) {
SDL_PrivateMouseButton(SDL_RELEASED, i+1, 0, 0);
418
419
420
421
}
}
prevmouseb = mb;
}
Mar 26, 2002
Mar 26, 2002
422
423
424
425
426
427
428
429
430
431
/* Read special keys */
if (ks & K_RSHIFT)
gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF;
if (ks & K_LSHIFT)
gem_currentkeyboard[SCANCODE_LEFTSHIFT]=0xFF;
if (ks & K_CTRL)
gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF;
if (ks & K_ALT)
gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF;