SDL_events.h 26 KB

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