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