include/SDL_events.h
author Sam Lantinga <slouken@libsdl.org>
Thu, 25 Mar 2010 01:08:26 -0700
changeset 4429 faa9fc8e7f67
parent 3697 f7b03b6838cb
child 4434 5c64052fb476
permissions -rw-r--r--
General improvements for user custom event registration

* Switched event type to enum (int32)
* Switched polling by mask to polling by type range
* Added SDL_RegisterEvents() to allow dynamic user event registration
* Spread events out to allow inserting new related events without breaking binary compatibility
* Added padding to event structures so they're the same size regardless of 32-bit compiler structure packing settings
* Split SDL_HasEvent() to SDL_HasEvent() for a single event and SDL_HasEvents() for a range of events
* Added SDL_GetEventState() as a shortcut for SDL_EventState(X, SDL_QUERY)
* Added SDL_FlushEvent() and SDL_FlushEvents() to clear events from the event queue
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@3697
     3
    Copyright (C) 1997-2010 Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@0
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@251
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@0
    22
slouken@1895
    23
/**
slouken@3407
    24
 *  \file SDL_events.h
slouken@3407
    25
 *  
slouken@3407
    26
 *  Include file for SDL event handling.
slouken@1895
    27
 */
slouken@0
    28
slouken@0
    29
#ifndef _SDL_events_h
slouken@0
    30
#define _SDL_events_h
slouken@0
    31
slouken@1356
    32
#include "SDL_stdinc.h"
slouken@1358
    33
#include "SDL_error.h"
slouken@1895
    34
#include "SDL_video.h"
slouken@0
    35
#include "SDL_keyboard.h"
slouken@0
    36
#include "SDL_mouse.h"
slouken@0
    37
#include "SDL_joystick.h"
slouken@0
    38
#include "SDL_quit.h"
slouken@0
    39
slouken@0
    40
#include "begin_code.h"
slouken@0
    41
/* Set up for C function definitions, even when using C++ */
slouken@0
    42
#ifdef __cplusplus
slouken@1895
    43
/* *INDENT-OFF* */
slouken@0
    44
extern "C" {
slouken@1895
    45
/* *INDENT-ON* */
slouken@0
    46
#endif
slouken@0
    47
slouken@1330
    48
/* General keyboard/mouse state definitions */
slouken@1330
    49
#define SDL_RELEASED	0
slouken@1330
    50
#define SDL_PRESSED	1
slouken@1330
    51
slouken@1895
    52
/**
slouken@3407
    53
 * \brief The types of events that can be delivered.
slouken@1895
    54
 */
slouken@1895
    55
typedef enum
slouken@1895
    56
{
slouken@4429
    57
    SDL_FIRSTEVENT     = 0,     /**< Unused (do not remove) */
slouken@4429
    58
slouken@4429
    59
    /* Application events */
slouken@4429
    60
    SDL_QUIT           = 0x100, /**< User-requested quit */
slouken@4429
    61
slouken@4429
    62
    /* Window events */
slouken@4429
    63
    SDL_WINDOWEVENT    = 0x200, /**< Window state change */
slouken@4429
    64
    SDL_SYSWMEVENT,             /**< System specific event */
slouken@4429
    65
slouken@4429
    66
    /* Keyboard events */
slouken@4429
    67
    SDL_KEYDOWN        = 0x300, /**< Keys pressed */
slouken@1895
    68
    SDL_KEYUP,                  /**< Keys released */
slouken@3280
    69
    SDL_TEXTEDITING,            /**< Keyboard text editing (composition) */
slouken@1957
    70
    SDL_TEXTINPUT,              /**< Keyboard text input */
slouken@4429
    71
slouken@4429
    72
    /* Mouse events */
slouken@4429
    73
    SDL_MOUSEMOTION    = 0x400, /**< Mouse moved */
slouken@1895
    74
    SDL_MOUSEBUTTONDOWN,        /**< Mouse button pressed */
slouken@1895
    75
    SDL_MOUSEBUTTONUP,          /**< Mouse button released */
slouken@1957
    76
    SDL_MOUSEWHEEL,             /**< Mouse wheel motion */
slouken@4429
    77
slouken@4429
    78
    /* Tablet events */
slouken@4429
    79
    SDL_PROXIMITYIN    = 0x500, /**< Proximity In event */
slouken@4429
    80
    SDL_PROXIMITYOUT,           /**< Proximity Out event */
slouken@4429
    81
slouken@4429
    82
    /* Joystick events */
slouken@4429
    83
    SDL_JOYAXISMOTION  = 0x600, /**< Joystick axis motion */
slouken@1895
    84
    SDL_JOYBALLMOTION,          /**< Joystick trackball motion */
slouken@1895
    85
    SDL_JOYHATMOTION,           /**< Joystick hat position change */
slouken@1895
    86
    SDL_JOYBUTTONDOWN,          /**< Joystick button pressed */
slouken@1895
    87
    SDL_JOYBUTTONUP,            /**< Joystick button released */
slouken@4429
    88
slouken@4429
    89
    /* Obsolete events */
slouken@4429
    90
    SDL_EVENT_COMPAT1 = 0x7000, /**< SDL 1.2 events for compatibility */
slouken@4429
    91
    SDL_EVENT_COMPAT2,
slouken@4429
    92
    SDL_EVENT_COMPAT3,
slouken@4429
    93
slouken@4429
    94
    /** Events ::SDL_USEREVENT through ::SDL_LASTEVENT are for your use,
slouken@4429
    95
     *  and should be allocated with SDL_RegisterEvents()
slouken@4429
    96
     */
slouken@4429
    97
    SDL_USEREVENT    = 0x8000,
slouken@4429
    98
slouken@3407
    99
    /**
slouken@3407
   100
     *  This last event is only for bounding internal arrays
slouken@1895
   101
     */
slouken@4429
   102
    SDL_LASTEVENT    = 0xFFFF
slouken@1294
   103
} SDL_EventType;
slouken@0
   104
slouken@1895
   105
/**
slouken@3407
   106
 *  \brief Window state change event data (event.window.*)
slouken@1895
   107
 */
slouken@1895
   108
typedef struct SDL_WindowEvent
slouken@1895
   109
{
slouken@4429
   110
    Uint32 type;        /**< ::SDL_WINDOWEVENT */
slouken@4429
   111
    Uint32 windowID;    /**< The associated window */
slouken@4429
   112
    Uint8 event;        /**< ::SDL_WindowEventID */
slouken@4429
   113
    Uint8 padding1;
slouken@4429
   114
    Uint8 padding2;
slouken@4429
   115
    Uint8 padding3;
slouken@4429
   116
    int data1;          /**< event dependent data */
slouken@4429
   117
    int data2;          /**< event dependent data */
slouken@1895
   118
} SDL_WindowEvent;
slouken@0
   119
slouken@1895
   120
/**
slouken@3407
   121
 *  \brief Keyboard button event structure (event.key.*)
slouken@1895
   122
 */
slouken@1895
   123
typedef struct SDL_KeyboardEvent
slouken@1895
   124
{
slouken@4429
   125
    Uint32 type;        /**< ::SDL_KEYDOWN or ::SDL_KEYUP */
slouken@4429
   126
    Uint32 windowID;    /**< The window with keyboard focus, if any */
slouken@4429
   127
    Uint8 which;        /**< The keyboard device index */
slouken@4429
   128
    Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
slouken@4429
   129
    Uint8 padding1;
slouken@4429
   130
    Uint8 padding2;
slouken@4429
   131
    SDL_keysym keysym;  /**< The key that was pressed or released */
slouken@0
   132
} SDL_KeyboardEvent;
slouken@0
   133
slouken@3407
   134
#define SDL_TEXTEDITINGEVENT_TEXT_SIZE (32)
slouken@1895
   135
/**
slouken@3407
   136
 *  \brief Keyboard text editing event structure (event.edit.*)
slouken@3280
   137
 */
slouken@3280
   138
typedef struct SDL_TextEditingEvent
slouken@3280
   139
{
slouken@4429
   140
    Uint32 type;                                /**< ::SDL_TEXTEDITING */
slouken@3280
   141
    char text[SDL_TEXTEDITINGEVENT_TEXT_SIZE];  /**< The editing text */
slouken@3280
   142
    int start;                                  /**< The start cursor of selected editing text */
slouken@3280
   143
    int length;                                 /**< The length of selected editing text */
slouken@3280
   144
} SDL_TextEditingEvent;
slouken@3280
   145
slouken@3407
   146
slouken@3407
   147
#define SDL_TEXTINPUTEVENT_TEXT_SIZE (32)
slouken@3280
   148
/**
slouken@3407
   149
 *  \brief Keyboard text input event structure (event.text.*)
slouken@1895
   150
 */
slouken@1895
   151
typedef struct SDL_TextInputEvent
slouken@1895
   152
{
slouken@4429
   153
    Uint32 type;                              /**< ::SDL_TEXTINPUT */
slouken@3685
   154
    Uint32 windowID;                          /**< The window with keyboard focus, if any */
bob@2300
   155
    Uint8 which;                              /**< The keyboard device index */
slouken@4429
   156
    Uint8 padding1;
slouken@4429
   157
    Uint8 padding2;
slouken@4429
   158
    Uint8 padding3;
bob@2300
   159
    char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];  /**< The input text */
slouken@1895
   160
} SDL_TextInputEvent;
slouken@1895
   161
