Skip to content

Latest commit

 

History

History
377 lines (327 loc) · 9.83 KB

SDL_gemevents.c

File metadata and controls

377 lines (327 loc) · 9.83 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Dec 31, 2011
Dec 31, 2011
3
Copyright (C) 1997-2012 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"
Aug 26, 2011
Aug 26, 2011
39
#include "SDL_gemmouse_c.h"
Feb 21, 2006
Feb 21, 2006
40
41
42
#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
43
#include "../ataricommon/SDL_ataridevmouse_c.h"
44
45
46
47
48
49
50
51
52
53
/* Variables */
static unsigned char gem_currentkeyboard[ATARIBIOS_MAXKEYS];
static unsigned char gem_previouskeyboard[ATARIBIOS_MAXKEYS];
/* Functions prototypes */
static int do_messages(_THIS, short *message);
static void do_keyboard(short kc, short ks);
Mar 26, 2002
Mar 26, 2002
54
static void do_mouse(_THIS, short mx, short my, short mb, short ks);
55
56
57
58
59
/* Functions */
void GEM_InitOSKeymap(_THIS)
{
Feb 7, 2006
Feb 7, 2006
60
61
SDL_memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard));
SDL_memset(gem_previouskeyboard, 0, sizeof(gem_previouskeyboard));
62
63
64
/* Mouse init */
GEM_mouse_relative = SDL_FALSE;
Sep 13, 2006
Sep 13, 2006
65
66
SDL_Atari_InitInternalKeymap(this);
67
68
69
70
}
void GEM_PumpEvents(_THIS)
{
Jul 9, 2010
Jul 9, 2010
71
72
short prevkc, prevks;
static short maskmouseb=0;
73
74
75
int i;
SDL_keysym keysym;
Feb 7, 2006
Feb 7, 2006
76
SDL_memset(gem_currentkeyboard,0,sizeof(gem_currentkeyboard));
Mar 26, 2002
Mar 26, 2002
77
prevkc = prevks = 0;
Jul 9, 2010
Jul 9, 2010
78
79
80
for (;;)
{
Jul 7, 2005
Jul 7, 2005
81
int quit, resultat, event_mask, mouse_event;
Mar 26, 2002
Mar 26, 2002
82
short buffer[8], kc;
Jun 3, 2005
Jun 3, 2005
83
short x2,y2,w2,h2;
Jul 9, 2010
Jul 9, 2010
84
85
short mousex, mousey, mouseb, dummy;
short kstate;
Jul 7, 2005
Jul 7, 2005
87
88
89
quit =
mouse_event =
x2=y2=w2=h2 = 0;
Jul 9, 2010
Jul 9, 2010
91
event_mask = MU_MESAG|MU_TIMER|MU_KEYBD|MU_BUTTON;
Jun 3, 2005
Jun 3, 2005
92
93
if (!GEM_fullscreen && (GEM_handle>=0)) {
wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
Jul 7, 2005
Jul 7, 2005
94
event_mask |= MU_M1;
Jul 13, 2007
Jul 13, 2007
95
96
mouse_event = ( (SDL_GetAppState() & SDL_APPMOUSEFOCUS)
== SDL_APPMOUSEFOCUS) ? MO_LEAVE : MO_ENTER;
Jun 3, 2005
Jun 3, 2005
97
98
}
99
resultat = evnt_multi(
Jun 3, 2005
Jun 3, 2005
100
event_mask,
Jul 9, 2010
Jul 9, 2010
101
0x101,7,maskmouseb,
Jul 7, 2005
Jul 7, 2005
102
103
mouse_event,x2,y2,w2,h2,
0,0,0,0,0,
104
105
buffer,
10,
Jul 9, 2010
Jul 9, 2010
106
&mousex,&mousey,&mouseb,&kstate,&kc,&dummy
107
108
109
110
111
112
113
);
/* Message event ? */
if (resultat & MU_MESAG)
quit = do_messages(this, buffer);
/* Keyboard event ? */
Mar 26, 2002
Mar 26, 2002
114
115
116
if (resultat & MU_KEYBD) {
if ((prevkc != kc) || (prevks != kstate)) {
do_keyboard(kc,kstate);
Oct 11, 2012
Oct 11, 2012
117
118
prevkc = kc;
prevks = ks;
Mar 26, 2002
Mar 26, 2002
119
120
121
122
123
} else {
/* Avoid looping, if repeating same key */
break;
}
}
Jun 3, 2005
Jun 3, 2005
125
126
127
/* Mouse entering/leaving window */
if (resultat & MU_M1) {
if (this->input_grab == SDL_GRAB_OFF) {
Jul 13, 2007
Jul 13, 2007
128
129
130
/* Switch mouse focus state */
SDL_PrivateAppActive((mouse_event == MO_ENTER),
SDL_APPMOUSEFOCUS);
Jun 3, 2005
Jun 3, 2005
131
}
Jul 13, 2007
Jul 13, 2007
132
GEM_CheckMouseMode(this);
Jun 3, 2005
Jun 3, 2005
133
134
}
Jul 9, 2010
Jul 9, 2010
135
136
137
138
139
140
/* Mouse button event ? */
if (resultat & MU_BUTTON) {
do_mouse(this, mousex, mousey, mouseb, kstate);
maskmouseb = mouseb & 7;
}
141
142
143
144
145
/* Timer event ? */
if ((resultat & MU_TIMER) || quit)
break;
}
Mar 26, 2002
Mar 26, 2002
146
/* Now generate keyboard events */
147
148
149
for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
/* Key pressed ? */
if (gem_currentkeyboard[i] && !gem_previouskeyboard[i])
Jan 1, 2006
Jan 1, 2006
150
SDL_PrivateKeyboard(SDL_PRESSED,
Sep 13, 2006
Sep 13, 2006
151
SDL_Atari_TranslateKey(i, &keysym, SDL_TRUE));
152
153
154
/* Key unpressed ? */
if (gem_previouskeyboard[i] && !gem_currentkeyboard[i])
Jan 1, 2006
Jan 1, 2006
155
SDL_PrivateKeyboard(SDL_RELEASED,
Sep 13, 2006
Sep 13, 2006
156
SDL_Atari_TranslateKey(i, &keysym, SDL_FALSE));
157
158
}
Feb 7, 2006
Feb 7, 2006
159
SDL_memcpy(gem_previouskeyboard,gem_currentkeyboard,sizeof(gem_previouskeyboard));
Nov 30, 2004
Nov 30, 2004
160
161
162
/* Refresh window name ? */
if (GEM_refresh_name) {
Jul 13, 2007
Jul 13, 2007
163
164
165
166
167
168
169
170
const char *window_name =
(SDL_GetAppState() & SDL_APPACTIVE)
? GEM_title_name : GEM_icon_name;
if (window_name) {
wind_set(GEM_handle,WF_NAME,
(short)(((unsigned long)window_name)>>16),
(short)(((unsigned long)window_name) & 0xffff),
0,0);
Nov 30, 2004
Nov 30, 2004
171
172
173
}
GEM_refresh_name = SDL_FALSE;
}
174
175
176
177
}
static int do_messages(_THIS, short *message)
{
Sep 3, 2011
Sep 3, 2011
178
int quit, check_mouse_mode;
Aug 5, 2004
Aug 5, 2004
179
short x2,y2,w2,h2;
Jul 13, 2007
Jul 13, 2007
181
quit = check_mouse_mode = 0;
182
183
184
switch (message[0]) {
case WM_CLOSED:
case AP_TERM:
Sep 3, 2011
Sep 3, 2011
185
SDL_PrivateQuit();
186
187
188
189
190
191
192
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
193
194
/* Continue with TOP event processing */
case WM_ONTOP:
195
SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
Jun 7, 2005
Jun 7, 2005
196
197
198
if (VDI_setpalette) {
VDI_setpalette(this, VDI_curpalette);
}
Jul 13, 2007
Jul 13, 2007
199
check_mouse_mode = 1;
200
201
break;
case WM_REDRAW:
Nov 6, 2004
Nov 6, 2004
202
203
204
if (!GEM_lock_redraw) {
GEM_wind_redraw(this, message[3],&message[4]);
}
205
206
207
208
209
210
211
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
212
SDL_PrivateAppActive(0, SDL_APPACTIVE);
Nov 12, 2003
Nov 12, 2003
214
215
216
217
218
/* 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;
}
Jul 13, 2007
Jul 13, 2007
219
check_mouse_mode = 1;
220
221
222
223
224
225
226
227
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
228
229
230
231
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;
}
Jul 13, 2007
Jul 13, 2007
232
check_mouse_mode = 1;
233
234
235
break;
case WM_SIZED:
wind_set (message[3], WF_CURRXYWH, message[4], message[5], message[6], message[7]);
Aug 5, 2004
Aug 5, 2004
236
wind_get (message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2);
Nov 6, 2004
Nov 6, 2004
237
238
GEM_win_fulled = SDL_FALSE; /* Cancel maximized flag */
GEM_lock_redraw = SDL_TRUE; /* Prevent redraw till buffers resized */
Aug 5, 2004
Aug 5, 2004
239
SDL_PrivateResize(w2, h2);
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
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
256
wind_get (message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2);
Nov 6, 2004
Nov 6, 2004
257
GEM_lock_redraw = SDL_TRUE; /* Prevent redraw till buffers resized */
Aug 5, 2004
Aug 5, 2004
258
SDL_PrivateResize(w2, h2);
259
260
261
}
break;
case WM_BOTTOMED:
Jul 7, 2005
Jul 7, 2005
262
263
wind_set(message[3],WF_BOTTOM,0,0,0,0);
/* Continue with BOTTOM event processing */
264
265
case WM_UNTOPPED:
SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
Jun 7, 2005
Jun 7, 2005
266
267
268
if (VDI_setpalette) {
VDI_setpalette(this, VDI_oldpalette);
}
Jul 13, 2007
Jul 13, 2007
269
check_mouse_mode = 1;
270
271
break;
}
Jul 13, 2007
Jul 13, 2007
272
273
274
275
if (check_mouse_mode) {
GEM_CheckMouseMode(this);
}
276
277
278
279
280
281
return quit;
}
static void do_keyboard(short kc, short ks)
{
Sep 13, 2006
Sep 13, 2006
282
int scancode;
283
284
if (kc) {
Sep 13, 2006
Sep 13, 2006
285
scancode=(kc>>8) & (ATARIBIOS_MAXKEYS-1);
286
287
288
289
290
291
292
293
294
295
296
297
298
299
gem_currentkeyboard[scancode]=0xFF;
}
/* 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
300
static void do_mouse(_THIS, short mx, short my, short mb, short ks)
Mar 26, 2002
Mar 26, 2002
302
static short prevmousex=0, prevmousey=0, prevmouseb=0;
Aug 10, 2004
Aug 10, 2004
303
304
short x2, y2, w2, h2;
Jun 3, 2005
Jun 3, 2005
305
306
307
308
309
/* Don't return mouse events if out of window */
if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS)==0) {
return;
}
Aug 10, 2004
Aug 10, 2004
310
311
/* Retrieve window coords, and generate mouse events accordingly */
x2 = y2 = 0;
Aug 10, 2004
Aug 10, 2004
312
313
w2 = VDI_w;
h2 = VDI_h;
Aug 10, 2004
Aug 10, 2004
314
315
316
317
318
319
320
321
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
322
323
/* Mouse motion ? */
Jan 25, 2006
Jan 25, 2006
324
if (GEM_mouse_relative) {
Feb 23, 2006
Feb 23, 2006
325
326
327
328
329
if (GEM_usedevmouse) {
SDL_AtariDevMouse_PostMouseEvents(this, SDL_FALSE);
} else {
SDL_AtariXbios_PostMouseEvents(this, SDL_FALSE);
}
Jan 25, 2006
Jan 25, 2006
330
331
} else {
if ((prevmousex!=mx) || (prevmousey!=my)) {
Aug 10, 2004
Aug 10, 2004
332
333
334
335
int posx, posy;
/* Give mouse position relative to window position */
posx = mx - x2;
Aug 10, 2004
Aug 10, 2004
336
if (posx<0) posx = 0;
Aug 10, 2004
Aug 10, 2004
337
338
if (posx>w2) posx = w2-1;
posy = my - y2;
Aug 10, 2004
Aug 10, 2004
339
if (posy<0) posy = 0;
Aug 10, 2004
Aug 10, 2004
340
341
342
if (posy>h2) posy = h2-1;
SDL_PrivateMouseMotion(0, 0, posx, posy);
343
344
345
346
347
348
349
350
351
}
prevmousex = mx;
prevmousey = my;
}
/* Mouse button ? */
if (prevmouseb!=mb) {
int i;
Jul 9, 2010
Jul 9, 2010
352
for (i=0;i<3;i++) {
353
354
355
356
357
int curbutton, prevbutton;
curbutton = mb & (1<<i);
prevbutton = prevmouseb & (1<<i);
Mar 26, 2002
Mar 26, 2002
358
359
if (curbutton && !prevbutton) {
SDL_PrivateMouseButton(SDL_PRESSED, i+1, 0, 0);
Mar 26, 2002
Mar 26, 2002
361
362
if (!curbutton && prevbutton) {
SDL_PrivateMouseButton(SDL_RELEASED, i+1, 0, 0);
363
364
365
366
}
}
prevmouseb = mb;
}
Mar 26, 2002
Mar 26, 2002
367
368
369
370
371
372
373
374
375
376
/* 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;