include/SDL_events.h
author Sam Lantinga <slouken@libsdl.org>
Sun, 03 Mar 2013 01:01:33 -0800
changeset 6951 7833f01322b3
parent 6950 1ddb72193079
child 6964 c8aa24f05042
permissions -rw-r--r--
Updated touch API
* Normalized touch coordinates as floats in the 0...1 range
* Removed unused touchpad concepts from the API
* Added API functions to get active touch devices and current finger state
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    21 
    22 /**
    23  *  \file SDL_events.h
    24  *  
    25  *  Include file for SDL event handling.
    26  */
    27 
    28 #ifndef _SDL_events_h
    29 #define _SDL_events_h
    30 
    31 #include "SDL_stdinc.h"
    32 #include "SDL_error.h"
    33 #include "SDL_video.h"
    34 #include "SDL_keyboard.h"
    35 #include "SDL_mouse.h"
    36 #include "SDL_joystick.h"
    37 #include "SDL_gamecontroller.h"
    38 #include "SDL_quit.h"
    39 #include "SDL_gesture.h"
    40 #include "SDL_touch.h"
    41 
    42 #include "begin_code.h"
    43 /* Set up for C function definitions, even when using C++ */
    44 #ifdef __cplusplus
    45 /* *INDENT-OFF* */
    46 extern "C" {
    47 /* *INDENT-ON* */
    48 #endif
    49 
    50 /* General keyboard/mouse state definitions */
    51 #define SDL_RELEASED	0
    52 #define SDL_PRESSED	1
    53 
    54 /**
    55  * \brief The types of events that can be delivered.
    56  */
    57 typedef enum
    58 {
    59     SDL_FIRSTEVENT     = 0,     /**< Unused (do not remove) */
    60 
    61     /* Application events */
    62     SDL_QUIT           = 0x100, /**< User-requested quit */
    63 
    64     /* Window events */
    65     SDL_WINDOWEVENT    = 0x200, /**< Window state change */
    66     SDL_SYSWMEVENT,             /**< System specific event */
    67 
    68     /* Keyboard events */
    69     SDL_KEYDOWN        = 0x300, /**< Key pressed */
    70     SDL_KEYUP,                  /**< Key released */
    71     SDL_TEXTEDITING,            /**< Keyboard text editing (composition) */
    72     SDL_TEXTINPUT,              /**< Keyboard text input */
    73 
    74     /* Mouse events */
    75     SDL_MOUSEMOTION    = 0x400, /**< Mouse moved */
    76     SDL_MOUSEBUTTONDOWN,        /**< Mouse button pressed */
    77     SDL_MOUSEBUTTONUP,          /**< Mouse button released */
    78     SDL_MOUSEWHEEL,             /**< Mouse wheel motion */
    79 
    80     /* Tablet or multiple mice input device events */
    81     SDL_INPUTMOTION    = 0x500, /**< Input moved */
    82     SDL_INPUTBUTTONDOWN,        /**< Input button pressed */
    83     SDL_INPUTBUTTONUP,          /**< Input button released */
    84     SDL_INPUTWHEEL,             /**< Input wheel motion */
    85     SDL_INPUTPROXIMITYIN,       /**< Input pen entered proximity */
    86     SDL_INPUTPROXIMITYOUT,      /**< Input pen left proximity */
    87 
    88     /* Joystick events */
    89     SDL_JOYAXISMOTION  = 0x600, /**< Joystick axis motion */
    90     SDL_JOYBALLMOTION,          /**< Joystick trackball motion */
    91     SDL_JOYHATMOTION,           /**< Joystick hat position change */
    92     SDL_JOYBUTTONDOWN,          /**< Joystick button pressed */
    93     SDL_JOYBUTTONUP,            /**< Joystick button released */
    94     SDL_JOYDEVICEADDED,         /**< A new joystick has been inserted into the system */
    95     SDL_JOYDEVICEREMOVED,       /**< An opened joystick has been removed */
    96 
    97 	/* Game controller events */
    98 	SDL_CONTROLLERAXISMOTION  = 0x650, /**< Game controller axis motion */
    99 	SDL_CONTROLLERBUTTONDOWN,          /**< Game controller button pressed */
   100 	SDL_CONTROLLERBUTTONUP,            /**< Game controller button released */
   101 	SDL_CONTROLLERDEVICEADDED,         /**< A new Game controller has been inserted into the system */
   102 	SDL_CONTROLLERDEVICEREMOVED,       /**< An opened Game controller has been removed */
   103 
   104     /* Touch events */
   105     SDL_FINGERDOWN      = 0x700,
   106     SDL_FINGERUP,
   107     SDL_FINGERMOTION,
   108 
   109     /* Gesture events */
   110     SDL_DOLLARGESTURE   = 0x800,
   111     SDL_DOLLARRECORD,
   112     SDL_MULTIGESTURE,
   113 
   114     /* Clipboard events */
   115     SDL_CLIPBOARDUPDATE = 0x900, /**< The clipboard changed */
   116 
   117     /* Drag and drop events */
   118     SDL_DROPFILE        = 0x1000, /**< The system requests a file open */
   119 
   120     /** Events ::SDL_USEREVENT through ::SDL_LASTEVENT are for your use,
   121      *  and should be allocated with SDL_RegisterEvents()
   122      */
   123     SDL_USEREVENT    = 0x8000,
   124 
   125     /**
   126      *  This last event is only for bounding internal arrays
   127      */
   128     SDL_LASTEVENT    = 0xFFFF
   129 } SDL_EventType;
   130 
   131 /**
   132  *  \brief Fields shared by every event
   133  */
   134 typedef struct SDL_GenericEvent
   135 {
   136     Uint32 type;
   137     Uint32 timestamp;
   138 } SDL_GenericEvent;
   139     
   140 /**
   141  *  \brief Window state change event data (event.window.*)
   142  */
   143 typedef struct SDL_WindowEvent
   144 {
   145     Uint32 type;        /**< ::SDL_WINDOWEVENT */
   146     Uint32 timestamp;
   147     Uint32 windowID;    /**< The associated window */
   148     Uint8 event;        /**< ::SDL_WindowEventID */
   149     Uint8 padding1;
   150     Uint8 padding2;
   151     Uint8 padding3;
   152     Sint32 data1;       /**< event dependent data */
   153     Sint32 data2;       /**< event dependent data */
   154 } SDL_WindowEvent;
   155 
   156 /**
   157  *  \brief Keyboard button event structure (event.key.*)
   158  */
   159 typedef struct SDL_KeyboardEvent
   160 {
   161     Uint32 type;        /**< ::SDL_KEYDOWN or ::SDL_KEYUP */
   162     Uint32 timestamp;
   163     Uint32 windowID;    /**< The window with keyboard focus, if any */
   164     Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
   165     Uint8 repeat;       /**< Non-zero if this is a key repeat */
   166     Uint8 padding2;
   167     Uint8 padding3;
   168     SDL_Keysym keysym;  /**< The key that was pressed or released */
   169 } SDL_KeyboardEvent;
   170 
   171 #define SDL_TEXTEDITINGEVENT_TEXT_SIZE (32)
   172 /**
   173  *  \brief Keyboard text editing event structure (event.edit.*)
   174  */
   175 typedef struct SDL_TextEditingEvent
   176 {
   177     Uint32 type;                                /**< ::SDL_TEXTEDITING */
   178     Uint32 timestamp;
   179     Uint32 windowID;                            /**< The window with keyboard focus, if any */
   180     char text[SDL_TEXTEDITINGEVENT_TEXT_SIZE];  /**< The editing text */
   181     Sint32 start;                               /**< The start cursor of selected editing text */
   182     Sint32 length;                              /**< The length of selected editing text */
   183 } SDL_TextEditingEvent;
   184 
   185 
   186 #define SDL_TEXTINPUTEVENT_TEXT_SIZE (32)
   187 /**
   188  *  \brief Keyboard text input event structure (event.text.*)
   189  */
   190 typedef struct SDL_TextInputEvent
   191 {
   192     Uint32 type;                              /**< ::SDL_TEXTINPUT */
   193     Uint32 timestamp;
   194     Uint32 windowID;                          /**< The window with keyboard focus, if any */
   195     char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];  /**< The input text */
   196 } SDL_TextInputEvent;
   197 
   198 /**
   199  *  \brief Mouse motion event structure (event.motion.*)
   200  */
   201 typedef struct SDL_MouseMotionEvent
   202 {
   203     Uint32 type;        /**< ::SDL_MOUSEMOTION */
   204     Uint32 timestamp;
   205     Uint32 windowID;    /**< The window with mouse focus, if any */
   206     Uint32 which;       /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
   207     Uint8 state;        /**< The current button state */
   208     Uint8 padding1;
   209     Uint8 padding2;
   210     Uint8 padding3;
   211     Sint32 x;           /**< X coordinate, relative to window */
   212     Sint32 y;           /**< Y coordinate, relative to window */
   213     Sint32 xrel;        /**< The relative motion in the X direction */
   214     Sint32 yrel;        /**< The relative motion in the Y direction */
   215 } SDL_MouseMotionEvent;
   216 
   217 /**
   218  *  \brief Mouse button event structure (event.button.*)
   219  */
   220 typedef struct SDL_MouseButtonEvent
   221 {
   222     Uint32 type;        /**< ::SDL_MOUSEBUTTONDOWN or ::SDL_MOUSEBUTTONUP */
   223     Uint32 timestamp;
   224     Uint32 windowID;    /**< The window with mouse focus, if any */
   225     Uint32 which;       /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
   226     Uint8 button;       /**< The mouse button index */
   227     Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
   228     Uint8 padding1;
   229     Uint8 padding2;
   230     Sint32 x;           /**< X coordinate, relative to window */
   231     Sint32 y;           /**< Y coordinate, relative to window */
   232 } SDL_MouseButtonEvent;
   233 
   234 /**
   235  *  \brief Mouse wheel event structure (event.wheel.*)
   236  */
   237 typedef struct SDL_MouseWheelEvent
   238 {
   239     Uint32 type;        /**< ::SDL_MOUSEWHEEL */
   240     Uint32 timestamp;
   241     Uint32 windowID;    /**< The window with mouse focus, if any */
   242     Uint32 which;       /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
   243     Sint32 x;           /**< The amount scrolled horizontally */
   244     Sint32 y;           /**< The amount scrolled vertically */
   245 } SDL_MouseWheelEvent;
   246 
   247 /**
   248  *  \brief Joystick axis motion event structure (event.jaxis.*)
   249  */
   250 typedef struct SDL_JoyAxisEvent
   251 {
   252     Uint32 type;        /**< ::SDL_JOYAXISMOTION */
   253     Uint32 timestamp;
   254     Uint32 which;       /**< The joystick instance id */
   255     Uint8 axis;         /**< The joystick axis index */
   256     Uint8 padding1;
   257     Uint8 padding2;
   258     Uint8 padding3;
   259     Sint16 value;       /**< The axis value (range: -32768 to 32767) */
   260     Uint16 padding4;
   261 } SDL_JoyAxisEvent;
   262 
   263 /**
   264  *  \brief Joystick trackball motion event structure (event.jball.*)
   265  */
   266 typedef struct SDL_JoyBallEvent
   267 {
   268     Uint32 type;        /**< ::SDL_JOYBALLMOTION */
   269     Uint32 timestamp;
   270     Uint32 which;       /**< The joystick instance id */
   271     Uint8 ball;         /**< The joystick trackball index */
   272     Uint8 padding1;
   273     Uint8 padding2;
   274     Uint8 padding3;
   275     Sint16 xrel;        /**< The relative motion in the X direction */
   276     Sint16 yrel;        /**< The relative motion in the Y direction */
   277 } SDL_JoyBallEvent;
   278 
   279 /**
   280  *  \brief Joystick hat position change event structure (event.jhat.*)
   281  */
   282 typedef struct SDL_JoyHatEvent
   283 {
   284     Uint32 type;        /**< ::SDL_JOYHATMOTION */
   285     Uint32 timestamp;
   286     Uint32 which;       /**< The joystick instance id */
   287     Uint8 hat;          /**< The joystick hat index */
   288     Uint8 value;        /**< The hat position value.
   289                          *   \sa ::SDL_HAT_LEFTUP ::SDL_HAT_UP ::SDL_HAT_RIGHTUP
   290                          *   \sa ::SDL_HAT_LEFT ::SDL_HAT_CENTERED ::SDL_HAT_RIGHT
   291                          *   \sa ::SDL_HAT_LEFTDOWN ::SDL_HAT_DOWN ::SDL_HAT_RIGHTDOWN
   292                          *   
   293                          *   Note that zero means the POV is centered.
   294                          */
   295     Uint8 padding1;
   296     Uint8 padding2;
   297 } SDL_JoyHatEvent;
   298 
   299 /**
   300  *  \brief Joystick button event structure (event.jbutton.*)
   301  */
   302 typedef struct SDL_JoyButtonEvent
   303 {
   304     Uint32 type;        /**< ::SDL_JOYBUTTONDOWN or ::SDL_JOYBUTTONUP */
   305     Uint32 timestamp;
   306     Uint32 which;       /**< The joystick instance id */
   307     Uint8 button;       /**< The joystick button index */
   308     Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
   309     Uint8 padding1;
   310     Uint8 padding2;
   311 } SDL_JoyButtonEvent;
   312 
   313 /**
   314  *  \brief Joystick device event structure (event.jdevice.*)
   315  */
   316 typedef struct SDL_JoyDeviceEvent
   317 {
   318 	Uint32 type;        /**< ::SDL_JOYDEVICEADDED or ::SDL_JOYDEVICEREMOVED */
   319 	Uint32 timestamp;
   320 	Uint32 which;       /**< The joystick device index for the ADDED event, instance id for the REMOVED event */
   321 } SDL_JoyDeviceEvent;
   322 
   323 
   324 /**
   325  *  \brief Game controller axis motion event structure (event.caxis.*)
   326  */
   327 typedef struct SDL_ControllerAxisEvent
   328 {
   329     Uint32 type;        /**< ::SDL_CONTROLLERAXISMOTION */
   330     Uint32 timestamp;
   331     Uint32 which;       /**< The joystick instance id */
   332     Uint8 axis;         /**< The controller axis (SDL_GameControllerAxis) */
   333     Uint8 padding1;
   334     Uint8 padding2;
   335     Uint8 padding3;
   336     Sint16 value;       /**< The axis value (range: -32768 to 32767) */
   337     Uint16 padding4;
   338 } SDL_ControllerAxisEvent;
   339 
   340 
   341 /**
   342  *  \brief Game controller button event structure (event.cbutton.*)
   343  */
   344 typedef struct SDL_ControllerButtonEvent
   345 {
   346     Uint32 type;        /**< ::SDL_CONTROLLERBUTTONDOWN or ::SDL_CONTROLLERBUTTONUP */
   347     Uint32 timestamp;
   348     Uint32 which;       /**< The joystick instance id */
   349     Uint8 button;       /**< The controller button (SDL_GameControllerButton) */
   350     Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
   351     Uint8 padding1;
   352     Uint8 padding2;
   353 } SDL_ControllerButtonEvent;
   354 
   355 
   356 /**
   357  *  \brief Controller device event structure (event.cdevice.*)
   358  */
   359 typedef struct SDL_ControllerDeviceEvent
   360 {
   361 	Uint32 type;        /**< ::SDL_CONTROLLERDEVICEADDED or ::SDL_CONTROLLERDEVICEREMOVED */
   362 	Uint32 timestamp;
   363 	Uint32 which;       /**< The joystick device index for the ADDED event, instance id for the REMOVED event */
   364 } SDL_ControllerDeviceEvent;
   365 
   366 
   367 /**
   368  *  \brief Touch finger event structure (event.tfinger.*)
   369  */
   370 typedef struct SDL_TouchFingerEvent
   371 {
   372     Uint32 type;        /**< ::SDL_FINGERMOTION or ::SDL_FINGERDOWN or ::SDL_FINGERUP */
   373     Uint32 timestamp;
   374     SDL_TouchID touchId; /**< The touch device id */
   375     SDL_FingerID fingerId;
   376     float x;            /**< Normalized in the range 0...1 */
   377     float y;            /**< Normalized in the range 0...1 */
   378     float dx;           /**< Normalized in the range 0...1 */
   379     float dy;           /**< Normalized in the range 0...1 */
   380     float pressure;     /**< Normalized in the range 0...1 */
   381 } SDL_TouchFingerEvent;
   382 
   383 
   384 /**
   385  *  \brief Multiple Finger Gesture Event (event.mgesture.*)
   386  */
   387 typedef struct SDL_MultiGestureEvent
   388 {
   389     Uint32 type;        /**< ::SDL_MULTIGESTURE */
   390     Uint32 timestamp;
   391     SDL_TouchID touchId; /**< The touch device index */
   392     float dTheta;
   393     float dDist;
   394     float x;
   395     float y;  
   396     Uint16 numFingers;
   397     Uint16 padding;
   398 } SDL_MultiGestureEvent;
   399 
   400 
   401 /* (event.dgesture.*) */
   402 typedef struct SDL_DollarGestureEvent
   403 {
   404     Uint32 type;        /**< ::SDL_DOLLARGESTURE */
   405     Uint32 timestamp;
   406     SDL_TouchID touchId; /**< The touch device id */
   407     SDL_GestureID gestureId;
   408     Uint32 numFingers;
   409     float error;
   410     float x;            /**< Normalized center of gesture */
   411     float y;            /**< Normalized center of gesture */
   412 } SDL_DollarGestureEvent;
   413 
   414 
   415 /**
   416  *  \brief An event used to request a file open by the system (event.drop.*)
   417  *         This event is disabled by default, you can enable it with SDL_EventState()
   418  *  \note If you enable this event, you must free the filename in the event.
   419  */
   420 typedef struct SDL_DropEvent
   421 {
   422     Uint32 type;        /**< ::SDL_DROPFILE */
   423     Uint32 timestamp;
   424     char *file;         /**< The file name, which should be freed with SDL_free() */
   425 } SDL_DropEvent;
   426 
   427 
   428 /**
   429  *  \brief The "quit requested" event
   430  */
   431 typedef struct SDL_QuitEvent
   432 {
   433     Uint32 type;        /**< ::SDL_QUIT */
   434     Uint32 timestamp;
   435 } SDL_QuitEvent;
   436 
   437 
   438 /**
   439  *  \brief A user-defined event type (event.user.*)
   440  */
   441 typedef struct SDL_UserEvent
   442 {
   443     Uint32 type;        /**< ::SDL_USEREVENT through ::SDL_NUMEVENTS-1 */
   444     Uint32 timestamp;
   445     Uint32 windowID;    /**< The associated window if any */
   446     Sint32 code;        /**< User defined event code */
   447     void *data1;        /**< User defined data pointer */
   448     void *data2;        /**< User defined data pointer */
   449 } SDL_UserEvent;
   450 
   451 
   452 struct SDL_SysWMmsg;
   453 typedef struct SDL_SysWMmsg SDL_SysWMmsg;
   454 
   455 /**
   456  *  \brief A video driver dependent system event (event.syswm.*)
   457  *         This event is disabled by default, you can enable it with SDL_EventState()
   458  *
   459  *  \note If you want to use this event, you should include SDL_syswm.h.
   460  */
   461 typedef struct SDL_SysWMEvent
   462 {
   463     Uint32 type;        /**< ::SDL_SYSWMEVENT */
   464     Uint32 timestamp;
   465     SDL_SysWMmsg *msg;  /**< driver dependent data, defined in SDL_syswm.h */
   466 } SDL_SysWMEvent;
   467 
   468 /**
   469  *  \brief General event structure
   470  */
   471 typedef union SDL_Event
   472 {
   473     Uint32 type;                    /**< Event type, shared with all events */
   474     SDL_GenericEvent generic;       /**< Generic event data */
   475     SDL_WindowEvent window;         /**< Window event data */
   476     SDL_KeyboardEvent key;          /**< Keyboard event data */
   477     SDL_TextEditingEvent edit;      /**< Text editing event data */
   478     SDL_TextInputEvent text;        /**< Text input event data */
   479     SDL_MouseMotionEvent motion;    /**< Mouse motion event data */
   480     SDL_MouseButtonEvent button;    /**< Mouse button event data */
   481     SDL_MouseWheelEvent wheel;      /**< Mouse wheel event data */
   482     SDL_JoyAxisEvent jaxis;         /**< Joystick axis event data */
   483     SDL_JoyBallEvent jball;         /**< Joystick ball event data */
   484     SDL_JoyHatEvent jhat;           /**< Joystick hat event data */
   485     SDL_JoyButtonEvent jbutton;     /**< Joystick button event data */
   486     SDL_JoyDeviceEvent jdevice;     /**< Joystick device change event data */
   487 	SDL_ControllerAxisEvent caxis;		/**< Game Controller button event data */
   488 	SDL_ControllerButtonEvent cbutton;  /**< Game Controller button event data */
   489 	SDL_ControllerDeviceEvent cdevice;  /**< Game Controller device event data */
   490     SDL_QuitEvent quit;             /**< Quit request event data */
   491     SDL_UserEvent user;             /**< Custom event data */
   492     SDL_SysWMEvent syswm;           /**< System dependent window event data */
   493     SDL_TouchFingerEvent tfinger;   /**< Touch finger event data */
   494     SDL_MultiGestureEvent mgesture; /**< Gesture event data */
   495     SDL_DollarGestureEvent dgesture; /**< Gesture event data */
   496     SDL_DropEvent drop;             /**< Drag and drop event data */
   497 
   498     /* This is necessary for ABI compatibility between Visual C++ and GCC
   499        Visual C++ will respect the push pack pragma and use 52 bytes for
   500        this structure, and GCC will use the alignment of the largest datatype
   501        within the union, which is 8 bytes.
   502 
   503        So... we'll add padding to force the size to be 56 bytes for both.
   504     */
   505     Uint8 padding[56];
   506 } SDL_Event;
   507 
   508 
   509 /* Function prototypes */
   510 
   511 /**
   512  *  Pumps the event loop, gathering events from the input devices.
   513  *  
   514  *  This function updates the event queue and internal input device state.
   515  *  
   516  *  This should only be run in the thread that sets the video mode.
   517  */
   518 extern DECLSPEC void SDLCALL SDL_PumpEvents(void);
   519 
   520 /*@{*/
   521 typedef enum
   522 {
   523     SDL_ADDEVENT,
   524     SDL_PEEKEVENT,
   525     SDL_GETEVENT
   526 } SDL_eventaction;
   527 
   528 /**
   529  *  Checks the event queue for messages and optionally returns them.
   530  *  
   531  *  If \c action is ::SDL_ADDEVENT, up to \c numevents events will be added to
   532  *  the back of the event queue.
   533  *  
   534  *  If \c action is ::SDL_PEEKEVENT, up to \c numevents events at the front
   535  *  of the event queue, within the specified minimum and maximum type,
   536  *  will be returned and will not be removed from the queue.
   537  *  
   538  *  If \c action is ::SDL_GETEVENT, up to \c numevents events at the front 
   539  *  of the event queue, within the specified minimum and maximum type,
   540  *  will be returned and will be removed from the queue.
   541  *  
   542  *  \return The number of events actually stored, or -1 if there was an error.
   543  *  
   544  *  This function is thread-safe.
   545  */
   546 extern DECLSPEC int SDLCALL SDL_PeepEvents(SDL_Event * events, int numevents,
   547                                            SDL_eventaction action,
   548                                            Uint32 minType, Uint32 maxType);
   549 /*@}*/
   550 
   551 /**
   552  *  Checks to see if certain event types are in the event queue.
   553  */
   554 extern DECLSPEC SDL_bool SDLCALL SDL_HasEvent(Uint32 type);
   555 extern DECLSPEC SDL_bool SDLCALL SDL_HasEvents(Uint32 minType, Uint32 maxType);
   556 
   557 /**
   558  *  This function clears events from the event queue
   559  */
   560 extern DECLSPEC void SDLCALL SDL_FlushEvent(Uint32 type);
   561 extern DECLSPEC void SDLCALL SDL_FlushEvents(Uint32 minType, Uint32 maxType);
   562 
   563 /**
   564  *  \brief Polls for currently pending events.
   565  *  
   566  *  \return 1 if there are any pending events, or 0 if there are none available.
   567  *  
   568  *  \param event If not NULL, the next event is removed from the queue and 
   569  *               stored in that area.
   570  */
   571 extern DECLSPEC int SDLCALL SDL_PollEvent(SDL_Event * event);
   572 
   573 /**
   574  *  \brief Waits indefinitely for the next available event.
   575  *  
   576  *  \return 1, or 0 if there was an error while waiting for events.
   577  *   
   578  *  \param event If not NULL, the next event is removed from the queue and 
   579  *               stored in that area.
   580  */
   581 extern DECLSPEC int SDLCALL SDL_WaitEvent(SDL_Event * event);
   582 
   583 /**
   584  *  \brief Waits until the specified timeout (in milliseconds) for the next 
   585  *         available event.
   586  *  
   587  *  \return 1, or 0 if there was an error while waiting for events.
   588  *  
   589  *  \param event If not NULL, the next event is removed from the queue and 
   590  *               stored in that area.
   591  */
   592 extern DECLSPEC int SDLCALL SDL_WaitEventTimeout(SDL_Event * event,
   593                                                  int timeout);
   594 
   595 /**
   596  *  \brief Add an event to the event queue.
   597  *  
   598  *  \return 1 on success, 0 if the event was filtered, or -1 if the event queue 
   599  *          was full or there was some other error.
   600  */
   601 extern DECLSPEC int SDLCALL SDL_PushEvent(SDL_Event * event);
   602 
   603 typedef int (SDLCALL * SDL_EventFilter) (void *userdata, SDL_Event * event);
   604 
   605 /**
   606  *  Sets up a filter to process all events before they change internal state and
   607  *  are posted to the internal event queue.
   608  *  
   609  *  The filter is protypted as:
   610  *  \code
   611  *      int SDL_EventFilter(void *userdata, SDL_Event * event);
   612  *  \endcode
   613  *
   614  *  If the filter returns 1, then the event will be added to the internal queue.
   615  *  If it returns 0, then the event will be dropped from the queue, but the 
   616  *  internal state will still be updated.  This allows selective filtering of
   617  *  dynamically arriving events.
   618  *  
   619  *  \warning  Be very careful of what you do in the event filter function, as 
   620  *            it may run in a different thread!
   621  *  
   622  *  There is one caveat when dealing with the ::SDL_QUITEVENT event type.  The
   623  *  event filter is only called when the window manager desires to close the
   624  *  application window.  If the event filter returns 1, then the window will
   625  *  be closed, otherwise the window will remain open if possible.
   626  *
   627  *  If the quit event is generated by an interrupt signal, it will bypass the
   628  *  internal queue and be delivered to the application at the next event poll.
   629  */
   630 extern DECLSPEC void SDLCALL SDL_SetEventFilter(SDL_EventFilter filter,
   631                                                 void *userdata);
   632 
   633 /**
   634  *  Return the current event filter - can be used to "chain" filters.
   635  *  If there is no event filter set, this function returns SDL_FALSE.
   636  */
   637 extern DECLSPEC SDL_bool SDLCALL SDL_GetEventFilter(SDL_EventFilter * filter,
   638                                                     void **userdata);
   639 
   640 /**
   641  *  Add a function which is called when an event is added to the queue.
   642  */
   643 extern DECLSPEC void SDLCALL SDL_AddEventWatch(SDL_EventFilter filter,
   644                                                void *userdata);
   645 
   646 /**
   647  *  Remove an event watch function added with SDL_AddEventWatch()
   648  */
   649 extern DECLSPEC void SDLCALL SDL_DelEventWatch(SDL_EventFilter filter,
   650                                                void *userdata);
   651 
   652 /**
   653  *  Run the filter function on the current event queue, removing any
   654  *  events for which the filter returns 0.
   655  */
   656 extern DECLSPEC void SDLCALL SDL_FilterEvents(SDL_EventFilter filter,
   657                                               void *userdata);
   658 
   659 /*@{*/
   660 #define SDL_QUERY	-1
   661 #define SDL_IGNORE	 0
   662 #define SDL_DISABLE	 0
   663 #define SDL_ENABLE	 1
   664 
   665 /**
   666  *  This function allows you to set the state of processing certain events.
   667  *   - If \c state is set to ::SDL_IGNORE, that event will be automatically 
   668  *     dropped from the event queue and will not event be filtered.
   669  *   - If \c state is set to ::SDL_ENABLE, that event will be processed 
   670  *     normally.
   671  *   - If \c state is set to ::SDL_QUERY, SDL_EventState() will return the 
   672  *     current processing state of the specified event.
   673  */
   674 extern DECLSPEC Uint8 SDLCALL SDL_EventState(Uint32 type, int state);
   675 /*@}*/
   676 #define SDL_GetEventState(type) SDL_EventState(type, SDL_QUERY)
   677 
   678 /**
   679  *  This function allocates a set of user-defined events, and returns
   680  *  the beginning event number for that set of events.
   681  *
   682  *  If there aren't enough user-defined events left, this function
   683  *  returns (Uint32)-1
   684  */
   685 extern DECLSPEC Uint32 SDLCALL SDL_RegisterEvents(int numevents);
   686 
   687 /* Ends C function definitions when using C++ */
   688 #ifdef __cplusplus
   689 /* *INDENT-OFF* */
   690 }
   691 /* *INDENT-ON* */
   692 #endif
   693 #include "close_code.h"
   694 
   695 #endif /* _SDL_events_h */
   696 
   697 /* vi: set ts=4 sw=4 expandtab: */