slouken@1895
   162
/**
slouken@3407
   163
 *  \brief Mouse motion event structure (event.motion.*)
slouken@1895
   164
 */
slouken@1895
   165
typedef struct SDL_MouseMotionEvent
slouken@1895
   166
{
slouken@4429
   167
    Uint32 type;        /**< ::SDL_MOUSEMOTION */
slouken@4429
   168
    Uint32 windowID;    /**< The window with mouse focus, if any */
slouken@4429
   169
    Uint8 which;        /**< The mouse device index */
slouken@4429
   170
    Uint8 state;        /**< The current button state */
slouken@4429
   171
    Uint8 padding1;
slouken@4429
   172
    Uint8 padding2;
slouken@4429
   173
    int x;              /**< X coordinate, relative to window */
slouken@4429
   174
    int y;              /**< Y coordinate, relative to window */
slouken@4429
   175
    int z;              /**< Z coordinate, for future use */
slouken@4429
   176
    int pressure;       /**< Pressure reported by tablets */
slouken@4429
   177
    int pressure_max;   /**< Maximum value of the pressure reported by the device */
slouken@4429
   178
    int pressure_min;   /**< Minimum value of the pressure reported by the device */
slouken@4429
   179
    int rotation;       /**< For future use */
slouken@4429
   180
    int tilt_x;         /**< For future use */
slouken@4429
   181
    int tilt_y;         /**< For future use */
slouken@4429
   182
    int cursor;         /**< The cursor being used in the event */
slouken@4429
   183
    int xrel;           /**< The relative motion in the X direction */
slouken@4429
   184
    int yrel;           /**< The relative motion in the Y direction */
slouken@0
   185
} SDL_MouseMotionEvent;
slouken@0
   186
slouken@1895
   187
/**
slouken@3407
   188
 *  \brief Mouse button event structure (event.button.*)
slouken@1895
   189
 */
slouken@1895
   190
typedef struct SDL_MouseButtonEvent
slouken@1895
   191
{
slouken@4429
   192
    Uint32 type;        /**< ::SDL_MOUSEBUTTONDOWN or ::SDL_MOUSEBUTTONUP */
slouken@4429
   193
    Uint32 windowID;    /**< The window with mouse focus, if any */
slouken@4429
   194
    Uint8 which;        /**< The mouse device index */
slouken@4429
   195
    Uint8 button;       /**< The mouse button index */
slouken@4429
   196
    Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
slouken@4429
   197
    Uint8 padding1;
slouken@4429
   198
    int x;              /**< X coordinate, relative to window */
slouken@4429
   199
    int y;              /**< Y coordinate, relative to window */
slouken@0
   200
} SDL_MouseButtonEvent;
slouken@0
   201
slouken@1895
   202
/**
slouken@3407
   203
 *  \brief Mouse wheel event structure (event.wheel.*)
slouken@1895
   204
 */
slouken@1895
   205
