include/SDL_events.h

/* [<][>]
[^][v][top][bottom][index][help] */

FUNCTIONS

This source file includes following functions.
  1. SDL_EVENTMASK

   1 /*
   2     SDL - Simple DirectMedia Layer
   3     Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
   4 
   5     This library is free software; you can redistribute it and/or
   6     modify it under the terms of the GNU Library General Public
   7     License as published by the Free Software Foundation; either
   8     version 2 of the License, or (at your option) any later version.
   9 
  10     This library is distributed in the hope that it will be useful,
  11     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13     Library General Public License for more details.
  14 
  15     You should have received a copy of the GNU Library General Public
  16     License along with this library; if not, write to the Free
  17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18 
  19     Sam Lantinga
  20     slouken@devolution.com
  21 */
  22 
  23 #ifdef SAVE_RCSID
  24 static char rcsid =
  25  "@(#) $Id: SDL_events.h,v 1.4.2.15 2001/03/05 17:09:44 hercules Exp $";
  26 #endif
  27 
  28 /* Include file for SDL event handling */
  29 
  30 #ifndef _SDL_events_h
  31 #define _SDL_events_h
  32 
  33 #include "SDL_types.h"
  34 #include "SDL_active.h"
  35 #include "SDL_keyboard.h"
  36 #include "SDL_mouse.h"
  37 #include "SDL_joystick.h"
  38 #include "SDL_quit.h"
  39 
  40 #include "begin_code.h"
  41 /* Set up for C function definitions, even when using C++ */
  42 #ifdef __cplusplus
  43 extern "C" {
  44 #endif
  45 
  46 /* Event enumerations */
  47 enum { SDL_NOEVENT = 0,                 /* Unused (do not remove) */
  48        SDL_ACTIVEEVENT,                 /* Application loses/gains visibility */
  49        SDL_KEYDOWN,                     /* Keys pressed */
  50        SDL_KEYUP,                       /* Keys released */
  51        SDL_MOUSEMOTION,                 /* Mouse moved */
  52        SDL_MOUSEBUTTONDOWN,             /* Mouse button pressed */
  53        SDL_MOUSEBUTTONUP,               /* Mouse button released */
  54        SDL_JOYAXISMOTION,               /* Joystick axis motion */
  55        SDL_JOYBALLMOTION,               /* Joystick trackball motion */
  56        SDL_JOYHATMOTION,                /* Joystick hat position change */
  57        SDL_JOYBUTTONDOWN,               /* Joystick button pressed */
  58        SDL_JOYBUTTONUP,                 /* Joystick button released */
  59        SDL_QUIT,                        /* User-requested quit */
  60        SDL_SYSWMEVENT,                  /* System specific event */
  61        SDL_EVENT_RESERVEDA,             /* Reserved for future use.. */
  62        SDL_EVENT_RESERVEDB,             /* Reserved for future use.. */
  63        SDL_VIDEORESIZE,                 /* User resized video mode */
  64        SDL_VIDEOEXPOSE,                 /* Screen needs to be redrawn */
  65        SDL_EVENT_RESERVED2,             /* Reserved for future use.. */
  66        SDL_EVENT_RESERVED3,             /* Reserved for future use.. */
  67        SDL_EVENT_RESERVED4,             /* Reserved for future use.. */
  68        SDL_EVENT_RESERVED5,             /* Reserved for future use.. */
  69        SDL_EVENT_RESERVED6,             /* Reserved for future use.. */
  70        SDL_EVENT_RESERVED7,             /* Reserved for future use.. */
  71        /* Events SDL_USEREVENT through SDL_MAXEVENTS-1 are for your use */
  72        SDL_USEREVENT = 24,
  73        /* This last event is only for bounding internal arrays
  74           It is the number of bits in the event mask datatype -- Uint32
  75         */
  76        SDL_NUMEVENTS = 32
  77 };
  78 
  79 /* Predefined event masks */
  80 #define SDL_EVENTMASK(X)        (1<<(X))
     /* [<][>][^][v][top][bottom][index][help] */
  81 enum {
  82         SDL_ACTIVEEVENTMASK     = SDL_EVENTMASK(SDL_ACTIVEEVENT),
  83         SDL_KEYDOWNMASK         = SDL_EVENTMASK(SDL_KEYDOWN),
  84         SDL_KEYUPMASK           = SDL_EVENTMASK(SDL_KEYUP),
  85         SDL_MOUSEMOTIONMASK     = SDL_EVENTMASK(SDL_MOUSEMOTION),
  86         SDL_MOUSEBUTTONDOWNMASK = SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN),
  87         SDL_MOUSEBUTTONUPMASK   = SDL_EVENTMASK(SDL_MOUSEBUTTONUP),
  88         SDL_MOUSEEVENTMASK      = SDL_EVENTMASK(SDL_MOUSEMOTION)|
  89                                   SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN)|
  90                                   SDL_EVENTMASK(SDL_MOUSEBUTTONUP),
  91         SDL_JOYAXISMOTIONMASK   = SDL_EVENTMASK(SDL_JOYAXISMOTION),
  92         SDL_JOYBALLMOTIONMASK   = SDL_EVENTMASK(SDL_JOYBALLMOTION),
  93         SDL_JOYHATMOTIONMASK    = SDL_EVENTMASK(SDL_JOYHATMOTION),
  94         SDL_JOYBUTTONDOWNMASK   = SDL_EVENTMASK(SDL_JOYBUTTONDOWN),
  95         SDL_JOYBUTTONUPMASK     = SDL_EVENTMASK(SDL_JOYBUTTONUP),
  96         SDL_JOYEVENTMASK        = SDL_EVENTMASK(SDL_JOYAXISMOTION)|
  97                                   SDL_EVENTMASK(SDL_JOYBALLMOTION)|
  98                                   SDL_EVENTMASK(SDL_JOYHATMOTION)|
  99                                   SDL_EVENTMASK(SDL_JOYBUTTONDOWN)|
 100                                   SDL_EVENTMASK(SDL_JOYBUTTONUP),
 101         SDL_VIDEORESIZEMASK     = SDL_EVENTMASK(SDL_VIDEORESIZE),
 102         SDL_VIDEOEXPOSEMASK     = SDL_EVENTMASK(SDL_VIDEOEXPOSE),
 103         SDL_QUITMASK            = SDL_EVENTMASK(SDL_QUIT),
 104         SDL_SYSWMEVENTMASK      = SDL_EVENTMASK(SDL_SYSWMEVENT)
 105 };
 106 #define SDL_ALLEVENTS           0xFFFFFFFF
 107 
 108 /* Application visibility event structure */
 109 typedef struct {
 110         Uint8 type;     /* SDL_ACTIVEEVENT */
 111         Uint8 gain;     /* Whether given states were gained or lost (1/0) */
 112         Uint8 state;    /* A mask of the focus states */
 113 } SDL_ActiveEvent;
 114 
 115 /* Keyboard event structure */
 116 typedef struct {
 117         Uint8 type;     /* SDL_KEYDOWN or SDL_KEYUP */
 118         Uint8 which;    /* The keyboard device index */
 119         Uint8 state;    /* SDL_PRESSED or SDL_RELEASED */
 120         SDL_keysym keysym;
 121 } SDL_KeyboardEvent;
 122 
 123 /* Mouse motion event structure */
 124 typedef struct {
 125         Uint8 type;     /* SDL_MOUSEMOTION */
 126         Uint8 which;    /* The mouse device index */
 127         Uint8 state;    /* The current button state */
 128         Uint16 x, y;    /* The X/Y coordinates of the mouse */
 129         Sint16 xrel;    /* The relative motion in the X direction */
 130         Sint16 yrel;    /* The relative motion in the Y direction */
 131 } SDL_MouseMotionEvent;
 132 
 133 /* Mouse button event structure */
 134 typedef struct {
 135         Uint8 type;     /* SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP */
 136         Uint8 which;    /* The mouse device index */
 137         Uint8 button;   /* The mouse button index */
 138         Uint8 state;    /* SDL_PRESSED or SDL_RELEASED */
 139         Uint16 x, y;    /* The X/Y coordinates of the mouse at press time */
 140 } SDL_MouseButtonEvent;
 141 
 142 /* Joystick axis motion event structure */
 143 typedef struct {
 144         Uint8 type;     /* SDL_JOYAXISMOTION */
 145         Uint8 which;    /* The joystick device index */
 146         Uint8 axis;     /* The joystick axis index */
 147         Sint16 value;   /* The axis value (range: -32768 to 32767) */
 148 } SDL_JoyAxisEvent;
 149 
 150 /* Joystick trackball motion event structure */
 151 typedef struct {
 152         Uint8 type;     /* SDL_JOYBALLMOTION */
 153         Uint8 which;    /* The joystick device index */
 154         Uint8 ball;     /* The joystick trackball index */
 155         Sint16 xrel;    /* The relative motion in the X direction */
 156         Sint16 yrel;    /* The relative motion in the Y direction */
 157 } SDL_JoyBallEvent;
 158 
 159 /* Joystick hat position change event structure */
 160 typedef struct {
 161         Uint8 type;     /* SDL_JOYHATMOTION */
 162         Uint8 which;    /* The joystick device index */
 163         Uint8 hat;      /* The joystick hat index */
 164         Uint8 value;    /* The hat position value:
 165                                 8   1   2
 166                                 7   0   3
 167                                 6   5   4
 168                            Note that zero means the POV is centered.
 169                         */
 170 } SDL_JoyHatEvent;
 171 
 172 /* Joystick button event structure */
 173 typedef struct {
 174         Uint8 type;     /* SDL_JOYBUTTONDOWN or SDL_JOYBUTTONUP */
 175         Uint8 which;    /* The joystick device index */
 176         Uint8 button;   /* The joystick button index */
 177         Uint8 state;    /* SDL_PRESSED or SDL_RELEASED */
 178 } SDL_JoyButtonEvent;
 179 
 180 /* The "window resized" event
 181    When you get this event, you are responsible for setting a new video
 182    mode with the new width and height.
 183  */
 184 typedef struct {
 185         Uint8 type;     /* SDL_VIDEORESIZE */
 186         int w;          /* New width */
 187         int h;          /* New height */
 188 } SDL_ResizeEvent;
 189 
 190 /* The "screen redraw" event */
 191 typedef struct {
 192         Uint8 type;     /* SDL_VIDEOEXPOSE */
 193 } SDL_ExposeEvent;
 194 
 195 /* The "quit requested" event */
 196 typedef struct {
 197         Uint8 type;     /* SDL_QUIT */
 198 } SDL_QuitEvent;
 199 
 200 /* A user-defined event type */
 201 typedef struct {
 202         Uint8 type;     /* SDL_USEREVENT through SDL_NUMEVENTS-1 */
 203         int code;       /* User defined event code */
 204         void *data1;    /* User defined data pointer */
 205         void *data2;    /* User defined data pointer */
 206 } SDL_UserEvent;
 207 
 208 /* If you want to use this event, you should include SDL_syswm.h */
 209 struct SDL_SysWMmsg;
 210 typedef struct SDL_SysWMmsg SDL_SysWMmsg;
 211 typedef struct {
 212         Uint8 type;
 213         SDL_SysWMmsg *msg;
 214 } SDL_SysWMEvent;
 215 
 216 /* General event structure */
 217 typedef union {
 218         Uint8 type;
 219         SDL_ActiveEvent active;
 220         SDL_KeyboardEvent key;
 221         SDL_MouseMotionEvent motion;
 222         SDL_MouseButtonEvent button;
 223         SDL_JoyAxisEvent jaxis;
 224         SDL_JoyBallEvent jball;
 225         SDL_JoyHatEvent jhat;
 226         SDL_JoyButtonEvent jbutton;
 227         SDL_ResizeEvent resize;
 228         SDL_ExposeEvent expose;
 229         SDL_QuitEvent quit;
 230         SDL_UserEvent user;
 231         SDL_SysWMEvent syswm;
 232 } SDL_Event;
 233 
 234 
 235 /* Function prototypes */
 236 
 237 /* Pumps the event loop, gathering events from the input devices.
 238    This function updates the event queue and internal input device state.
 239    This should only be run in the thread that sets the video mode.
 240 */
 241 extern DECLSPEC void SDL_PumpEvents(void);
 242 
 243 /* Checks the event queue for messages and optionally returns them.
 244    If 'action' is SDL_ADDEVENT, up to 'numevents' events will be added to
 245    the back of the event queue.
 246    If 'action' is SDL_PEEKEVENT, up to 'numevents' events at the front
 247    of the event queue, matching 'mask', will be returned and will not
 248    be removed from the queue.
 249    If 'action' is SDL_GETEVENT, up to 'numevents' events at the front 
 250    of the event queue, matching 'mask', will be returned and will be
 251    removed from the queue.
 252    This function returns the number of events actually stored, or -1
 253    if there was an error.  This function is thread-safe.
 254 */
 255 typedef enum {
 256         SDL_ADDEVENT,
 257         SDL_PEEKEVENT,
 258         SDL_GETEVENT
 259 } SDL_eventaction;
 260 /* */
 261 extern DECLSPEC int SDL_PeepEvents(SDL_Event *events, int numevents,
 262                                 SDL_eventaction action, Uint32 mask);
 263 
 264 /* Polls for currently pending events, and returns 1 if there are any pending
 265    events, or 0 if there are none available.  If 'event' is not NULL, the next
 266    event is removed from the queue and stored in that area.
 267  */
 268 extern DECLSPEC int SDL_PollEvent(SDL_Event *event);
 269 
 270 /* Waits indefinitely for the next available event, returning 1, or 0 if there
 271    was an error while waiting for events.  If 'event' is not NULL, the next
 272    event is removed from the queue and stored in that area.
 273  */
 274 extern DECLSPEC int SDL_WaitEvent(SDL_Event *event);
 275 
 276 /* Add an event to the event queue.
 277    This function returns 0, or -1 if the event couldn't be added to
 278    the event queue.  If the event queue is full, this function fails.
 279  */
 280 extern DECLSPEC int SDL_PushEvent(SDL_Event *event);
 281 
 282 /*
 283   This function sets up a filter to process all events before they
 284   change internal state and are posted to the internal event queue.
 285 
 286   The filter is protypted as:
 287 */
 288 typedef int (*SDL_EventFilter)(const SDL_Event *event);
 289 /*
 290   If the filter returns 1, then the event will be added to the internal queue.
 291   If it returns 0, then the event will be dropped from the queue, but the 
 292   internal state will still be updated.  This allows selective filtering of
 293   dynamically arriving events.
 294 
 295   WARNING:  Be very careful of what you do in the event filter function, as 
 296             it may run in a different thread!
 297 
 298   There is one caveat when dealing with the SDL_QUITEVENT event type.  The
 299   event filter is only called when the window manager desires to close the
 300   application window.  If the event filter returns 1, then the window will
 301   be closed, otherwise the window will remain open if possible.
 302   If the quit event is generated by an interrupt signal, it will bypass the
 303   internal queue and be delivered to the application at the next event poll.
 304 */
 305 extern DECLSPEC void SDL_SetEventFilter(SDL_EventFilter filter);
 306 
 307 /*
 308   Return the current event filter - can be used to "chain" filters.
 309   If there is no event filter set, this function returns NULL.
 310 */
 311 extern DECLSPEC SDL_EventFilter SDL_GetEventFilter(void);
 312 
 313 /*
 314   This function allows you to set the state of processing certain events.
 315   If 'state' is set to SDL_IGNORE, that event will be automatically dropped
 316   from the event queue and will not event be filtered.
 317   If 'state' is set to SDL_ENABLE, that event will be processed normally.
 318   If 'state' is set to SDL_QUERY, SDL_EventState() will return the 
 319   current processing state of the specified event.
 320 */
 321 #define SDL_QUERY       -1
 322 #define SDL_IGNORE       0
 323 #define SDL_DISABLE      0
 324 #define SDL_ENABLE       1
 325 extern DECLSPEC Uint8 SDL_EventState(Uint8 type, int state);
 326 
 327 
 328 /* Ends C function definitions when using C++ */
 329 #ifdef __cplusplus
 330 }
 331 #endif
 332 #include "close_code.h"
 333 
 334 #endif /* _SDL_events_h */

/* [<][>][^][v][top][bottom][index][help] */