Skip to content

Latest commit

 

History

History
453 lines (383 loc) · 11.1 KB

SDL_gemevents.c

File metadata and controls

453 lines (383 loc) · 11.1 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
/*
* GEM SDL video driver implementation
* inspired from the Dummy SDL driver
Sep 30, 2017
Sep 30, 2017
27
*
28
29
30
31
32
33
34
* Patrice Mandin
* and work from
* Olivier Landemarre, Johan Klockars, Xavier Joubert, Claude Attard
*/
#include <gem.h>
Aug 2, 2014
Aug 2, 2014
35
#include "SDL_timer.h"
Feb 16, 2006
Feb 16, 2006
36
37
#include "../../events/SDL_sysevents.h"
#include "../../events/SDL_events_c.h"
38
39
#include "SDL_gemvideo.h"
#include "SDL_gemevents_c.h"
Aug 26, 2011
Aug 26, 2011
40
#include "SDL_gemmouse_c.h"
Feb 21, 2006
Feb 21, 2006
41
42
43
#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
44
#include "../ataricommon/SDL_ataridevmouse_c.h"
Aug 2, 2014
Aug 2, 2014
46
47
48
49
/* Duration after which we consider key released */
#define KEY_PRESS_DURATION 100
Sep 11, 2014
Sep 11, 2014
50
51
#define MSG_SDL_ID (('S'<<8)|'D')
52
53
54
55
/* Variables */
static unsigned char gem_currentkeyboard[ATARIBIOS_MAXKEYS];
static unsigned char gem_previouskeyboard[ATARIBIOS_MAXKEYS];
Aug 2, 2014
Aug 2, 2014
56
static Uint32 keyboard_ticks[ATARIBIOS_MAXKEYS];
Nov 4, 2012
Nov 4, 2012
58
static short prevmx=0,prevmy=0,prevmb=0;
Sep 11, 2014
Sep 11, 2014
59
static short dummy_msgbuf[8] = {MSG_SDL_ID,0,0,0, 0,0,0,0};
Nov 4, 2012
Nov 4, 2012
60
61
62
/* Functions prototypes */
Sep 11, 2014
Sep 11, 2014
63
static int do_messages(_THIS, short *message, short latest_msg_id);
Aug 2, 2014
Aug 2, 2014
64
65
static void do_keyboard(short kc, Uint32 tick);
static void do_keyboard_special(short ks, Uint32 tick);
Oct 12, 2012
Oct 12, 2012
66
67
static void do_mouse_motion(_THIS, short mx, short my);
static void do_mouse_buttons(_THIS, short mb);
Oct 12, 2012
Oct 12, 2012
68
static int mouse_in_work_area(int winhandle, short mx, short my);
Aug 2, 2014
Aug 2, 2014
69
static void clearKeyboardState(Uint32 tick);
70
71
72
73
74
/* Functions */
void GEM_InitOSKeymap(_THIS)
{
Feb 7, 2006
Feb 7, 2006
75
76
SDL_memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard));
SDL_memset(gem_previouskeyboard, 0, sizeof(gem_previouskeyboard));
Aug 2, 2014
Aug 2, 2014
77
SDL_memset(keyboard_ticks, 0, sizeof(keyboard_ticks));
78
79
80
/* Mouse init */
GEM_mouse_relative = SDL_FALSE;
Sep 13, 2006
Sep 13, 2006
81
82
SDL_Atari_InitInternalKeymap(this);
83
84
85
86
}
void GEM_PumpEvents(_THIS)
{
Nov 4, 2012
Nov 4, 2012
87
short prevkc=0, mousex, mousey, mouseb, kstate;
Sep 11, 2014
Sep 11, 2014
88
int i, quit = 0;
Nov 4, 2012
Nov 4, 2012
89
SDL_keysym keysym;
Aug 2, 2014
Aug 2, 2014
90
Uint32 cur_tick;
Sep 11, 2014
Sep 11, 2014
91
92
static Uint32 prev_now = 0, prev_msg = 0;
static short latest_msg_id = 0;
Aug 2, 2014
Aug 2, 2014
94
cur_tick = SDL_GetTicks();
Sep 11, 2014
Sep 11, 2014
95
96
97
98
99
100
if (prev_now == cur_tick) {
return;
}
prev_now = cur_tick;
SDL_AtariMint_BackgroundTasks();
Aug 2, 2014
Aug 2, 2014
101
clearKeyboardState(cur_tick);
Jul 9, 2010
Jul 9, 2010
102
Sep 11, 2014
Sep 11, 2014
103
104
105
106
107
108
109
if (prev_msg) {
/* Wait at least 20ms before each event processing loop */
if (cur_tick-prev_msg < 20) {
return;
}
}
prev_msg = cur_tick;
Sep 11, 2014
Sep 11, 2014
111
112
113
114
115
dummy_msgbuf[1] = ++latest_msg_id;
if (appl_write(GEM_ap_id, sizeof(dummy_msgbuf), dummy_msgbuf) == 0) {
/* If it fails, wait for previous id */
--latest_msg_id;
}
Jun 3, 2005
Jun 3, 2005
116
Sep 11, 2014
Sep 11, 2014
117
118
119
while (!quit) {
int resultat;
short buffer[8], kc, dummy;
Jul 28, 2014
Jul 28, 2014
120
121
resultat = evnt_multi(
Nov 4, 2012
Nov 4, 2012
122
123
124
MU_MESAG|MU_TIMER|MU_KEYBD,
0,0,0,
0,0,0,0,0,
Jul 7, 2005
Jul 7, 2005
125
0,0,0,0,0,
126
buffer,
Sep 11, 2014
Sep 11, 2014
127
1000,
Nov 4, 2012
Nov 4, 2012
128
&dummy,&dummy,&dummy,&kstate,&kc,&dummy
129
130
131
132
);
/* Message event ? */
if (resultat & MU_MESAG)
Sep 11, 2014
Sep 11, 2014
133
quit = do_messages(this, buffer, latest_msg_id);
134
135
/* Keyboard event ? */
Mar 26, 2002
Mar 26, 2002
136
if (resultat & MU_KEYBD) {
Aug 2, 2014
Aug 2, 2014
137
do_keyboard_special(kstate, cur_tick);
Oct 12, 2012
Oct 12, 2012
138
if (prevkc != kc) {
Aug 2, 2014
Aug 2, 2014
139
do_keyboard(kc, cur_tick);
Oct 11, 2012
Oct 11, 2012
140
prevkc = kc;
Mar 26, 2002
Mar 26, 2002
141
142
}
}
Sep 11, 2014
Sep 11, 2014
144
145
146
147
/* Timer event ? Just used as a safeguard */
if (resultat & MU_TIMER) {
quit = 1;
}
148
149
}
Sep 11, 2014
Sep 11, 2014
150
151
GEM_CheckMouseMode(this);
Nov 4, 2012
Nov 4, 2012
152
153
/* Update mouse state */
graf_mkstate(&mousex, &mousey, &mouseb, &kstate);
Aug 2, 2014
Aug 2, 2014
154
do_keyboard_special(kstate, cur_tick);
Nov 4, 2012
Nov 4, 2012
155
156
157
do_mouse_motion(this, mousex, mousey);
do_mouse_buttons(this, mouseb);
Mar 26, 2002
Mar 26, 2002
158
/* Now generate keyboard events */
159
160
161
for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
/* Key pressed ? */
if (gem_currentkeyboard[i] && !gem_previouskeyboard[i])
Jan 1, 2006
Jan 1, 2006
162
SDL_PrivateKeyboard(SDL_PRESSED,
Sep 13, 2006
Sep 13, 2006
163
SDL_Atari_TranslateKey(i, &keysym, SDL_TRUE));
Sep 30, 2017
Sep 30, 2017
164
165
166
/* Key unpressed ? */
if (gem_previouskeyboard[i] && !gem_currentkeyboard[i])
Jan 1, 2006
Jan 1, 2006
167
SDL_PrivateKeyboard(SDL_RELEASED,
Sep 13, 2006
Sep 13, 2006
168
SDL_Atari_TranslateKey(i, &keysym, SDL_FALSE));
169
170
}
Feb 7, 2006
Feb 7, 2006
171
SDL_memcpy(gem_previouskeyboard,gem_currentkeyboard,sizeof(gem_previouskeyboard));
Nov 30, 2004
Nov 30, 2004
172
173
174
/* Refresh window name ? */
if (GEM_refresh_name) {
Jul 13, 2007
Jul 13, 2007
175
176
177
178
179
180
181
182
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
183
184
185
}
GEM_refresh_name = SDL_FALSE;
}
Sep 11, 2014
Sep 11, 2014
188
static int do_messages(_THIS, short *message, short latest_msg_id)
Oct 6, 2017
Oct 6, 2017
190
int quit, update_work_area, sdl_resize;
Oct 6, 2017
Oct 6, 2017
192
quit = update_work_area = sdl_resize = 0;
193
switch (message[0]) {
Sep 11, 2014
Sep 11, 2014
194
195
196
case MSG_SDL_ID:
quit=(message[1] == latest_msg_id);
break;
197
case WM_CLOSED:
Sep 30, 2017
Sep 30, 2017
198
case AP_TERM:
Sep 3, 2011
Sep 3, 2011
199
SDL_PrivateQuit();
200
201
202
203
quit=1;
break;
case WM_MOVED:
wind_set(message[3],WF_CURRXYWH,message[4],message[5],message[6],message[7]);
Sep 30, 2017
Sep 30, 2017
204
update_work_area = 1;
205
206
207
break;
case WM_TOPPED:
wind_set(message[3],WF_TOP,message[4],0,0,0);
Jul 7, 2005
Jul 7, 2005
208
209
/* Continue with TOP event processing */
case WM_ONTOP:
210
SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
Oct 12, 2017
Oct 12, 2017
211
VDI_setpalette(this, VDI_curpalette);
212
213
break;
case WM_REDRAW:
Nov 6, 2004
Nov 6, 2004
214
if (!GEM_lock_redraw) {
Oct 7, 2017
Oct 7, 2017
215
GEM_wind_redraw(this, message[3], &message[4], SDL_FALSE);
Nov 6, 2004
Nov 6, 2004
216
}
217
218
219
break;
case WM_ICONIFY:
case WM_ALLICONIFY:
Sep 30, 2017
Sep 30, 2017
220
wind_set (message[3],WF_ICONIFY,message[4],message[5],message[6],message[7]);
221
222
223
/* If we're active, make ourselves inactive */
if ( SDL_GetAppState() & SDL_APPACTIVE ) {
/* Send an internal deactivate event */
Jul 7, 2005
Jul 7, 2005
224
SDL_PrivateAppActive(0, SDL_APPACTIVE);
Nov 12, 2003
Nov 12, 2003
226
227
/* Update window title */
if (GEM_refresh_name && GEM_icon_name) {
Sep 30, 2017
Sep 30, 2017
228
229
230
231
wind_set(GEM_handle,WF_NAME,
(short)(((unsigned long)GEM_icon_name)>>16),
(short)(((unsigned long)GEM_icon_name) & 0xffff),
0,0);
Nov 12, 2003
Nov 12, 2003
232
233
GEM_refresh_name = SDL_FALSE;
}
Oct 6, 2017
Oct 6, 2017
234
235
GEM_iconified = SDL_TRUE;
update_work_area = 1;
236
237
break;
case WM_UNICONIFY:
Sep 30, 2017
Sep 30, 2017
238
wind_set (message[3],WF_UNICONIFY,message[4],message[5],message[6],message[7]);
239
240
241
242
243
/* 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
244
if (GEM_refresh_name && GEM_title_name) {
Sep 30, 2017
Sep 30, 2017
245
246
247
248
wind_set(GEM_handle,WF_NAME,
(short)(((unsigned long)GEM_title_name)>>16),
(short)(((unsigned long)GEM_title_name) & 0xffff),
0,0);
Nov 12, 2003
Nov 12, 2003
249
250
GEM_refresh_name = SDL_FALSE;
}
Oct 6, 2017
Oct 6, 2017
251
GEM_iconified = SDL_FALSE;
Sep 30, 2017
Sep 30, 2017
252
update_work_area = 1;
253
254
255
break;
case WM_SIZED:
wind_set (message[3], WF_CURRXYWH, message[4], message[5], message[6], message[7]);
Sep 30, 2017
Sep 30, 2017
256
update_work_area = sdl_resize = 1;
Nov 6, 2004
Nov 6, 2004
257
258
GEM_win_fulled = SDL_FALSE; /* Cancel maximized flag */
GEM_lock_redraw = SDL_TRUE; /* Prevent redraw till buffers resized */
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
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);
Sep 30, 2017
Sep 30, 2017
275
update_work_area = sdl_resize = 1;
Nov 6, 2004
Nov 6, 2004
276
GEM_lock_redraw = SDL_TRUE; /* Prevent redraw till buffers resized */
277
278
279
}
break;
case WM_BOTTOMED:
Jul 7, 2005
Jul 7, 2005
280
281
wind_set(message[3],WF_BOTTOM,0,0,0,0);
/* Continue with BOTTOM event processing */
282
283
case WM_UNTOPPED:
SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
Oct 12, 2017
Oct 12, 2017
284
VDI_setpalette(this, VDI_oldpalette);
285
286
break;
}
Sep 30, 2017
Sep 30, 2017
287
Sep 30, 2017
Sep 30, 2017
288
if (update_work_area) {
Oct 7, 2017
Oct 7, 2017
289
GEM_align_work_area(this, message[3], SDL_TRUE);
Sep 30, 2017
Sep 30, 2017
290
Sep 30, 2017
Sep 30, 2017
291
292
293
294
295
if (sdl_resize) {
SDL_PrivateResize(GEM_work_w, GEM_work_h);
}
}
296
297
298
return quit;
}
Aug 2, 2014
Aug 2, 2014
299
static void do_keyboard(short kc, Uint32 tick)
Sep 13, 2006
Sep 13, 2006
301
int scancode;
302
303
if (kc) {
Sep 13, 2006
Sep 13, 2006
304
scancode=(kc>>8) & (ATARIBIOS_MAXKEYS-1);
305
gem_currentkeyboard[scancode]=0xFF;
Aug 2, 2014
Aug 2, 2014
306
keyboard_ticks[scancode]=tick;
Oct 12, 2012
Oct 12, 2012
308
}
Aug 2, 2014
Aug 2, 2014
310
static void do_keyboard_special(short ks, Uint32 tick)
Oct 12, 2012
Oct 12, 2012
311
{
Aug 2, 2014
Aug 2, 2014
312
313
int scancode=0;
314
315
/* Read special keys */
if (ks & K_RSHIFT)
Aug 2, 2014
Aug 2, 2014
316
scancode=SCANCODE_RIGHTSHIFT;
317
if (ks & K_LSHIFT)
Aug 2, 2014
Aug 2, 2014
318
scancode=SCANCODE_LEFTSHIFT;
319
if (ks & K_CTRL)
Aug 2, 2014
Aug 2, 2014
320
scancode=SCANCODE_LEFTCONTROL;
321
if (ks & K_ALT)
Aug 2, 2014
Aug 2, 2014
322
323
324
325
326
327
scancode=SCANCODE_LEFTALT;
if (scancode) {
gem_currentkeyboard[scancode]=0xFF;
keyboard_ticks[scancode]=tick;
}
Oct 12, 2012
Oct 12, 2012
330
static void do_mouse_motion(_THIS, short mx, short my)
Aug 10, 2004
Aug 10, 2004
332
333
short x2, y2, w2, h2;
Nov 4, 2012
Nov 4, 2012
334
335
336
337
338
339
340
341
342
343
if (this->input_grab == SDL_GRAB_OFF) {
/* Switch mouse focus state */
if (!GEM_fullscreen && (GEM_handle>=0)) {
SDL_PrivateAppActive(
mouse_in_work_area(GEM_handle, mx,my),
SDL_APPMOUSEFOCUS);
}
}
GEM_CheckMouseMode(this);
Jun 3, 2005
Jun 3, 2005
344
345
346
347
348
/* Don't return mouse events if out of window */
if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS)==0) {
return;
}
Oct 12, 2012
Oct 12, 2012
349
350
351
352
353
354
355
356
357
358
/* Relative mouse motion ? */
if (GEM_mouse_relative) {
if (GEM_usedevmouse) {
SDL_AtariDevMouse_PostMouseEvents(this, SDL_FALSE);
} else {
SDL_AtariXbios_PostMouseEvents(this, SDL_FALSE);
}
return;
}
Aug 10, 2004
Aug 10, 2004
359
360
/* Retrieve window coords, and generate mouse events accordingly */
x2 = y2 = 0;
Aug 10, 2004
Aug 10, 2004
361
362
w2 = VDI_w;
h2 = VDI_h;
Aug 10, 2004
Aug 10, 2004
363
if ((!GEM_fullscreen) && (GEM_handle>=0)) {
Sep 30, 2017
Sep 30, 2017
364
365
366
367
x2 = GEM_work_x;
y2 = GEM_work_y;
w2 = GEM_work_w;
h2 = GEM_work_h;
Aug 10, 2004
Aug 10, 2004
368
}
Mar 26, 2002
Mar 26, 2002
369
Nov 4, 2012
Nov 4, 2012
370
if ((prevmx!=mx) || (prevmy!=my)) {
Oct 12, 2012
Oct 12, 2012
371
372
373
374
375
376
377
378
379
380
381
int posx, posy;
/* Give mouse position relative to window position */
posx = mx - x2;
if (posx<0) posx = 0;
if (posx>w2) posx = w2-1;
posy = my - y2;
if (posy<0) posy = 0;
if (posy>h2) posy = h2-1;
SDL_PrivateMouseMotion(0, 0, posx, posy);
Nov 4, 2012
Nov 4, 2012
383
384
385
prevmx = mx;
prevmy = my;
Oct 12, 2012
Oct 12, 2012
386
}
Oct 12, 2012
Oct 12, 2012
388
389
390
static void do_mouse_buttons(_THIS, short mb)
{
int i;
Oct 12, 2012
Oct 12, 2012
392
393
394
395
/* Don't return mouse events if out of window */
if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS)==0)
return;
Nov 4, 2012
Nov 4, 2012
396
if (prevmb==mb)
Oct 12, 2012
Oct 12, 2012
397
398
399
400
return;
for (i=0;i<3;i++) {
int curbutton, prevbutton;
Sep 30, 2017
Sep 30, 2017
401
Oct 12, 2012
Oct 12, 2012
402
curbutton = mb & (1<<i);
Nov 4, 2012
Nov 4, 2012
403
prevbutton = prevmb & (1<<i);
Sep 30, 2017
Sep 30, 2017
404
Oct 12, 2012
Oct 12, 2012
405
406
407
408
409
if (curbutton && !prevbutton) {
SDL_PrivateMouseButton(SDL_PRESSED, i+1, 0, 0);
}
if (!curbutton && prevbutton) {
SDL_PrivateMouseButton(SDL_RELEASED, i+1, 0, 0);
410
411
}
}
Oct 12, 2012
Oct 12, 2012
412
Nov 4, 2012
Nov 4, 2012
413
prevmb = mb;
Oct 12, 2012
Oct 12, 2012
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
/* Check if mouse in visible area of the window */
static int mouse_in_work_area(int winhandle, short mx, short my)
{
short todo[4];
short inside[4] = {mx,my,1,1};
/* Browse the rectangle list */
if (wind_get(winhandle, WF_FIRSTXYWH, &todo[0], &todo[1], &todo[2], &todo[3])!=0) {
while (todo[2] && todo[3]) {
if (rc_intersect((GRECT *)inside,(GRECT *)todo)) {
return 1;
}
if (wind_get(winhandle, WF_NEXTXYWH, &todo[0], &todo[1], &todo[2], &todo[3])==0) {
break;
}
}
}
return 0;
}
Aug 2, 2014
Aug 2, 2014
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
/* Clear key state for which we did not receive events for a while */
static void clearKeyboardState(Uint32 tick)
{
int i;
for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
if (keyboard_ticks[i]) {
if (tick-keyboard_ticks[i] > KEY_PRESS_DURATION) {
gem_currentkeyboard[i]=0;
keyboard_ticks[i]=0;
}
}
}
}