🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

794 lines
30 KiB

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