diff options
author | Franklin Wei <git@fwei.tk> | 2017-01-21 15:18:31 -0500 |
---|---|---|
committer | Franklin Wei <git@fwei.tk> | 2017-12-23 21:01:26 -0500 |
commit | a855d6202536ff28e5aae4f22a0f31d8f5b325d0 (patch) | |
tree | 8c75f224dd64ed360505afa8843d016b0d75000b /apps/plugins/sdl/src/events | |
parent | 01c6dcf6c7b9bb1ad2fa0450f99bacc5f3d3e04b (diff) | |
download | rockbox-a855d6202536ff28e5aae4f22a0f31d8f5b325d0.tar.gz rockbox-a855d6202536ff28e5aae4f22a0f31d8f5b325d0.zip |
Port of Duke Nukem 3D
This ports Fabien Sanglard's Chocolate Duke to run on a version of SDL
for Rockbox.
Change-Id: I8f2c4c78af19de10c1633ed7bb7a997b43256dd9
Diffstat (limited to 'apps/plugins/sdl/src/events')
-rw-r--r-- | apps/plugins/sdl/src/events/SDL_active.c | 95 | ||||
-rw-r--r-- | apps/plugins/sdl/src/events/SDL_events.c | 501 | ||||
-rw-r--r-- | apps/plugins/sdl/src/events/SDL_events_c.h | 83 | ||||
-rw-r--r-- | apps/plugins/sdl/src/events/SDL_expose.c | 51 | ||||
-rw-r--r-- | apps/plugins/sdl/src/events/SDL_keyboard.c | 614 | ||||
-rw-r--r-- | apps/plugins/sdl/src/events/SDL_mouse.c | 268 | ||||
-rw-r--r-- | apps/plugins/sdl/src/events/SDL_quit.c | 124 | ||||
-rw-r--r-- | apps/plugins/sdl/src/events/SDL_resize.c | 71 | ||||
-rw-r--r-- | apps/plugins/sdl/src/events/SDL_sysevents.h | 46 |
9 files changed, 1853 insertions, 0 deletions
diff --git a/apps/plugins/sdl/src/events/SDL_active.c b/apps/plugins/sdl/src/events/SDL_active.c new file mode 100644 index 0000000000..201fb8054f --- /dev/null +++ b/apps/plugins/sdl/src/events/SDL_active.c | |||
@@ -0,0 +1,95 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 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 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | /* Application focus/iconification handling code for SDL */ | ||
25 | |||
26 | #include "SDL_events.h" | ||
27 | #include "SDL_events_c.h" | ||
28 | |||
29 | |||
30 | /* These are static for our active event handling code */ | ||
31 | static Uint8 SDL_appstate = 0; | ||
32 | |||
33 | /* Public functions */ | ||
34 | int SDL_AppActiveInit(void) | ||
35 | { | ||
36 | /* Start completely active */ | ||
37 | SDL_appstate = (SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS); | ||
38 | |||
39 | /* That's it! */ | ||
40 | return(0); | ||
41 | } | ||
42 | void SDL_AppActiveQuit(void) | ||
43 | { | ||
44 | } | ||
45 | |||
46 | Uint8 SDL_GetAppState(void) | ||
47 | { | ||
48 | return(SDL_appstate); | ||
49 | } | ||
50 | |||
51 | /* This is global for SDL_eventloop.c */ | ||
52 | int SDL_PrivateAppActive(Uint8 gain, Uint8 state) | ||
53 | { | ||
54 | int posted; | ||
55 | Uint8 new_state; | ||
56 | |||
57 | /* Modify the current state with the given mask */ | ||
58 | if ( gain ) { | ||
59 | new_state = (SDL_appstate | state); | ||
60 | } else { | ||
61 | new_state = (SDL_appstate & ~state); | ||
62 | } | ||
63 | |||
64 | /* Drop events that don't change state */ | ||
65 | if ( new_state == SDL_appstate ) { | ||
66 | return(0); | ||
67 | } | ||
68 | |||
69 | /* Update internal active state */ | ||
70 | SDL_appstate = new_state; | ||
71 | |||
72 | /* Post the event, if desired */ | ||
73 | posted = 0; | ||
74 | if ( SDL_ProcessEvents[SDL_ACTIVEEVENT] == SDL_ENABLE ) { | ||
75 | SDL_Event event; | ||
76 | SDL_memset(&event, 0, sizeof(event)); | ||
77 | event.type = SDL_ACTIVEEVENT; | ||
78 | event.active.gain = gain; | ||
79 | event.active.state = state; | ||
80 | if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { | ||
81 | posted = 1; | ||
82 | SDL_PushEvent(&event); | ||
83 | } | ||
84 | } | ||
85 | |||
86 | /* If we lost keyboard focus, post key-up events */ | ||
87 | if ( (state & SDL_APPINPUTFOCUS) && !gain ) { | ||
88 | SDL_ResetKeyboard(); | ||
89 | } | ||
90 | /* If we were minimized, post button-up events */ | ||
91 | if ( (state & SDL_APPACTIVE) && !gain ) { | ||
92 | SDL_ResetMouse(); | ||
93 | } | ||
94 | return(posted); | ||
95 | } | ||
diff --git a/apps/plugins/sdl/src/events/SDL_events.c b/apps/plugins/sdl/src/events/SDL_events.c new file mode 100644 index 0000000000..6a146e45ff --- /dev/null +++ b/apps/plugins/sdl/src/events/SDL_events.c | |||
@@ -0,0 +1,501 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 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 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | /* General event handling code for SDL */ | ||
25 | |||
26 | #include "SDL.h" | ||
27 | #include "SDL_syswm.h" | ||
28 | #include "SDL_sysevents.h" | ||
29 | #include "SDL_events_c.h" | ||
30 | #include "../timer/SDL_timer_c.h" | ||
31 | #if !SDL_JOYSTICK_DISABLED | ||
32 | #include "../joystick/SDL_joystick_c.h" | ||
33 | #endif | ||
34 | |||
35 | /* Public data -- the event filter */ | ||
36 | SDL_EventFilter SDL_EventOK = NULL; | ||
37 | Uint8 SDL_ProcessEvents[SDL_NUMEVENTS]; | ||
38 | static Uint32 SDL_eventstate = 0; | ||
39 | |||
40 | /* Private data -- event queue */ | ||
41 | #define MAXEVENTS 128 | ||
42 | static struct { | ||
43 | SDL_mutex *lock; | ||
44 | int active; | ||
45 | int head; | ||
46 | int tail; | ||
47 | SDL_Event event[MAXEVENTS]; | ||
48 | int wmmsg_next; | ||
49 | struct SDL_SysWMmsg wmmsg[MAXEVENTS]; | ||
50 | } SDL_EventQ; | ||
51 | |||
52 | /* Private data -- event locking structure */ | ||
53 | static struct { | ||
54 | SDL_mutex *lock; | ||
55 | int safe; | ||
56 | } SDL_EventLock; | ||
57 | |||
58 | /* Thread functions */ | ||
59 | static SDL_Thread *SDL_EventThread = NULL; /* Thread handle */ | ||
60 | static Uint32 event_thread; /* The event thread id */ | ||
61 | |||
62 | void SDL_Lock_EventThread(void) | ||
63 | { | ||
64 | if ( SDL_EventThread && (SDL_ThreadID() != event_thread) ) { | ||
65 | /* Grab lock and spin until we're sure event thread stopped */ | ||
66 | SDL_mutexP(SDL_EventLock.lock); | ||
67 | while ( ! SDL_EventLock.safe ) { | ||
68 | SDL_Delay(1); | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | void SDL_Unlock_EventThread(void) | ||
73 | { | ||
74 | if ( SDL_EventThread && (SDL_ThreadID() != event_thread) ) { | ||
75 | SDL_mutexV(SDL_EventLock.lock); | ||
76 | } | ||
77 | } | ||
78 | |||
79 | #ifdef __OS2__ | ||
80 | /* | ||
81 | * We'll increase the priority of GobbleEvents thread, so it will process | ||
82 | * events in time for sure! For this, we need the DosSetPriority() API | ||
83 | * from the os2.h include file. | ||
84 | */ | ||
85 | #define INCL_DOSPROCESS | ||
86 | #include <os2.h> | ||
87 | #include <time.h> | ||
88 | #endif | ||
89 | |||
90 | static int SDLCALL SDL_GobbleEvents(void *unused) | ||
91 | { | ||
92 | event_thread = SDL_ThreadID(); | ||
93 | |||
94 | #ifdef __OS2__ | ||
95 | #ifdef USE_DOSSETPRIORITY | ||
96 | /* Increase thread priority, so it will process events in time for sure! */ | ||
97 | DosSetPriority(PRTYS_THREAD, PRTYC_REGULAR, +16, 0); | ||
98 | #endif | ||
99 | #endif | ||
100 | |||
101 | while ( SDL_EventQ.active ) { | ||
102 | SDL_VideoDevice *video = current_video; | ||
103 | SDL_VideoDevice *this = current_video; | ||
104 | |||
105 | /* Get events from the video subsystem */ | ||
106 | if ( video ) { | ||
107 | video->PumpEvents(this); | ||
108 | } | ||
109 | |||
110 | /* Queue pending key-repeat events */ | ||
111 | SDL_CheckKeyRepeat(); | ||
112 | |||
113 | #if !SDL_JOYSTICK_DISABLED | ||
114 | /* Check for joystick state change */ | ||
115 | if ( SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK) ) { | ||
116 | SDL_JoystickUpdate(); | ||
117 | } | ||
118 | #endif | ||
119 | |||
120 | /* Give up the CPU for the rest of our timeslice */ | ||
121 | SDL_EventLock.safe = 1; | ||
122 | if ( SDL_timer_running ) { | ||
123 | SDL_ThreadedTimerCheck(); | ||
124 | } | ||
125 | SDL_Delay(1); | ||
126 | |||
127 | /* Check for event locking. | ||
128 | On the P of the lock mutex, if the lock is held, this thread | ||
129 | will wait until the lock is released before continuing. The | ||
130 | safe flag will be set, meaning that the other thread can go | ||
131 | about it's business. The safe flag is reset before the V, | ||
132 | so as soon as the mutex is free, other threads can see that | ||
133 | it's not safe to interfere with the event thread. | ||
134 | */ | ||
135 | SDL_mutexP(SDL_EventLock.lock); | ||
136 | SDL_EventLock.safe = 0; | ||
137 | SDL_mutexV(SDL_EventLock.lock); | ||
138 | } | ||
139 | SDL_SetTimerThreaded(0); | ||
140 | event_thread = 0; | ||
141 | return(0); | ||
142 | } | ||
143 | |||
144 | static int SDL_StartEventThread(Uint32 flags) | ||
145 | { | ||
146 | /* Reset everything to zero */ | ||
147 | SDL_EventThread = NULL; | ||
148 | SDL_memset(&SDL_EventLock, 0, sizeof(SDL_EventLock)); | ||
149 | |||
150 | /* Create the lock and set ourselves active */ | ||
151 | #if !SDL_THREADS_DISABLED | ||
152 | SDL_EventQ.lock = SDL_CreateMutex(); | ||
153 | if ( SDL_EventQ.lock == NULL ) { | ||
154 | #ifdef __MACOS__ /* MacOS classic you can't multithread, so no lock needed */ | ||
155 | ; | ||
156 | #else | ||
157 | return(-1); | ||
158 | #endif | ||
159 | } | ||
160 | #endif /* !SDL_THREADS_DISABLED */ | ||
161 | SDL_EventQ.active = 1; | ||
162 | |||
163 | if ( (flags&SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD ) { | ||
164 | SDL_EventLock.lock = SDL_CreateMutex(); | ||
165 | if ( SDL_EventLock.lock == NULL ) { | ||
166 | return(-1); | ||
167 | } | ||
168 | SDL_EventLock.safe = 0; | ||
169 | |||
170 | /* The event thread will handle timers too */ | ||
171 | SDL_SetTimerThreaded(2); | ||
172 | #if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC) && !defined(__SYMBIAN32__) | ||
173 | #undef SDL_CreateThread | ||
174 | SDL_EventThread = SDL_CreateThread(SDL_GobbleEvents, NULL, NULL, NULL); | ||
175 | #else | ||
176 | SDL_EventThread = SDL_CreateThread(SDL_GobbleEvents, NULL); | ||
177 | #endif | ||
178 | if ( SDL_EventThread == NULL ) { | ||
179 | return(-1); | ||
180 | } | ||
181 | } else { | ||
182 | event_thread = 0; | ||
183 | } | ||
184 | return(0); | ||
185 | } | ||
186 | |||
187 | static void SDL_StopEventThread(void) | ||
188 | { | ||
189 | SDL_EventQ.active = 0; | ||
190 | if ( SDL_EventThread ) { | ||
191 | SDL_WaitThread(SDL_EventThread, NULL); | ||
192 | SDL_EventThread = NULL; | ||
193 | SDL_DestroyMutex(SDL_EventLock.lock); | ||
194 | SDL_EventLock.lock = NULL; | ||
195 | } | ||
196 | #ifndef IPOD | ||
197 | SDL_DestroyMutex(SDL_EventQ.lock); | ||
198 | SDL_EventQ.lock = NULL; | ||
199 | #endif | ||
200 | } | ||
201 | |||
202 | Uint32 SDL_EventThreadID(void) | ||
203 | { | ||
204 | return(event_thread); | ||
205 | } | ||
206 | |||
207 | /* Public functions */ | ||
208 | |||
209 | void SDL_StopEventLoop(void) | ||
210 | { | ||
211 | /* Halt the event thread, if running */ | ||
212 | SDL_StopEventThread(); | ||
213 | |||
214 | /* Shutdown event handlers */ | ||
215 | SDL_AppActiveQuit(); | ||
216 | SDL_KeyboardQuit(); | ||
217 | SDL_MouseQuit(); | ||
218 | SDL_QuitQuit(); | ||
219 | |||
220 | /* Clean out EventQ */ | ||
221 | SDL_EventQ.head = 0; | ||
222 | SDL_EventQ.tail = 0; | ||
223 | SDL_EventQ.wmmsg_next = 0; | ||
224 | } | ||
225 | |||
226 | /* This function (and associated calls) may be called more than once */ | ||
227 | int SDL_StartEventLoop(Uint32 flags) | ||
228 | { | ||
229 | int retcode; | ||
230 | |||
231 | /* Clean out the event queue */ | ||
232 | SDL_EventThread = NULL; | ||
233 | SDL_EventQ.lock = NULL; | ||
234 | SDL_StopEventLoop(); | ||
235 | |||
236 | /* No filter to start with, process most event types */ | ||
237 | SDL_EventOK = NULL; | ||
238 | SDL_memset(SDL_ProcessEvents,SDL_ENABLE,sizeof(SDL_ProcessEvents)); | ||
239 | SDL_eventstate = ~0; | ||
240 | /* It's not save to call SDL_EventState() yet */ | ||
241 | SDL_eventstate &= ~(0x00000001 << SDL_SYSWMEVENT); | ||
242 | SDL_ProcessEvents[SDL_SYSWMEVENT] = SDL_IGNORE; | ||
243 | |||
244 | /* Initialize event handlers */ | ||
245 | retcode = 0; | ||
246 | retcode += SDL_AppActiveInit(); | ||
247 | retcode += SDL_KeyboardInit(); | ||
248 | retcode += SDL_MouseInit(); | ||
249 | retcode += SDL_QuitInit(); | ||
250 | if ( retcode < 0 ) { | ||
251 | /* We don't expect them to fail, but... */ | ||
252 | return(-1); | ||
253 | } | ||
254 | /* Create the lock and event thread */ | ||
255 | if ( SDL_StartEventThread(flags) < 0 ) { | ||
256 | SDL_StopEventLoop(); | ||
257 | return(-1); | ||
258 | } | ||
259 | return(0); | ||
260 | } | ||
261 | |||
262 | |||
263 | /* Add an event to the event queue -- called with the queue locked */ | ||
264 | static int SDL_AddEvent(SDL_Event *event) | ||
265 | { | ||
266 | int tail, added; | ||
267 | |||
268 | tail = (SDL_EventQ.tail+1)%MAXEVENTS; | ||
269 | if ( tail == SDL_EventQ.head ) { | ||
270 | /* Overflow, drop event */ | ||
271 | added = 0; | ||
272 | } else { | ||
273 | SDL_EventQ.event[SDL_EventQ.tail] = *event; | ||
274 | if (event->type == SDL_SYSWMEVENT) { | ||
275 | /* Note that it's possible to lose an event */ | ||
276 | int next = SDL_EventQ.wmmsg_next; | ||
277 | SDL_EventQ.wmmsg[next] = *event->syswm.msg; | ||
278 | SDL_EventQ.event[SDL_EventQ.tail].syswm.msg = | ||
279 | &SDL_EventQ.wmmsg[next]; | ||
280 | SDL_EventQ.wmmsg_next = (next+1)%MAXEVENTS; | ||
281 | } | ||
282 | SDL_EventQ.tail = tail; | ||
283 | added = 1; | ||
284 | } | ||
285 | return(added); | ||
286 | } | ||
287 | |||
288 | /* Cut an event, and return the next valid spot, or the tail */ | ||
289 | /* -- called with the queue locked */ | ||
290 | static int SDL_CutEvent(int spot) | ||
291 | { | ||
292 | if ( spot == SDL_EventQ.head ) { | ||
293 | SDL_EventQ.head = (SDL_EventQ.head+1)%MAXEVENTS; | ||
294 | return(SDL_EventQ.head); | ||
295 | } else | ||
296 | if ( (spot+1)%MAXEVENTS == SDL_EventQ.tail ) { | ||
297 | SDL_EventQ.tail = spot; | ||
298 | return(SDL_EventQ.tail); | ||
299 | } else | ||
300 | /* We cut the middle -- shift everything over */ | ||
301 | { | ||
302 | int here, next; | ||
303 | |||
304 | /* This can probably be optimized with SDL_memcpy() -- careful! */ | ||
305 | if ( --SDL_EventQ.tail < 0 ) { | ||
306 | SDL_EventQ.tail = MAXEVENTS-1; | ||
307 | } | ||
308 | for ( here=spot; here != SDL_EventQ.tail; here = next ) { | ||
309 | next = (here+1)%MAXEVENTS; | ||
310 | SDL_EventQ.event[here] = SDL_EventQ.event[next]; | ||
311 | } | ||
312 | return(spot); | ||
313 | } | ||
314 | /* NOTREACHED */ | ||
315 | } | ||
316 | |||
317 | /* Lock the event queue, take a peep at it, and unlock it */ | ||
318 | int SDL_PeepEvents(SDL_Event *events, int numevents, SDL_eventaction action, | ||
319 | Uint32 mask) | ||
320 | { | ||
321 | int i, used; | ||
322 | |||
323 | /* Don't look after we've quit */ | ||
324 | if ( ! SDL_EventQ.active ) { | ||
325 | return(-1); | ||
326 | } | ||
327 | /* Lock the event queue */ | ||
328 | used = 0; | ||
329 | if ( SDL_mutexP(SDL_EventQ.lock) == 0 ) { | ||
330 | if ( action == SDL_ADDEVENT ) { | ||
331 | for ( i=0; i<numevents; ++i ) { | ||
332 | used += SDL_AddEvent(&events[i]); | ||
333 | } | ||
334 | } else { | ||
335 | SDL_Event tmpevent; | ||
336 | int spot; | ||
337 | |||
338 | /* If 'events' is NULL, just see if they exist */ | ||
339 | if ( events == NULL ) { | ||
340 | action = SDL_PEEKEVENT; | ||
341 | numevents = 1; | ||
342 | events = &tmpevent; | ||
343 | } | ||
344 | spot = SDL_EventQ.head; | ||
345 | while ((used < numevents)&&(spot != SDL_EventQ.tail)) { | ||
346 | if ( mask & SDL_EVENTMASK(SDL_EventQ.event[spot].type) ) { | ||
347 | events[used++] = SDL_EventQ.event[spot]; | ||
348 | if ( action == SDL_GETEVENT ) { | ||
349 | spot = SDL_CutEvent(spot); | ||
350 | } else { | ||
351 | spot = (spot+1)%MAXEVENTS; | ||
352 | } | ||
353 | } else { | ||
354 | spot = (spot+1)%MAXEVENTS; | ||
355 | } | ||
356 | } | ||
357 | } | ||
358 | SDL_mutexV(SDL_EventQ.lock); | ||
359 | } else { | ||
360 | SDL_SetError("Couldn't lock event queue"); | ||
361 | used = -1; | ||
362 | } | ||
363 | return(used); | ||
364 | } | ||
365 | |||
366 | /* Run the system dependent event loops */ | ||
367 | void SDL_PumpEvents(void) | ||
368 | { | ||
369 | if ( !SDL_EventThread ) { | ||
370 | SDL_VideoDevice *video = current_video; | ||
371 | SDL_VideoDevice *this = current_video; | ||
372 | |||
373 | /* Get events from the video subsystem */ | ||
374 | if ( video ) { | ||
375 | video->PumpEvents(this); | ||
376 | } | ||
377 | |||
378 | /* Queue pending key-repeat events */ | ||
379 | SDL_CheckKeyRepeat(); | ||
380 | |||
381 | #if !SDL_JOYSTICK_DISABLED | ||
382 | /* Check for joystick state change */ | ||
383 | if ( SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK) ) { | ||
384 | SDL_JoystickUpdate(); | ||
385 | } | ||
386 | #endif | ||
387 | } | ||
388 | } | ||
389 | |||
390 | /* Public functions */ | ||
391 | |||
392 | int SDL_PollEvent (SDL_Event *event) | ||
393 | { | ||
394 | SDL_PumpEvents(); | ||
395 | |||
396 | /* We can't return -1, just return 0 (no event) on error */ | ||
397 | if ( SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS) <= 0 ) | ||
398 | return 0; | ||
399 | return 1; | ||
400 | } | ||
401 | |||
402 | int SDL_WaitEvent (SDL_Event *event) | ||
403 | { | ||
404 | while ( 1 ) { | ||
405 | SDL_PumpEvents(); | ||
406 | switch(SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS)) { | ||
407 | case -1: return 0; | ||
408 | case 1: return 1; | ||
409 | case 0: SDL_Delay(10); | ||
410 | } | ||
411 | } | ||
412 | } | ||
413 | |||
414 | int SDL_PushEvent(SDL_Event *event) | ||
415 | { | ||
416 | if ( SDL_PeepEvents(event, 1, SDL_ADDEVENT, 0) <= 0 ) | ||
417 | return -1; | ||
418 | return 0; | ||
419 | } | ||
420 | |||
421 | void SDL_SetEventFilter (SDL_EventFilter filter) | ||
422 | { | ||
423 | SDL_Event bitbucket; | ||
424 | |||
425 | /* Set filter and discard pending events */ | ||
426 | SDL_EventOK = filter; | ||
427 | while ( SDL_PollEvent(&bitbucket) > 0 ) | ||
428 | ; | ||
429 | } | ||
430 | |||
431 | SDL_EventFilter SDL_GetEventFilter(void) | ||
432 | { | ||
433 | return(SDL_EventOK); | ||
434 | } | ||
435 | |||
436 | Uint8 SDL_EventState (Uint8 type, int state) | ||
437 | { | ||
438 | SDL_Event bitbucket; | ||
439 | Uint8 current_state; | ||
440 | |||
441 | /* If SDL_ALLEVENTS was specified... */ | ||
442 | if ( type == 0xFF ) { | ||
443 | current_state = SDL_IGNORE; | ||
444 | for ( type=0; type<SDL_NUMEVENTS; ++type ) { | ||
445 | if ( SDL_ProcessEvents[type] != SDL_IGNORE ) { | ||
446 | current_state = SDL_ENABLE; | ||
447 | } | ||
448 | SDL_ProcessEvents[type] = state; | ||
449 | if ( state == SDL_ENABLE ) { | ||
450 | SDL_eventstate |= (0x00000001 << (type)); | ||
451 | } else { | ||
452 | SDL_eventstate &= ~(0x00000001 << (type)); | ||
453 | } | ||
454 | } | ||
455 | while ( SDL_PollEvent(&bitbucket) > 0 ) | ||
456 | ; | ||
457 | return(current_state); | ||
458 | } | ||
459 | |||
460 | /* Just set the state for one event type */ | ||
461 | current_state = SDL_ProcessEvents[type]; | ||
462 | switch (state) { | ||
463 | case SDL_IGNORE: | ||
464 | case SDL_ENABLE: | ||
465 | /* Set state and discard pending events */ | ||
466 | SDL_ProcessEvents[type] = state; | ||
467 | if ( state == SDL_ENABLE ) { | ||
468 | SDL_eventstate |= (0x00000001 << (type)); | ||
469 | } else { | ||
470 | SDL_eventstate &= ~(0x00000001 << (type)); | ||
471 | } | ||
472 | while ( SDL_PollEvent(&bitbucket) > 0 ) | ||
473 | ; | ||
474 | break; | ||
475 | default: | ||
476 | /* Querying state? */ | ||
477 | break; | ||
478 | } | ||
479 | return(current_state); | ||
480 | } | ||
481 | |||
482 | /* This is a generic event handler. | ||
483 | */ | ||
484 | int SDL_PrivateSysWMEvent(SDL_SysWMmsg *message) | ||
485 | { | ||
486 | int posted; | ||
487 | |||
488 | posted = 0; | ||
489 | if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) { | ||
490 | SDL_Event event; | ||
491 | SDL_memset(&event, 0, sizeof(event)); | ||
492 | event.type = SDL_SYSWMEVENT; | ||
493 | event.syswm.msg = message; | ||
494 | if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { | ||
495 | posted = 1; | ||
496 | SDL_PushEvent(&event); | ||
497 | } | ||
498 | } | ||
499 | /* Update internal event state */ | ||
500 | return(posted); | ||
501 | } | ||
diff --git a/apps/plugins/sdl/src/events/SDL_events_c.h b/apps/plugins/sdl/src/events/SDL_events_c.h new file mode 100644 index 0000000000..4378451507 --- /dev/null +++ b/apps/plugins/sdl/src/events/SDL_events_c.h | |||
@@ -0,0 +1,83 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 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 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | /* Useful functions and variables from SDL_events.c */ | ||
25 | #include "SDL_events.h" | ||
26 | |||
27 | /* Start and stop the event processing loop */ | ||
28 | extern int SDL_StartEventLoop(Uint32 flags); | ||
29 | extern void SDL_StopEventLoop(void); | ||
30 | extern void SDL_QuitInterrupt(void); | ||
31 | |||
32 | extern void SDL_Lock_EventThread(void); | ||
33 | extern void SDL_Unlock_EventThread(void); | ||
34 | extern Uint32 SDL_EventThreadID(void); | ||
35 | |||
36 | /* Event handler init routines */ | ||
37 | extern int SDL_AppActiveInit(void); | ||
38 | extern int SDL_KeyboardInit(void); | ||
39 | extern int SDL_MouseInit(void); | ||
40 | extern int SDL_QuitInit(void); | ||
41 | |||
42 | /* Event handler quit routines */ | ||
43 | extern void SDL_AppActiveQuit(void); | ||
44 | extern void SDL_KeyboardQuit(void); | ||
45 | extern void SDL_MouseQuit(void); | ||
46 | extern void SDL_QuitQuit(void); | ||
47 | |||
48 | /* The event filter function */ | ||
49 | extern SDL_EventFilter SDL_EventOK; | ||
50 | |||
51 | /* The array of event processing states */ | ||
52 | extern Uint8 SDL_ProcessEvents[SDL_NUMEVENTS]; | ||
53 | |||
54 | /* Internal event queueing functions | ||
55 | (from SDL_active.c, SDL_mouse.c, SDL_keyboard.c, SDL_quit.c, SDL_events.c) | ||
56 | */ | ||
57 | extern int SDL_PrivateAppActive(Uint8 gain, Uint8 state); | ||
58 | extern int SDL_PrivateMouseMotion(Uint8 buttonstate, int relative, | ||
59 | Sint16 x, Sint16 y); | ||
60 | extern int SDL_PrivateMouseButton(Uint8 state, Uint8 button,Sint16 x,Sint16 y); | ||
61 | extern int SDL_PrivateKeyboard(Uint8 state, SDL_keysym *key); | ||
62 | extern int SDL_PrivateResize(int w, int h); | ||
63 | extern int SDL_PrivateExpose(void); | ||
64 | extern int SDL_PrivateQuit(void); | ||
65 | extern int SDL_PrivateSysWMEvent(SDL_SysWMmsg *message); | ||
66 | |||
67 | /* Used to clamp the mouse coordinates separately from the video surface */ | ||
68 | extern void SDL_SetMouseRange(int maxX, int maxY); | ||
69 | |||
70 | /* Used by the activity event handler to remove mouse focus */ | ||
71 | extern void SDL_ResetMouse(void); | ||
72 | |||
73 | /* Used by the activity event handler to remove keyboard focus */ | ||
74 | extern void SDL_ResetKeyboard(void); | ||
75 | |||
76 | /* Used by the event loop to queue pending keyboard repeat events */ | ||
77 | extern void SDL_CheckKeyRepeat(void); | ||
78 | |||
79 | /* Used by the OS keyboard code to detect whether or not to do UNICODE */ | ||
80 | #ifndef DEFAULT_UNICODE_TRANSLATION | ||
81 | #define DEFAULT_UNICODE_TRANSLATION 0 /* Default off because of overhead */ | ||
82 | #endif | ||
83 | extern int SDL_TranslateUNICODE; | ||
diff --git a/apps/plugins/sdl/src/events/SDL_expose.c b/apps/plugins/sdl/src/events/SDL_expose.c new file mode 100644 index 0000000000..d5b01436d9 --- /dev/null +++ b/apps/plugins/sdl/src/events/SDL_expose.c | |||
@@ -0,0 +1,51 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 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 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | /* Refresh event handling code for SDL */ | ||
25 | |||
26 | #include "SDL_events.h" | ||
27 | #include "SDL_events_c.h" | ||
28 | |||
29 | |||
30 | /* This is global for SDL_eventloop.c */ | ||
31 | int SDL_PrivateExpose(void) | ||
32 | { | ||
33 | int posted; | ||
34 | SDL_Event events[32]; | ||
35 | |||
36 | /* Pull out all old refresh events */ | ||
37 | SDL_PeepEvents(events, sizeof(events)/sizeof(events[0]), | ||
38 | SDL_GETEVENT, SDL_VIDEOEXPOSEMASK); | ||
39 | |||
40 | /* Post the event, if desired */ | ||
41 | posted = 0; | ||
42 | if ( SDL_ProcessEvents[SDL_VIDEOEXPOSE] == SDL_ENABLE ) { | ||
43 | SDL_Event event; | ||
44 | event.type = SDL_VIDEOEXPOSE; | ||
45 | if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { | ||
46 | posted = 1; | ||
47 | SDL_PushEvent(&event); | ||
48 | } | ||
49 | } | ||
50 | return(posted); | ||
51 | } | ||
diff --git a/apps/plugins/sdl/src/events/SDL_keyboard.c b/apps/plugins/sdl/src/events/SDL_keyboard.c new file mode 100644 index 0000000000..ee5fad5a84 --- /dev/null +++ b/apps/plugins/sdl/src/events/SDL_keyboard.c | |||
@@ -0,0 +1,614 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 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 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | /* General keyboard handling code for SDL */ | ||
25 | |||
26 | #include "SDL_timer.h" | ||
27 | #include "SDL_events.h" | ||
28 | #include "SDL_events_c.h" | ||
29 | #include "SDL_sysevents.h" | ||
30 | |||
31 | |||
32 | /* Global keystate information */ | ||
33 | static Uint8 SDL_KeyState[SDLK_LAST]; | ||
34 | static SDLMod SDL_ModState; | ||
35 | int SDL_TranslateUNICODE = 0; | ||
36 | |||
37 | static const char *keynames[SDLK_LAST]; /* Array of keycode names */ | ||
38 | |||
39 | /* | ||
40 | * jk 991215 - added | ||
41 | */ | ||
42 | struct { | ||
43 | int firsttime; /* if we check against the delay or repeat value */ | ||
44 | int delay; /* the delay before we start repeating */ | ||
45 | int interval; /* the delay between key repeat events */ | ||
46 | Uint32 timestamp; /* the time the first keydown event occurred */ | ||
47 | |||
48 | SDL_Event evt; /* the event we are supposed to repeat */ | ||
49 | } SDL_KeyRepeat; | ||
50 | |||
51 | /* Global no-lock-keys support */ | ||
52 | static Uint8 SDL_NoLockKeys; | ||
53 | |||
54 | #define SDL_NLK_CAPS 0x01 | ||
55 | #define SDL_NLK_NUM 0x02 | ||
56 | |||
57 | /* Public functions */ | ||
58 | int SDL_KeyboardInit(void) | ||
59 | { | ||
60 | const char* env; | ||
61 | SDL_VideoDevice *video = current_video; | ||
62 | SDL_VideoDevice *this = current_video; | ||
63 | |||
64 | /* Set default mode of UNICODE translation */ | ||
65 | SDL_EnableUNICODE(DEFAULT_UNICODE_TRANSLATION); | ||
66 | |||
67 | /* Initialize the tables */ | ||
68 | SDL_ModState = KMOD_NONE; | ||
69 | SDL_memset((void*)keynames, 0, sizeof(keynames)); | ||
70 | SDL_memset(SDL_KeyState, 0, sizeof(SDL_KeyState)); | ||
71 | video->InitOSKeymap(this); | ||
72 | |||
73 | SDL_EnableKeyRepeat(0, 0); | ||
74 | |||
75 | /* Allow environment override to disable special lock-key behavior */ | ||
76 | SDL_NoLockKeys = 0; | ||
77 | env = SDL_getenv("SDL_DISABLE_LOCK_KEYS"); | ||
78 | if (env) { | ||
79 | switch (SDL_atoi(env)) { | ||
80 | case 1: | ||
81 | SDL_NoLockKeys = SDL_NLK_CAPS | SDL_NLK_NUM; | ||
82 | break; | ||
83 | case 2: | ||
84 | SDL_NoLockKeys = SDL_NLK_CAPS; | ||
85 | break; | ||
86 | case 3: | ||
87 | SDL_NoLockKeys = SDL_NLK_NUM; | ||
88 | break; | ||
89 | default: | ||
90 | break; | ||
91 | } | ||
92 | } | ||
93 | |||
94 | /* Fill in the blanks in keynames */ | ||
95 | keynames[SDLK_BACKSPACE] = "backspace"; | ||
96 | keynames[SDLK_TAB] = "tab"; | ||
97 | keynames[SDLK_CLEAR] = "clear"; | ||
98 | keynames[SDLK_RETURN] = "return"; | ||
99 | keynames[SDLK_PAUSE] = "pause"; | ||
100 | keynames[SDLK_ESCAPE] = "escape"; | ||
101 | keynames[SDLK_SPACE] = "space"; | ||
102 | keynames[SDLK_EXCLAIM] = "!"; | ||
103 | keynames[SDLK_QUOTEDBL] = "\""; | ||
104 | keynames[SDLK_HASH] = "#"; | ||
105 | keynames[SDLK_DOLLAR] = "$"; | ||
106 | keynames[SDLK_AMPERSAND] = "&"; | ||
107 | keynames[SDLK_QUOTE] = "'"; | ||
108 | keynames[SDLK_LEFTPAREN] = "("; | ||
109 | keynames[SDLK_RIGHTPAREN] = ")"; | ||
110 | keynames[SDLK_ASTERISK] = "*"; | ||
111 | keynames[SDLK_PLUS] = "+"; | ||
112 | keynames[SDLK_COMMA] = ","; | ||
113 | keynames[SDLK_MINUS] = "-"; | ||
114 | keynames[SDLK_PERIOD] = "."; | ||
115 | keynames[SDLK_SLASH] = "/"; | ||
116 | keynames[SDLK_0] = "0"; | ||
117 | keynames[SDLK_1] = "1"; | ||
118 | keynames[SDLK_2] = "2"; | ||
119 | keynames[SDLK_3] = "3"; | ||
120 | keynames[SDLK_4] = "4"; | ||
121 | keynames[SDLK_5] = "5"; | ||
122 | keynames[SDLK_6] = "6"; | ||
123 | keynames[SDLK_7] = "7"; | ||
124 | keynames[SDLK_8] = "8"; | ||
125 | keynames[SDLK_9] = "9"; | ||
126 | keynames[SDLK_COLON] = ":"; | ||
127 | keynames[SDLK_SEMICOLON] = ";"; | ||
128 | keynames[SDLK_LESS] = "<"; | ||
129 | keynames[SDLK_EQUALS] = "="; | ||
130 | keynames[SDLK_GREATER] = ">"; | ||
131 | keynames[SDLK_QUESTION] = "?"; | ||
132 | keynames[SDLK_AT] = "@"; | ||
133 | keynames[SDLK_LEFTBRACKET] = "["; | ||
134 | keynames[SDLK_BACKSLASH] = "\\"; | ||
135 | keynames[SDLK_RIGHTBRACKET] = "]"; | ||
136 | keynames[SDLK_CARET] = "^"; | ||
137 | keynames[SDLK_UNDERSCORE] = "_"; | ||
138 | keynames[SDLK_BACKQUOTE] = "`"; | ||
139 | keynames[SDLK_a] = "a"; | ||
140 | keynames[SDLK_b] = "b"; | ||
141 | keynames[SDLK_c] = "c"; | ||
142 | keynames[SDLK_d] = "d"; | ||
143 | keynames[SDLK_e] = "e"; | ||
144 | keynames[SDLK_f] = "f"; | ||
145 | keynames[SDLK_g] = "g"; | ||
146 | keynames[SDLK_h] = "h"; | ||
147 | keynames[SDLK_i] = "i"; | ||
148 | keynames[SDLK_j] = "j"; | ||
149 | keynames[SDLK_k] = "k"; | ||
150 | keynames[SDLK_l] = "l"; | ||
151 | keynames[SDLK_m] = "m"; | ||
152 | keynames[SDLK_n] = "n"; | ||
153 | keynames[SDLK_o] = "o"; | ||
154 | keynames[SDLK_p] = "p"; | ||
155 | keynames[SDLK_q] = "q"; | ||
156 | keynames[SDLK_r] = "r"; | ||
157 | keynames[SDLK_s] = "s"; | ||
158 | keynames[SDLK_t] = "t"; | ||
159 | keynames[SDLK_u] = "u"; | ||
160 | keynames[SDLK_v] = "v"; | ||
161 | keynames[SDLK_w] = "w"; | ||
162 | keynames[SDLK_x] = "x"; | ||
163 | keynames[SDLK_y] = "y"; | ||
164 | keynames[SDLK_z] = "z"; | ||
165 | keynames[SDLK_DELETE] = "delete"; | ||
166 | |||
167 | keynames[SDLK_WORLD_0] = "world 0"; | ||
168 | keynames[SDLK_WORLD_1] = "world 1"; | ||
169 | keynames[SDLK_WORLD_2] = "world 2"; | ||
170 | keynames[SDLK_WORLD_3] = "world 3"; | ||
171 | keynames[SDLK_WORLD_4] = "world 4"; | ||
172 | keynames[SDLK_WORLD_5] = "world 5"; | ||
173 | keynames[SDLK_WORLD_6] = "world 6"; | ||
174 | keynames[SDLK_WORLD_7] = "world 7"; | ||
175 | keynames[SDLK_WORLD_8] = "world 8"; | ||
176 | keynames[SDLK_WORLD_9] = "world 9"; | ||
177 | keynames[SDLK_WORLD_10] = "world 10"; | ||
178 | keynames[SDLK_WORLD_11] = "world 11"; | ||
179 | keynames[SDLK_WORLD_12] = "world 12"; | ||
180 | keynames[SDLK_WORLD_13] = "world 13"; | ||
181 | keynames[SDLK_WORLD_14] = "world 14"; | ||
182 | keynames[SDLK_WORLD_15] = "world 15"; | ||
183 | keynames[SDLK_WORLD_16] = "world 16"; | ||
184 | keynames[SDLK_WORLD_17] = "world 17"; | ||
185 | keynames[SDLK_WORLD_18] = "world 18"; | ||
186 | keynames[SDLK_WORLD_19] = "world 19"; | ||
187 | keynames[SDLK_WORLD_20] = "world 20"; | ||
188 | keynames[SDLK_WORLD_21] = "world 21"; | ||
189 | keynames[SDLK_WORLD_22] = "world 22"; | ||
190 | keynames[SDLK_WORLD_23] = "world 23"; | ||
191 | keynames[SDLK_WORLD_24] = "world 24"; | ||
192 | keynames[SDLK_WORLD_25] = "world 25"; | ||
193 | keynames[SDLK_WORLD_26] = "world 26"; | ||
194 | keynames[SDLK_WORLD_27] = "world 27"; | ||
195 | keynames[SDLK_WORLD_28] = "world 28"; | ||
196 | keynames[SDLK_WORLD_29] = "world 29"; | ||
197 | keynames[SDLK_WORLD_30] = "world 30"; | ||
198 | keynames[SDLK_WORLD_31] = "world 31"; | ||
199 | keynames[SDLK_WORLD_32] = "world 32"; | ||
200 | keynames[SDLK_WORLD_33] = "world 33"; | ||
201 | keynames[SDLK_WORLD_34] = "world 34"; | ||
202 | keynames[SDLK_WORLD_35] = "world 35"; | ||
203 | keynames[SDLK_WORLD_36] = "world 36"; | ||
204 | keynames[SDLK_WORLD_37] = "world 37"; | ||
205 | keynames[SDLK_WORLD_38] = "world 38"; | ||
206 | keynames[SDLK_WORLD_39] = "world 39"; | ||
207 | keynames[SDLK_WORLD_40] = "world 40"; | ||
208 | keynames[SDLK_WORLD_41] = "world 41"; | ||
209 | keynames[SDLK_WORLD_42] = "world 42"; | ||
210 | keynames[SDLK_WORLD_43] = "world 43"; | ||
211 | keynames[SDLK_WORLD_44] = "world 44"; | ||
212 | keynames[SDLK_WORLD_45] = "world 45"; | ||
213 | keynames[SDLK_WORLD_46] = "world 46"; | ||
214 | keynames[SDLK_WORLD_47] = "world 47"; | ||
215 | keynames[SDLK_WORLD_48] = "world 48"; | ||
216 | keynames[SDLK_WORLD_49] = "world 49"; | ||
217 | keynames[SDLK_WORLD_50] = "world 50"; | ||
218 | keynames[SDLK_WORLD_51] = "world 51"; | ||
219 | keynames[SDLK_WORLD_52] = "world 52"; | ||
220 | keynames[SDLK_WORLD_53] = "world 53"; | ||
221 | keynames[SDLK_WORLD_54] = "world 54"; | ||
222 | keynames[SDLK_WORLD_55] = "world 55"; | ||
223 | keynames[SDLK_WORLD_56] = "world 56"; | ||
224 | keynames[SDLK_WORLD_57] = "world 57"; | ||
225 | keynames[SDLK_WORLD_58] = "world 58"; | ||
226 | keynames[SDLK_WORLD_59] = "world 59"; | ||
227 | keynames[SDLK_WORLD_60] = "world 60"; | ||
228 | keynames[SDLK_WORLD_61] = "world 61"; | ||
229 | keynames[SDLK_WORLD_62] = "world 62"; | ||
230 | keynames[SDLK_WORLD_63] = "world 63"; | ||
231 | keynames[SDLK_WORLD_64] = "world 64"; | ||
232 | keynames[SDLK_WORLD_65] = "world 65"; | ||
233 | keynames[SDLK_WORLD_66] = "world 66"; | ||
234 | keynames[SDLK_WORLD_67] = "world 67"; | ||
235 | keynames[SDLK_WORLD_68] = "world 68"; | ||
236 | keynames[SDLK_WORLD_69] = "world 69"; | ||
237 | keynames[SDLK_WORLD_70] = "world 70"; | ||
238 | keynames[SDLK_WORLD_71] = "world 71"; | ||
239 | keynames[SDLK_WORLD_72] = "world 72"; | ||
240 | keynames[SDLK_WORLD_73] = "world 73"; | ||
241 | keynames[SDLK_WORLD_74] = "world 74"; | ||
242 | keynames[SDLK_WORLD_75] = "world 75"; | ||
243 | keynames[SDLK_WORLD_76] = "world 76"; | ||
244 | keynames[SDLK_WORLD_77] = "world 77"; | ||
245 | keynames[SDLK_WORLD_78] = "world 78"; | ||
246 | keynames[SDLK_WORLD_79] = "world 79"; | ||
247 | keynames[SDLK_WORLD_80] = "world 80"; | ||
248 | keynames[SDLK_WORLD_81] = "world 81"; | ||
249 | keynames[SDLK_WORLD_82] = "world 82"; | ||
250 | keynames[SDLK_WORLD_83] = "world 83"; | ||
251 | keynames[SDLK_WORLD_84] = "world 84"; | ||
252 | keynames[SDLK_WORLD_85] = "world 85"; | ||
253 | keynames[SDLK_WORLD_86] = "world 86"; | ||
254 | keynames[SDLK_WORLD_87] = "world 87"; | ||
255 | keynames[SDLK_WORLD_88] = "world 88"; | ||
256 | keynames[SDLK_WORLD_89] = "world 89"; | ||
257 | keynames[SDLK_WORLD_90] = "world 90"; | ||
258 | keynames[SDLK_WORLD_91] = "world 91"; | ||
259 | keynames[SDLK_WORLD_92] = "world 92"; | ||
260 | keynames[SDLK_WORLD_93] = "world 93"; | ||
261 | keynames[SDLK_WORLD_94] = "world 94"; | ||
262 | keynames[SDLK_WORLD_95] = "world 95"; | ||
263 | |||
264 | keynames[SDLK_KP0] = "[0]"; | ||
265 | keynames[SDLK_KP1] = "[1]"; | ||
266 | keynames[SDLK_KP2] = "[2]"; | ||
267 | keynames[SDLK_KP3] = "[3]"; | ||
268 | keynames[SDLK_KP4] = "[4]"; | ||
269 | keynames[SDLK_KP5] = "[5]"; | ||
270 | keynames[SDLK_KP6] = "[6]"; | ||
271 | keynames[SDLK_KP7] = "[7]"; | ||
272 | keynames[SDLK_KP8] = "[8]"; | ||
273 | keynames[SDLK_KP9] = "[9]"; | ||
274 | keynames[SDLK_KP_PERIOD] = "[.]"; | ||
275 | keynames[SDLK_KP_DIVIDE] = "[/]"; | ||
276 | keynames[SDLK_KP_MULTIPLY] = "[*]"; | ||
277 | keynames[SDLK_KP_MINUS] = "[-]"; | ||
278 | keynames[SDLK_KP_PLUS] = "[+]"; | ||
279 | keynames[SDLK_KP_ENTER] = "enter"; | ||
280 | keynames[SDLK_KP_EQUALS] = "equals"; | ||
281 | |||
282 | keynames[SDLK_UP] = "up"; | ||
283 | keynames[SDLK_DOWN] = "down"; | ||
284 | keynames[SDLK_RIGHT] = "right"; | ||
285 | keynames[SDLK_LEFT] = "left"; | ||
286 | keynames[SDLK_DOWN] = "down"; | ||
287 | keynames[SDLK_INSERT] = "insert"; | ||
288 | keynames[SDLK_HOME] = "home"; | ||
289 | keynames[SDLK_END] = "end"; | ||
290 | keynames[SDLK_PAGEUP] = "page up"; | ||
291 | keynames[SDLK_PAGEDOWN] = "page down"; | ||
292 | |||
293 | keynames[SDLK_F1] = "f1"; | ||
294 | keynames[SDLK_F2] = "f2"; | ||
295 | keynames[SDLK_F3] = "f3"; | ||
296 | keynames[SDLK_F4] = "f4"; | ||
297 | keynames[SDLK_F5] = "f5"; | ||
298 | keynames[SDLK_F6] = "f6"; | ||
299 | keynames[SDLK_F7] = "f7"; | ||
300 | keynames[SDLK_F8] = "f8"; | ||
301 | keynames[SDLK_F9] = "f9"; | ||
302 | keynames[SDLK_F10] = "f10"; | ||
303 | keynames[SDLK_F11] = "f11"; | ||
304 | keynames[SDLK_F12] = "f12"; | ||
305 | keynames[SDLK_F13] = "f13"; | ||
306 | keynames[SDLK_F14] = "f14"; | ||
307 | keynames[SDLK_F15] = "f15"; | ||
308 | |||
309 | keynames[SDLK_NUMLOCK] = "numlock"; | ||
310 | keynames[SDLK_CAPSLOCK] = "caps lock"; | ||
311 | keynames[SDLK_SCROLLOCK] = "scroll lock"; | ||
312 | keynames[SDLK_RSHIFT] = "right shift"; | ||
313 | keynames[SDLK_LSHIFT] = "left shift"; | ||
314 | keynames[SDLK_RCTRL] = "right ctrl"; | ||
315 | keynames[SDLK_LCTRL] = "left ctrl"; | ||
316 | keynames[SDLK_RALT] = "right alt"; | ||
317 | keynames[SDLK_LALT] = "left alt"; | ||
318 | keynames[SDLK_RMETA] = "right meta"; | ||
319 | keynames[SDLK_LMETA] = "left meta"; | ||
320 | keynames[SDLK_LSUPER] = "left super"; /* "Windows" keys */ | ||
321 | keynames[SDLK_RSUPER] = "right super"; | ||
322 | keynames[SDLK_MODE] = "alt gr"; | ||
323 | keynames[SDLK_COMPOSE] = "compose"; | ||
324 | |||
325 | keynames[SDLK_HELP] = "help"; | ||
326 | keynames[SDLK_PRINT] = "print screen"; | ||
327 | keynames[SDLK_SYSREQ] = "sys req"; | ||
328 | keynames[SDLK_BREAK] = "break"; | ||
329 | keynames[SDLK_MENU] = "menu"; | ||
330 | keynames[SDLK_POWER] = "power"; | ||
331 | keynames[SDLK_EURO] = "euro"; | ||
332 | keynames[SDLK_UNDO] = "undo"; | ||
333 | |||
334 | /* Done. Whew. */ | ||
335 | return(0); | ||
336 | } | ||
337 | void SDL_KeyboardQuit(void) | ||
338 | { | ||
339 | } | ||
340 | |||
341 | /* We lost the keyboard, so post key up messages for all pressed keys */ | ||
342 | void SDL_ResetKeyboard(void) | ||
343 | { | ||
344 | SDL_keysym keysym; | ||
345 | SDLKey key; | ||
346 | |||
347 | SDL_memset(&keysym, 0, (sizeof keysym)); | ||
348 | for ( key=SDLK_FIRST; key<SDLK_LAST; ++key ) { | ||
349 | if ( SDL_KeyState[key] == SDL_PRESSED ) { | ||
350 | keysym.sym = key; | ||
351 | SDL_PrivateKeyboard(SDL_RELEASED, &keysym); | ||
352 | } | ||
353 | } | ||
354 | SDL_KeyRepeat.timestamp = 0; | ||
355 | } | ||
356 | |||
357 | int SDL_EnableUNICODE(int enable) | ||
358 | { | ||
359 | int old_mode; | ||
360 | |||
361 | old_mode = SDL_TranslateUNICODE; | ||
362 | if ( enable >= 0 ) { | ||
363 | SDL_TranslateUNICODE = enable; | ||
364 | } | ||
365 | return(old_mode); | ||
366 | } | ||
367 | |||
368 | Uint8 * SDL_GetKeyState (int *numkeys) | ||
369 | { | ||
370 | if ( numkeys != (int *)0 ) | ||
371 | *numkeys = SDLK_LAST; | ||
372 | return(SDL_KeyState); | ||
373 | } | ||
374 | SDLMod SDL_GetModState (void) | ||
375 | { | ||
376 | return(SDL_ModState); | ||
377 | } | ||
378 | void SDL_SetModState (SDLMod modstate) | ||
379 | { | ||
380 | SDL_ModState = modstate; | ||
381 | } | ||
382 | |||
383 | char *SDL_GetKeyName(SDLKey key) | ||
384 | { | ||
385 | const char *keyname; | ||
386 | |||
387 | keyname = NULL; | ||
388 | if ( key < SDLK_LAST ) { | ||
389 | keyname = keynames[key]; | ||
390 | } | ||
391 | if ( keyname == NULL ) { | ||
392 | keyname = "unknown key"; | ||
393 | } | ||
394 | /* FIXME: make this function const in 1.3 */ | ||
395 | return (char *)(keyname); | ||
396 | } | ||
397 | |||
398 | /* These are global for SDL_eventloop.c */ | ||
399 | int SDL_PrivateKeyboard(Uint8 state, SDL_keysym *keysym) | ||
400 | { | ||
401 | SDL_Event event; | ||
402 | int posted, repeatable; | ||
403 | Uint16 modstate; | ||
404 | |||
405 | SDL_memset(&event, 0, sizeof(event)); | ||
406 | |||
407 | #if 0 | ||
408 | printf("The '%s' key has been %s\n", SDL_GetKeyName(keysym->sym), | ||
409 | state == SDL_PRESSED ? "pressed" : "released"); | ||
410 | #endif | ||
411 | /* Set up the keysym */ | ||
412 | modstate = (Uint16)SDL_ModState; | ||
413 | |||
414 | repeatable = 0; | ||
415 | |||
416 | if ( state == SDL_PRESSED ) { | ||
417 | keysym->mod = (SDLMod)modstate; | ||
418 | switch (keysym->sym) { | ||
419 | case SDLK_UNKNOWN: | ||
420 | break; | ||
421 | case SDLK_NUMLOCK: | ||
422 | modstate ^= KMOD_NUM; | ||
423 | if ( SDL_NoLockKeys & SDL_NLK_NUM ) | ||
424 | break; | ||
425 | if ( ! (modstate&KMOD_NUM) ) | ||
426 | state = SDL_RELEASED; | ||
427 | keysym->mod = (SDLMod)modstate; | ||
428 | break; | ||
429 | case SDLK_CAPSLOCK: | ||
430 | modstate ^= KMOD_CAPS; | ||
431 | if ( SDL_NoLockKeys & SDL_NLK_CAPS ) | ||
432 | break; | ||
433 | if ( ! (modstate&KMOD_CAPS) ) | ||
434 | state = SDL_RELEASED; | ||
435 | keysym->mod = (SDLMod)modstate; | ||
436 | break; | ||
437 | case SDLK_LCTRL: | ||
438 | modstate |= KMOD_LCTRL; | ||
439 | break; | ||
440 | case SDLK_RCTRL: | ||
441 | modstate |= KMOD_RCTRL; | ||
442 | break; | ||
443 | case SDLK_LSHIFT: | ||
444 | modstate |= KMOD_LSHIFT; | ||
445 | break; | ||
446 | case SDLK_RSHIFT: | ||
447 | modstate |= KMOD_RSHIFT; | ||
448 | break; | ||
449 | case SDLK_LALT: | ||
450 | modstate |= KMOD_LALT; | ||
451 | break; | ||
452 | case SDLK_RALT: | ||
453 | modstate |= KMOD_RALT; | ||
454 | break; | ||
455 | case SDLK_LMETA: | ||
456 | modstate |= KMOD_LMETA; | ||
457 | break; | ||
458 | case SDLK_RMETA: | ||
459 | modstate |= KMOD_RMETA; | ||
460 | break; | ||
461 | case SDLK_MODE: | ||
462 | modstate |= KMOD_MODE; | ||
463 | break; | ||
464 | default: | ||
465 | repeatable = 1; | ||
466 | break; | ||
467 | } | ||
468 | } else { | ||
469 | switch (keysym->sym) { | ||
470 | case SDLK_UNKNOWN: | ||
471 | break; | ||
472 | case SDLK_NUMLOCK: | ||
473 | if ( SDL_NoLockKeys & SDL_NLK_NUM ) | ||
474 | break; | ||
475 | /* Only send keydown events */ | ||
476 | return(0); | ||
477 | case SDLK_CAPSLOCK: | ||
478 | if ( SDL_NoLockKeys & SDL_NLK_CAPS ) | ||
479 | break; | ||
480 | /* Only send keydown events */ | ||
481 | return(0); | ||
482 | case SDLK_LCTRL: | ||
483 | modstate &= ~KMOD_LCTRL; | ||
484 | break; | ||
485 | case SDLK_RCTRL: | ||
486 | modstate &= ~KMOD_RCTRL; | ||
487 | break; | ||
488 | case SDLK_LSHIFT: | ||
489 | modstate &= ~KMOD_LSHIFT; | ||
490 | break; | ||
491 | case SDLK_RSHIFT: | ||
492 | modstate &= ~KMOD_RSHIFT; | ||
493 | break; | ||
494 | case SDLK_LALT: | ||
495 | modstate &= ~KMOD_LALT; | ||
496 | break; | ||
497 | case SDLK_RALT: | ||
498 | modstate &= ~KMOD_RALT; | ||
499 | break; | ||
500 | case SDLK_LMETA: | ||
501 | modstate &= ~KMOD_LMETA; | ||
502 | break; | ||
503 | case SDLK_RMETA: | ||
504 | modstate &= ~KMOD_RMETA; | ||
505 | break; | ||
506 | case SDLK_MODE: | ||
507 | modstate &= ~KMOD_MODE; | ||
508 | break; | ||
509 | default: | ||
510 | break; | ||
511 | } | ||
512 | keysym->mod = (SDLMod)modstate; | ||
513 | } | ||
514 | |||
515 | /* Figure out what type of event this is */ | ||
516 | switch (state) { | ||
517 | case SDL_PRESSED: | ||
518 | event.type = SDL_KEYDOWN; | ||
519 | break; | ||
520 | case SDL_RELEASED: | ||
521 | event.type = SDL_KEYUP; | ||
522 | /* | ||
523 | * jk 991215 - Added | ||
524 | */ | ||
525 | if ( SDL_KeyRepeat.timestamp && | ||
526 | SDL_KeyRepeat.evt.key.keysym.sym == keysym->sym ) { | ||
527 | SDL_KeyRepeat.timestamp = 0; | ||
528 | } | ||
529 | break; | ||
530 | default: | ||
531 | /* Invalid state -- bail */ | ||
532 | return(0); | ||
533 | } | ||
534 | |||
535 | if ( keysym->sym != SDLK_UNKNOWN ) { | ||
536 | /* Drop events that don't change state */ | ||
537 | if ( SDL_KeyState[keysym->sym] == state ) { | ||
538 | #if 0 | ||
539 | printf("Keyboard event didn't change state - dropped!\n"); | ||
540 | #endif | ||
541 | return(0); | ||
542 | } | ||
543 | |||
544 | /* Update internal keyboard state */ | ||
545 | SDL_ModState = (SDLMod)modstate; | ||
546 | SDL_KeyState[keysym->sym] = state; | ||
547 | } | ||
548 | |||
549 | /* Post the event, if desired */ | ||
550 | posted = 0; | ||
551 | if ( SDL_ProcessEvents[event.type] == SDL_ENABLE ) { | ||
552 | event.key.state = state; | ||
553 | event.key.keysym = *keysym; | ||
554 | /* | ||
555 | * jk 991215 - Added | ||
556 | */ | ||
557 | if (repeatable && (SDL_KeyRepeat.delay != 0)) { | ||
558 | SDL_KeyRepeat.evt = event; | ||
559 | SDL_KeyRepeat.firsttime = 1; | ||
560 | SDL_KeyRepeat.timestamp=SDL_GetTicks(); | ||
561 | } | ||
562 | if ( (SDL_EventOK == NULL) || SDL_EventOK(&event) ) { | ||
563 | posted = 1; | ||
564 | SDL_PushEvent(&event); | ||
565 | } | ||
566 | } | ||
567 | return(posted); | ||
568 | } | ||
569 | |||
570 | /* | ||
571 | * jk 991215 - Added | ||
572 | */ | ||
573 | void SDL_CheckKeyRepeat(void) | ||
574 | { | ||
575 | if ( SDL_KeyRepeat.timestamp ) { | ||
576 | Uint32 now, interval; | ||
577 | |||
578 | now = SDL_GetTicks(); | ||
579 | interval = (now - SDL_KeyRepeat.timestamp); | ||
580 | if ( SDL_KeyRepeat.firsttime ) { | ||
581 | if ( interval > (Uint32)SDL_KeyRepeat.delay ) { | ||
582 | SDL_KeyRepeat.timestamp = now; | ||
583 | SDL_KeyRepeat.firsttime = 0; | ||
584 | } | ||
585 | } else { | ||
586 | if ( interval > (Uint32)SDL_KeyRepeat.interval ) { | ||
587 | SDL_KeyRepeat.timestamp = now; | ||
588 | if ( (SDL_EventOK == NULL) || SDL_EventOK(&SDL_KeyRepeat.evt) ) { | ||
589 | SDL_PushEvent(&SDL_KeyRepeat.evt); | ||
590 | } | ||
591 | } | ||
592 | } | ||
593 | } | ||
594 | } | ||
595 | |||
596 | int SDL_EnableKeyRepeat(int delay, int interval) | ||
597 | { | ||
598 | if ( (delay < 0) || (interval < 0) ) { | ||
599 | SDL_SetError("keyboard repeat value less than zero"); | ||
600 | return(-1); | ||
601 | } | ||
602 | SDL_KeyRepeat.firsttime = 0; | ||
603 | SDL_KeyRepeat.delay = delay; | ||
604 | SDL_KeyRepeat.interval = interval; | ||
605 | SDL_KeyRepeat.timestamp = 0; | ||
606 | return(0); | ||
607 | } | ||
608 | |||
609 | void SDL_GetKeyRepeat(int *delay, int *interval) | ||
610 | { | ||
611 | *delay = SDL_KeyRepeat.delay; | ||
612 | *interval = SDL_KeyRepeat.interval; | ||
613 | } | ||
614 | |||
diff --git a/apps/plugins/sdl/src/events/SDL_mouse.c b/apps/plugins/sdl/src/events/SDL_mouse.c new file mode 100644 index 0000000000..e37a4c6af3 --- /dev/null +++ b/apps/plugins/sdl/src/events/SDL_mouse.c | |||
@@ -0,0 +1,268 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 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 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | /* General mouse handling code for SDL */ | ||
25 | |||
26 | #include "SDL_events.h" | ||
27 | #include "SDL_events_c.h" | ||
28 | #include "../video/SDL_cursor_c.h" | ||
29 | #include "../video/SDL_sysvideo.h" | ||
30 | |||
31 | |||
32 | /* These are static for our mouse handling code */ | ||
33 | static Sint16 SDL_MouseX = 0; | ||
34 | static Sint16 SDL_MouseY = 0; | ||
35 | static Sint16 SDL_DeltaX = 0; | ||
36 | static Sint16 SDL_DeltaY = 0; | ||
37 | static Sint16 SDL_MouseMaxX = 0; | ||
38 | static Sint16 SDL_MouseMaxY = 0; | ||
39 | static Uint8 SDL_ButtonState = 0; | ||
40 | |||
41 | |||
42 | /* Public functions */ | ||
43 | int SDL_MouseInit(void) | ||
44 | { | ||
45 | /* The mouse is at (0,0) */ | ||
46 | SDL_MouseX = 0; | ||
47 | SDL_MouseY = 0; | ||
48 | SDL_DeltaX = 0; | ||
49 | SDL_DeltaY = 0; | ||
50 | SDL_MouseMaxX = 0; | ||
51 | SDL_MouseMaxY = 0; | ||
52 | SDL_ButtonState = 0; | ||
53 | |||
54 | /* That's it! */ | ||
55 | return(0); | ||
56 | } | ||
57 | void SDL_MouseQuit(void) | ||
58 | { | ||
59 | } | ||
60 | |||
61 | /* We lost the mouse, so post button up messages for all pressed buttons */ | ||
62 | void SDL_ResetMouse(void) | ||
63 | { | ||
64 | Uint8 i; | ||
65 | for ( i = 0; i < sizeof(SDL_ButtonState)*8; ++i ) { | ||
66 | if ( SDL_ButtonState & SDL_BUTTON(i) ) { | ||
67 | SDL_PrivateMouseButton(SDL_RELEASED, i, 0, 0); | ||
68 | } | ||
69 | } | ||
70 | } | ||
71 | |||
72 | Uint8 SDL_GetMouseState (int *x, int *y) | ||
73 | { | ||
74 | if ( x ) { | ||
75 | *x = SDL_MouseX; | ||
76 | } | ||
77 | if ( y ) { | ||
78 | *y = SDL_MouseY; | ||
79 | } | ||
80 | return(SDL_ButtonState); | ||
81 | } | ||
82 | |||
83 | Uint8 SDL_GetRelativeMouseState (int *x, int *y) | ||
84 | { | ||
85 | if ( x ) | ||
86 | *x = SDL_DeltaX; | ||
87 | if ( y ) | ||
88 | *y = SDL_DeltaY; | ||
89 | SDL_DeltaX = 0; | ||
90 | SDL_DeltaY = 0; | ||
91 | return(SDL_ButtonState); | ||
92 | } | ||
93 | |||
94 | static void ClipOffset(Sint16 *x, Sint16 *y) | ||
95 | { | ||
96 | /* This clips absolute mouse coordinates when the apparent | ||
97 | display surface is smaller than the real display surface. | ||
98 | */ | ||
99 | if ( SDL_VideoSurface && SDL_VideoSurface->offset ) { | ||
100 | *y -= SDL_VideoSurface->offset/SDL_VideoSurface->pitch; | ||
101 | *x -= (SDL_VideoSurface->offset%SDL_VideoSurface->pitch)/ | ||
102 | SDL_VideoSurface->format->BytesPerPixel; | ||
103 | } | ||
104 | } | ||
105 | |||
106 | void SDL_SetMouseRange(int maxX, int maxY) | ||
107 | { | ||
108 | SDL_MouseMaxX = (Sint16)maxX; | ||
109 | SDL_MouseMaxY = (Sint16)maxY; | ||
110 | } | ||
111 | |||
112 | /* These are global for SDL_eventloop.c */ | ||
113 | int SDL_PrivateMouseMotion(Uint8 buttonstate, int relative, Sint16 x, Sint16 y) | ||
114 | { | ||
115 | int posted; | ||
116 | Uint16 X, Y; | ||
117 | Sint16 Xrel; | ||
118 | Sint16 Yrel; | ||
119 | |||
120 | /* Default buttonstate is the current one */ | ||
121 | if ( ! buttonstate ) { | ||
122 | buttonstate = SDL_ButtonState; | ||
123 | } | ||
124 | |||
125 | Xrel = x; | ||
126 | Yrel = y; | ||
127 | if ( relative ) { | ||
128 | /* Push the cursor around */ | ||
129 | x = (SDL_MouseX+x); | ||
130 | y = (SDL_MouseY+y); | ||
131 | } else { | ||
132 | /* Do we need to clip {x,y} ? */ | ||
133 | ClipOffset(&x, &y); | ||
134 | } | ||
135 | |||
136 | /* Mouse coordinates range from 0 - width-1 and 0 - height-1 */ | ||
137 | if ( x < 0 ) | ||
138 | X = 0; | ||
139 | else | ||
140 | if ( x >= SDL_MouseMaxX ) | ||
141 | X = SDL_MouseMaxX-1; | ||
142 | else | ||
143 | X = (Uint16)x; | ||
144 | |||
145 | if ( y < 0 ) | ||
146 | Y = 0; | ||
147 | else | ||
148 | if ( y >= SDL_MouseMaxY ) | ||
149 | Y = SDL_MouseMaxY-1; | ||
150 | else | ||
151 | Y = (Uint16)y; | ||
152 | |||
153 | /* If not relative mode, generate relative motion from clamped X/Y. | ||
154 | This prevents lots of extraneous large delta relative motion when | ||
155 | the screen is windowed mode and the mouse is outside the window. | ||
156 | */ | ||
157 | if ( ! relative ) { | ||
158 | Xrel = X-SDL_MouseX; | ||
159 | Yrel = Y-SDL_MouseY; | ||
160 | } | ||
161 | |||
162 | /* Drop events that don't change state */ | ||
163 | if ( ! Xrel && ! Yrel ) { | ||
164 | #if 0 | ||
165 | printf("Mouse event didn't change state - dropped!\n"); | ||
166 | #endif | ||
167 | return(0); | ||
168 | } | ||
169 | |||
170 | /* Update internal mouse state */ | ||
171 | SDL_ButtonState = buttonstate; | ||
172 | SDL_MouseX = X; | ||
173 | SDL_MouseY = Y; | ||
174 | SDL_DeltaX += Xrel; | ||
175 | SDL_DeltaY += Yrel; | ||
176 | SDL_MoveCursor(SDL_MouseX, SDL_MouseY); | ||
177 | |||
178 | /* Post the event, if desired */ | ||
179 | posted = 0; | ||
180 | if ( SDL_ProcessEvents[SDL_MOUSEMOTION] == SDL_ENABLE ) { | ||
181 | SDL_Event event; | ||
182 | SDL_memset(&event, 0, sizeof(event)); | ||
183 | event.type = SDL_MOUSEMOTION; | ||
184 | event.motion.state = buttonstate; | ||
185 | event.motion.x = X; | ||
186 | event.motion.y = Y; | ||
187 | event.motion.xrel = Xrel; | ||
188 | event.motion.yrel = Yrel; | ||
189 | if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { | ||
190 | posted = 1; | ||
191 | SDL_PushEvent(&event); | ||
192 | } | ||
193 | } | ||
194 | return(posted); | ||
195 | } | ||
196 | |||
197 | int SDL_PrivateMouseButton(Uint8 state, Uint8 button, Sint16 x, Sint16 y) | ||
198 | { | ||
199 | SDL_Event event; | ||
200 | int posted; | ||
201 | int move_mouse; | ||
202 | Uint8 buttonstate; | ||
203 | |||
204 | SDL_memset(&event, 0, sizeof(event)); | ||
205 | |||
206 | /* Check parameters */ | ||
207 | if ( x || y ) { | ||
208 | ClipOffset(&x, &y); | ||
209 | move_mouse = 1; | ||
210 | /* Mouse coordinates range from 0 - width-1 and 0 - height-1 */ | ||
211 | if ( x < 0 ) | ||
212 | x = 0; | ||
213 | else | ||
214 | if ( x >= SDL_MouseMaxX ) | ||
215 | x = SDL_MouseMaxX-1; | ||
216 | |||
217 | if ( y < 0 ) | ||
218 | y = 0; | ||
219 | else | ||
220 | if ( y >= SDL_MouseMaxY ) | ||
221 | y = SDL_MouseMaxY-1; | ||
222 | } else { | ||
223 | move_mouse = 0; | ||
224 | } | ||
225 | if ( ! x ) | ||
226 | x = SDL_MouseX; | ||
227 | if ( ! y ) | ||
228 | y = SDL_MouseY; | ||
229 | |||
230 | /* Figure out which event to perform */ | ||
231 | buttonstate = SDL_ButtonState; | ||
232 | switch ( state ) { | ||
233 | case SDL_PRESSED: | ||
234 | event.type = SDL_MOUSEBUTTONDOWN; | ||
235 | buttonstate |= SDL_BUTTON(button); | ||
236 | break; | ||
237 | case SDL_RELEASED: | ||
238 | event.type = SDL_MOUSEBUTTONUP; | ||
239 | buttonstate &= ~SDL_BUTTON(button); | ||
240 | break; | ||
241 | default: | ||
242 | /* Invalid state -- bail */ | ||
243 | return(0); | ||
244 | } | ||
245 | |||
246 | /* Update internal mouse state */ | ||
247 | SDL_ButtonState = buttonstate; | ||
248 | if ( move_mouse ) { | ||
249 | SDL_MouseX = x; | ||
250 | SDL_MouseY = y; | ||
251 | SDL_MoveCursor(SDL_MouseX, SDL_MouseY); | ||
252 | } | ||
253 | |||
254 | /* Post the event, if desired */ | ||
255 | posted = 0; | ||
256 | if ( SDL_ProcessEvents[event.type] == SDL_ENABLE ) { | ||
257 | event.button.state = state; | ||
258 | event.button.button = button; | ||
259 | event.button.x = x; | ||
260 | event.button.y = y; | ||
261 | if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { | ||
262 | posted = 1; | ||
263 | SDL_PushEvent(&event); | ||
264 | } | ||
265 | } | ||
266 | return(posted); | ||
267 | } | ||
268 | |||
diff --git a/apps/plugins/sdl/src/events/SDL_quit.c b/apps/plugins/sdl/src/events/SDL_quit.c new file mode 100644 index 0000000000..2e6c56e796 --- /dev/null +++ b/apps/plugins/sdl/src/events/SDL_quit.c | |||
@@ -0,0 +1,124 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 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 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | /* General quit handling code for SDL */ | ||
25 | |||
26 | #ifdef HAVE_SIGNAL_H | ||
27 | #include <signal.h> | ||
28 | #endif | ||
29 | |||
30 | #include "SDL_events.h" | ||
31 | #include "SDL_events_c.h" | ||
32 | |||
33 | |||
34 | #ifdef HAVE_SIGNAL_H | ||
35 | static void SDL_HandleSIG(int sig) | ||
36 | { | ||
37 | /* Reset the signal handler */ | ||
38 | signal(sig, SDL_HandleSIG); | ||
39 | |||
40 | /* Signal a quit interrupt */ | ||
41 | SDL_PrivateQuit(); | ||
42 | } | ||
43 | #endif /* HAVE_SIGNAL_H */ | ||
44 | |||
45 | /* Public functions */ | ||
46 | int SDL_QuitInit(void) | ||
47 | { | ||
48 | #ifdef HAVE_SIGACTION | ||
49 | struct sigaction action; | ||
50 | sigaction(SIGINT, NULL, &action); | ||
51 | # ifdef HAVE_SA_SIGACTION | ||
52 | if ( action.sa_handler == SIG_DFL && action.sa_sigaction == (void*)SIG_DFL ) { | ||
53 | # else | ||
54 | if ( action.sa_handler == SIG_DFL ) { | ||
55 | # endif | ||
56 | action.sa_handler = SDL_HandleSIG; | ||
57 | sigaction(SIGINT, &action, NULL); | ||
58 | } | ||
59 | sigaction(SIGTERM, NULL, &action); | ||
60 | # ifdef HAVE_SA_SIGACTION | ||
61 | if ( action.sa_handler == SIG_DFL && action.sa_sigaction == (void*)SIG_DFL ) { | ||
62 | # else | ||
63 | if ( action.sa_handler == SIG_DFL ) { | ||
64 | # endif | ||
65 | action.sa_handler = SDL_HandleSIG; | ||
66 | sigaction(SIGTERM, &action, NULL); | ||
67 | } | ||
68 | #elif HAVE_SIGNAL_H | ||
69 | void (*ohandler)(int); | ||
70 | |||
71 | /* Both SIGINT and SIGTERM are translated into quit interrupts */ | ||
72 | ohandler = signal(SIGINT, SDL_HandleSIG); | ||
73 | if ( ohandler != SIG_DFL ) | ||
74 | signal(SIGINT, ohandler); | ||
75 | ohandler = signal(SIGTERM, SDL_HandleSIG); | ||
76 | if ( ohandler != SIG_DFL ) | ||
77 | signal(SIGTERM, ohandler); | ||
78 | #endif /* HAVE_SIGNAL_H */ | ||
79 | |||
80 | /* That's it! */ | ||
81 | return(0); | ||
82 | } | ||
83 | void SDL_QuitQuit(void) | ||
84 | { | ||
85 | #ifdef HAVE_SIGACTION | ||
86 | struct sigaction action; | ||
87 | sigaction(SIGINT, NULL, &action); | ||
88 | if ( action.sa_handler == SDL_HandleSIG ) { | ||
89 | action.sa_handler = SIG_DFL; | ||
90 | sigaction(SIGINT, &action, NULL); | ||
91 | } | ||
92 | sigaction(SIGTERM, NULL, &action); | ||
93 | if ( action.sa_handler == SDL_HandleSIG ) { | ||
94 | action.sa_handler = SIG_DFL; | ||
95 | sigaction(SIGTERM, &action, NULL); | ||
96 | } | ||
97 | #elif HAVE_SIGNAL_H | ||
98 | void (*ohandler)(int); | ||
99 | |||
100 | ohandler = signal(SIGINT, SIG_DFL); | ||
101 | if ( ohandler != SDL_HandleSIG ) | ||
102 | signal(SIGINT, ohandler); | ||
103 | ohandler = signal(SIGTERM, SIG_DFL); | ||
104 | if ( ohandler != SDL_HandleSIG ) | ||
105 | signal(SIGTERM, ohandler); | ||
106 | #endif /* HAVE_SIGNAL_H */ | ||
107 | } | ||
108 | |||
109 | /* This function returns 1 if it's okay to close the application window */ | ||
110 | int SDL_PrivateQuit(void) | ||
111 | { | ||
112 | int posted; | ||
113 | |||
114 | posted = 0; | ||
115 | if ( SDL_ProcessEvents[SDL_QUIT] == SDL_ENABLE ) { | ||
116 | SDL_Event event; | ||
117 | event.type = SDL_QUIT; | ||
118 | if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { | ||
119 | posted = 1; | ||
120 | SDL_PushEvent(&event); | ||
121 | } | ||
122 | } | ||
123 | return(posted); | ||
124 | } | ||
diff --git a/apps/plugins/sdl/src/events/SDL_resize.c b/apps/plugins/sdl/src/events/SDL_resize.c new file mode 100644 index 0000000000..e754a07d3f --- /dev/null +++ b/apps/plugins/sdl/src/events/SDL_resize.c | |||
@@ -0,0 +1,71 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 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 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | /* Resize event handling code for SDL */ | ||
25 | |||
26 | #include "SDL_events.h" | ||
27 | #include "SDL_events_c.h" | ||
28 | #include "../video/SDL_sysvideo.h" | ||
29 | |||
30 | |||
31 | /* Keep the last resize event so we don't post duplicates */ | ||
32 | static struct { | ||
33 | int w; | ||
34 | int h; | ||
35 | } last_resize; | ||
36 | |||
37 | /* This is global for SDL_eventloop.c */ | ||
38 | int SDL_PrivateResize(int w, int h) | ||
39 | { | ||
40 | int posted; | ||
41 | SDL_Event events[32]; | ||
42 | |||
43 | /* See if this event would change the video surface */ | ||
44 | if ( !w || !h || | ||
45 | (( last_resize.w == w ) && ( last_resize.h == h )) || | ||
46 | !SDL_VideoSurface ) { | ||
47 | return(0); | ||
48 | } | ||
49 | last_resize.w = w; | ||
50 | last_resize.h = h; | ||
51 | |||
52 | SDL_SetMouseRange(w, h); | ||
53 | |||
54 | /* Pull out all old resize events */ | ||
55 | SDL_PeepEvents(events, sizeof(events)/sizeof(events[0]), | ||
56 | SDL_GETEVENT, SDL_VIDEORESIZEMASK); | ||
57 | |||
58 | /* Post the event, if desired */ | ||
59 | posted = 0; | ||
60 | if ( SDL_ProcessEvents[SDL_VIDEORESIZE] == SDL_ENABLE ) { | ||
61 | SDL_Event event; | ||
62 | event.type = SDL_VIDEORESIZE; | ||
63 | event.resize.w = w; | ||
64 | event.resize.h = h; | ||
65 | if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { | ||
66 | posted = 1; | ||
67 | SDL_PushEvent(&event); | ||
68 | } | ||
69 | } | ||
70 | return(posted); | ||
71 | } | ||
diff --git a/apps/plugins/sdl/src/events/SDL_sysevents.h b/apps/plugins/sdl/src/events/SDL_sysevents.h new file mode 100644 index 0000000000..480bfe15f9 --- /dev/null +++ b/apps/plugins/sdl/src/events/SDL_sysevents.h | |||
@@ -0,0 +1,46 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | |||
5 | This library is SDL_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 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | #include "../video/SDL_sysvideo.h" | ||
25 | |||
26 | /* Useful functions and variables from SDL_sysevents.c */ | ||
27 | |||
28 | #ifdef __BEOS__ /* The Be event loop runs in a separate thread */ | ||
29 | #define MUST_THREAD_EVENTS | ||
30 | #endif | ||
31 | |||
32 | #ifdef __WIN32__ /* Win32 doesn't allow a separate event thread */ | ||
33 | #define CANT_THREAD_EVENTS | ||
34 | #endif | ||
35 | |||
36 | #ifdef IPOD /* iPod doesn't support threading at all */ | ||
37 | #define CANT_THREAD_EVENTS | ||
38 | #endif | ||
39 | |||
40 | #ifdef __MACOS__ /* MacOS 7/8 don't support preemptive multi-tasking */ | ||
41 | #define CANT_THREAD_EVENTS | ||
42 | #endif | ||
43 | |||
44 | #ifdef __OS2__ /* The OS/2 event loop runs in a separate thread */ | ||
45 | #define MUST_THREAD_EVENTS | ||
46 | #endif | ||