This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
/
SDL_gemevents.c
383 lines (335 loc) · 11.6 KB
1
2
/*
SDL - Simple DirectMedia Layer
3
Copyright (C) 1997-2006 Sam Lantinga
4
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
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
13
Lesser General Public License for more details.
14
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
*/
22
#include "SDL_config.h"
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
* 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>
#include "SDL_gemvideo.h"
36
37
#include "SDL_gemevents.h"
#include "../../events/SDL_events_c.h"
38
#include "../ataricommon/SDL_atarikeys.h" /* for keyboard scancodes */
39
40
#include "../ataricommon/SDL_atarievents_c.h"
#include "../ataricommon/SDL_xbiosevents_c.h"
41
#include "../ataricommon/SDL_ataridevmouse_c.h"
42
43
44
45
46
47
48
49
50
51
/* 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);
52
static void do_mouse(_THIS, short mx, short my, short mb, short ks);
53
54
55
/* Functions */
56
57
void
GEM_PumpEvents(_THIS)
58
{
59
#if 0
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
short mousex, mousey, mouseb, dummy;
short kstate, prevkc, prevks;
int i;
SDL_keysym keysym;
SDL_memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard));
prevkc = prevks = 0;
for (;;) {
int quit, resultat, event_mask, mouse_event;
short buffer[8], kc;
short x2, y2, w2, h2;
quit = mouse_event = x2 = y2 = w2 = h2 = 0;
event_mask = MU_MESAG | MU_TIMER | MU_KEYBD;
if (!GEM_fullscreen && (GEM_handle >= 0)) {
wind_get(GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
event_mask |= MU_M1;
79
80
mouse_event = ((SDL_GetAppState() & SDL_APPMOUSEFOCUS) ==
SDL_APPMOUSEFOCUS) ? MO_LEAVE : MO_ENTER;
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
}
resultat = evnt_multi(event_mask,
0, 0, 0,
mouse_event, x2, y2, w2, h2,
0, 0, 0, 0, 0,
buffer,
10,
&dummy, &dummy, &dummy, &kstate, &kc, &dummy);
/* Message event ? */
if (resultat & MU_MESAG)
quit = do_messages(this, buffer);
/* Keyboard event ? */
if (resultat & MU_KEYBD) {
if ((prevkc != kc) || (prevks != kstate)) {
do_keyboard(kc, kstate);
} else {
/* Avoid looping, if repeating same key */
break;
}
}
/* Mouse entering/leaving window */
if (resultat & MU_M1) {
if (this->input_grab == SDL_GRAB_OFF) {
108
109
110
/* Switch mouse focus state */
SDL_PrivateAppActive((mouse_event == MO_ENTER),
SDL_APPMOUSEFOCUS);
111
}
112
GEM_CheckMouseMode(this);
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
}
/* Timer event ? */
if ((resultat & MU_TIMER) || quit)
break;
}
/* Update mouse */
graf_mkstate(&mousex, &mousey, &mouseb, &kstate);
do_mouse(this, mousex, mousey, mouseb, kstate);
/* Now generate keyboard events */
for (i = 0; i < ATARIBIOS_MAXKEYS; i++) {
/* Key pressed ? */
if (gem_currentkeyboard[i] && !gem_previouskeyboard[i])
SDL_PrivateKeyboard(SDL_PRESSED,
129
SDL_Atari_TranslateKey(i, &keysym, SDL_TRUE));
130
131
132
133
/* Key unpressed ? */
if (gem_previouskeyboard[i] && !gem_currentkeyboard[i])
SDL_PrivateKeyboard(SDL_RELEASED,
134
135
SDL_Atari_TranslateKey(i, &keysym,
SDL_FALSE));
136
137
138
139
140
141
142
}
SDL_memcpy(gem_previouskeyboard, gem_currentkeyboard,
sizeof(gem_previouskeyboard));
/* Refresh window name ? */
if (GEM_refresh_name) {
143
144
145
146
147
148
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);
149
150
151
}
GEM_refresh_name = SDL_FALSE;
}
152
#endif
153
154
}
155
156
static int
do_messages(_THIS, short *message)
157
{
158
159
#if 0
int quit, posted, check_mouse_mode;
160
161
short x2, y2, w2, h2;
162
quit = check_mouse_mode = 0;
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
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);
/* Continue with TOP event processing */
case WM_ONTOP:
SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
if (VDI_setpalette) {
VDI_setpalette(this, VDI_curpalette);
}
181
check_mouse_mode = 1;
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
break;
case WM_REDRAW:
if (!GEM_lock_redraw) {
GEM_wind_redraw(this, message[3], &message[4]);
}
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 */
SDL_PrivateAppActive(0, SDL_APPACTIVE);
}
/* 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;
}
205
check_mouse_mode = 1;
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
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);
}
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;
}
222
check_mouse_mode = 1;
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
break;
case WM_SIZED:
wind_set(message[3], WF_CURRXYWH, message[4], message[5],
message[6], message[7]);
wind_get(message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2);
GEM_win_fulled = SDL_FALSE; /* Cancel maximized flag */
GEM_lock_redraw = SDL_TRUE; /* Prevent redraw till buffers resized */
SDL_PrivateResize(w2, h2);
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);
wind_get(message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2);
GEM_lock_redraw = SDL_TRUE; /* Prevent redraw till buffers resized */
SDL_PrivateResize(w2, h2);
}
break;
case WM_BOTTOMED:
wind_set(message[3], WF_BOTTOM, 0, 0, 0, 0);
/* Continue with BOTTOM event processing */
case WM_UNTOPPED:
SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
if (VDI_setpalette) {
VDI_setpalette(this, VDI_oldpalette);
}
260
check_mouse_mode = 1;
261
262
263
break;
}
264
265
266
267
if (check_mouse_mode) {
GEM_CheckMouseMode(this);
}
268
return quit;
269
270
271
#else
return 0;
#endif
272
273
}
274
275
static void
do_keyboard(short kc, short ks)
276
{
277
#if 0
278
279
280
int scancode, asciicode;
if (kc) {
281
282
scancode = (kc >> 8) & (ATARIBIOS_MAXKEYS - 1);
gem_currentkeyboard[scancode] = 0xFF;
283
284
285
286
287
288
289
290
291
292
293
}
/* 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;
294
#endif
295
296
}
297
298
static void
do_mouse(_THIS, short mx, short my, short mb, short ks)
299
{
300
#if 0
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
static short prevmousex = 0, prevmousey = 0, prevmouseb = 0;
short x2, y2, w2, h2;
/* Don't return mouse events if out of window */
if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS) == 0) {
return;
}
/* Retrieve window coords, and generate mouse events accordingly */
x2 = y2 = 0;
w2 = VDI_w;
h2 = VDI_h;
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;
}
}
/* Mouse motion ? */
if (GEM_mouse_relative) {
if (GEM_usedevmouse) {
SDL_AtariDevMouse_PostMouseEvents(this, SDL_FALSE);
} else {
SDL_AtariXbios_PostMouseEvents(this, SDL_FALSE);
}
} else {
if ((prevmousex != mx) || (prevmousey != my)) {
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);
}
prevmousex = mx;
prevmousey = my;
}
/* Mouse button ? */
if (prevmouseb != mb) {
int i;
for (i = 0; i < 2; i++) {
int curbutton, prevbutton;
curbutton = mb & (1 << i);
prevbutton = prevmouseb & (1 << i);
if (curbutton && !prevbutton) {
SDL_PrivateMouseButton(SDL_PRESSED, i + 1, 0, 0);
}
if (!curbutton && prevbutton) {
SDL_PrivateMouseButton(SDL_RELEASED, i + 1, 0, 0);
}
}
prevmouseb = mb;
}
/* 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;
380
#endif
381
}
382
383
/* vi: set ts=4 sw=4 expandtab: */