typedef struct SDL_MouseWheelEvent
slouken@1895
   206
{
slouken@4429
   207
    Uint32 type;        /**< ::SDL_MOUSEWHEEL */
slouken@4429
   208
    Uint32 windowID;    /**< The window with mouse focus, if any */
slouken@4429
   209
    Uint8 which;        /**< The mouse device index */
slouken@4429
   210
    Uint8 padding1;
slouken@4429
   211
    Uint8 padding2;
slouken@4429
   212
    Uint8 padding3;
slouken@4429
   213
    int x;              /**< The amount scrolled horizontally */
slouken@4429
   214
    int y;              /**< The amount scrolled vertically */
slouken@1895
   215
} SDL_MouseWheelEvent;
slouken@1895
   216
slouken@1895
   217
/**
slouken@4429
   218
 * \brief Tablet pen proximity event
slouken@4429
   219
 */
slouken@4429
   220
typedef struct SDL_ProximityEvent
slouken@4429
   221
{
slouken@4429
   222
    Uint32 type;        /**< ::SDL_PROXIMITYIN or ::SDL_PROXIMITYOUT */
slouken@4429
   223
    Uint32 windowID;    /**< The associated window */
slouken@4429
   224
    Uint8 which;
slouken@4429
   225
    Uint8 padding1;
slouken@4429
   226
    Uint8 padding2;
slouken@4429
   227
    Uint8 padding3;
slouken@4429
   228
    int cursor;
slouken@4429
   229
    int x;
slouken@4429
   230
    int y;
slouken@4429
   231
} SDL_ProximityEvent;
slouken@4429
   232
slouken@4429
   233
/**
slouken@3407
   234
 *  \brief Joystick axis motion event structure (event.jaxis.*)
slouken@1895
   235
 */
slouken@1895
   236
typedef struct SDL_JoyAxisEvent
slouken@1895
   237
{
slouken@4429
   238
    Uint32 type;        /**< ::SDL_JOYAXISMOTION */
slouken@1895
   239
    Uint8 which;        /**< The joystick device index */
slouken@1895
   240
    Uint8 axis;         /**< The joystick axis index */
slouken@4429
   241
    Uint8 padding1;
slouken@4429
   242
    Uint8 padding2;
slouken@1895
   243
    int value;          /**< The axis value (range: -32768 to 32767) */
slouken@0
   244
} SDL_JoyAxisEvent;
slouken@0
   245
slouken@1895
   246
/**
slouken@3407
   247
 *  \brief Joystick trackball motion event structure (event.jball.*)
slouken@1895
   248
 */
slouken@1895
   249
typedef struct SDL_JoyBallEvent
slouken@1895
   250
{
slouken@4429
   251
    Uint32 type;        /**< ::SDL_JOYBALLMOTION */
slouken@1895
   252
    Uint8 which;        /**< The joystick device index */
slouken@1895
   253
    Uint8 ball;         /**< The joystick trackball index */
slouken@4429
   254
    Uint8 padding1;
slouken@4429
   255
    Uint8 padding2;
slouken@1895
   256
    int xrel;           /**< The relative motion in the X direction */
slouken@1895
   257
    int yrel;           /**< The relative motion in the Y direction */
slouken@0
   258
} SDL_JoyBallEvent;
slouken@0
   259
slouken@1895
   260
/**
slouken@3407
   261
 *  \brief Joystick hat position change event structure (event.jhat.*)
slouken@1895
   262
 */
slouken@1895
   263
typedef struct SDL_JoyHatEvent
slouken@1895
   264
{
slouken@4429
   265
    Uint32 type;        /**< ::SDL_JOYHATMOTION */
slouken@1895
   266
    Uint8 which;        /**< The joystick device index */
slouken@1895
   267
    Uint8 hat;          /**< The joystick hat index */
slouken@3407
   268
    Uint8 value;        /**< The hat position value.
slouken@3407
   269
                         *   \sa ::SDL_HAT_LEFTUP ::SDL_HAT_UP ::SDL_HAT_RIGHTUP
slouken@3407
   270
                         *   \sa ::SDL_HAT_LEFT ::SDL_HAT_CENTERED ::SDL_HAT_RIGHT
slouken@3407
   271
                         *   \sa ::SDL_HAT_LEFTDOWN ::SDL_HAT_DOWN ::SDL_HAT_RIGHTDOWN
slouken@3407
   272
                         *   
slouken@3407
   273
                         *   Note that zero means the POV is centered.
slouken@1895
   274
                         */
slouken@4429
   275
    Uint8 padding1;
slouken@0
   276
} SDL_JoyHatEvent;
slouken@0
   277
