Initial revision
--HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401
This commit is contained in:
commit
2f110628a7
892 changed files with 170313 additions and 0 deletions
6
src/events/.cvsignore
Normal file
6
src/events/.cvsignore
Normal file
|
@ -0,0 +1,6 @@
|
|||
Makefile.in
|
||||
Makefile
|
||||
.libs
|
||||
*.o
|
||||
*.lo
|
||||
*.la
|
19
src/events/Makefile.am
Normal file
19
src/events/Makefile.am
Normal file
|
@ -0,0 +1,19 @@
|
|||
|
||||
## Makefile.am for the SDL event handling library
|
||||
|
||||
noinst_LTLIBRARIES = libevents.la
|
||||
|
||||
# Include the architecture-independent sources
|
||||
COMMON_SRCS = \
|
||||
SDL_events.c \
|
||||
SDL_events_c.h \
|
||||
SDL_expose.c \
|
||||
SDL_sysevents.h \
|
||||
SDL_quit.c \
|
||||
SDL_active.c \
|
||||
SDL_keyboard.c \
|
||||
SDL_mouse.c \
|
||||
SDL_resize.c
|
||||
|
||||
libevents_la_SOURCES = $(COMMON_SRCS)
|
||||
|
95
src/events/SDL_active.c
Normal file
95
src/events/SDL_active.c
Normal file
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@devolution.com
|
||||
*/
|
||||
|
||||
#ifdef SAVE_RCSID
|
||||
static char rcsid =
|
||||
"@(#) $Id$";
|
||||
#endif
|
||||
|
||||
/* Application focus/iconification handling code for SDL */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
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;
|
||||
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();
|
||||
}
|
||||
return(posted);
|
||||
}
|
475
src/events/SDL_events.c
Normal file
475
src/events/SDL_events.c
Normal file
|
@ -0,0 +1,475 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@devolution.com
|
||||
*/
|
||||
|
||||
#ifdef SAVE_RCSID
|
||||
static char rcsid =
|
||||
"@(#) $Id$";
|
||||
#endif
|
||||
|
||||
/* General event handling code for SDL */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_thread.h"
|
||||
#include "SDL_mutex.h"
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_events_c.h"
|
||||
#include "SDL_timer_c.h"
|
||||
#ifndef DISABLE_JOYSTICK
|
||||
#include "SDL_joystick_c.h"
|
||||
#endif
|
||||
#ifndef ENABLE_X11
|
||||
#define DISABLE_X11
|
||||
#endif
|
||||
#include "SDL_syswm.h"
|
||||
#include "SDL_sysevents.h"
|
||||
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
|
||||
static int SDL_GobbleEvents(void *unused)
|
||||
{
|
||||
SDL_SetTimerThreaded(2);
|
||||
event_thread = SDL_ThreadID();
|
||||
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();
|
||||
|
||||
#ifndef DISABLE_JOYSTICK
|
||||
/* 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;
|
||||
memset(&SDL_EventLock, 0, sizeof(SDL_EventLock));
|
||||
|
||||
/* Create the lock and set ourselves active */
|
||||
#ifndef DISABLE_THREADS
|
||||
SDL_EventQ.lock = SDL_CreateMutex();
|
||||
if ( SDL_EventQ.lock == NULL ) {
|
||||
#ifdef macintosh /* On MacOS 7/8, you can't multithread, so no lock needed */
|
||||
;
|
||||
#else
|
||||
return(-1);
|
||||
#endif
|
||||
}
|
||||
#endif /* !DISABLE_THREADS */
|
||||
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;
|
||||
|
||||
SDL_EventThread = SDL_CreateThread(SDL_GobbleEvents, NULL);
|
||||
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_DestroyMutex(SDL_EventQ.lock);
|
||||
}
|
||||
|
||||
Uint32 SDL_EventThreadID(void)
|
||||
{
|
||||
return(event_thread);
|
||||
}
|
||||
|
||||
/* Public functions */
|
||||
|
||||
void SDL_StopEventLoop(void)
|
||||
{
|
||||
/* Halt the event thread, if running */
|
||||
SDL_StopEventThread();
|
||||
|
||||
/* 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;
|
||||
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 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(0);
|
||||
}
|
||||
/* 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();
|
||||
|
||||
#ifndef DISABLE_JOYSTICK
|
||||
/* 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();
|
||||
|
||||
return(SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS));
|
||||
}
|
||||
|
||||
int SDL_WaitEvent (SDL_Event *event)
|
||||
{
|
||||
while ( 1 ) {
|
||||
SDL_PumpEvents();
|
||||
switch(SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS)) {
|
||||
case -1: return -1;
|
||||
case 1: return 1;
|
||||
case 0: SDL_Delay(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int SDL_PushEvent(SDL_Event *event)
|
||||
{
|
||||
return(SDL_PeepEvents(event, 1, SDL_ADDEVENT, 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;
|
||||
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);
|
||||
}
|
78
src/events/SDL_events_c.h
Normal file
78
src/events/SDL_events_c.h
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@devolution.com
|
||||
*/
|
||||
|
||||
#ifdef SAVE_RCSID
|
||||
static char rcsid =
|
||||
"@(#) $Id$";
|
||||
#endif
|
||||
|
||||
/* 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();
|
||||
extern void SDL_Unlock_EventThread();
|
||||
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);
|
||||
|
||||
/* 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 by the activity event handler to remove mouse focus */
|
||||
extern void SDL_MouseFocus(int focus);
|
||||
|
||||
/* 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;
|
55
src/events/SDL_expose.c
Normal file
55
src/events/SDL_expose.c
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@devolution.com
|
||||
*/
|
||||
|
||||
#ifdef SAVE_RCSID
|
||||
static char rcsid =
|
||||
"@(#) $Id$";
|
||||
#endif
|
||||
|
||||
/* 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);
|
||||
}
|
572
src/events/SDL_keyboard.c
Normal file
572
src/events/SDL_keyboard.c
Normal file
|
@ -0,0 +1,572 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@devolution.com
|
||||
*/
|
||||
|
||||
#ifdef SAVE_RCSID
|
||||
static char rcsid =
|
||||
"@(#) $Id$";
|
||||
#endif
|
||||
|
||||
/* General keyboard handling code for SDL */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_timer.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 char *keynames[SDLK_LAST]; /* Array of keycode names */
|
||||
|
||||
/*
|
||||
* jk 991215 - added
|
||||
*/
|
||||
#define MINIMUM_REPEAT_INTERVAL 30 /* Minimum repeat interval (30 ms) */
|
||||
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;
|
||||
|
||||
/* Public functions */
|
||||
int SDL_KeyboardInit(void)
|
||||
{
|
||||
SDL_VideoDevice *video = current_video;
|
||||
SDL_VideoDevice *this = current_video;
|
||||
Uint16 i;
|
||||
|
||||
/* Set default mode of UNICODE translation */
|
||||
SDL_EnableUNICODE(DEFAULT_UNICODE_TRANSLATION);
|
||||
|
||||
/* Initialize the tables */
|
||||
SDL_ModState = KMOD_NONE;
|
||||
for ( i=0; i<SDL_TABLESIZE(keynames); ++i )
|
||||
keynames[i] = NULL;
|
||||
for ( i=0; i<SDL_TABLESIZE(SDL_KeyState); ++i )
|
||||
SDL_KeyState[i] = SDL_RELEASED;
|
||||
video->InitOSKeymap(this);
|
||||
|
||||
SDL_EnableKeyRepeat(0, 0);
|
||||
|
||||
/* 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";
|
||||
|
||||
/* Done. Whew. */
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* We lost the keyboard, so post key up messages for all pressed keys */
|
||||
void SDL_ResetKeyboard(void)
|
||||
{
|
||||
SDL_keysym keysym;
|
||||
SDLKey key;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
char *keyname;
|
||||
|
||||
keyname = NULL;
|
||||
if ( key < SDLK_LAST ) {
|
||||
keyname = keynames[key];
|
||||
}
|
||||
if ( keyname == NULL ) {
|
||||
keyname = "unknown key";
|
||||
}
|
||||
return(keyname);
|
||||
}
|
||||
|
||||
/* These are global for SDL_eventloop.c */
|
||||
int SDL_PrivateKeyboard(Uint8 state, SDL_keysym *keysym)
|
||||
{
|
||||
SDL_Event event;
|
||||
int posted, repeatable;
|
||||
Uint16 modstate;
|
||||
|
||||
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_NUMLOCK:
|
||||
modstate ^= KMOD_NUM;
|
||||
if ( ! (modstate&KMOD_NUM) )
|
||||
state = SDL_RELEASED;
|
||||
keysym->mod = (SDLMod)modstate;
|
||||
break;
|
||||
case SDLK_CAPSLOCK:
|
||||
modstate ^= KMOD_CAPS;
|
||||
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_NUMLOCK:
|
||||
case SDLK_CAPSLOCK:
|
||||
/* 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.timestamp = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* Invalid state -- bail */
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* Drop events that don't change state */
|
||||
if ( SDL_KeyState[keysym->sym] == state ) {
|
||||
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;
|
||||
if ( (SDL_EventOK == NULL) || SDL_EventOK(&event) ) {
|
||||
posted = 1;
|
||||
/*
|
||||
* jk 991215 - Added
|
||||
*/
|
||||
if (repeatable && (SDL_KeyRepeat.delay != 0)) {
|
||||
SDL_KeyRepeat.evt = event;
|
||||
SDL_KeyRepeat.firsttime = 1;
|
||||
SDL_KeyRepeat.timestamp=SDL_GetTicks();
|
||||
}
|
||||
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;
|
||||
SDL_PushEvent(&SDL_KeyRepeat.evt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int SDL_EnableKeyRepeat(int delay, int interval)
|
||||
{
|
||||
if ( delay < 0 ) {
|
||||
SDL_SetError("keyboard repeat delay less than zero");
|
||||
return(-1);
|
||||
}
|
||||
SDL_KeyRepeat.firsttime = 0;
|
||||
SDL_KeyRepeat.delay = delay;
|
||||
if ( interval < MINIMUM_REPEAT_INTERVAL ) {
|
||||
SDL_KeyRepeat.interval = MINIMUM_REPEAT_INTERVAL;
|
||||
} else {
|
||||
SDL_KeyRepeat.interval = interval;
|
||||
}
|
||||
SDL_KeyRepeat.timestamp = 0;
|
||||
return(0);
|
||||
}
|
||||
|
247
src/events/SDL_mouse.c
Normal file
247
src/events/SDL_mouse.c
Normal file
|
@ -0,0 +1,247 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@devolution.com
|
||||
*/
|
||||
|
||||
#ifdef SAVE_RCSID
|
||||
static char rcsid =
|
||||
"@(#) $Id$";
|
||||
#endif
|
||||
|
||||
/* General mouse handling code for SDL */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_events_c.h"
|
||||
#include "SDL_cursor_c.h"
|
||||
#include "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 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_ButtonState = 0;
|
||||
|
||||
/* That's it! */
|
||||
return(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->offset ) {
|
||||
*y -= SDL_VideoSurface->offset/SDL_VideoSurface->pitch;
|
||||
*x -= (SDL_VideoSurface->offset%SDL_VideoSurface->pitch)/
|
||||
SDL_VideoSurface->format->BytesPerPixel;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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;
|
||||
|
||||
/* Don't handle mouse motion if there's no cursor surface */
|
||||
if ( SDL_VideoSurface == NULL ) {
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* 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_VideoSurface->w )
|
||||
X = SDL_VideoSurface->w-1;
|
||||
else
|
||||
X = (Uint16)x;
|
||||
|
||||
if ( y < 0 )
|
||||
Y = 0;
|
||||
else
|
||||
if ( y >= SDL_VideoSurface->h )
|
||||
Y = SDL_VideoSurface->h-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;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
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;
|
||||
|
||||
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_VideoSurface->w )
|
||||
x = SDL_VideoSurface->w-1;
|
||||
|
||||
if ( y < 0 )
|
||||
y = 0;
|
||||
else
|
||||
if ( y >= SDL_VideoSurface->h )
|
||||
y = SDL_VideoSurface->h-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);
|
||||
}
|
||||
|
84
src/events/SDL_quit.c
Normal file
84
src/events/SDL_quit.c
Normal file
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@devolution.com
|
||||
*/
|
||||
|
||||
#ifdef SAVE_RCSID
|
||||
static char rcsid =
|
||||
"@(#) $Id$";
|
||||
#endif
|
||||
|
||||
/* General quit handling code for SDL */
|
||||
|
||||
#include <stdio.h>
|
||||
#ifndef NO_SIGNAL_H
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_events_c.h"
|
||||
|
||||
|
||||
#ifndef NO_SIGNAL_H
|
||||
static void SDL_HandleSIG(int sig)
|
||||
{
|
||||
/* Reset the signal handler */
|
||||
signal(sig, SDL_HandleSIG);
|
||||
|
||||
/* Signal a quit interrupt */
|
||||
SDL_PrivateQuit();
|
||||
}
|
||||
#endif /* NO_SIGNAL_H */
|
||||
|
||||
/* Public functions */
|
||||
int SDL_QuitInit(void)
|
||||
{
|
||||
#ifndef NO_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 /* NO_SIGNAL_H */
|
||||
|
||||
/* That's it! */
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
76
src/events/SDL_resize.c
Normal file
76
src/events/SDL_resize.c
Normal file
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@devolution.com
|
||||
*/
|
||||
|
||||
#ifdef SAVE_RCSID
|
||||
static char rcsid =
|
||||
"@(#) $Id$";
|
||||
#endif
|
||||
|
||||
/* Resize event handling code for SDL */
|
||||
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_events_c.h"
|
||||
#include "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)) ) {
|
||||
return(0);
|
||||
}
|
||||
last_resize.w = w;
|
||||
last_resize.h = h;
|
||||
if ( ! SDL_VideoSurface ||
|
||||
((w == SDL_VideoSurface->w) && (h == SDL_VideoSurface->h)) ) {
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
42
src/events/SDL_sysevents.h
Normal file
42
src/events/SDL_sysevents.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@devolution.com
|
||||
*/
|
||||
|
||||
#ifdef SAVE_RCSID
|
||||
static char rcsid =
|
||||
"@(#) $Id$";
|
||||
#endif
|
||||
|
||||
#include "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 macintosh /* MacOS 7/8 don't support preemptive multi-tasking */
|
||||
#define CANT_THREAD_EVENTS
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue