SDL_events.h 29 KB

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