slouken@1895
   278
/**
slouken@3407
   279
 *  \brief Joystick button event structure (event.jbutton.*)
slouken@1895
   280
 */
slouken@1895
   281
typedef struct SDL_JoyButtonEvent
slouken@1895
   282
{
slouken@4429
   283
    Uint32 type;        /**< ::SDL_JOYBUTTONDOWN or ::SDL_JOYBUTTONUP */
slouken@1895
   284
    Uint8 which;        /**< The joystick device index */
slouken@1895
   285
    Uint8 button;       /**< The joystick button index */
slouken@3407
   286
    Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
slouken@4429
   287
    Uint8 padding1;
slouken@0
   288
} SDL_JoyButtonEvent;
slouken@0
   289
slouken@1895
   290
/**
slouken@3407
   291
 *  \brief The "quit requested" event
slouken@0
   292
 */
slouken@1895
   293
typedef struct SDL_QuitEvent
slouken@1895
   294
{
slouken@4429
   295
    Uint32 type;        /**< ::SDL_QUIT */
slouken@1895
   296
} SDL_QuitEvent;
slouken@1895
   297
slouken@1895
   298
/**
slouken@3407
   299
 *  \brief A user-defined event type (event.user.*)
slouken@1895
   300
 */
slouken@1895
   301
typedef struct SDL_UserEvent
slouken@1895
   302
{
slouken@4429
   303
    Uint32 type;        /**< ::SDL_USEREVENT through ::SDL_NUMEVENTS-1 */
slouken@4429
   304
    Uint32 windowID;    /**< The associated window if any */
slouken@4429
   305
    int code;           /**< User defined event code */
slouken@4429
   306
    void *data1;        /**< User defined data pointer */
slouken@4429
   307
    void *data2;        /**< User defined data pointer */
slouken@1895
   308
} SDL_UserEvent;
slouken@1895
   309
slouken@1895
   310
struct SDL_SysWMmsg;
slouken@1895
   311
typedef struct SDL_SysWMmsg SDL_SysWMmsg;
slouken@3407
   312
slouken@3407
   313
/**
slouken@3407
   314
 *  \brief A video driver dependent system event (event.syswm.*)
slouken@3407
   315
 *  
slouken@3407
   316
 *  \note If you want to use this event, you should include SDL_syswm.h.
slouken@3407
   317
 */
slouken@1895
   318
typedef struct SDL_SysWMEvent
slouken@1895
   319
{
slouken@4429
   320
    Uint32 type;        /**< ::SDL_SYSWMEVENT */
slouken@1895
   321
    SDL_SysWMmsg *msg;  /**< driver dependent data, defined in SDL_syswm.h */
slouken@1895
   322
} SDL_SysWMEvent;
slouken@1895
   323
bob@3167
   324
#ifndef SDL_NO_COMPAT
slouken@3407
   325
/**
slouken@3407
   326
 *  \addtogroup Compatibility 
slouken@3407
   327
 */
slouken@3407
   328
/*@{*/
slouken@3407
   329
slouken@3407
   330
/**
slouken@3407
   331
 *  \name Typedefs for backwards compatibility
slouken@3407
   332
 */
slouken@3407
   333
/*@{*/
bob@3167
   334
typedef struct SDL_ActiveEvent
bob@3167
   335
{
slouken@4429
   336
    Uint32 type;
bob@3167
   337
    Uint8 gain;
bob@3167
   338
    Uint8 state;
bob@3167
   339
} SDL_ActiveEvent;
bob@3167
   340
bob@3167
   341
typedef struct SDL_ResizeEvent
bob@3167
   342
{
slouken@4429
   343
    Uint32 type;
bob@3167
   344
    int w;
bob@3167
   345
    int h;
bob@3167
   346
} SDL_ResizeEvent;
slouken@3407
   347
/*@}*/
slouken@3407
   348
slouken@3407
   349
/*@}*//*Compatibility*/
bob@3167
   350
#endif
bob@3167
   351
slouken@1895
   352
/**
slouken@3407
   353
 *  \brief General event structure
slouken@1895
   354
 */
slouken@1895
   355
typedef union SDL_Event
slouken@1895
   356
{
slouken@4429
   357
    Uint32 type;                    /**< Event type, shared with all events */
slouken@1895
   358
    SDL_WindowEvent window;         /**< Window event data */
slouken@1895
   359
    SDL_KeyboardEvent key;          /**< Keyboard event data */
slouken@3280
   360
    SDL_TextEditingEvent edit;      /**< Text editing event data */
bob@2300
   361
    SDL_TextInputEvent text;        /**< Text input event data */
slouken@1895
   362
    SDL_MouseMotionEvent motion;    /**< Mouse motion event data */
slouken@1895
   363
    SDL_MouseButtonEvent button;    /**< Mouse button event data */
bob@2300
   364
    SDL_MouseWheelEvent wheel;      /**< Mouse wheel event data */
slouken@1895
   365
    SDL_JoyAxisEvent jaxis;         /**< Joystick axis event data */
slouken@1895
   366
    SDL_JoyBallEvent jball;         /**< Joystick ball event data */
slouken@1895
   367
    SDL_JoyHatEvent jhat;           /**< Joystick hat event data */
slouken@1895
   368
    SDL_JoyButtonEvent jbutton;     /**< Joystick button event data */
slouken@1895
   369
    SDL_QuitEvent quit;             /**< Quit request event data */
slouken@1895
   370
    SDL_UserEvent user;             /**< Custom event data */
slouken@1895
   371
    SDL_SysWMEvent syswm;           /**< System dependent window event data */
slouken@2710
   372
    SDL_ProximityEvent proximity;   /**< Proximity In or Out event */
slouken@0
   373
slouken@3407
   374
    /** Temporarily here for backwards compatibility */
slouken@3407
   375
    /*@{*/
bob@3167
   376
#ifndef SDL_NO_COMPAT
slouken@1895
   377
    SDL_ActiveEvent active;
slouken@1895
   378
    SDL_ResizeEvent resize;
bob@3167
   379
#endif
slouken@3407
   380
    /*@}*/
slouken@0
   381
} SDL_Event;
slouken@0
   382
slouken@0
   383
slouken@0
   384
/* Function prototypes */
slouken@0
   385
slouken@3407
   386
/**
slouken@3407
   387
 *  Pumps the event loop, gathering events from the input devices.
slouken@3407
   388
 *  
slouken@3407
   389
 *  This function updates the event queue and internal input device state.
slouken@3407
   390
 *  
slouken@3407
   391
 *  This should only be run in the thread that sets the video mode.
slouken@3407
   392
 */
slouken@337
   393
extern DECLSPEC void SDLCALL SDL_PumpEvents(void);
slouken@0
   394
slouken@3407
   395
/*@{*/
slouken@1895
   396
typedef enum
slouken@1895
   397
{
slouken@1895
   398
    SDL_ADDEVENT,
slouken@1895
   399
    SDL_PEEKEVENT,
slouken@1895
   400
    SDL_GETEVENT
slouken@0
   401
} SDL_eventaction;
slouken@3407
   402
slouken@3407
   403
/**
slouken@3407
   404
 *  Checks the event queue for messages and optionally returns them.
slouken@3407
   405
 *  
slouken@3407
   406
 *  If \c action is ::SDL_ADDEVENT, up to \c numevents events will be added to
slouken@3407
   407
 *  the back of the event queue.
slouken@3407
   408
 *  
slouken@3407
   409
 *  If \c action is ::SDL_PEEKEVENT, up to \c numevents events at the front
slouken@3407
   410
 *  of the event queue, matching \c mask, will be returned and will not
slouken@3407
   411
 *  be removed from the queue.
slouken@3407
   412
 *  
slouken@3407
   413
 *  If \c action is ::SDL_GETEVENT, up to \c numevents events at the front 
slouken@3407
   414
 *  of the event queue, matching \c mask, will be returned and will be
slouken@3407
   415
 *  removed from the queue.
slouken@3407
   416
 *  
slouken@3407
   417
 *  \return The number of events actually stored, or -1 if there was an error.
slouken@3407
   418
 *  
slouken@3407
   419
 *  This function is thread-safe.
slouken@3407
   420
 */
slouken@1895
   421
extern DECLSPEC int SDLCALL SDL_PeepEvents(SDL_Event * events, int numevents,
slouken@1895
   422
                                           SDL_eventaction action,
slouken@4429
   423
                                           Uint32 minType, Uint32 maxType);
