diff options
Diffstat (limited to 'distrib/sdl-1.2.15/src/events')
-rw-r--r-- | distrib/sdl-1.2.15/src/events/SDL_active.c | 95 | ||||
-rw-r--r-- | distrib/sdl-1.2.15/src/events/SDL_events.c | 502 | ||||
-rw-r--r-- | distrib/sdl-1.2.15/src/events/SDL_events_c.h | 83 | ||||
-rw-r--r-- | distrib/sdl-1.2.15/src/events/SDL_expose.c | 51 | ||||
-rw-r--r-- | distrib/sdl-1.2.15/src/events/SDL_keyboard.c | 614 | ||||
-rw-r--r-- | distrib/sdl-1.2.15/src/events/SDL_mouse.c | 268 | ||||
-rw-r--r-- | distrib/sdl-1.2.15/src/events/SDL_quit.c | 124 | ||||
-rw-r--r-- | distrib/sdl-1.2.15/src/events/SDL_resize.c | 71 | ||||
-rw-r--r-- | distrib/sdl-1.2.15/src/events/SDL_sysevents.h | 46 |
9 files changed, 1854 insertions, 0 deletions
diff --git a/distrib/sdl-1.2.15/src/events/SDL_active.c b/distrib/sdl-1.2.15/src/events/SDL_active.c new file mode 100644 index 0000000..201fb80 --- /dev/null +++ b/distrib/sdl-1.2.15/src/events/SDL_active.c @@ -0,0 +1,95 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + 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 + Lesser General Public License for more details. + + 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 + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +/* Application focus/iconification handling code for SDL */ + +#include "SDL_events.h" +#include "SDL_events_c.h" + + +/* These are static for our active event handling code */ +static Uint8 SDL_appstate = 0; + +/* Public functions */ +int SDL_AppActiveInit(void) +{ + /* Start completely active */ + SDL_appstate = (SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS); + + /* That's it! */ + return(0); +} +void SDL_AppActiveQuit(void) +{ +} + +Uint8 SDL_GetAppState(void) +{ + return(SDL_appstate); +} + +/* This is global for SDL_eventloop.c */ +int SDL_PrivateAppActive(Uint8 gain, Uint8 state) +{ + int posted; + Uint8 new_state; + + /* Modify the current state with the given mask */ + if ( gain ) { + new_state = (SDL_appstate | state); + } else { + new_state = (SDL_appstate & ~state); + } + + /* Drop events that don't change state */ + if ( new_state == SDL_appstate ) { + return(0); + } + + /* Update internal active state */ + SDL_appstate = new_state; + + /* Post the event, if desired */ + posted = 0; + if ( SDL_ProcessEvents[SDL_ACTIVEEVENT] == SDL_ENABLE ) { + SDL_Event event; + SDL_memset(&event, 0, sizeof(event)); + event.type = SDL_ACTIVEEVENT; + event.active.gain = gain; + event.active.state = state; + if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { + posted = 1; + SDL_PushEvent(&event); + } + } + + /* If we lost keyboard focus, post key-up events */ + if ( (state & SDL_APPINPUTFOCUS) && !gain ) { + SDL_ResetKeyboard(); + } + /* If we were minimized, post button-up events */ + if ( (state & SDL_APPACTIVE) && !gain ) { + SDL_ResetMouse(); + } + return(posted); +} diff --git a/distrib/sdl-1.2.15/src/events/SDL_events.c b/distrib/sdl-1.2.15/src/events/SDL_events.c new file mode 100644 index 0000000..8f23c01 --- /dev/null +++ b/distrib/sdl-1.2.15/src/events/SDL_events.c @@ -0,0 +1,502 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + 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 + Lesser General Public License for more details. + + 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 + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +/* General event handling code for SDL */ + +#include "SDL.h" +#include "SDL_syswm.h" +#include "SDL_sysevents.h" +#include "SDL_events_c.h" +#include "../timer/SDL_timer_c.h" +#if !SDL_JOYSTICK_DISABLED +#include "../joystick/SDL_joystick_c.h" +#endif + +/* Public data -- the event filter */ +SDL_EventFilter SDL_EventOK = NULL; +Uint8 SDL_ProcessEvents[SDL_NUMEVENTS]; +static Uint32 SDL_eventstate = 0; + +/* Private data -- event queue */ +#define MAXEVENTS 128 +static struct { + SDL_mutex *lock; + int active; + int head; + int tail; + SDL_Event event[MAXEVENTS]; + int wmmsg_next; + struct SDL_SysWMmsg wmmsg[MAXEVENTS]; +} SDL_EventQ; + +/* Private data -- event locking structure */ +static struct { + SDL_mutex *lock; + int safe; +} SDL_EventLock; + +/* Thread functions */ +static SDL_Thread *SDL_EventThread = NULL; /* Thread handle */ +static Uint32 event_thread; /* The event thread id */ + +void SDL_Lock_EventThread(void) +{ + if ( SDL_EventThread && (SDL_ThreadID() != event_thread) ) { + /* Grab lock and spin until we're sure event thread stopped */ + SDL_mutexP(SDL_EventLock.lock); + while ( ! SDL_EventLock.safe ) { + SDL_Delay(1); + } + } +} +void SDL_Unlock_EventThread(void) +{ + if ( SDL_EventThread && (SDL_ThreadID() != event_thread) ) { + SDL_mutexV(SDL_EventLock.lock); + } +} + +#ifdef __OS2__ +/* + * We'll increase the priority of GobbleEvents thread, so it will process + * events in time for sure! For this, we need the DosSetPriority() API + * from the os2.h include file. + */ +#define INCL_DOSPROCESS +#include <os2.h> +#include <time.h> +#endif + +static int SDLCALL SDL_GobbleEvents(void *unused) +{ + event_thread = SDL_ThreadID(); + +#ifdef __OS2__ +#ifdef USE_DOSSETPRIORITY + /* Increase thread priority, so it will process events in time for sure! */ + DosSetPriority(PRTYS_THREAD, PRTYC_REGULAR, +16, 0); +#endif +#endif + + while ( SDL_EventQ.active ) { + SDL_VideoDevice *video = current_video; + SDL_VideoDevice *this = current_video; + + /* Get events from the video subsystem */ + if ( video ) { + video->PumpEvents(this); + } + + /* Queue pending key-repeat events */ + SDL_CheckKeyRepeat(); + +#if !SDL_JOYSTICK_DISABLED + /* Check for joystick state change */ + if ( SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK) ) { + SDL_JoystickUpdate(); + } +#endif + + /* Give up the CPU for the rest of our timeslice */ + SDL_EventLock.safe = 1; + if ( SDL_timer_running ) { + SDL_ThreadedTimerCheck(); + } + SDL_Delay(1); + + /* Check for event locking. + On the P of the lock mutex, if the lock is held, this thread + will wait until the lock is released before continuing. The + safe flag will be set, meaning that the other thread can go + about it's business. The safe flag is reset before the V, + so as soon as the mutex is free, other threads can see that + it's not safe to interfere with the event thread. + */ + SDL_mutexP(SDL_EventLock.lock); + SDL_EventLock.safe = 0; + SDL_mutexV(SDL_EventLock.lock); + } + SDL_SetTimerThreaded(0); + event_thread = 0; + return(0); +} + +static int SDL_StartEventThread(Uint32 flags) +{ + /* Reset everything to zero */ + SDL_EventThread = NULL; + SDL_memset(&SDL_EventLock, 0, sizeof(SDL_EventLock)); + + /* Create the lock and set ourselves active */ +#if !SDL_THREADS_DISABLED + SDL_EventQ.lock = SDL_CreateMutex(); + if ( SDL_EventQ.lock == NULL ) { +#ifdef __MACOS__ /* MacOS classic you can't multithread, so no lock needed */ + ; +#else + return(-1); +#endif + } +#endif /* !SDL_THREADS_DISABLED */ + SDL_EventQ.active = 1; + + if ( (flags&SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD ) { + SDL_EventLock.lock = SDL_CreateMutex(); + if ( SDL_EventLock.lock == NULL ) { + return(-1); + } + SDL_EventLock.safe = 0; + + /* The event thread will handle timers too */ + SDL_SetTimerThreaded(2); +#if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC) && !defined(__SYMBIAN32__) +#undef SDL_CreateThread + SDL_EventThread = SDL_CreateThread(SDL_GobbleEvents, NULL, NULL, NULL); +#else + SDL_EventThread = SDL_CreateThread(SDL_GobbleEvents, NULL); +#endif + if ( SDL_EventThread == NULL ) { + return(-1); + } + } else { + event_thread = 0; + } + return(0); +} + +static void SDL_StopEventThread(void) +{ + SDL_EventQ.active = 0; + if ( SDL_EventThread ) { + SDL_WaitThread(SDL_EventThread, NULL); + SDL_EventThread = NULL; + SDL_DestroyMutex(SDL_EventLock.lock); + SDL_EventLock.lock = NULL; + } +#ifndef IPOD + SDL_DestroyMutex(SDL_EventQ.lock); + SDL_EventQ.lock = NULL; +#endif +} + +Uint32 SDL_EventThreadID(void) +{ + return(event_thread); +} + +/* Public functions */ + +void SDL_StopEventLoop(void) +{ + /* Halt the event thread, if running */ + SDL_StopEventThread(); + + /* Shutdown event handlers */ + SDL_AppActiveQuit(); + SDL_KeyboardQuit(); + SDL_MouseQuit(); + SDL_QuitQuit(); + + /* Clean out EventQ */ + SDL_EventQ.head = 0; + SDL_EventQ.tail = 0; + SDL_EventQ.wmmsg_next = 0; +} + +/* This function (and associated calls) may be called more than once */ +int SDL_StartEventLoop(Uint32 flags) +{ + int retcode; + + /* Clean out the event queue */ + SDL_EventThread = NULL; + SDL_EventQ.lock = NULL; + SDL_StopEventLoop(); + + /* No filter to start with, process most event types */ + SDL_EventOK = NULL; + SDL_memset(SDL_ProcessEvents,SDL_ENABLE,sizeof(SDL_ProcessEvents)); + SDL_eventstate = ~0; + /* It's not save to call SDL_EventState() yet */ + SDL_eventstate &= ~(0x00000001 << SDL_SYSWMEVENT); + SDL_ProcessEvents[SDL_SYSWMEVENT] = SDL_IGNORE; + + /* Initialize event handlers */ + retcode = 0; + retcode += SDL_AppActiveInit(); + retcode += SDL_KeyboardInit(); + retcode += SDL_MouseInit(); + retcode += SDL_QuitInit(); + if ( retcode < 0 ) { + /* We don't expect them to fail, but... */ + return(-1); + } + + /* Create the lock and event thread */ + if ( SDL_StartEventThread(flags) < 0 ) { + SDL_StopEventLoop(); + return(-1); + } + return(0); +} + + +/* Add an event to the event queue -- called with the queue locked */ +static int SDL_AddEvent(SDL_Event *event) +{ + int tail, added; + + tail = (SDL_EventQ.tail+1)%MAXEVENTS; + if ( tail == SDL_EventQ.head ) { + /* Overflow, drop event */ + added = 0; + } else { + SDL_EventQ.event[SDL_EventQ.tail] = *event; + if (event->type == SDL_SYSWMEVENT) { + /* Note that it's possible to lose an event */ + int next = SDL_EventQ.wmmsg_next; + SDL_EventQ.wmmsg[next] = *event->syswm.msg; + SDL_EventQ.event[SDL_EventQ.tail].syswm.msg = + &SDL_EventQ.wmmsg[next]; + SDL_EventQ.wmmsg_next = (next+1)%MAXEVENTS; + } + SDL_EventQ.tail = tail; + added = 1; + } + return(added); +} + +/* Cut an event, and return the next valid spot, or the tail */ +/* -- called with the queue locked */ +static int SDL_CutEvent(int spot) +{ + if ( spot == SDL_EventQ.head ) { + SDL_EventQ.head = (SDL_EventQ.head+1)%MAXEVENTS; + return(SDL_EventQ.head); + } else + if ( (spot+1)%MAXEVENTS == SDL_EventQ.tail ) { + SDL_EventQ.tail = spot; + return(SDL_EventQ.tail); + } else + /* We cut the middle -- shift everything over */ + { + int here, next; + + /* This can probably be optimized with SDL_memcpy() -- careful! */ + if ( --SDL_EventQ.tail < 0 ) { + SDL_EventQ.tail = MAXEVENTS-1; + } + for ( here=spot; here != SDL_EventQ.tail; here = next ) { + next = (here+1)%MAXEVENTS; + SDL_EventQ.event[here] = SDL_EventQ.event[next]; + } + return(spot); + } + /* NOTREACHED */ +} + +/* Lock the event queue, take a peep at it, and unlock it */ +int SDL_PeepEvents(SDL_Event *events, int numevents, SDL_eventaction action, + Uint32 mask) +{ + int i, used; + + /* Don't look after we've quit */ + if ( ! SDL_EventQ.active ) { + return(-1); + } + /* Lock the event queue */ + used = 0; + if ( SDL_mutexP(SDL_EventQ.lock) == 0 ) { + if ( action == SDL_ADDEVENT ) { + for ( i=0; i<numevents; ++i ) { + used += SDL_AddEvent(&events[i]); + } + } else { + SDL_Event tmpevent; + int spot; + + /* If 'events' is NULL, just see if they exist */ + if ( events == NULL ) { + action = SDL_PEEKEVENT; + numevents = 1; + events = &tmpevent; + } + spot = SDL_EventQ.head; + while ((used < numevents)&&(spot != SDL_EventQ.tail)) { + if ( mask & SDL_EVENTMASK(SDL_EventQ.event[spot].type) ) { + events[used++] = SDL_EventQ.event[spot]; + if ( action == SDL_GETEVENT ) { + spot = SDL_CutEvent(spot); + } else { + spot = (spot+1)%MAXEVENTS; + } + } else { + spot = (spot+1)%MAXEVENTS; + } + } + } + SDL_mutexV(SDL_EventQ.lock); + } else { + SDL_SetError("Couldn't lock event queue"); + used = -1; + } + return(used); +} + +/* Run the system dependent event loops */ +void SDL_PumpEvents(void) +{ + if ( !SDL_EventThread ) { + SDL_VideoDevice *video = current_video; + SDL_VideoDevice *this = current_video; + + /* Get events from the video subsystem */ + if ( video ) { + video->PumpEvents(this); + } + + /* Queue pending key-repeat events */ + SDL_CheckKeyRepeat(); + +#if !SDL_JOYSTICK_DISABLED + /* Check for joystick state change */ + if ( SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK) ) { + SDL_JoystickUpdate(); + } +#endif + } +} + +/* Public functions */ + +int SDL_PollEvent (SDL_Event *event) +{ + SDL_PumpEvents(); + + /* We can't return -1, just return 0 (no event) on error */ + if ( SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS) <= 0 ) + return 0; + return 1; +} + +int SDL_WaitEvent (SDL_Event *event) +{ + while ( 1 ) { + SDL_PumpEvents(); + switch(SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS)) { + case -1: return 0; + case 1: return 1; + case 0: SDL_Delay(10); + } + } +} + +int SDL_PushEvent(SDL_Event *event) +{ + if ( SDL_PeepEvents(event, 1, SDL_ADDEVENT, 0) <= 0 ) + return -1; + return 0; +} + +void SDL_SetEventFilter (SDL_EventFilter filter) +{ + SDL_Event bitbucket; + + /* Set filter and discard pending events */ + SDL_EventOK = filter; + while ( SDL_PollEvent(&bitbucket) > 0 ) + ; +} + +SDL_EventFilter SDL_GetEventFilter(void) +{ + return(SDL_EventOK); +} + +Uint8 SDL_EventState (Uint8 type, int state) +{ + SDL_Event bitbucket; + Uint8 current_state; + + /* If SDL_ALLEVENTS was specified... */ + if ( type == 0xFF ) { + current_state = SDL_IGNORE; + for ( type=0; type<SDL_NUMEVENTS; ++type ) { + if ( SDL_ProcessEvents[type] != SDL_IGNORE ) { + current_state = SDL_ENABLE; + } + SDL_ProcessEvents[type] = state; + if ( state == SDL_ENABLE ) { + SDL_eventstate |= (0x00000001 << (type)); + } else { + SDL_eventstate &= ~(0x00000001 << (type)); + } + } + while ( SDL_PollEvent(&bitbucket) > 0 ) + ; + return(current_state); + } + + /* Just set the state for one event type */ + current_state = SDL_ProcessEvents[type]; + switch (state) { + case SDL_IGNORE: + case SDL_ENABLE: + /* Set state and discard pending events */ + SDL_ProcessEvents[type] = state; + if ( state == SDL_ENABLE ) { + SDL_eventstate |= (0x00000001 << (type)); + } else { + SDL_eventstate &= ~(0x00000001 << (type)); + } + while ( SDL_PollEvent(&bitbucket) > 0 ) + ; + break; + default: + /* Querying state? */ + break; + } + return(current_state); +} + +/* This is a generic event handler. + */ +int SDL_PrivateSysWMEvent(SDL_SysWMmsg *message) +{ + int posted; + + posted = 0; + if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) { + SDL_Event event; + SDL_memset(&event, 0, sizeof(event)); + event.type = SDL_SYSWMEVENT; + event.syswm.msg = message; + if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { + posted = 1; + SDL_PushEvent(&event); + } + } + /* Update internal event state */ + return(posted); +} diff --git a/distrib/sdl-1.2.15/src/events/SDL_events_c.h b/distrib/sdl-1.2.15/src/events/SDL_events_c.h new file mode 100644 index 0000000..4378451 --- /dev/null +++ b/distrib/sdl-1.2.15/src/events/SDL_events_c.h @@ -0,0 +1,83 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + 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 + Lesser General Public License for more details. + + 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 + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +/* Useful functions and variables from SDL_events.c */ +#include "SDL_events.h" + +/* Start and stop the event processing loop */ +extern int SDL_StartEventLoop(Uint32 flags); +extern void SDL_StopEventLoop(void); +extern void SDL_QuitInterrupt(void); + +extern void SDL_Lock_EventThread(void); +extern void SDL_Unlock_EventThread(void); +extern Uint32 SDL_EventThreadID(void); + +/* Event handler init routines */ +extern int SDL_AppActiveInit(void); +extern int SDL_KeyboardInit(void); +extern int SDL_MouseInit(void); +extern int SDL_QuitInit(void); + +/* Event handler quit routines */ +extern void SDL_AppActiveQuit(void); +extern void SDL_KeyboardQuit(void); +extern void SDL_MouseQuit(void); +extern void SDL_QuitQuit(void); + +/* The event filter function */ +extern SDL_EventFilter SDL_EventOK; + +/* The array of event processing states */ +extern Uint8 SDL_ProcessEvents[SDL_NUMEVENTS]; + +/* Internal event queueing functions + (from SDL_active.c, SDL_mouse.c, SDL_keyboard.c, SDL_quit.c, SDL_events.c) + */ +extern int SDL_PrivateAppActive(Uint8 gain, Uint8 state); +extern int SDL_PrivateMouseMotion(Uint8 buttonstate, int relative, + Sint16 x, Sint16 y); +extern int SDL_PrivateMouseButton(Uint8 state, Uint8 button,Sint16 x,Sint16 y); +extern int SDL_PrivateKeyboard(Uint8 state, SDL_keysym *key); +extern int SDL_PrivateResize(int w, int h); +extern int SDL_PrivateExpose(void); +extern int SDL_PrivateQuit(void); +extern int SDL_PrivateSysWMEvent(SDL_SysWMmsg *message); + +/* Used to clamp the mouse coordinates separately from the video surface */ +extern void SDL_SetMouseRange(int maxX, int maxY); + +/* Used by the activity event handler to remove mouse focus */ +extern void SDL_ResetMouse(void); + +/* Used by the activity event handler to remove keyboard focus */ +extern void SDL_ResetKeyboard(void); + +/* Used by the event loop to queue pending keyboard repeat events */ +extern void SDL_CheckKeyRepeat(void); + +/* Used by the OS keyboard code to detect whether or not to do UNICODE */ +#ifndef DEFAULT_UNICODE_TRANSLATION +#define DEFAULT_UNICODE_TRANSLATION 0 /* Default off because of overhead */ +#endif +extern int SDL_TranslateUNICODE; diff --git a/distrib/sdl-1.2.15/src/events/SDL_expose.c b/distrib/sdl-1.2.15/src/events/SDL_expose.c new file mode 100644 index 0000000..d5b0143 --- /dev/null +++ b/distrib/sdl-1.2.15/src/events/SDL_expose.c @@ -0,0 +1,51 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + 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 + Lesser General Public License for more details. + + 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 + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +/* Refresh event handling code for SDL */ + +#include "SDL_events.h" +#include "SDL_events_c.h" + + +/* This is global for SDL_eventloop.c */ +int SDL_PrivateExpose(void) +{ + int posted; + SDL_Event events[32]; + + /* Pull out all old refresh events */ + SDL_PeepEvents(events, sizeof(events)/sizeof(events[0]), + SDL_GETEVENT, SDL_VIDEOEXPOSEMASK); + + /* Post the event, if desired */ + posted = 0; + if ( SDL_ProcessEvents[SDL_VIDEOEXPOSE] == SDL_ENABLE ) { + SDL_Event event; + event.type = SDL_VIDEOEXPOSE; + if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { + posted = 1; + SDL_PushEvent(&event); + } + } + return(posted); +} diff --git a/distrib/sdl-1.2.15/src/events/SDL_keyboard.c b/distrib/sdl-1.2.15/src/events/SDL_keyboard.c new file mode 100644 index 0000000..5753927 --- /dev/null +++ b/distrib/sdl-1.2.15/src/events/SDL_keyboard.c @@ -0,0 +1,614 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + 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 + Lesser General Public License for more details. + + 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 + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +/* General keyboard handling code for SDL */ + +#include "SDL_timer.h" +#include "SDL_events.h" +#include "SDL_events_c.h" +#include "SDL_sysevents.h" + + +/* Global keystate information */ +static Uint8 SDL_KeyState[SDLK_LAST]; +static SDLMod SDL_ModState; +int SDL_TranslateUNICODE = 0; + +static const char *keynames[SDLK_LAST]; /* Array of keycode names */ + +/* + * jk 991215 - added + */ +struct { + int firsttime; /* if we check against the delay or repeat value */ + int delay; /* the delay before we start repeating */ + int interval; /* the delay between key repeat events */ + Uint32 timestamp; /* the time the first keydown event occurred */ + + SDL_Event evt; /* the event we are supposed to repeat */ +} SDL_KeyRepeat; + +/* Global no-lock-keys support */ +static Uint8 SDL_NoLockKeys; + +#define SDL_NLK_CAPS 0x01 +#define SDL_NLK_NUM 0x02 + +/* Public functions */ +int SDL_KeyboardInit(void) +{ + const char* env; + SDL_VideoDevice *video = current_video; + SDL_VideoDevice *this = current_video; + + /* Set default mode of UNICODE translation */ + SDL_EnableUNICODE(DEFAULT_UNICODE_TRANSLATION); + + /* Initialize the tables */ + SDL_ModState = KMOD_NONE; + SDL_memset((void*)keynames, 0, sizeof(keynames)); + SDL_memset(SDL_KeyState, 0, sizeof(SDL_KeyState)); + video->InitOSKeymap(this); + + SDL_EnableKeyRepeat(0, 0); + + /* Allow environment override to disable special lock-key behavior */ + SDL_NoLockKeys = 0; + env = SDL_getenv("SDL_DISABLE_LOCK_KEYS"); + if (env) { + switch (SDL_atoi(env)) { + case 1: + SDL_NoLockKeys = SDL_NLK_CAPS | SDL_NLK_NUM; + break; + case 2: + SDL_NoLockKeys = SDL_NLK_CAPS; + break; + case 3: + SDL_NoLockKeys = SDL_NLK_NUM; + break; + default: + break; + } + } + + /* Fill in the blanks in keynames */ + keynames[SDLK_BACKSPACE] = "backspace"; + keynames[SDLK_TAB] = "tab"; + keynames[SDLK_CLEAR] = "clear"; + keynames[SDLK_RETURN] = "return"; + keynames[SDLK_PAUSE] = "pause"; + keynames[SDLK_ESCAPE] = "escape"; + keynames[SDLK_SPACE] = "space"; + keynames[SDLK_EXCLAIM] = "!"; + keynames[SDLK_QUOTEDBL] = "\""; + keynames[SDLK_HASH] = "#"; + keynames[SDLK_DOLLAR] = "$"; + keynames[SDLK_AMPERSAND] = "&"; + keynames[SDLK_QUOTE] = "'"; + keynames[SDLK_LEFTPAREN] = "("; + keynames[SDLK_RIGHTPAREN] = ")"; + keynames[SDLK_ASTERISK] = "*"; + keynames[SDLK_PLUS] = "+"; + keynames[SDLK_COMMA] = ","; + keynames[SDLK_MINUS] = "-"; + keynames[SDLK_PERIOD] = "."; + keynames[SDLK_SLASH] = "/"; + keynames[SDLK_0] = "0"; + keynames[SDLK_1] = "1"; + keynames[SDLK_2] = "2"; + keynames[SDLK_3] = "3"; + keynames[SDLK_4] = "4"; + keynames[SDLK_5] = "5"; + keynames[SDLK_6] = "6"; + keynames[SDLK_7] = "7"; + keynames[SDLK_8] = "8"; + keynames[SDLK_9] = "9"; + keynames[SDLK_COLON] = ":"; + keynames[SDLK_SEMICOLON] = ";"; + keynames[SDLK_LESS] = "<"; + keynames[SDLK_EQUALS] = "="; + keynames[SDLK_GREATER] = ">"; + keynames[SDLK_QUESTION] = "?"; + keynames[SDLK_AT] = "@"; + keynames[SDLK_LEFTBRACKET] = "["; + keynames[SDLK_BACKSLASH] = "\\"; + keynames[SDLK_RIGHTBRACKET] = "]"; + keynames[SDLK_CARET] = "^"; + keynames[SDLK_UNDERSCORE] = "_"; + keynames[SDLK_BACKQUOTE] = "`"; + keynames[SDLK_a] = "a"; + keynames[SDLK_b] = "b"; + keynames[SDLK_c] = "c"; + keynames[SDLK_d] = "d"; + keynames[SDLK_e] = "e"; + keynames[SDLK_f] = "f"; + keynames[SDLK_g] = "g"; + keynames[SDLK_h] = "h"; + keynames[SDLK_i] = "i"; + keynames[SDLK_j] = "j"; + keynames[SDLK_k] = "k"; + keynames[SDLK_l] = "l"; + keynames[SDLK_m] = "m"; + keynames[SDLK_n] = "n"; + keynames[SDLK_o] = "o"; + keynames[SDLK_p] = "p"; + keynames[SDLK_q] = "q"; + keynames[SDLK_r] = "r"; + keynames[SDLK_s] = "s"; + keynames[SDLK_t] = "t"; + keynames[SDLK_u] = "u"; + keynames[SDLK_v] = "v"; + keynames[SDLK_w] = "w"; + keynames[SDLK_x] = "x"; + keynames[SDLK_y] = "y"; + keynames[SDLK_z] = "z"; + keynames[SDLK_DELETE] = "delete"; + + keynames[SDLK_WORLD_0] = "world 0"; + keynames[SDLK_WORLD_1] = "world 1"; + keynames[SDLK_WORLD_2] = "world 2"; + keynames[SDLK_WORLD_3] = "world 3"; + keynames[SDLK_WORLD_4] = "world 4"; + keynames[SDLK_WORLD_5] = "world 5"; + keynames[SDLK_WORLD_6] = "world 6"; + keynames[SDLK_WORLD_7] = "world 7"; + keynames[SDLK_WORLD_8] = "world 8"; + keynames[SDLK_WORLD_9] = "world 9"; + keynames[SDLK_WORLD_10] = "world 10"; + keynames[SDLK_WORLD_11] = "world 11"; + keynames[SDLK_WORLD_12] = "world 12"; + keynames[SDLK_WORLD_13] = "world 13"; + keynames[SDLK_WORLD_14] = "world 14"; + keynames[SDLK_WORLD_15] = "world 15"; + keynames[SDLK_WORLD_16] = "world 16"; + keynames[SDLK_WORLD_17] = "world 17"; + keynames[SDLK_WORLD_18] = "world 18"; + keynames[SDLK_WORLD_19] = "world 19"; + keynames[SDLK_WORLD_20] = "world 20"; + keynames[SDLK_WORLD_21] = "world 21"; + keynames[SDLK_WORLD_22] = "world 22"; + keynames[SDLK_WORLD_23] = "world 23"; + keynames[SDLK_WORLD_24] = "world 24"; + keynames[SDLK_WORLD_25] = "world 25"; + keynames[SDLK_WORLD_26] = "world 26"; + keynames[SDLK_WORLD_27] = "world 27"; + keynames[SDLK_WORLD_28] = "world 28"; + keynames[SDLK_WORLD_29] = "world 29"; + keynames[SDLK_WORLD_30] = "world 30"; + keynames[SDLK_WORLD_31] = "world 31"; + keynames[SDLK_WORLD_32] = "world 32"; + keynames[SDLK_WORLD_33] = "world 33"; + keynames[SDLK_WORLD_34] = "world 34"; + keynames[SDLK_WORLD_35] = "world 35"; + keynames[SDLK_WORLD_36] = "world 36"; + keynames[SDLK_WORLD_37] = "world 37"; + keynames[SDLK_WORLD_38] = "world 38"; + keynames[SDLK_WORLD_39] = "world 39"; + keynames[SDLK_WORLD_40] = "world 40"; + keynames[SDLK_WORLD_41] = "world 41"; + keynames[SDLK_WORLD_42] = "world 42"; + keynames[SDLK_WORLD_43] = "world 43"; + keynames[SDLK_WORLD_44] = "world 44"; + keynames[SDLK_WORLD_45] = "world 45"; + keynames[SDLK_WORLD_46] = "world 46"; + keynames[SDLK_WORLD_47] = "world 47"; + keynames[SDLK_WORLD_48] = "world 48"; + keynames[SDLK_WORLD_49] = "world 49"; + keynames[SDLK_WORLD_50] = "world 50"; + keynames[SDLK_WORLD_51] = "world 51"; + keynames[SDLK_WORLD_52] = "world 52"; + keynames[SDLK_WORLD_53] = "world 53"; + keynames[SDLK_WORLD_54] = "world 54"; + keynames[SDLK_WORLD_55] = "world 55"; + keynames[SDLK_WORLD_56] = "world 56"; + keynames[SDLK_WORLD_57] = "world 57"; + keynames[SDLK_WORLD_58] = "world 58"; + keynames[SDLK_WORLD_59] = "world 59"; + keynames[SDLK_WORLD_60] = "world 60"; + keynames[SDLK_WORLD_61] = "world 61"; + keynames[SDLK_WORLD_62] = "world 62"; + keynames[SDLK_WORLD_63] = "world 63"; + keynames[SDLK_WORLD_64] = "world 64"; + keynames[SDLK_WORLD_65] = "world 65"; + keynames[SDLK_WORLD_66] = "world 66"; + keynames[SDLK_WORLD_67] = "world 67"; + keynames[SDLK_WORLD_68] = "world 68"; + keynames[SDLK_WORLD_69] = "world 69"; + keynames[SDLK_WORLD_70] = "world 70"; + keynames[SDLK_WORLD_71] = "world 71"; + keynames[SDLK_WORLD_72] = "world 72"; + keynames[SDLK_WORLD_73] = "world 73"; + keynames[SDLK_WORLD_74] = "world 74"; + keynames[SDLK_WORLD_75] = "world 75"; + keynames[SDLK_WORLD_76] = "world 76"; + keynames[SDLK_WORLD_77] = "world 77"; + keynames[SDLK_WORLD_78] = "world 78"; + keynames[SDLK_WORLD_79] = "world 79"; + keynames[SDLK_WORLD_80] = "world 80"; + keynames[SDLK_WORLD_81] = "world 81"; + keynames[SDLK_WORLD_82] = "world 82"; + keynames[SDLK_WORLD_83] = "world 83"; + keynames[SDLK_WORLD_84] = "world 84"; + keynames[SDLK_WORLD_85] = "world 85"; + keynames[SDLK_WORLD_86] = "world 86"; + keynames[SDLK_WORLD_87] = "world 87"; + keynames[SDLK_WORLD_88] = "world 88"; + keynames[SDLK_WORLD_89] = "world 89"; + keynames[SDLK_WORLD_90] = "world 90"; + keynames[SDLK_WORLD_91] = "world 91"; + keynames[SDLK_WORLD_92] = "world 92"; + keynames[SDLK_WORLD_93] = "world 93"; + keynames[SDLK_WORLD_94] = "world 94"; + keynames[SDLK_WORLD_95] = "world 95"; + + keynames[SDLK_KP0] = "[0]"; + keynames[SDLK_KP1] = "[1]"; + keynames[SDLK_KP2] = "[2]"; + keynames[SDLK_KP3] = "[3]"; + keynames[SDLK_KP4] = "[4]"; + keynames[SDLK_KP5] = "[5]"; + keynames[SDLK_KP6] = "[6]"; + keynames[SDLK_KP7] = "[7]"; + keynames[SDLK_KP8] = "[8]"; + keynames[SDLK_KP9] = "[9]"; + keynames[SDLK_KP_PERIOD] = "[.]"; + keynames[SDLK_KP_DIVIDE] = "[/]"; + keynames[SDLK_KP_MULTIPLY] = "[*]"; + keynames[SDLK_KP_MINUS] = "[-]"; + keynames[SDLK_KP_PLUS] = "[+]"; + keynames[SDLK_KP_ENTER] = "enter"; + keynames[SDLK_KP_EQUALS] = "equals"; + + keynames[SDLK_UP] = "up"; + keynames[SDLK_DOWN] = "down"; + keynames[SDLK_RIGHT] = "right"; + keynames[SDLK_LEFT] = "left"; + keynames[SDLK_DOWN] = "down"; + keynames[SDLK_INSERT] = "insert"; + keynames[SDLK_HOME] = "home"; + keynames[SDLK_END] = "end"; + keynames[SDLK_PAGEUP] = "page up"; + keynames[SDLK_PAGEDOWN] = "page down"; + + keynames[SDLK_F1] = "f1"; + keynames[SDLK_F2] = "f2"; + keynames[SDLK_F3] = "f3"; + keynames[SDLK_F4] = "f4"; + keynames[SDLK_F5] = "f5"; + keynames[SDLK_F6] = "f6"; + keynames[SDLK_F7] = "f7"; + keynames[SDLK_F8] = "f8"; + keynames[SDLK_F9] = "f9"; + keynames[SDLK_F10] = "f10"; + keynames[SDLK_F11] = "f11"; + keynames[SDLK_F12] = "f12"; + keynames[SDLK_F13] = "f13"; + keynames[SDLK_F14] = "f14"; + keynames[SDLK_F15] = "f15"; + + keynames[SDLK_NUMLOCK] = "numlock"; + keynames[SDLK_CAPSLOCK] = "caps lock"; + keynames[SDLK_SCROLLOCK] = "scroll lock"; + keynames[SDLK_RSHIFT] = "right shift"; + keynames[SDLK_LSHIFT] = "left shift"; + keynames[SDLK_RCTRL] = "right ctrl"; + keynames[SDLK_LCTRL] = "left ctrl"; + keynames[SDLK_RALT] = "right alt"; + keynames[SDLK_LALT] = "left alt"; + keynames[SDLK_RMETA] = "right meta"; + keynames[SDLK_LMETA] = "left meta"; + keynames[SDLK_LSUPER] = "left super"; /* "Windows" keys */ + keynames[SDLK_RSUPER] = "right super"; + keynames[SDLK_MODE] = "alt gr"; + keynames[SDLK_COMPOSE] = "compose"; + + keynames[SDLK_HELP] = "help"; + keynames[SDLK_PRINT] = "print screen"; + keynames[SDLK_SYSREQ] = "sys req"; + keynames[SDLK_BREAK] = "break"; + keynames[SDLK_MENU] = "menu"; + keynames[SDLK_POWER] = "power"; + keynames[SDLK_EURO] = "euro"; + keynames[SDLK_UNDO] = "undo"; + + /* Done. Whew. */ + return(0); +} +void SDL_KeyboardQuit(void) +{ +} + +/* We lost the keyboard, so post key up messages for all pressed keys */ +void SDL_ResetKeyboard(void) +{ + SDL_keysym keysym; + SDLKey key; + + SDL_memset(&keysym, 0, (sizeof keysym)); + for ( key=SDLK_FIRST; key<SDLK_LAST; ++key ) { + if ( SDL_KeyState[key] == SDL_PRESSED ) { + keysym.sym = key; + SDL_PrivateKeyboard(SDL_RELEASED, &keysym); + } + } + SDL_KeyRepeat.timestamp = 0; +} + +int SDL_EnableUNICODE(int enable) +{ + int old_mode; + + old_mode = SDL_TranslateUNICODE; + if ( enable >= 0 ) { + SDL_TranslateUNICODE = enable; + } + return(old_mode); +} + +Uint8 * SDL_GetKeyState (int *numkeys) +{ + if ( numkeys != (int *)0 ) + *numkeys = SDLK_LAST; + return(SDL_KeyState); +} +SDLMod SDL_GetModState (void) +{ + return(SDL_ModState); +} +void SDL_SetModState (SDLMod modstate) +{ + SDL_ModState = modstate; +} + +char *SDL_GetKeyName(SDLKey key) +{ + const char *keyname; + + keyname = NULL; + if ( key < SDLK_LAST ) { + keyname = keynames[key]; + } + if ( keyname == NULL ) { + keyname = "unknown key"; + } + /* FIXME: make this function const in 1.3 */ + return (char *)(keyname); +} + +/* These are global for SDL_eventloop.c */ +int SDL_PrivateKeyboard(Uint8 state, SDL_keysym *keysym) +{ + SDL_Event event; + int posted, repeatable; + Uint16 modstate; + + SDL_memset(&event, 0, sizeof(event)); + +#if 0 +printf("The '%s' key has been %s\n", SDL_GetKeyName(keysym->sym), + state == SDL_PRESSED ? "pressed" : "released"); +#endif + /* Set up the keysym */ + modstate = (Uint16)SDL_ModState; + + repeatable = 0; + + if ( state == SDL_PRESSED ) { + keysym->mod = (SDLMod)modstate; + switch (keysym->sym) { + case SDLK_UNKNOWN: + break; + case SDLK_NUMLOCK: + modstate ^= KMOD_NUM; + if ( SDL_NoLockKeys & SDL_NLK_NUM ) + break; + if ( ! (modstate&KMOD_NUM) ) + state = SDL_RELEASED; + keysym->mod = (SDLMod)modstate; + break; + case SDLK_CAPSLOCK: + modstate ^= KMOD_CAPS; + if ( SDL_NoLockKeys & SDL_NLK_CAPS ) + break; + if ( ! (modstate&KMOD_CAPS) ) + state = SDL_RELEASED; + keysym->mod = (SDLMod)modstate; + break; + case SDLK_LCTRL: + modstate |= KMOD_LCTRL; + break; + case SDLK_RCTRL: + modstate |= KMOD_RCTRL; + break; + case SDLK_LSHIFT: + modstate |= KMOD_LSHIFT; + break; + case SDLK_RSHIFT: + modstate |= KMOD_RSHIFT; + break; + case SDLK_LALT: + modstate |= KMOD_LALT; + break; + case SDLK_RALT: + modstate |= KMOD_RALT; + break; + case SDLK_LMETA: + modstate |= KMOD_LMETA; + break; + case SDLK_RMETA: + modstate |= KMOD_RMETA; + break; + case SDLK_MODE: + modstate |= KMOD_MODE; + break; + default: + repeatable = 1; + break; + } + } else { + switch (keysym->sym) { + case SDLK_UNKNOWN: + break; + case SDLK_NUMLOCK: + if ( SDL_NoLockKeys & SDL_NLK_NUM ) + break; + /* Only send keydown events */ + return(0); + case SDLK_CAPSLOCK: + if ( SDL_NoLockKeys & SDL_NLK_CAPS ) + break; + /* Only send keydown events */ + return(0); + case SDLK_LCTRL: + modstate &= ~KMOD_LCTRL; + break; + case SDLK_RCTRL: + modstate &= ~KMOD_RCTRL; + break; + case SDLK_LSHIFT: + modstate &= ~KMOD_LSHIFT; + break; + case SDLK_RSHIFT: + modstate &= ~KMOD_RSHIFT; + break; + case SDLK_LALT: + modstate &= ~KMOD_LALT; + break; + case SDLK_RALT: + modstate &= ~KMOD_RALT; + break; + case SDLK_LMETA: + modstate &= ~KMOD_LMETA; + break; + case SDLK_RMETA: + modstate &= ~KMOD_RMETA; + break; + case SDLK_MODE: + modstate &= ~KMOD_MODE; + break; + default: + break; + } + keysym->mod = (SDLMod)modstate; + } + + /* Figure out what type of event this is */ + switch (state) { + case SDL_PRESSED: + event.type = SDL_KEYDOWN; + break; + case SDL_RELEASED: + event.type = SDL_KEYUP; + /* + * jk 991215 - Added + */ + if ( SDL_KeyRepeat.timestamp && + SDL_KeyRepeat.evt.key.keysym.sym == keysym->sym ) { + SDL_KeyRepeat.timestamp = 0; + } + break; + default: + /* Invalid state -- bail */ + return(0); + } + + if ( keysym->sym != SDLK_UNKNOWN ) { + /* Drop events that don't change state */ + if ( SDL_KeyState[keysym->sym] == state ) { +#if 0 +printf("Keyboard event didn't change state - dropped!\n"); +#endif + return(0); + } + + /* Update internal keyboard state */ + SDL_ModState = (SDLMod)modstate; + SDL_KeyState[keysym->sym] = state; + } + + /* Post the event, if desired */ + posted = 0; + if ( SDL_ProcessEvents[event.type] == SDL_ENABLE ) { + event.key.state = state; + event.key.keysym = *keysym; + /* + * jk 991215 - Added + */ + if (repeatable && (SDL_KeyRepeat.delay != 0)) { + SDL_KeyRepeat.evt = event; + SDL_KeyRepeat.firsttime = 1; + SDL_KeyRepeat.timestamp=SDL_GetTicks(); + } + if ( (SDL_EventOK == NULL) || SDL_EventOK(&event) ) { + posted = 1; + SDL_PushEvent(&event); + } + } + return(posted); +} + +/* + * jk 991215 - Added + */ +void SDL_CheckKeyRepeat(void) +{ + if ( SDL_KeyRepeat.timestamp ) { + Uint32 now, interval; + + now = SDL_GetTicks(); + interval = (now - SDL_KeyRepeat.timestamp); + if ( SDL_KeyRepeat.firsttime ) { + if ( interval > (Uint32)SDL_KeyRepeat.delay ) { + SDL_KeyRepeat.timestamp = now; + SDL_KeyRepeat.firsttime = 0; + } + } else { + if ( interval > (Uint32)SDL_KeyRepeat.interval ) { + SDL_KeyRepeat.timestamp = now; + if ( (SDL_EventOK == NULL) || SDL_EventOK(&SDL_KeyRepeat.evt) ) { + SDL_PushEvent(&SDL_KeyRepeat.evt); + } + } + } + } +} + +int SDL_EnableKeyRepeat(int delay, int interval) +{ + if ( (delay < 0) || (interval < 0) ) { + SDL_SetError("keyboard repeat value less than zero"); + return(-1); + } + SDL_KeyRepeat.firsttime = 0; + SDL_KeyRepeat.delay = delay; + SDL_KeyRepeat.interval = interval; + SDL_KeyRepeat.timestamp = 0; + return(0); +} + +void SDL_GetKeyRepeat(int *delay, int *interval) +{ + *delay = SDL_KeyRepeat.delay; + *interval = SDL_KeyRepeat.interval; +} + diff --git a/distrib/sdl-1.2.15/src/events/SDL_mouse.c b/distrib/sdl-1.2.15/src/events/SDL_mouse.c new file mode 100644 index 0000000..e37a4c6 --- /dev/null +++ b/distrib/sdl-1.2.15/src/events/SDL_mouse.c @@ -0,0 +1,268 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + 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 + Lesser General Public License for more details. + + 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 + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +/* General mouse handling code for SDL */ + +#include "SDL_events.h" +#include "SDL_events_c.h" +#include "../video/SDL_cursor_c.h" +#include "../video/SDL_sysvideo.h" + + +/* These are static for our mouse handling code */ +static Sint16 SDL_MouseX = 0; +static Sint16 SDL_MouseY = 0; +static Sint16 SDL_DeltaX = 0; +static Sint16 SDL_DeltaY = 0; +static Sint16 SDL_MouseMaxX = 0; +static Sint16 SDL_MouseMaxY = 0; +static Uint8 SDL_ButtonState = 0; + + +/* Public functions */ +int SDL_MouseInit(void) +{ + /* The mouse is at (0,0) */ + SDL_MouseX = 0; + SDL_MouseY = 0; + SDL_DeltaX = 0; + SDL_DeltaY = 0; + SDL_MouseMaxX = 0; + SDL_MouseMaxY = 0; + SDL_ButtonState = 0; + + /* That's it! */ + return(0); +} +void SDL_MouseQuit(void) +{ +} + +/* We lost the mouse, so post button up messages for all pressed buttons */ +void SDL_ResetMouse(void) +{ + Uint8 i; + for ( i = 0; i < sizeof(SDL_ButtonState)*8; ++i ) { + if ( SDL_ButtonState & SDL_BUTTON(i) ) { + SDL_PrivateMouseButton(SDL_RELEASED, i, 0, 0); + } + } +} + +Uint8 SDL_GetMouseState (int *x, int *y) +{ + if ( x ) { + *x = SDL_MouseX; + } + if ( y ) { + *y = SDL_MouseY; + } + return(SDL_ButtonState); +} + +Uint8 SDL_GetRelativeMouseState (int *x, int *y) +{ + if ( x ) + *x = SDL_DeltaX; + if ( y ) + *y = SDL_DeltaY; + SDL_DeltaX = 0; + SDL_DeltaY = 0; + return(SDL_ButtonState); +} + +static void ClipOffset(Sint16 *x, Sint16 *y) +{ + /* This clips absolute mouse coordinates when the apparent + display surface is smaller than the real display surface. + */ + if ( SDL_VideoSurface && SDL_VideoSurface->offset ) { + *y -= SDL_VideoSurface->offset/SDL_VideoSurface->pitch; + *x -= (SDL_VideoSurface->offset%SDL_VideoSurface->pitch)/ + SDL_VideoSurface->format->BytesPerPixel; + } +} + +void SDL_SetMouseRange(int maxX, int maxY) +{ + SDL_MouseMaxX = (Sint16)maxX; + SDL_MouseMaxY = (Sint16)maxY; +} + +/* These are global for SDL_eventloop.c */ +int SDL_PrivateMouseMotion(Uint8 buttonstate, int relative, Sint16 x, Sint16 y) +{ + int posted; + Uint16 X, Y; + Sint16 Xrel; + Sint16 Yrel; + + /* Default buttonstate is the current one */ + if ( ! buttonstate ) { + buttonstate = SDL_ButtonState; + } + + Xrel = x; + Yrel = y; + if ( relative ) { + /* Push the cursor around */ + x = (SDL_MouseX+x); + y = (SDL_MouseY+y); + } else { + /* Do we need to clip {x,y} ? */ + ClipOffset(&x, &y); + } + + /* Mouse coordinates range from 0 - width-1 and 0 - height-1 */ + if ( x < 0 ) + X = 0; + else + if ( x >= SDL_MouseMaxX ) + X = SDL_MouseMaxX-1; + else + X = (Uint16)x; + + if ( y < 0 ) + Y = 0; + else + if ( y >= SDL_MouseMaxY ) + Y = SDL_MouseMaxY-1; + else + Y = (Uint16)y; + + /* If not relative mode, generate relative motion from clamped X/Y. + This prevents lots of extraneous large delta relative motion when + the screen is windowed mode and the mouse is outside the window. + */ + if ( ! relative ) { + Xrel = X-SDL_MouseX; + Yrel = Y-SDL_MouseY; + } + + /* Drop events that don't change state */ + if ( ! Xrel && ! Yrel ) { +#if 0 +printf("Mouse event didn't change state - dropped!\n"); +#endif + return(0); + } + + /* Update internal mouse state */ + SDL_ButtonState = buttonstate; + SDL_MouseX = X; + SDL_MouseY = Y; + SDL_DeltaX += Xrel; + SDL_DeltaY += Yrel; + SDL_MoveCursor(SDL_MouseX, SDL_MouseY); + + /* Post the event, if desired */ + posted = 0; + if ( SDL_ProcessEvents[SDL_MOUSEMOTION] == SDL_ENABLE ) { + SDL_Event event; + SDL_memset(&event, 0, sizeof(event)); + event.type = SDL_MOUSEMOTION; + event.motion.state = buttonstate; + event.motion.x = X; + event.motion.y = Y; + event.motion.xrel = Xrel; + event.motion.yrel = Yrel; + if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { + posted = 1; + SDL_PushEvent(&event); + } + } + return(posted); +} + +int SDL_PrivateMouseButton(Uint8 state, Uint8 button, Sint16 x, Sint16 y) +{ + SDL_Event event; + int posted; + int move_mouse; + Uint8 buttonstate; + + SDL_memset(&event, 0, sizeof(event)); + + /* Check parameters */ + if ( x || y ) { + ClipOffset(&x, &y); + move_mouse = 1; + /* Mouse coordinates range from 0 - width-1 and 0 - height-1 */ + if ( x < 0 ) + x = 0; + else + if ( x >= SDL_MouseMaxX ) + x = SDL_MouseMaxX-1; + + if ( y < 0 ) + y = 0; + else + if ( y >= SDL_MouseMaxY ) + y = SDL_MouseMaxY-1; + } else { + move_mouse = 0; + } + if ( ! x ) + x = SDL_MouseX; + if ( ! y ) + y = SDL_MouseY; + + /* Figure out which event to perform */ + buttonstate = SDL_ButtonState; + switch ( state ) { + case SDL_PRESSED: + event.type = SDL_MOUSEBUTTONDOWN; + buttonstate |= SDL_BUTTON(button); + break; + case SDL_RELEASED: + event.type = SDL_MOUSEBUTTONUP; + buttonstate &= ~SDL_BUTTON(button); + break; + default: + /* Invalid state -- bail */ + return(0); + } + + /* Update internal mouse state */ + SDL_ButtonState = buttonstate; + if ( move_mouse ) { + SDL_MouseX = x; + SDL_MouseY = y; + SDL_MoveCursor(SDL_MouseX, SDL_MouseY); + } + + /* Post the event, if desired */ + posted = 0; + if ( SDL_ProcessEvents[event.type] == SDL_ENABLE ) { + event.button.state = state; + event.button.button = button; + event.button.x = x; + event.button.y = y; + if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { + posted = 1; + SDL_PushEvent(&event); + } + } + return(posted); +} + diff --git a/distrib/sdl-1.2.15/src/events/SDL_quit.c b/distrib/sdl-1.2.15/src/events/SDL_quit.c new file mode 100644 index 0000000..2e6c56e --- /dev/null +++ b/distrib/sdl-1.2.15/src/events/SDL_quit.c @@ -0,0 +1,124 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + 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 + Lesser General Public License for more details. + + 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 + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +/* General quit handling code for SDL */ + +#ifdef HAVE_SIGNAL_H +#include <signal.h> +#endif + +#include "SDL_events.h" +#include "SDL_events_c.h" + + +#ifdef HAVE_SIGNAL_H +static void SDL_HandleSIG(int sig) +{ + /* Reset the signal handler */ + signal(sig, SDL_HandleSIG); + + /* Signal a quit interrupt */ + SDL_PrivateQuit(); +} +#endif /* HAVE_SIGNAL_H */ + +/* Public functions */ +int SDL_QuitInit(void) +{ +#ifdef HAVE_SIGACTION + struct sigaction action; + sigaction(SIGINT, NULL, &action); +# ifdef HAVE_SA_SIGACTION + if ( action.sa_handler == SIG_DFL && action.sa_sigaction == (void*)SIG_DFL ) { +# else + if ( action.sa_handler == SIG_DFL ) { +# endif + action.sa_handler = SDL_HandleSIG; + sigaction(SIGINT, &action, NULL); + } + sigaction(SIGTERM, NULL, &action); +# ifdef HAVE_SA_SIGACTION + if ( action.sa_handler == SIG_DFL && action.sa_sigaction == (void*)SIG_DFL ) { +# else + if ( action.sa_handler == SIG_DFL ) { +# endif + action.sa_handler = SDL_HandleSIG; + sigaction(SIGTERM, &action, NULL); + } +#elif HAVE_SIGNAL_H + void (*ohandler)(int); + + /* Both SIGINT and SIGTERM are translated into quit interrupts */ + ohandler = signal(SIGINT, SDL_HandleSIG); + if ( ohandler != SIG_DFL ) + signal(SIGINT, ohandler); + ohandler = signal(SIGTERM, SDL_HandleSIG); + if ( ohandler != SIG_DFL ) + signal(SIGTERM, ohandler); +#endif /* HAVE_SIGNAL_H */ + + /* That's it! */ + return(0); +} +void SDL_QuitQuit(void) +{ +#ifdef HAVE_SIGACTION + struct sigaction action; + sigaction(SIGINT, NULL, &action); + if ( action.sa_handler == SDL_HandleSIG ) { + action.sa_handler = SIG_DFL; + sigaction(SIGINT, &action, NULL); + } + sigaction(SIGTERM, NULL, &action); + if ( action.sa_handler == SDL_HandleSIG ) { + action.sa_handler = SIG_DFL; + sigaction(SIGTERM, &action, NULL); + } +#elif HAVE_SIGNAL_H + void (*ohandler)(int); + + ohandler = signal(SIGINT, SIG_DFL); + if ( ohandler != SDL_HandleSIG ) + signal(SIGINT, ohandler); + ohandler = signal(SIGTERM, SIG_DFL); + if ( ohandler != SDL_HandleSIG ) + signal(SIGTERM, ohandler); +#endif /* HAVE_SIGNAL_H */ +} + +/* This function returns 1 if it's okay to close the application window */ +int SDL_PrivateQuit(void) +{ + int posted; + + posted = 0; + if ( SDL_ProcessEvents[SDL_QUIT] == SDL_ENABLE ) { + SDL_Event event; + event.type = SDL_QUIT; + if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { + posted = 1; + SDL_PushEvent(&event); + } + } + return(posted); +} diff --git a/distrib/sdl-1.2.15/src/events/SDL_resize.c b/distrib/sdl-1.2.15/src/events/SDL_resize.c new file mode 100644 index 0000000..e754a07 --- /dev/null +++ b/distrib/sdl-1.2.15/src/events/SDL_resize.c @@ -0,0 +1,71 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + 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 + Lesser General Public License for more details. + + 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 + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +/* Resize event handling code for SDL */ + +#include "SDL_events.h" +#include "SDL_events_c.h" +#include "../video/SDL_sysvideo.h" + + +/* Keep the last resize event so we don't post duplicates */ +static struct { + int w; + int h; +} last_resize; + +/* This is global for SDL_eventloop.c */ +int SDL_PrivateResize(int w, int h) +{ + int posted; + SDL_Event events[32]; + + /* See if this event would change the video surface */ + if ( !w || !h || + (( last_resize.w == w ) && ( last_resize.h == h )) || + !SDL_VideoSurface ) { + return(0); + } + last_resize.w = w; + last_resize.h = h; + + SDL_SetMouseRange(w, h); + + /* Pull out all old resize events */ + SDL_PeepEvents(events, sizeof(events)/sizeof(events[0]), + SDL_GETEVENT, SDL_VIDEORESIZEMASK); + + /* Post the event, if desired */ + posted = 0; + if ( SDL_ProcessEvents[SDL_VIDEORESIZE] == SDL_ENABLE ) { + SDL_Event event; + event.type = SDL_VIDEORESIZE; + event.resize.w = w; + event.resize.h = h; + if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { + posted = 1; + SDL_PushEvent(&event); + } + } + return(posted); +} diff --git a/distrib/sdl-1.2.15/src/events/SDL_sysevents.h b/distrib/sdl-1.2.15/src/events/SDL_sysevents.h new file mode 100644 index 0000000..480bfe1 --- /dev/null +++ b/distrib/sdl-1.2.15/src/events/SDL_sysevents.h @@ -0,0 +1,46 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is SDL_free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + 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 + Lesser General Public License for more details. + + 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 + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#include "../video/SDL_sysvideo.h" + +/* Useful functions and variables from SDL_sysevents.c */ + +#ifdef __BEOS__ /* The Be event loop runs in a separate thread */ +#define MUST_THREAD_EVENTS +#endif + +#ifdef __WIN32__ /* Win32 doesn't allow a separate event thread */ +#define CANT_THREAD_EVENTS +#endif + +#ifdef IPOD /* iPod doesn't support threading at all */ +#define CANT_THREAD_EVENTS +#endif + +#ifdef __MACOS__ /* MacOS 7/8 don't support preemptive multi-tasking */ +#define CANT_THREAD_EVENTS +#endif + +#ifdef __OS2__ /* The OS/2 event loop runs in a separate thread */ +#define MUST_THREAD_EVENTS +#endif |