include/SDL_events.h
changeset 0 74212992fb08
child 251 b8688cfdc232
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/include/SDL_events.h	Thu Apr 26 16:45:43 2001 +0000
     1.3 @@ -0,0 +1,334 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Library General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Library General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Library General Public
    1.19 +    License along with this library; if not, write to the Free
    1.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@devolution.com
    1.24 +*/
    1.25 +
    1.26 +#ifdef SAVE_RCSID
    1.27 +static char rcsid =
    1.28 + "@(#) $Id$";
    1.29 +#endif
    1.30 +
    1.31 +/* Include file for SDL event handling */
    1.32 +
    1.33 +#ifndef _SDL_events_h
    1.34 +#define _SDL_events_h
    1.35 +
    1.36 +#include "SDL_types.h"
    1.37 +#include "SDL_active.h"
    1.38 +#include "SDL_keyboard.h"
    1.39 +#include "SDL_mouse.h"
    1.40 +#include "SDL_joystick.h"
    1.41 +#include "SDL_quit.h"
    1.42 +
    1.43 +#include "begin_code.h"
    1.44 +/* Set up for C function definitions, even when using C++ */
    1.45 +#ifdef __cplusplus
    1.46 +extern "C" {
    1.47 +#endif
    1.48 +
    1.49 +/* Event enumerations */
    1.50 +enum { SDL_NOEVENT = 0,			/* Unused (do not remove) */
    1.51 +       SDL_ACTIVEEVENT,			/* Application loses/gains visibility */
    1.52 +       SDL_KEYDOWN,			/* Keys pressed */
    1.53 +       SDL_KEYUP,			/* Keys released */
    1.54 +       SDL_MOUSEMOTION,			/* Mouse moved */
    1.55 +       SDL_MOUSEBUTTONDOWN,		/* Mouse button pressed */
    1.56 +       SDL_MOUSEBUTTONUP,		/* Mouse button released */
    1.57 +       SDL_JOYAXISMOTION,		/* Joystick axis motion */
    1.58 +       SDL_JOYBALLMOTION,		/* Joystick trackball motion */
    1.59 +       SDL_JOYHATMOTION,		/* Joystick hat position change */
    1.60 +       SDL_JOYBUTTONDOWN,		/* Joystick button pressed */
    1.61 +       SDL_JOYBUTTONUP,			/* Joystick button released */
    1.62 +       SDL_QUIT,			/* User-requested quit */
    1.63 +       SDL_SYSWMEVENT,			/* System specific event */
    1.64 +       SDL_EVENT_RESERVEDA,		/* Reserved for future use.. */
    1.65 +       SDL_EVENT_RESERVEDB,		/* Reserved for future use.. */
    1.66 +       SDL_VIDEORESIZE,			/* User resized video mode */
    1.67 +       SDL_VIDEOEXPOSE,			/* Screen needs to be redrawn */
    1.68 +       SDL_EVENT_RESERVED2,		/* Reserved for future use.. */
    1.69 +       SDL_EVENT_RESERVED3,		/* Reserved for future use.. */
    1.70 +       SDL_EVENT_RESERVED4,		/* Reserved for future use.. */
    1.71 +       SDL_EVENT_RESERVED5,		/* Reserved for future use.. */
    1.72 +       SDL_EVENT_RESERVED6,		/* Reserved for future use.. */
    1.73 +       SDL_EVENT_RESERVED7,		/* Reserved for future use.. */
    1.74 +       /* Events SDL_USEREVENT through SDL_MAXEVENTS-1 are for your use */
    1.75 +       SDL_USEREVENT = 24,
    1.76 +       /* This last event is only for bounding internal arrays
    1.77 +	  It is the number of bits in the event mask datatype -- Uint32
    1.78 +        */
    1.79 +       SDL_NUMEVENTS = 32
    1.80 +};
    1.81 +
    1.82 +/* Predefined event masks */
    1.83 +#define SDL_EVENTMASK(X)	(1<<(X))
    1.84 +enum {
    1.85 +	SDL_ACTIVEEVENTMASK	= SDL_EVENTMASK(SDL_ACTIVEEVENT),
    1.86 +	SDL_KEYDOWNMASK		= SDL_EVENTMASK(SDL_KEYDOWN),
    1.87 +	SDL_KEYUPMASK		= SDL_EVENTMASK(SDL_KEYUP),
    1.88 +	SDL_MOUSEMOTIONMASK	= SDL_EVENTMASK(SDL_MOUSEMOTION),
    1.89 +	SDL_MOUSEBUTTONDOWNMASK	= SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN),
    1.90 +	SDL_MOUSEBUTTONUPMASK	= SDL_EVENTMASK(SDL_MOUSEBUTTONUP),
    1.91 +	SDL_MOUSEEVENTMASK	= SDL_EVENTMASK(SDL_MOUSEMOTION)|
    1.92 +	                          SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN)|
    1.93 +	                          SDL_EVENTMASK(SDL_MOUSEBUTTONUP),
    1.94 +	SDL_JOYAXISMOTIONMASK	= SDL_EVENTMASK(SDL_JOYAXISMOTION),
    1.95 +	SDL_JOYBALLMOTIONMASK	= SDL_EVENTMASK(SDL_JOYBALLMOTION),
    1.96 +	SDL_JOYHATMOTIONMASK	= SDL_EVENTMASK(SDL_JOYHATMOTION),
    1.97 +	SDL_JOYBUTTONDOWNMASK	= SDL_EVENTMASK(SDL_JOYBUTTONDOWN),
    1.98 +	SDL_JOYBUTTONUPMASK	= SDL_EVENTMASK(SDL_JOYBUTTONUP),
    1.99 +	SDL_JOYEVENTMASK	= SDL_EVENTMASK(SDL_JOYAXISMOTION)|
   1.100 +	                          SDL_EVENTMASK(SDL_JOYBALLMOTION)|
   1.101 +	                          SDL_EVENTMASK(SDL_JOYHATMOTION)|
   1.102 +	                          SDL_EVENTMASK(SDL_JOYBUTTONDOWN)|
   1.103 +	                          SDL_EVENTMASK(SDL_JOYBUTTONUP),
   1.104 +	SDL_VIDEORESIZEMASK	= SDL_EVENTMASK(SDL_VIDEORESIZE),
   1.105 +	SDL_VIDEOEXPOSEMASK	= SDL_EVENTMASK(SDL_VIDEOEXPOSE),
   1.106 +	SDL_QUITMASK		= SDL_EVENTMASK(SDL_QUIT),
   1.107 +	SDL_SYSWMEVENTMASK	= SDL_EVENTMASK(SDL_SYSWMEVENT)
   1.108 +};
   1.109 +#define SDL_ALLEVENTS		0xFFFFFFFF
   1.110 +
   1.111 +/* Application visibility event structure */
   1.112 +typedef struct {
   1.113 +	Uint8 type;	/* SDL_ACTIVEEVENT */
   1.114 +	Uint8 gain;	/* Whether given states were gained or lost (1/0) */
   1.115 +	Uint8 state;	/* A mask of the focus states */
   1.116 +} SDL_ActiveEvent;
   1.117 +
   1.118 +/* Keyboard event structure */
   1.119 +typedef struct {
   1.120 +	Uint8 type;	/* SDL_KEYDOWN or SDL_KEYUP */
   1.121 +	Uint8 which;	/* The keyboard device index */
   1.122 +	Uint8 state;	/* SDL_PRESSED or SDL_RELEASED */
   1.123 +	SDL_keysym keysym;
   1.124 +} SDL_KeyboardEvent;
   1.125 +
   1.126 +/* Mouse motion event structure */
   1.127 +typedef struct {
   1.128 +	Uint8 type;	/* SDL_MOUSEMOTION */
   1.129 +	Uint8 which;	/* The mouse device index */
   1.130 +	Uint8 state;	/* The current button state */
   1.131 +	Uint16 x, y;	/* The X/Y coordinates of the mouse */
   1.132 +	Sint16 xrel;	/* The relative motion in the X direction */
   1.133 +	Sint16 yrel;	/* The relative motion in the Y direction */
   1.134 +} SDL_MouseMotionEvent;
   1.135 +
   1.136 +/* Mouse button event structure */
   1.137 +typedef struct {
   1.138 +	Uint8 type;	/* SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP */
   1.139 +	Uint8 which;	/* The mouse device index */
   1.140 +	Uint8 button;	/* The mouse button index */
   1.141 +	Uint8 state;	/* SDL_PRESSED or SDL_RELEASED */
   1.142 +	Uint16 x, y;	/* The X/Y coordinates of the mouse at press time */
   1.143 +} SDL_MouseButtonEvent;
   1.144 +
   1.145 +/* Joystick axis motion event structure */
   1.146 +typedef struct {
   1.147 +	Uint8 type;	/* SDL_JOYAXISMOTION */
   1.148 +	Uint8 which;	/* The joystick device index */
   1.149 +	Uint8 axis;	/* The joystick axis index */
   1.150 +	Sint16 value;	/* The axis value (range: -32768 to 32767) */
   1.151 +} SDL_JoyAxisEvent;
   1.152 +
   1.153 +/* Joystick trackball motion event structure */
   1.154 +typedef struct {
   1.155 +	Uint8 type;	/* SDL_JOYBALLMOTION */
   1.156 +	Uint8 which;	/* The joystick device index */
   1.157 +	Uint8 ball;	/* The joystick trackball index */
   1.158 +	Sint16 xrel;	/* The relative motion in the X direction */
   1.159 +	Sint16 yrel;	/* The relative motion in the Y direction */
   1.160 +} SDL_JoyBallEvent;
   1.161 +
   1.162 +/* Joystick hat position change event structure */
   1.163 +typedef struct {
   1.164 +	Uint8 type;	/* SDL_JOYHATMOTION */
   1.165 +	Uint8 which;	/* The joystick device index */
   1.166 +	Uint8 hat;	/* The joystick hat index */
   1.167 +	Uint8 value;	/* The hat position value:
   1.168 +				8   1   2
   1.169 +				7   0   3
   1.170 +				6   5   4
   1.171 +			   Note that zero means the POV is centered.
   1.172 +			*/
   1.173 +} SDL_JoyHatEvent;
   1.174 +
   1.175 +/* Joystick button event structure */
   1.176 +typedef struct {
   1.177 +	Uint8 type;	/* SDL_JOYBUTTONDOWN or SDL_JOYBUTTONUP */
   1.178 +	Uint8 which;	/* The joystick device index */
   1.179 +	Uint8 button;	/* The joystick button index */
   1.180 +	Uint8 state;	/* SDL_PRESSED or SDL_RELEASED */
   1.181 +} SDL_JoyButtonEvent;
   1.182 +
   1.183 +/* The "window resized" event
   1.184 +   When you get this event, you are responsible for setting a new video
   1.185 +   mode with the new width and height.
   1.186 + */
   1.187 +typedef struct {
   1.188 +	Uint8 type;	/* SDL_VIDEORESIZE */
   1.189 +	int w;		/* New width */
   1.190 +	int h;		/* New height */
   1.191 +} SDL_ResizeEvent;
   1.192 +
   1.193 +/* The "screen redraw" event */
   1.194 +typedef struct {
   1.195 +	Uint8 type;	/* SDL_VIDEOEXPOSE */
   1.196 +} SDL_ExposeEvent;
   1.197 +
   1.198 +/* The "quit requested" event */
   1.199 +typedef struct {
   1.200 +	Uint8 type;	/* SDL_QUIT */
   1.201 +} SDL_QuitEvent;
   1.202 +
   1.203 +/* A user-defined event type */
   1.204 +typedef struct {
   1.205 +	Uint8 type;	/* SDL_USEREVENT through SDL_NUMEVENTS-1 */
   1.206 +	int code;	/* User defined event code */
   1.207 +	void *data1;	/* User defined data pointer */
   1.208 +	void *data2;	/* User defined data pointer */
   1.209 +} SDL_UserEvent;
   1.210 +
   1.211 +/* If you want to use this event, you should include SDL_syswm.h */
   1.212 +struct SDL_SysWMmsg;
   1.213 +typedef struct SDL_SysWMmsg SDL_SysWMmsg;
   1.214 +typedef struct {
   1.215 +	Uint8 type;
   1.216 +	SDL_SysWMmsg *msg;
   1.217 +} SDL_SysWMEvent;
   1.218 +
   1.219 +/* General event structure */
   1.220 +typedef union {
   1.221 +	Uint8 type;
   1.222 +	SDL_ActiveEvent active;
   1.223 +	SDL_KeyboardEvent key;
   1.224 +	SDL_MouseMotionEvent motion;
   1.225 +	SDL_MouseButtonEvent button;
   1.226 +	SDL_JoyAxisEvent jaxis;
   1.227 +	SDL_JoyBallEvent jball;
   1.228 +	SDL_JoyHatEvent jhat;
   1.229 +	SDL_JoyButtonEvent jbutton;
   1.230 +	SDL_ResizeEvent resize;
   1.231 +	SDL_ExposeEvent expose;
   1.232 +	SDL_QuitEvent quit;
   1.233 +	SDL_UserEvent user;
   1.234 +	SDL_SysWMEvent syswm;
   1.235 +} SDL_Event;
   1.236 +
   1.237 +
   1.238 +/* Function prototypes */
   1.239 +
   1.240 +/* Pumps the event loop, gathering events from the input devices.
   1.241 +   This function updates the event queue and internal input device state.
   1.242 +   This should only be run in the thread that sets the video mode.
   1.243 +*/
   1.244 +extern DECLSPEC void SDL_PumpEvents(void);
   1.245 +
   1.246 +/* Checks the event queue for messages and optionally returns them.
   1.247 +   If 'action' is SDL_ADDEVENT, up to 'numevents' events will be added to
   1.248 +   the back of the event queue.
   1.249 +   If 'action' is SDL_PEEKEVENT, up to 'numevents' events at the front
   1.250 +   of the event queue, matching 'mask', will be returned and will not
   1.251 +   be removed from the queue.
   1.252 +   If 'action' is SDL_GETEVENT, up to 'numevents' events at the front 
   1.253 +   of the event queue, matching 'mask', will be returned and will be
   1.254 +   removed from the queue.
   1.255 +   This function returns the number of events actually stored, or -1
   1.256 +   if there was an error.  This function is thread-safe.
   1.257 +*/
   1.258 +typedef enum {
   1.259 +	SDL_ADDEVENT,
   1.260 +	SDL_PEEKEVENT,
   1.261 +	SDL_GETEVENT
   1.262 +} SDL_eventaction;
   1.263 +/* */
   1.264 +extern DECLSPEC int SDL_PeepEvents(SDL_Event *events, int numevents,
   1.265 +				SDL_eventaction action, Uint32 mask);
   1.266 +
   1.267 +/* Polls for currently pending events, and returns 1 if there are any pending
   1.268 +   events, or 0 if there are none available.  If 'event' is not NULL, the next
   1.269 +   event is removed from the queue and stored in that area.
   1.270 + */
   1.271 +extern DECLSPEC int SDL_PollEvent(SDL_Event *event);
   1.272 +
   1.273 +/* Waits indefinitely for the next available event, returning 1, or 0 if there
   1.274 +   was an error while waiting for events.  If 'event' is not NULL, the next
   1.275 +   event is removed from the queue and stored in that area.
   1.276 + */
   1.277 +extern DECLSPEC int SDL_WaitEvent(SDL_Event *event);
   1.278 +
   1.279 +/* Add an event to the event queue.
   1.280 +   This function returns 0, or -1 if the event couldn't be added to
   1.281 +   the event queue.  If the event queue is full, this function fails.
   1.282 + */
   1.283 +extern DECLSPEC int SDL_PushEvent(SDL_Event *event);
   1.284 +
   1.285 +/*
   1.286 +  This function sets up a filter to process all events before they
   1.287 +  change internal state and are posted to the internal event queue.
   1.288 +
   1.289 +  The filter is protypted as:
   1.290 +*/
   1.291 +typedef int (*SDL_EventFilter)(const SDL_Event *event);
   1.292 +/*
   1.293 +  If the filter returns 1, then the event will be added to the internal queue.
   1.294 +  If it returns 0, then the event will be dropped from the queue, but the 
   1.295 +  internal state will still be updated.  This allows selective filtering of
   1.296 +  dynamically arriving events.
   1.297 +
   1.298 +  WARNING:  Be very careful of what you do in the event filter function, as 
   1.299 +            it may run in a different thread!
   1.300 +
   1.301 +  There is one caveat when dealing with the SDL_QUITEVENT event type.  The
   1.302 +  event filter is only called when the window manager desires to close the
   1.303 +  application window.  If the event filter returns 1, then the window will
   1.304 +  be closed, otherwise the window will remain open if possible.
   1.305 +  If the quit event is generated by an interrupt signal, it will bypass the
   1.306 +  internal queue and be delivered to the application at the next event poll.
   1.307 +*/
   1.308 +extern DECLSPEC void SDL_SetEventFilter(SDL_EventFilter filter);
   1.309 +
   1.310 +/*
   1.311 +  Return the current event filter - can be used to "chain" filters.
   1.312 +  If there is no event filter set, this function returns NULL.
   1.313 +*/
   1.314 +extern DECLSPEC SDL_EventFilter SDL_GetEventFilter(void);
   1.315 +
   1.316 +/*
   1.317 +  This function allows you to set the state of processing certain events.
   1.318 +  If 'state' is set to SDL_IGNORE, that event will be automatically dropped
   1.319 +  from the event queue and will not event be filtered.
   1.320 +  If 'state' is set to SDL_ENABLE, that event will be processed normally.
   1.321 +  If 'state' is set to SDL_QUERY, SDL_EventState() will return the 
   1.322 +  current processing state of the specified event.
   1.323 +*/
   1.324 +#define SDL_QUERY	-1
   1.325 +#define SDL_IGNORE	 0
   1.326 +#define SDL_DISABLE	 0
   1.327 +#define SDL_ENABLE	 1
   1.328 +extern DECLSPEC Uint8 SDL_EventState(Uint8 type, int state);
   1.329 +
   1.330 +
   1.331 +/* Ends C function definitions when using C++ */
   1.332 +#ifdef __cplusplus
   1.333 +}
   1.334 +#endif
   1.335 +#include "close_code.h"
   1.336 +
   1.337 +#endif /* _SDL_events_h */