slouken@3407
   424
/*@}*/
slouken@1895
   425
slouken@3407
   426
/**
slouken@3407
   427
 *  Checks to see if certain event types are in the event queue.
slouken@1895
   428
 */
slouken@4429
   429
extern DECLSPEC SDL_bool SDLCALL SDL_HasEvent(Uint32 type);
slouken@4429
   430
extern DECLSPEC SDL_bool SDLCALL SDL_HasEvents(Uint32 minType, Uint32 maxType);
slouken@4429
   431
slouken@4429
   432
/**
slouken@4429
   433
 *  This function clears events from the event queue
slouken@4429
   434
 */
slouken@4429
   435
extern DECLSPEC void SDLCALL SDL_FlushEvent(Uint32 type);
slouken@4429
   436
extern DECLSPEC void SDLCALL SDL_FlushEvents(Uint32 minType, Uint32 maxType);
slouken@0
   437
slouken@3407
   438
/**
slouken@3407
   439
 *  \brief Polls for currently pending events.
slouken@3407
   440
 *  
slouken@3407
   441
 *  \return 1 if there are any pending events, or 0 if there are none available.
slouken@3407
   442
 *  
slouken@3407
   443
 *  \param event If not NULL, the next event is removed from the queue and 
slouken@3407
   444
 *               stored in that area.
slouken@0
   445
 */
slouken@1895
   446
extern DECLSPEC int SDLCALL SDL_PollEvent(SDL_Event * event);
slouken@0
   447
slouken@3407
   448
/**
slouken@3407
   449
 *  \brief Waits indefinitely for the next available event.
slouken@3407
   450
 *  
slouken@3407
   451
 *  \return 1, or 0 if there was an error while waiting for events.
slouken@3407
   452
 *   
slouken@3407
   453
 *  \param event If not NULL, the next event is removed from the queue and 
slouken@3407
   454
 *               stored in that area.
slouken@0
   455
 */
slouken@1895
   456
extern DECLSPEC int SDLCALL SDL_WaitEvent(SDL_Event * event);
slouken@0
   457
slouken@3407
   458
/**
slouken@3407
   459
 *  \brief Waits until the specified timeout (in milliseconds) for the next 
slouken@3407
   460
 *         available event.
slouken@3407
   461
 *  
slouken@3407
   462
 *  \return 1, or 0 if there was an error while waiting for events.
slouken@3407
   463
 *  
slouken@3407
   464
 *  \param event If not NULL, the next event is removed from the queue and 
slouken@3407
   465
 *               stored in that area.
slouken@3072
   466
 */
slouken@3072
   467
extern DECLSPEC int SDLCALL SDL_WaitEventTimeout(SDL_Event * event,
slouken@3072
   468
                                                 int timeout);
slouken@3072
   469
slouken@3407
   470
/**
slouken@3407
   471
 *  \brief Add an event to the event queue.
slouken@3407
   472
 *  
slouken@3407
   473
 *  \return 1 on success, 0 if the event was filtered, or -1 if the event queue 
slouken@3407
   474
 *          was full or there was some other error.
slouken@0
   475
 */
slouken@1895
   476
extern DECLSPEC int SDLCALL SDL_PushEvent(SDL_Event * event);
slouken@0
   477
slouken@3407
   478
typedef int (SDLCALL * SDL_EventFilter) (void *userdata, SDL_Event * event);
slouken@0
   479
slouken@3407
   480
