include/SDL_events.h
author Sam Lantinga <slouken@libsdl.org>
Tue, 21 Aug 2018 12:11:34 -0700
changeset 12130 24142c5073a4
parent 11811 5d94cb6b24d3
child 12143 673ec0369266
permissions -rw-r--r--
First pass on the new SDL sensor API
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2018 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 extern "C" {
    46 #endif
    47 
    48 /* General keyboard/mouse state definitions */
    49 #define SDL_RELEASED    0
    50 #define SDL_PRESSED 1
    51 
    52 /**
    53  * \brief The types of events that can be delivered.
    54  */
    55 typedef enum
    56 {
    57     SDL_FIRSTEVENT     = 0,     /**< Unused (do not remove) */
    58 
    59     /* Application events */
    60     SDL_QUIT           = 0x100, /**< User-requested quit */
    61 
    62     /* These application events have special meaning on iOS, see README-ios.md for details */
    63     SDL_APP_TERMINATING,        /**< The application is being terminated by the OS
    64                                      Called on iOS in applicationWillTerminate()
    65                                      Called on Android in onDestroy()
    66                                 */
    67     SDL_APP_LOWMEMORY,          /**< The application is low on memory, free memory if possible.
    68                                      Called on iOS in applicationDidReceiveMemoryWarning()
    69                                      Called on Android in onLowMemory()
    70                                 */
    71     SDL_APP_WILLENTERBACKGROUND, /**< The application is about to enter the background
    72                                      Called on iOS in applicationWillResignActive()
    73                                      Called on Android in onPause()
    74                                 */
    75     SDL_APP_DIDENTERBACKGROUND, /**< The application did enter the background and may not get CPU for some time
    76                                      Called on iOS in applicationDidEnterBackground()
    77                                      Called on Android in onPause()
    78                                 */
    79     SDL_APP_WILLENTERFOREGROUND, /**< The application is about to enter the foreground
    80                                      Called on iOS in applicationWillEnterForeground()
    81                                      Called on Android in onResume()
    82                                 */
    83     SDL_APP_DIDENTERFOREGROUND, /**< The application is now interactive
    84                                      Called on iOS in applicationDidBecomeActive()
    85                                      Called on Android in onResume()
    86                                 */
    87 
    88     /* Window events */
    89     SDL_WINDOWEVENT    = 0x200, /**< Window state change */
    90     SDL_SYSWMEVENT,             /**< System specific event */
    91 
    92     /* Keyboard events */
    93     SDL_KEYDOWN        = 0x300, /**< Key pressed */
    94     SDL_KEYUP,                  /**< Key released */
    95     SDL_TEXTEDITING,            /**< Keyboard text editing (composition) */
    96     SDL_TEXTINPUT,              /**< Keyboard text input */
    97     SDL_KEYMAPCHANGED,          /**< Keymap changed due to a system event such as an
    98                                      input language or keyboard layout change.
    99                                 */
   100 
   101     /* Mouse events */
   102     SDL_MOUSEMOTION    = 0x400, /**< Mouse moved */
   103     SDL_MOUSEBUTTONDOWN,        /**< Mouse button pressed */
   104     SDL_MOUSEBUTTONUP,          /**< Mouse button released */
   105     SDL_MOUSEWHEEL,             /**< Mouse wheel motion */
   106 
   107     /* Joystick events */
   108     SDL_JOYAXISMOTION  = 0x600, /**< Joystick axis motion */
   109     SDL_JOYBALLMOTION,          /**< Joystick trackball motion */
   110     SDL_JOYHATMOTION,           /**< Joystick hat position change */
   111     SDL_JOYBUTTONDOWN,          /**< Joystick button pressed */
   112     SDL_JOYBUTTONUP,            /**< Joystick button released */
   113     SDL_JOYDEVICEADDED,         /**< A new joystick has been inserted into the system */
   114     SDL_JOYDEVICEREMOVED,       /**< An opened joystick has been removed */
   115 
   116     /* Game controller events */
   117     SDL_CONTROLLERAXISMOTION  = 0x650, /**< Game controller axis motion */
   118     SDL_CONTROLLERBUTTONDOWN,          /**< Game controller button pressed */
   119     SDL_CONTROLLERBUTTONUP,            /**< Game controller button released */
   120     SDL_CONTROLLERDEVICEADDED,         /**< A new Game controller has been inserted into the system */
   121     SDL_CONTROLLERDEVICEREMOVED,       /**< An opened Game controller has been removed */
   122     SDL_CONTROLLERDEVICEREMAPPED,      /**< The controller mapping was updated */
   123 
   124     /* Touch events */
   125     SDL_FINGERDOWN      = 0x700,
   126     SDL_FINGERUP,
   127     SDL_FINGERMOTION,
   128 
   129     /* Gesture events */
   130     SDL_DOLLARGESTURE   = 0x800,
   131     SDL_DOLLARRECORD,
   132     SDL_MULTIGESTURE,
   133 
   134     /* Clipboard events */
   135     SDL_CLIPBOARDUPDATE = 0x900, /**< The clipboard changed */
   136 
   137     /* Drag and drop events */
   138     SDL_DROPFILE        = 0x1000, /**< The system requests a file open */
   139     SDL_DROPTEXT,                 /**< text/plain drag-and-drop event */
   140     SDL_DROPBEGIN,                /**< A new set of drops is beginning (NULL filename) */
   141     SDL_DROPCOMPLETE,             /**< Current set of drops is now complete (NULL filename) */
   142 
   143     /* Audio hotplug events */
   144     SDL_AUDIODEVICEADDED = 0x1100, /**< A new audio device is available */
   145     SDL_AUDIODEVICEREMOVED,        /**< An audio device has been removed. */
   146 
   147     /* Sensor events */
   148     SDL_SENSORUPDATE = 0x1200,     /**< A sensor was updated */
   149 
   150     /* Render events */
   151     SDL_RENDER_TARGETS_RESET = 0x2000, /**< The render targets have been reset and their contents need to be updated */
   152     SDL_RENDER_DEVICE_RESET, /**< The device has been reset and all textures need to be recreated */
   153 
   154     /** Events ::SDL_USEREVENT through ::SDL_LASTEVENT are for your use,
   155      *  and should be allocated with SDL_RegisterEvents()
   156      */
   157     SDL_USEREVENT    = 0x8000,
   158 
   159     /**
   160      *  This last event is only for bounding internal arrays
   161      */
   162     SDL_LASTEVENT    = 0xFFFF
   163 } SDL_EventType;
   164 
   165 /**
   166  *  \brief Fields shared by every event
   167  */
   168 typedef struct SDL_CommonEvent
   169 {
   170     Uint32 type;
   171     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
   172 } SDL_CommonEvent;
   173 
   174 /**
   175  *  \brief Window state change event data (event.window.*)
   176  */
   177 typedef struct SDL_WindowEvent
   178 {
   179     Uint32 type;        /**< ::SDL_WINDOWEVENT */
   180     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
   181     Uint32 windowID;    /**< The associated window */
   182     Uint8 event;        /**< ::SDL_WindowEventID */
   183     Uint8 padding1;
   184     Uint8 padding2;
   185     Uint8 padding3;
   186     Sint32 data1;       /**< event dependent data */
   187     Sint32 data2;       /**< event dependent data */
   188 } SDL_WindowEvent;
   189 
   190 /**
   191  *  \brief Keyboard button event structure (event.key.*)
   192  */
   193 typedef struct SDL_KeyboardEvent
   194 {
   195     Uint32 type;        /**< ::SDL_KEYDOWN or ::SDL_KEYUP */
   196     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
   197     Uint32 windowID;    /**< The window with keyboard focus, if any */
   198     Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
   199     Uint8 repeat;       /**< Non-zero if this is a key repeat */
   200     Uint8 padding2;
   201     Uint8 padding3;
   202     SDL_Keysym keysym;  /**< The key that was pressed or released */
   203 } SDL_KeyboardEvent;
   204 
   205 #define SDL_TEXTEDITINGEVENT_TEXT_SIZE (32)
   206 /**
   207  *  \brief Keyboard text editing event structure (event.edit.*)
   208  */
   209 typedef struct SDL_TextEditingEvent
   210 {
   211     Uint32 type;                                /**< ::SDL_TEXTEDITING */
   212     Uint32 timestamp;                           /**< In milliseconds, populated using SDL_GetTicks() */
   213     Uint32 windowID;                            /**< The window with keyboard focus, if any */
   214     char text[SDL_TEXTEDITINGEVENT_TEXT_SIZE];  /**< The editing text */
   215     Sint32 start;                               /**< The start cursor of selected editing text */
   216     Sint32 length;                              /**< The length of selected editing text */
   217 } SDL_TextEditingEvent;
   218 
   219 
   220 #define SDL_TEXTINPUTEVENT_TEXT_SIZE (32)
   221 /**
   222  *  \brief Keyboard text input event structure (event.text.*)
   223  */
   224 typedef struct SDL_TextInputEvent
   225 {
   226     Uint32 type;                              /**< ::SDL_TEXTINPUT */
   227     Uint32 timestamp;                         /**< In milliseconds, populated using SDL_GetTicks() */
   228     Uint32 windowID;                          /**< The window with keyboard focus, if any */
   229     char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];  /**< The input text */
   230 } SDL_TextInputEvent;
   231 
   232 /**
   233  *  \brief Mouse motion event structure (event.motion.*)
   234  */
   235 typedef struct SDL_MouseMotionEvent
   236 {
   237     Uint32 type;        /**< ::SDL_MOUSEMOTION */
   238     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
   239     Uint32 windowID;    /**< The window with mouse focus, if any */
   240     Uint32 which;       /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
   241     Uint32 state;       /**< The current button state */
   242     Sint32 x;           /**< X coordinate, relative to window */
   243     Sint32 y;           /**< Y coordinate, relative to window */
   244     Sint32 xrel;        /**< The relative motion in the X direction */
   245     Sint32 yrel;        /**< The relative motion in the Y direction */
   246 } SDL_MouseMotionEvent;
   247 
   248 /**
   249  *  \brief Mouse button event structure (event.button.*)
   250  */
   251 typedef struct SDL_MouseButtonEvent
   252 {
   253     Uint32 type;        /**< ::SDL_MOUSEBUTTONDOWN or ::SDL_MOUSEBUTTONUP */
   254     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
   255     Uint32 windowID;    /**< The window with mouse focus, if any */
   256     Uint32 which;       /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
   257     Uint8 button;       /**< The mouse button index */
   258     Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
   259     Uint8 clicks;       /**< 1 for single-click, 2 for double-click, etc. */
   260     Uint8 padding1;
   261     Sint32 x;           /**< X coordinate, relative to window */
   262     Sint32 y;           /**< Y coordinate, relative to window */
   263 } SDL_MouseButtonEvent;
   264 
   265 /**
   266  *  \brief Mouse wheel event structure (event.wheel.*)
   267  */
   268 typedef struct SDL_MouseWheelEvent
   269 {
   270     Uint32 type;        /**< ::SDL_MOUSEWHEEL */
   271     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
   272     Uint32 windowID;    /**< The window with mouse focus, if any */
   273     Uint32 which;       /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
   274     Sint32 x;           /**< The amount scrolled horizontally, positive to the right and negative to the left */
   275     Sint32 y;           /**< The amount scrolled vertically, positive away from the user and negative toward the user */
   276     Uint32 direction;   /**< Set to one of the SDL_MOUSEWHEEL_* defines. When FLIPPED the values in X and Y will be opposite. Multiply by -1 to change them back */
   277 } SDL_MouseWheelEvent;
   278 
   279 /**
   280  *  \brief Joystick axis motion event structure (event.jaxis.*)
   281  */
   282 typedef struct SDL_JoyAxisEvent
   283 {
   284     Uint32 type;        /**< ::SDL_JOYAXISMOTION */
   285     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
   286     SDL_JoystickID which; /**< The joystick instance id */
   287     Uint8 axis;         /**< The joystick axis index */
   288     Uint8 padding1;
   289     Uint8 padding2;
   290     Uint8 padding3;
   291     Sint16 value;       /**< The axis value (range: -32768 to 32767) */
   292     Uint16 padding4;
   293 } SDL_JoyAxisEvent;
   294 
   295 /**
   296  *  \brief Joystick trackball motion event structure (event.jball.*)
   297  */
   298 typedef struct SDL_JoyBallEvent
   299 {
   300     Uint32 type;        /**< ::SDL_JOYBALLMOTION */
   301     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
   302     SDL_JoystickID which; /**< The joystick instance id */
   303     Uint8 ball;         /**< The joystick trackball index */
   304     Uint8 padding1;
   305     Uint8 padding2;
   306     Uint8 padding3;
   307     Sint16 xrel;        /**< The relative motion in the X direction */
   308     Sint16 yrel;        /**< The relative motion in the Y direction */
   309 } SDL_JoyBallEvent;
   310 
   311 /**
   312  *  \brief Joystick hat position change event structure (event.jhat.*)
   313  */
   314 typedef struct SDL_JoyHatEvent
   315 {
   316     Uint32 type;        /**< ::SDL_JOYHATMOTION */
   317     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
   318     SDL_JoystickID which; /**< The joystick instance id */
   319     Uint8 hat;          /**< The joystick hat index */
   320     Uint8 value;        /**< The hat position value.
   321                          *   \sa ::SDL_HAT_LEFTUP ::SDL_HAT_UP ::SDL_HAT_RIGHTUP
   322                          *   \sa ::SDL_HAT_LEFT ::SDL_HAT_CENTERED ::SDL_HAT_RIGHT
   323                          *   \sa ::SDL_HAT_LEFTDOWN ::SDL_HAT_DOWN ::SDL_HAT_RIGHTDOWN
   324                          *
   325                          *   Note that zero means the POV is centered.
   326                          */
   327     Uint8 padding1;
   328     Uint8 padding2;
   329 } SDL_JoyHatEvent;
   330 
   331 /**
   332  *  \brief Joystick button event structure (event.jbutton.*)
   333  */
   334 typedef struct SDL_JoyButtonEvent
   335 {
   336     Uint32 type;        /**< ::SDL_JOYBUTTONDOWN or ::SDL_JOYBUTTONUP */
   337     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
   338     SDL_JoystickID which; /**< The joystick instance id */
   339     Uint8 button;       /**< The joystick button index */
   340     Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
   341     Uint8 padding1;
   342     Uint8 padding2;
   343 } SDL_JoyButtonEvent;
   344 
   345 /**
   346  *  \brief Joystick device event structure (event.jdevice.*)
   347  */
   348 typedef struct SDL_JoyDeviceEvent
   349 {
   350     Uint32 type;        /**< ::SDL_JOYDEVICEADDED or ::SDL_JOYDEVICEREMOVED */
   351     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
   352     Sint32 which;       /**< The joystick device index for the ADDED event, instance id for the REMOVED event */
   353 } SDL_JoyDeviceEvent;
   354 
   355 
   356 /**
   357  *  \brief Game controller axis motion event structure (event.caxis.*)
   358  */
   359 typedef struct SDL_ControllerAxisEvent
   360 {
   361     Uint32 type;        /**< ::SDL_CONTROLLERAXISMOTION */
   362     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
   363     SDL_JoystickID which; /**< The joystick instance id */
   364     Uint8 axis;         /**< The controller axis (SDL_GameControllerAxis) */
   365     Uint8 padding1;
   366     Uint8 padding2;
   367     Uint8 padding3;
   368     Sint16 value;       /**< The axis value (range: -32768 to 32767) */
   369     Uint16 padding4;
   370 } SDL_ControllerAxisEvent;
   371 
   372 
   373 /**
   374  *  \brief Game controller button event structure (event.cbutton.*)
   375  */
   376 typedef struct SDL_ControllerButtonEvent
   377 {
   378     Uint32 type;        /**< ::SDL_CONTROLLERBUTTONDOWN or ::SDL_CONTROLLERBUTTONUP */
   379     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
   380     SDL_JoystickID which; /**< The joystick instance id */
   381     Uint8 button;       /**< The controller button (SDL_GameControllerButton) */
   382     Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
   383     Uint8 padding1;
   384     Uint8 padding2;
   385 } SDL_ControllerButtonEvent;
   386 
   387 
   388 /**
   389  *  \brief Controller device event structure (event.cdevice.*)
   390  */
   391 typedef struct SDL_ControllerDeviceEvent
   392 {
   393     Uint32 type;        /**< ::SDL_CONTROLLERDEVICEADDED, ::SDL_CONTROLLERDEVICEREMOVED, or ::SDL_CONTROLLERDEVICEREMAPPED */
   394     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
   395     Sint32 which;       /**< The joystick device index for the ADDED event, instance id for the REMOVED or REMAPPED event */
   396 } SDL_ControllerDeviceEvent;
   397 
   398 /**
   399  *  \brief Audio device event structure (event.adevice.*)
   400  */
   401 typedef struct SDL_AudioDeviceEvent
   402 {
   403     Uint32 type;        /**< ::SDL_AUDIODEVICEADDED, or ::SDL_AUDIODEVICEREMOVED */
   404     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
   405     Uint32 which;       /**< The audio device index for the ADDED event (valid until next SDL_GetNumAudioDevices() call), SDL_AudioDeviceID for the REMOVED event */
   406     Uint8 iscapture;    /**< zero if an output device, non-zero if a capture device. */
   407     Uint8 padding1;
   408     Uint8 padding2;
   409     Uint8 padding3;
   410 } SDL_AudioDeviceEvent;
   411 
   412 
   413 /**
   414  *  \brief Touch finger event structure (event.tfinger.*)
   415  */
   416 typedef struct SDL_TouchFingerEvent
   417 {
   418     Uint32 type;        /**< ::SDL_FINGERMOTION or ::SDL_FINGERDOWN or ::SDL_FINGERUP */
   419     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
   420     SDL_TouchID touchId; /**< The touch device id */
   421     SDL_FingerID fingerId;
   422     float x;            /**< Normalized in the range 0...1 */
   423     float y;            /**< Normalized in the range 0...1 */
   424     float dx;           /**< Normalized in the range -1...1 */
   425     float dy;           /**< Normalized in the range -1...1 */
   426     float pressure;     /**< Normalized in the range 0...1 */
   427 } SDL_TouchFingerEvent;
   428 
   429 
   430 /**
   431  *  \brief Multiple Finger Gesture Event (event.mgesture.*)
   432  */
   433 typedef struct SDL_MultiGestureEvent
   434 {
   435     Uint32 type;        /**< ::SDL_MULTIGESTURE */
   436     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
   437     SDL_TouchID touchId; /**< The touch device id */
   438     float dTheta;
   439     float dDist;
   440     float x;
   441     float y;
   442     Uint16 numFingers;
   443     Uint16 padding;
   444 } SDL_MultiGestureEvent;
   445 
   446 
   447 /**
   448  * \brief Dollar Gesture Event (event.dgesture.*)
   449  */
   450 typedef struct SDL_DollarGestureEvent
   451 {
   452     Uint32 type;        /**< ::SDL_DOLLARGESTURE or ::SDL_DOLLARRECORD */
   453     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
   454     SDL_TouchID touchId; /**< The touch device id */
   455     SDL_GestureID gestureId;
   456     Uint32 numFingers;
   457     float error;
   458     float x;            /**< Normalized center of gesture */
   459     float y;            /**< Normalized center of gesture */
   460 } SDL_DollarGestureEvent;
   461 
   462 
   463 /**
   464  *  \brief An event used to request a file open by the system (event.drop.*)
   465  *         This event is enabled by default, you can disable it with SDL_EventState().
   466  *  \note If this event is enabled, you must free the filename in the event.
   467  */
   468 typedef struct SDL_DropEvent
   469 {
   470     Uint32 type;        /**< ::SDL_DROPBEGIN or ::SDL_DROPFILE or ::SDL_DROPTEXT or ::SDL_DROPCOMPLETE */
   471     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
   472     char *file;         /**< The file name, which should be freed with SDL_free(), is NULL on begin/complete */
   473     Uint32 windowID;    /**< The window that was dropped on, if any */
   474 } SDL_DropEvent;
   475 
   476 
   477 /**
   478  *  \brief Sensor event structure (event.sensor.*)
   479  */
   480 typedef struct SDL_SensorEvent
   481 {
   482     Uint32 type;        /**< ::SDL_SENSORUPDATE */
   483     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
   484     Sint32 which;       /**< The instance ID of the sensor */
   485     float data[6];      /**< Up to 6 values from the sensor - additional values can be queried using SDL_SensorGetData() */
   486 } SDL_SensorEvent;
   487 
   488 /**
   489  *  \brief The "quit requested" event
   490  */
   491 typedef struct SDL_QuitEvent
   492 {
   493     Uint32 type;        /**< ::SDL_QUIT */
   494     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
   495 } SDL_QuitEvent;
   496 
   497 /**
   498  *  \brief OS Specific event
   499  */
   500 typedef struct SDL_OSEvent
   501 {
   502     Uint32 type;        /**< ::SDL_QUIT */
   503     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
   504 } SDL_OSEvent;
   505 
   506 /**
   507  *  \brief A user-defined event type (event.user.*)
   508  */
   509 typedef struct SDL_UserEvent
   510 {
   511     Uint32 type;        /**< ::SDL_USEREVENT through ::SDL_LASTEVENT-1 */
   512     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
   513     Uint32 windowID;    /**< The associated window if any */
   514     Sint32 code;        /**< User defined event code */
   515     void *data1;        /**< User defined data pointer */
   516     void *data2;        /**< User defined data pointer */
   517 } SDL_UserEvent;
   518 
   519 
   520 struct SDL_SysWMmsg;
   521 typedef struct SDL_SysWMmsg SDL_SysWMmsg;
   522 
   523 /**
   524  *  \brief A video driver dependent system event (event.syswm.*)
   525  *         This event is disabled by default, you can enable it with SDL_EventState()
   526  *
   527  *  \note If you want to use this event, you should include SDL_syswm.h.
   528  */
   529 typedef struct SDL_SysWMEvent
   530 {
   531     Uint32 type;        /**< ::SDL_SYSWMEVENT */
   532     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
   533     SDL_SysWMmsg *msg;  /**< driver dependent data, defined in SDL_syswm.h */
   534 } SDL_SysWMEvent;
   535 
   536 /**
   537  *  \brief General event structure
   538  */
   539 typedef union SDL_Event
   540 {
   541     Uint32 type;                    /**< Event type, shared with all events */
   542     SDL_CommonEvent common;         /**< Common event data */
   543     SDL_WindowEvent window;         /**< Window event data */
   544     SDL_KeyboardEvent key;          /**< Keyboard event data */
   545     SDL_TextEditingEvent edit;      /**< Text editing event data */
   546     SDL_TextInputEvent text;        /**< Text input event data */
   547     SDL_MouseMotionEvent motion;    /**< Mouse motion event data */
   548     SDL_MouseButtonEvent button;    /**< Mouse button event data */
   549     SDL_MouseWheelEvent wheel;      /**< Mouse wheel event data */
   550     SDL_JoyAxisEvent jaxis;         /**< Joystick axis event data */
   551     SDL_JoyBallEvent jball;         /**< Joystick ball event data */
   552     SDL_JoyHatEvent jhat;           /**< Joystick hat event data */
   553     SDL_JoyButtonEvent jbutton;     /**< Joystick button event data */
   554     SDL_JoyDeviceEvent jdevice;     /**< Joystick device change event data */
   555     SDL_ControllerAxisEvent caxis;      /**< Game Controller axis event data */
   556     SDL_ControllerButtonEvent cbutton;  /**< Game Controller button event data */
   557     SDL_ControllerDeviceEvent cdevice;  /**< Game Controller device event data */
   558     SDL_AudioDeviceEvent adevice;   /**< Audio device event data */
   559     SDL_SensorEvent sensor;         /**< Sensor event data */
   560     SDL_QuitEvent quit;             /**< Quit request event data */
   561     SDL_UserEvent user;             /**< Custom event data */
   562     SDL_SysWMEvent syswm;           /**< System dependent window event data */
   563     SDL_TouchFingerEvent tfinger;   /**< Touch finger event data */
   564     SDL_MultiGestureEvent mgesture; /**< Gesture event data */
   565     SDL_DollarGestureEvent dgesture; /**< Gesture event data */
   566     SDL_DropEvent drop;             /**< Drag and drop event data */
   567 
   568     /* This is necessary for ABI compatibility between Visual C++ and GCC
   569        Visual C++ will respect the push pack pragma and use 52 bytes for
   570        this structure, and GCC will use the alignment of the largest datatype
   571        within the union, which is 8 bytes.
   572 
   573        So... we'll add padding to force the size to be 56 bytes for both.
   574     */
   575     Uint8 padding[56];
   576 } SDL_Event;
   577 
   578 
   579 /* Function prototypes */
   580 
   581 /**
   582  *  Pumps the event loop, gathering events from the input devices.
   583  *
   584  *  This function updates the event queue and internal input device state.
   585  *
   586  *  This should only be run in the thread that sets the video mode.
   587  */
   588 extern DECLSPEC void SDLCALL SDL_PumpEvents(void);
   589 
   590 /* @{ */
   591 typedef enum
   592 {
   593     SDL_ADDEVENT,
   594     SDL_PEEKEVENT,
   595     SDL_GETEVENT
   596 } SDL_eventaction;
   597 
   598 /**
   599  *  Checks the event queue for messages and optionally returns them.
   600  *
   601  *  If \c action is ::SDL_ADDEVENT, up to \c numevents events will be added to
   602  *  the back of the event queue.
   603  *
   604  *  If \c action is ::SDL_PEEKEVENT, up to \c numevents events at the front
   605  *  of the event queue, within the specified minimum and maximum type,
   606  *  will be returned and will not be removed from the queue.
   607  *
   608  *  If \c action is ::SDL_GETEVENT, up to \c numevents events at the front
   609  *  of the event queue, within the specified minimum and maximum type,
   610  *  will be returned and will be removed from the queue.
   611  *
   612  *  \return The number of events actually stored, or -1 if there was an error.
   613  *
   614  *  This function is thread-safe.
   615  */
   616 extern DECLSPEC int SDLCALL SDL_PeepEvents(SDL_Event * events, int numevents,
   617                                            SDL_eventaction action,
   618                                            Uint32 minType, Uint32 maxType);
   619 /* @} */
   620 
   621 /**
   622  *  Checks to see if certain event types are in the event queue.
   623  */
   624 extern DECLSPEC SDL_bool SDLCALL SDL_HasEvent(Uint32 type);
   625 extern DECLSPEC SDL_bool SDLCALL SDL_HasEvents(Uint32 minType, Uint32 maxType);
   626 
   627 /**
   628  *  This function clears events from the event queue
   629  *  This function only affects currently queued events. If you want to make
   630  *  sure that all pending OS events are flushed, you can call SDL_PumpEvents()
   631  *  on the main thread immediately before the flush call.
   632  */
   633 extern DECLSPEC void SDLCALL SDL_FlushEvent(Uint32 type);
   634 extern DECLSPEC void SDLCALL SDL_FlushEvents(Uint32 minType, Uint32 maxType);
   635 
   636 /**
   637  *  \brief Polls for currently pending events.
   638  *
   639  *  \return 1 if there are any pending events, or 0 if there are none available.
   640  *
   641  *  \param event If not NULL, the next event is removed from the queue and
   642  *               stored in that area.
   643  */
   644 extern DECLSPEC int SDLCALL SDL_PollEvent(SDL_Event * event);
   645 
   646 /**
   647  *  \brief Waits indefinitely for the next available event.
   648  *
   649  *  \return 1, or 0 if there was an error while waiting for events.
   650  *
   651  *  \param event If not NULL, the next event is removed from the queue and
   652  *               stored in that area.
   653  */
   654 extern DECLSPEC int SDLCALL SDL_WaitEvent(SDL_Event * event);
   655 
   656 /**
   657  *  \brief Waits until the specified timeout (in milliseconds) for the next
   658  *         available event.
   659  *
   660  *  \return 1, or 0 if there was an error while waiting for events.
   661  *
   662  *  \param event If not NULL, the next event is removed from the queue and
   663  *               stored in that area.
   664  *  \param timeout The timeout (in milliseconds) to wait for next event.
   665  */
   666 extern DECLSPEC int SDLCALL SDL_WaitEventTimeout(SDL_Event * event,
   667                                                  int timeout);
   668 
   669 /**
   670  *  \brief Add an event to the event queue.
   671  *
   672  *  \return 1 on success, 0 if the event was filtered, or -1 if the event queue
   673  *          was full or there was some other error.
   674  */
   675 extern DECLSPEC int SDLCALL SDL_PushEvent(SDL_Event * event);
   676 
   677 typedef int (SDLCALL * SDL_EventFilter) (void *userdata, SDL_Event * event);
   678 
   679 /**
   680  *  Sets up a filter to process all events before they change internal state and
   681  *  are posted to the internal event queue.
   682  *
   683  *  The filter is prototyped as:
   684  *  \code
   685  *      int SDL_EventFilter(void *userdata, SDL_Event * event);
   686  *  \endcode
   687  *
   688  *  If the filter returns 1, then the event will be added to the internal queue.
   689  *  If it returns 0, then the event will be dropped from the queue, but the
   690  *  internal state will still be updated.  This allows selective filtering of
   691  *  dynamically arriving events.
   692  *
   693  *  \warning  Be very careful of what you do in the event filter function, as
   694  *            it may run in a different thread!
   695  *
   696  *  There is one caveat when dealing with the ::SDL_QuitEvent event type.  The
   697  *  event filter is only called when the window manager desires to close the
   698  *  application window.  If the event filter returns 1, then the window will
   699  *  be closed, otherwise the window will remain open if possible.
   700  *
   701  *  If the quit event is generated by an interrupt signal, it will bypass the
   702  *  internal queue and be delivered to the application at the next event poll.
   703  */
   704 extern DECLSPEC void SDLCALL SDL_SetEventFilter(SDL_EventFilter filter,
   705                                                 void *userdata);
   706 
   707 /**
   708  *  Return the current event filter - can be used to "chain" filters.
   709  *  If there is no event filter set, this function returns SDL_FALSE.
   710  */
   711 extern DECLSPEC SDL_bool SDLCALL SDL_GetEventFilter(SDL_EventFilter * filter,
   712                                                     void **userdata);
   713 
   714 /**
   715  *  Add a function which is called when an event is added to the queue.
   716  */
   717 extern DECLSPEC void SDLCALL SDL_AddEventWatch(SDL_EventFilter filter,
   718                                                void *userdata);
   719 
   720 /**
   721  *  Remove an event watch function added with SDL_AddEventWatch()
   722  */
   723 extern DECLSPEC void SDLCALL SDL_DelEventWatch(SDL_EventFilter filter,
   724                                                void *userdata);
   725 
   726 /**
   727  *  Run the filter function on the current event queue, removing any
   728  *  events for which the filter returns 0.
   729  */
   730 extern DECLSPEC void SDLCALL SDL_FilterEvents(SDL_EventFilter filter,
   731                                               void *userdata);
   732 
   733 /* @{ */
   734 #define SDL_QUERY   -1
   735 #define SDL_IGNORE   0
   736 #define SDL_DISABLE  0
   737 #define SDL_ENABLE   1
   738 
   739 /**
   740  *  This function allows you to set the state of processing certain events.
   741  *   - If \c state is set to ::SDL_IGNORE, that event will be automatically
   742  *     dropped from the event queue and will not be filtered.
   743  *   - If \c state is set to ::SDL_ENABLE, that event will be processed
   744  *     normally.
   745  *   - If \c state is set to ::SDL_QUERY, SDL_EventState() will return the
   746  *     current processing state of the specified event.
   747  */
   748 extern DECLSPEC Uint8 SDLCALL SDL_EventState(Uint32 type, int state);
   749 /* @} */
   750 #define SDL_GetEventState(type) SDL_EventState(type, SDL_QUERY)
   751 
   752 /**
   753  *  This function allocates a set of user-defined events, and returns
   754  *  the beginning event number for that set of events.
   755  *
   756  *  If there aren't enough user-defined events left, this function
   757  *  returns (Uint32)-1
   758  */
   759 extern DECLSPEC Uint32 SDLCALL SDL_RegisterEvents(int numevents);
   760 
   761 /* Ends C function definitions when using C++ */
   762 #ifdef __cplusplus
   763 }
   764 #endif
   765 #include "close_code.h"
   766 
   767 #endif /* SDL_events_h_ */
   768 
   769 /* vi: set ts=4 sw=4 expandtab: */