/**
slouken@3407
   481
 *  Sets up a filter to process all events before they change internal state and
slouken@3407
   482
 *  are posted to the internal event queue.
slouken@3407
   483
 *  
slouken@3407
   484
 *  The filter is protypted as:
slouken@3407
   485
 *  \code
slouken@3407
   486
 *      int SDL_EventFilter(void *userdata, SDL_Event * event);
slouken@3407
   487
 *  \endcode
slouken@3407
   488
 *
slouken@3407
   489
 *  If the filter returns 1, then the event will be added to the internal queue.
slouken@3407
   490
 *  If it returns 0, then the event will be dropped from the queue, but the 
slouken@3407
   491
 *  internal state will still be updated.  This allows selective filtering of
slouken@3407
   492
 *  dynamically arriving events.
slouken@3407
   493
 *  
slouken@3407
   494
 *  \warning  Be very careful of what you do in the event filter function, as 
slouken@3407
   495
 *            it may run in a different thread!
slouken@3407
   496
 *  
slouken@3407
   497
 *  There is one caveat when dealing with the ::SDL_QUITEVENT event type.  The
slouken@3407
   498
 *  event filter is only called when the window manager desires to close the
slouken@3407
   499
 *  application window.  If the event filter returns 1, then the window will
slouken@3407
   500
 *  be closed, otherwise the window will remain open if possible.
slouken@3407
   501
 *
slouken@3407
   502
 *  If the quit event is generated by an interrupt signal, it will bypass the
slouken@3407
   503
 *  internal queue and be delivered to the application at the next event poll.
slouken@3407
   504
 */
slouken@1895
   505
extern DECLSPEC void SDLCALL SDL_SetEventFilter(SDL_EventFilter filter,
slouken@1895
   506
                                                void *userdata);
slouken@0
   507
slouken@3407
   508
/**
slouken@3407
   509
 *  Return the current event filter - can be used to "chain" filters.
slouken@3407
   510
 *  If there is no event filter set, this function returns SDL_FALSE.
slouken@3407
   511
 */
slouken@1895
   512
extern DECLSPEC SDL_bool SDLCALL SDL_GetEventFilter(SDL_EventFilter * filter,
slouken@1895
   513
                                                    void **userdata);
slouken@1895
   514
slouken@3407
   515
/**
slouken@3407
   516
 *  Run the filter function on the current event queue, removing any
slouken@3407
   517
 *  events for which the filter returns 0.
slouken@3407
   518
 */
slouken@1895
   519
extern DECLSPEC void SDLCALL SDL_FilterEvents(SDL_EventFilter filter,
slouken@1895
   520
                                              void *userdata);
slouken@0
   521
slouken@3407
   522
/*@{*/
slouken@0
   523
#define SDL_QUERY	-1
slouken@0
   524
#define SDL_IGNORE	 0
slouken@0
   525
#define SDL_DISABLE	 0
slouken@0
   526
#define SDL_ENABLE	 1
slouken@3407
   527
slouken@3407
   528
/**
slouken@3407
   529
 *  This function allows you to set the state of processing certain events.
slouken@3407
   530
 *   - If \c state is set to ::SDL_IGNORE, that event will be automatically 
slouken@3407
   531
 *     dropped from the event queue and will not event be filtered.
slouken@3407
   532
 *   - If \c state is set to ::SDL_ENABLE, that event will be processed 
slouken@3407
   533
 *     normally.
slouken@3407
   534
 *   - If \c state is set to ::SDL_QUERY, SDL_EventState() will return the 
slouken@3407
   535
 *     current processing state of the specified event.
slouken@3407
   536
 */
slouken@4429
   537
extern DECLSPEC Uint8 SDLCALL SDL_EventState(Uint32 type, int state);
slouken@3407
   538
/*@}*/
slouken@4429
   539
#define SDL_GetEventState(type) SDL_EventState(type, SDL_QUERY)
slouken@4429
   540
slouken@4429
   541
/**
slouken@4429
   542
 *  This function allocates a set of user-defined events, and returns
slouken@4429
   543
 *  the beginning event number for that set of events.
slouken@4429
   544
 *
slouken@4429
   545
 *  If there aren't enough user-defined events left, this function
slouken@4429
   546
 *  returns (Uint32)-1
slouken@4429
   547
 */
slouken@4429
   548
extern DECLSPEC Uint32 SDLCALL SDL_RegisterEvents(int numevents);
slouken@0
   549
slouken@0
   550
/* Ends C function definitions when using C++ */
slouken@0
   551
#ifdef __cplusplus
slouken@1895
   552
/* *INDENT-OFF* */
slouken@0
   553
}
slouken@1895
   554
/* *INDENT-ON* */
slouken@0
   555
#endif
slouken@0
   556
#include "close_code.h"
slouken@0
   557
slouken@0
   558
#endif /* _SDL_events_h */
slouken@1895
   559
slouken@1895
   560
/* vi: set ts=4 sw=4 expandtab: */