gosu 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. checksums.yaml +4 -4
  2. data/dependencies/SDL/include/SDL.h +108 -14
  3. data/dependencies/SDL/include/SDL_assert.h +81 -50
  4. data/dependencies/SDL/include/SDL_atomic.h +135 -35
  5. data/dependencies/SDL/include/SDL_audio.h +960 -355
  6. data/dependencies/SDL/include/SDL_bits.h +11 -6
  7. data/dependencies/SDL/include/SDL_blendmode.h +91 -14
  8. data/dependencies/SDL/include/SDL_clipboard.h +30 -7
  9. data/dependencies/SDL/include/SDL_config.h +277 -27
  10. data/dependencies/SDL/include/SDL_config_android.h +13 -38
  11. data/dependencies/SDL/include/SDL_config_iphoneos.h +21 -62
  12. data/dependencies/SDL/include/SDL_config_macosx.h +23 -92
  13. data/dependencies/SDL/include/SDL_config_minimal.h +1 -4
  14. data/dependencies/SDL/include/SDL_config_pandora.h +15 -22
  15. data/dependencies/SDL/include/SDL_config_psp.h +16 -37
  16. data/dependencies/SDL/include/SDL_config_windows.h +28 -91
  17. data/dependencies/SDL/include/SDL_config_winrt.h +33 -61
  18. data/dependencies/SDL/include/SDL_config_wiz.h +28 -56
  19. data/dependencies/SDL/include/SDL_copying.h +1 -1
  20. data/dependencies/SDL/include/SDL_cpuinfo.h +331 -71
  21. data/dependencies/SDL/include/SDL_egl.h +906 -280
  22. data/dependencies/SDL/include/SDL_endian.h +101 -47
  23. data/dependencies/SDL/include/SDL_error.h +70 -19
  24. data/dependencies/SDL/include/SDL_events.h +387 -79
  25. data/dependencies/SDL/include/SDL_filesystem.h +73 -64
  26. data/dependencies/SDL/include/SDL_gamecontroller.h +585 -125
  27. data/dependencies/SDL/include/SDL_gesture.h +36 -6
  28. data/dependencies/SDL/include/SDL_haptic.h +304 -210
  29. data/dependencies/SDL/include/SDL_hidapi.h +451 -0
  30. data/dependencies/SDL/include/SDL_hints.h +1286 -897
  31. data/dependencies/SDL/include/SDL_joystick.h +577 -130
  32. data/dependencies/SDL/include/SDL_keyboard.h +162 -63
  33. data/dependencies/SDL/include/SDL_keycode.h +7 -5
  34. data/dependencies/SDL/include/SDL_loadso.h +42 -8
  35. data/dependencies/SDL/include/SDL_locale.h +34 -32
  36. data/dependencies/SDL/include/SDL_log.h +212 -19
  37. data/dependencies/SDL/include/SDL_main.h +72 -17
  38. data/dependencies/SDL/include/SDL_messagebox.h +70 -23
  39. data/dependencies/SDL/include/SDL_metal.h +27 -32
  40. data/dependencies/SDL/include/SDL_misc.h +19 -15
  41. data/dependencies/SDL/include/SDL_mouse.h +262 -110
  42. data/dependencies/SDL/include/SDL_mutex.h +286 -66
  43. data/dependencies/SDL/include/SDL_name.h +1 -1
  44. data/dependencies/SDL/include/SDL_opengl.h +1 -1
  45. data/dependencies/SDL/include/SDL_opengles.h +1 -1
  46. data/dependencies/SDL/include/SDL_opengles2.h +2 -2
  47. data/dependencies/SDL/include/SDL_pixels.h +199 -34
  48. data/dependencies/SDL/include/SDL_platform.h +39 -2
  49. data/dependencies/SDL/include/SDL_power.h +23 -10
  50. data/dependencies/SDL/include/SDL_quit.h +1 -1
  51. data/dependencies/SDL/include/SDL_rect.h +78 -28
  52. data/dependencies/SDL/include/SDL_render.h +1204 -472
  53. data/dependencies/SDL/include/SDL_revision.h +2 -2
  54. data/dependencies/SDL/include/SDL_rwops.h +605 -33
  55. data/dependencies/SDL/include/SDL_scancode.h +1 -1
  56. data/dependencies/SDL/include/SDL_sensor.h +76 -42
  57. data/dependencies/SDL/include/SDL_shape.h +38 -27
  58. data/dependencies/SDL/include/SDL_stdinc.h +96 -24
  59. data/dependencies/SDL/include/SDL_surface.h +571 -139
  60. data/dependencies/SDL/include/SDL_system.h +339 -101
  61. data/dependencies/SDL/include/SDL_syswm.h +50 -20
  62. data/dependencies/SDL/include/SDL_test.h +1 -1
  63. data/dependencies/SDL/include/SDL_test_assert.h +2 -2
  64. data/dependencies/SDL/include/SDL_test_common.h +23 -6
  65. data/dependencies/SDL/include/SDL_test_compare.h +1 -1
  66. data/dependencies/SDL/include/SDL_test_crc32.h +1 -1
  67. data/dependencies/SDL/include/SDL_test_font.h +3 -3
  68. data/dependencies/SDL/include/SDL_test_fuzzer.h +28 -26
  69. data/dependencies/SDL/include/SDL_test_harness.h +6 -6
  70. data/dependencies/SDL/include/SDL_test_images.h +1 -1
  71. data/dependencies/SDL/include/SDL_test_log.h +1 -1
  72. data/dependencies/SDL/include/SDL_test_md5.h +1 -1
  73. data/dependencies/SDL/include/SDL_test_memory.h +1 -1
  74. data/dependencies/SDL/include/SDL_test_random.h +2 -2
  75. data/dependencies/SDL/include/SDL_thread.h +226 -128
  76. data/dependencies/SDL/include/SDL_timer.h +129 -22
  77. data/dependencies/SDL/include/SDL_touch.h +48 -8
  78. data/dependencies/SDL/include/SDL_types.h +1 -1
  79. data/dependencies/SDL/include/SDL_version.h +72 -46
  80. data/dependencies/SDL/include/SDL_video.h +1266 -460
  81. data/dependencies/SDL/include/SDL_vulkan.h +100 -161
  82. data/dependencies/SDL/include/begin_code.h +22 -1
  83. data/dependencies/SDL/include/close_code.h +1 -1
  84. data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
  85. data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
  86. data/dependencies/SDL_sound/SDL_sound.c +83 -7
  87. data/dependencies/SDL_sound/SDL_sound.h +4 -4
  88. data/dependencies/SDL_sound/SDL_sound_aiff.c +9 -12
  89. data/dependencies/SDL_sound/SDL_sound_au.c +7 -7
  90. data/dependencies/SDL_sound/SDL_sound_coreaudio.c +3 -3
  91. data/dependencies/SDL_sound/SDL_sound_flac.c +1 -1
  92. data/dependencies/SDL_sound/SDL_sound_internal.h +17 -10
  93. data/dependencies/SDL_sound/SDL_sound_modplug.c +25 -27
  94. data/dependencies/SDL_sound/SDL_sound_mp3.c +5 -17
  95. data/dependencies/SDL_sound/SDL_sound_raw.c +11 -11
  96. data/dependencies/SDL_sound/SDL_sound_shn.c +8 -7
  97. data/dependencies/SDL_sound/SDL_sound_voc.c +6 -4
  98. data/dependencies/SDL_sound/SDL_sound_vorbis.c +6 -11
  99. data/dependencies/SDL_sound/SDL_sound_wav.c +35 -29
  100. data/dependencies/SDL_sound/dr_flac.h +618 -220
  101. data/dependencies/SDL_sound/dr_mp3.h +263 -94
  102. data/dependencies/SDL_sound/libmodplug/fastmix.c +58 -64
  103. data/dependencies/SDL_sound/libmodplug/libmodplug.h +25 -103
  104. data/dependencies/SDL_sound/libmodplug/load_669.c +14 -17
  105. data/dependencies/SDL_sound/libmodplug/load_amf.c +11 -7
  106. data/dependencies/SDL_sound/libmodplug/load_ams.c +65 -22
  107. data/dependencies/SDL_sound/libmodplug/load_dbm.c +8 -4
  108. data/dependencies/SDL_sound/libmodplug/load_dmf.c +55 -25
  109. data/dependencies/SDL_sound/libmodplug/load_far.c +9 -13
  110. data/dependencies/SDL_sound/libmodplug/load_gdm.c +448 -0
  111. data/dependencies/SDL_sound/libmodplug/load_it.c +45 -49
  112. data/dependencies/SDL_sound/libmodplug/load_mdl.c +80 -53
  113. data/dependencies/SDL_sound/libmodplug/load_med.c +20 -12
  114. data/dependencies/SDL_sound/libmodplug/load_mod.c +40 -15
  115. data/dependencies/SDL_sound/libmodplug/load_mt2.c +29 -17
  116. data/dependencies/SDL_sound/libmodplug/load_okt.c +12 -8
  117. data/dependencies/SDL_sound/libmodplug/load_psm.c +101 -78
  118. data/dependencies/SDL_sound/libmodplug/load_ptm.c +18 -17
  119. data/dependencies/SDL_sound/libmodplug/load_s3m.c +9 -7
  120. data/dependencies/SDL_sound/libmodplug/load_stm.c +3 -2
  121. data/dependencies/SDL_sound/libmodplug/load_ult.c +2 -2
  122. data/dependencies/SDL_sound/libmodplug/load_umx.c +315 -35
  123. data/dependencies/SDL_sound/libmodplug/load_xm.c +25 -21
  124. data/dependencies/SDL_sound/libmodplug/mmcmp.c +295 -149
  125. data/dependencies/SDL_sound/libmodplug/modplug.c +7 -123
  126. data/dependencies/SDL_sound/libmodplug/modplug.h +32 -29
  127. data/dependencies/SDL_sound/libmodplug/snd_dsp.c +0 -1
  128. data/dependencies/SDL_sound/libmodplug/snd_flt.c +2 -2
  129. data/dependencies/SDL_sound/libmodplug/snd_fx.c +24 -18
  130. data/dependencies/SDL_sound/libmodplug/sndfile.c +55 -156
  131. data/dependencies/SDL_sound/libmodplug/sndmix.c +7 -12
  132. data/dependencies/SDL_sound/libmodplug/tables.h +10 -15
  133. data/dependencies/SDL_sound/stb_vorbis.h +508 -325
  134. data/dependencies/{al_soft → mojoAL}/AL/al.h +38 -30
  135. data/dependencies/{al_soft → mojoAL}/AL/alc.h +27 -56
  136. data/dependencies/mojoAL/mojoal.c +4594 -0
  137. data/ext/gosu/extconf.rb +29 -30
  138. data/include/Gosu/Audio.hpp +70 -85
  139. data/include/Gosu/Color.hpp +19 -11
  140. data/include/Gosu/Font.hpp +40 -44
  141. data/include/Gosu/Graphics.hpp +58 -71
  142. data/include/Gosu/GraphicsBase.hpp +26 -33
  143. data/include/Gosu/Image.hpp +56 -62
  144. data/include/Gosu/ImageData.hpp +23 -27
  145. data/include/Gosu/Inspection.hpp +1 -4
  146. data/include/Gosu/TextInput.hpp +34 -40
  147. data/include/Gosu/Version.hpp +1 -1
  148. data/include/Gosu/Window.hpp +71 -70
  149. data/lib/SDL2.dll +0 -0
  150. data/lib/gosu/compat.rb +24 -37
  151. data/lib/gosu.rb +2 -2
  152. data/lib64/SDL2.dll +0 -0
  153. data/src/Audio.cpp +86 -86
  154. data/src/AudioFile.hpp +6 -6
  155. data/src/AudioFileAudioToolbox.cpp +1 -1
  156. data/src/AudioFileSDLSound.cpp +1 -1
  157. data/src/AudioImpl.hpp +5 -5
  158. data/src/BitmapIO.cpp +0 -20
  159. data/src/BlockAllocator.cpp +2 -1
  160. data/src/Channel.cpp +22 -20
  161. data/src/Color.cpp +12 -9
  162. data/src/EmptyImageData.hpp +15 -17
  163. data/src/FileUnix.cpp +1 -1
  164. data/src/FileWin.cpp +1 -1
  165. data/src/Font.cpp +48 -53
  166. data/src/Graphics.cpp +135 -143
  167. data/src/Image.cpp +41 -42
  168. data/src/Input.cpp +1 -1
  169. data/src/InputUIKit.cpp +1 -1
  170. data/src/LargeImageData.cpp +108 -101
  171. data/src/LargeImageData.hpp +17 -15
  172. data/src/Log.hpp +6 -6
  173. data/src/Macro.cpp +35 -37
  174. data/src/Macro.hpp +11 -11
  175. data/src/Math.cpp +8 -1
  176. data/src/Resolution.cpp +12 -7
  177. data/src/RubyGosu.cxx +5 -5
  178. data/src/TexChunk.cpp +50 -41
  179. data/src/TexChunk.hpp +22 -22
  180. data/src/Text.cpp +37 -37
  181. data/src/TextBuilder.cpp +60 -57
  182. data/src/TextBuilder.hpp +20 -20
  183. data/src/TextInput.cpp +127 -135
  184. data/src/TrueTypeFont.cpp +107 -107
  185. data/src/TrueTypeFont.hpp +39 -38
  186. data/src/TrueTypeFontApple.cpp +19 -22
  187. data/src/TrueTypeFontUnix.cpp +21 -26
  188. data/src/TrueTypeFontWin.cpp +30 -30
  189. data/src/Window.cpp +95 -86
  190. data/src/WindowUIKit.cpp +46 -49
  191. metadata +7 -17
  192. data/dependencies/SDL/include/SDL_config_os2.h +0 -188
  193. data/dependencies/SDL_sound/libmodplug/load_abc.c +0 -4725
  194. data/dependencies/SDL_sound/libmodplug/load_mid.c +0 -1405
  195. data/dependencies/SDL_sound/libmodplug/load_pat.c +0 -1143
  196. data/dependencies/SDL_sound/libmodplug/load_pat.h +0 -25
  197. data/dependencies/al_soft/AL/alext.h +0 -585
  198. data/dependencies/al_soft/AL/efx-creative.h +0 -3
  199. data/dependencies/al_soft/AL/efx-presets.h +0 -402
  200. data/dependencies/al_soft/AL/efx.h +0 -762
  201. data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
  202. data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
  203. data/lib/OpenAL32.dll +0 -0
  204. data/lib64/OpenAL32.dll +0 -0
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  Simple DirectMedia Layer
3
- Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
3
+ Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
4
4
 
5
5
  This software is provided 'as-is', without any express or implied
6
6
  warranty. In no event will the authors be held liable for any damages
@@ -50,7 +50,7 @@ extern "C" {
50
50
  #define SDL_PRESSED 1
51
51
 
52
52
  /**
53
- * \brief The types of events that can be delivered.
53
+ * The types of events that can be delivered.
54
54
  */
55
55
  typedef enum
56
56
  {
@@ -160,6 +160,9 @@ typedef enum
160
160
  SDL_RENDER_TARGETS_RESET = 0x2000, /**< The render targets have been reset and their contents need to be updated */
161
161
  SDL_RENDER_DEVICE_RESET, /**< The device has been reset and all textures need to be recreated */
162
162
 
163
+ /* Internal events */
164
+ SDL_POLLSENTINEL = 0x7F00, /**< Signals the end of an event poll cycle */
165
+
163
166
  /** Events ::SDL_USEREVENT through ::SDL_LASTEVENT are for your use,
164
167
  * and should be allocated with SDL_RegisterEvents()
165
168
  */
@@ -298,6 +301,8 @@ typedef struct SDL_MouseWheelEvent
298
301
  Sint32 x; /**< The amount scrolled horizontally, positive to the right and negative to the left */
299
302
  Sint32 y; /**< The amount scrolled vertically, positive away from the user and negative toward the user */
300
303
  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 */
304
+ float preciseX; /**< The amount scrolled horizontally, positive to the right and negative to the left, with float precision (added in 2.0.18) */
305
+ float preciseY; /**< The amount scrolled vertically, positive away from the user and negative toward the user, with float precision (added in 2.0.18) */
301
306
  } SDL_MouseWheelEvent;
302
307
 
303
308
  /**
@@ -620,28 +625,49 @@ typedef union SDL_Event
620
625
  SDL_DollarGestureEvent dgesture; /**< Gesture event data */
621
626
  SDL_DropEvent drop; /**< Drag and drop event data */
622
627
 
623
- /* This is necessary for ABI compatibility between Visual C++ and GCC
624
- Visual C++ will respect the push pack pragma and use 52 bytes for
625
- this structure, and GCC will use the alignment of the largest datatype
626
- within the union, which is 8 bytes.
628
+ /* This is necessary for ABI compatibility between Visual C++ and GCC.
629
+ Visual C++ will respect the push pack pragma and use 52 bytes (size of
630
+ SDL_TextEditingEvent, the largest structure for 32-bit and 64-bit
631
+ architectures) for this union, and GCC will use the alignment of the
632
+ largest datatype within the union, which is 8 bytes on 64-bit
633
+ architectures.
627
634
 
628
635
  So... we'll add padding to force the size to be 56 bytes for both.
636
+
637
+ On architectures where pointers are 16 bytes, this needs rounding up to
638
+ the next multiple of 16, 64, and on architectures where pointers are
639
+ even larger the size of SDL_UserEvent will dominate as being 3 pointers.
629
640
  */
630
- Uint8 padding[56];
641
+ Uint8 padding[sizeof(void *) <= 8 ? 56 : sizeof(void *) == 16 ? 64 : 3 * sizeof(void *)];
631
642
  } SDL_Event;
632
643
 
633
644
  /* Make sure we haven't broken binary compatibility */
634
- SDL_COMPILE_TIME_ASSERT(SDL_Event, sizeof(SDL_Event) == 56);
645
+ SDL_COMPILE_TIME_ASSERT(SDL_Event, sizeof(SDL_Event) == sizeof(((SDL_Event *)NULL)->padding));
635
646
 
636
647
 
637
648
  /* Function prototypes */
638
649
 
639
650
  /**
640
- * Pumps the event loop, gathering events from the input devices.
651
+ * Pump the event loop, gathering events from the input devices.
652
+ *
653
+ * This function updates the event queue and internal input device state.
641
654
  *
642
- * This function updates the event queue and internal input device state.
655
+ * **WARNING**: This should only be run in the thread that initialized the
656
+ * video subsystem, and for extra safety, you should consider only doing those
657
+ * things on the main thread in any case.
643
658
  *
644
- * This should only be run in the thread that sets the video mode.
659
+ * SDL_PumpEvents() gathers all the pending input information from devices and
660
+ * places it in the event queue. Without calls to SDL_PumpEvents() no events
661
+ * would ever be placed on the queue. Often the need for calls to
662
+ * SDL_PumpEvents() is hidden from the user since SDL_PollEvent() and
663
+ * SDL_WaitEvent() implicitly call SDL_PumpEvents(). However, if you are not
664
+ * polling or waiting for events (e.g. you are filtering them), then you must
665
+ * call SDL_PumpEvents() to force an event queue update.
666
+ *
667
+ * \since This function is available since SDL 2.0.0.
668
+ *
669
+ * \sa SDL_PollEvent
670
+ * \sa SDL_WaitEvent
645
671
  */
646
672
  extern DECLSPEC void SDLCALL SDL_PumpEvents(void);
647
673
 
@@ -654,22 +680,42 @@ typedef enum
654
680
  } SDL_eventaction;
655
681
 
656
682
  /**
657
- * Checks the event queue for messages and optionally returns them.
683
+ * Check the event queue for messages and optionally return them.
684
+ *
685
+ * `action` may be any of the following:
658
686
  *
659
- * If \c action is ::SDL_ADDEVENT, up to \c numevents events will be added to
660
- * the back of the event queue.
687
+ * - `SDL_ADDEVENT`: up to `numevents` events will be added to the back of the
688
+ * event queue.
689
+ * - `SDL_PEEKEVENT`: `numevents` events at the front of the event queue,
690
+ * within the specified minimum and maximum type, will be returned to the
691
+ * caller and will _not_ be removed from the queue.
692
+ * - `SDL_GETEVENT`: up to `numevents` events at the front of the event queue,
693
+ * within the specified minimum and maximum type, will be returned to the
694
+ * caller and will be removed from the queue.
661
695
  *
662
- * If \c action is ::SDL_PEEKEVENT, up to \c numevents events at the front
663
- * of the event queue, within the specified minimum and maximum type,
664
- * will be returned and will not be removed from the queue.
696
+ * You may have to call SDL_PumpEvents() before calling this function.
697
+ * Otherwise, the events may not be ready to be filtered when you call
698
+ * SDL_PeepEvents().
665
699
  *
666
- * If \c action is ::SDL_GETEVENT, up to \c numevents events at the front
667
- * of the event queue, within the specified minimum and maximum type,
668
- * will be returned and will be removed from the queue.
700
+ * This function is thread-safe.
669
701
  *
670
- * \return The number of events actually stored, or -1 if there was an error.
702
+ * \param events destination buffer for the retrieved events
703
+ * \param numevents if action is SDL_ADDEVENT, the number of events to add
704
+ * back to the event queue; if action is SDL_PEEKEVENT or
705
+ * SDL_GETEVENT, the maximum number of events to retrieve
706
+ * \param action action to take; see [[#action|Remarks]] for details
707
+ * \param minType minimum value of the event type to be considered;
708
+ * SDL_FIRSTEVENT is a safe choice
709
+ * \param maxType maximum value of the event type to be considered;
710
+ * SDL_LASTEVENT is a safe choice
711
+ * \returns the number of events actually stored or a negative error code on
712
+ * failure; call SDL_GetError() for more information.
671
713
  *
672
- * This function is thread-safe.
714
+ * \since This function is available since SDL 2.0.0.
715
+ *
716
+ * \sa SDL_PollEvent
717
+ * \sa SDL_PumpEvents
718
+ * \sa SDL_PushEvent
673
719
  */
674
720
  extern DECLSPEC int SDLCALL SDL_PeepEvents(SDL_Event * events, int numevents,
675
721
  SDL_eventaction action,
@@ -677,113 +723,354 @@ extern DECLSPEC int SDLCALL SDL_PeepEvents(SDL_Event * events, int numevents,
677
723
  /* @} */
678
724
 
679
725
  /**
680
- * Checks to see if certain event types are in the event queue.
726
+ * Check for the existence of a certain event type in the event queue.
727
+ *
728
+ * If you need to check for a range of event types, use SDL_HasEvents()
729
+ * instead.
730
+ *
731
+ * \param type the type of event to be queried; see SDL_EventType for details
732
+ * \returns SDL_TRUE if events matching `type` are present, or SDL_FALSE if
733
+ * events matching `type` are not present.
734
+ *
735
+ * \since This function is available since SDL 2.0.0.
736
+ *
737
+ * \sa SDL_HasEvents
681
738
  */
682
739
  extern DECLSPEC SDL_bool SDLCALL SDL_HasEvent(Uint32 type);
740
+
741
+
742
+ /**
743
+ * Check for the existence of certain event types in the event queue.
744
+ *
745
+ * If you need to check for a single event type, use SDL_HasEvent() instead.
746
+ *
747
+ * \param minType the low end of event type to be queried, inclusive; see
748
+ * SDL_EventType for details
749
+ * \param maxType the high end of event type to be queried, inclusive; see
750
+ * SDL_EventType for details
751
+ * \returns SDL_TRUE if events with type >= `minType` and <= `maxType` are
752
+ * present, or SDL_FALSE if not.
753
+ *
754
+ * \since This function is available since SDL 2.0.0.
755
+ *
756
+ * \sa SDL_HasEvents
757
+ */
683
758
  extern DECLSPEC SDL_bool SDLCALL SDL_HasEvents(Uint32 minType, Uint32 maxType);
684
759
 
685
760
  /**
686
- * This function clears events from the event queue
687
- * This function only affects currently queued events. If you want to make
688
- * sure that all pending OS events are flushed, you can call SDL_PumpEvents()
689
- * on the main thread immediately before the flush call.
761
+ * Clear events of a specific type from the event queue.
762
+ *
763
+ * This will unconditionally remove any events from the queue that match
764
+ * `type`. If you need to remove a range of event types, use SDL_FlushEvents()
765
+ * instead.
766
+ *
767
+ * It's also normal to just ignore events you don't care about in your event
768
+ * loop without calling this function.
769
+ *
770
+ * This function only affects currently queued events. If you want to make
771
+ * sure that all pending OS events are flushed, you can call SDL_PumpEvents()
772
+ * on the main thread immediately before the flush call.
773
+ *
774
+ * \param type the type of event to be cleared; see SDL_EventType for details
775
+ *
776
+ * \since This function is available since SDL 2.0.0.
777
+ *
778
+ * \sa SDL_FlushEvents
690
779
  */
691
780
  extern DECLSPEC void SDLCALL SDL_FlushEvent(Uint32 type);
781
+
782
+ /**
783
+ * Clear events of a range of types from the event queue.
784
+ *
785
+ * This will unconditionally remove any events from the queue that are in the
786
+ * range of `minType` to `maxType`, inclusive. If you need to remove a single
787
+ * event type, use SDL_FlushEvent() instead.
788
+ *
789
+ * It's also normal to just ignore events you don't care about in your event
790
+ * loop without calling this function.
791
+ *
792
+ * This function only affects currently queued events. If you want to make
793
+ * sure that all pending OS events are flushed, you can call SDL_PumpEvents()
794
+ * on the main thread immediately before the flush call.
795
+ *
796
+ * \param minType the low end of event type to be cleared, inclusive; see
797
+ * SDL_EventType for details
798
+ * \param maxType the high end of event type to be cleared, inclusive; see
799
+ * SDL_EventType for details
800
+ *
801
+ * \since This function is available since SDL 2.0.0.
802
+ *
803
+ * \sa SDL_FlushEvent
804
+ */
692
805
  extern DECLSPEC void SDLCALL SDL_FlushEvents(Uint32 minType, Uint32 maxType);
693
806
 
694
807
  /**
695
- * \brief Polls for currently pending events.
808
+ * Poll for currently pending events.
809
+ *
810
+ * If `event` is not NULL, the next event is removed from the queue and stored
811
+ * in the SDL_Event structure pointed to by `event`. The 1 returned refers to
812
+ * this event, immediately stored in the SDL Event structure -- not an event
813
+ * to follow.
696
814
  *
697
- * \return 1 if there are any pending events, or 0 if there are none available.
815
+ * If `event` is NULL, it simply returns 1 if there is an event in the queue,
816
+ * but will not remove it from the queue.
698
817
  *
699
- * \param event If not NULL, the next event is removed from the queue and
700
- * stored in that area.
818
+ * As this function may implicitly call SDL_PumpEvents(), you can only call
819
+ * this function in the thread that set the video mode.
820
+ *
821
+ * SDL_PollEvent() is the favored way of receiving system events since it can
822
+ * be done from the main loop and does not suspend the main loop while waiting
823
+ * on an event to be posted.
824
+ *
825
+ * The common practice is to fully process the event queue once every frame,
826
+ * usually as a first step before updating the game's state:
827
+ *
828
+ * ```c
829
+ * while (game_is_still_running) {
830
+ * SDL_Event event;
831
+ * while (SDL_PollEvent(&event)) { // poll until all events are handled!
832
+ * // decide what to do with this event.
833
+ * }
834
+ *
835
+ * // update game state, draw the current frame
836
+ * }
837
+ * ```
838
+ *
839
+ * \param event the SDL_Event structure to be filled with the next event from
840
+ * the queue, or NULL
841
+ * \returns 1 if there is a pending event or 0 if there are none available.
842
+ *
843
+ * \since This function is available since SDL 2.0.0.
844
+ *
845
+ * \sa SDL_GetEventFilter
846
+ * \sa SDL_PeepEvents
847
+ * \sa SDL_PushEvent
848
+ * \sa SDL_SetEventFilter
849
+ * \sa SDL_WaitEvent
850
+ * \sa SDL_WaitEventTimeout
701
851
  */
702
852
  extern DECLSPEC int SDLCALL SDL_PollEvent(SDL_Event * event);
703
853
 
704
854
  /**
705
- * \brief Waits indefinitely for the next available event.
855
+ * Wait indefinitely for the next available event.
856
+ *
857
+ * If `event` is not NULL, the next event is removed from the queue and stored
858
+ * in the SDL_Event structure pointed to by `event`.
859
+ *
860
+ * As this function may implicitly call SDL_PumpEvents(), you can only call
861
+ * this function in the thread that initialized the video subsystem.
706
862
  *
707
- * \return 1, or 0 if there was an error while waiting for events.
863
+ * \param event the SDL_Event structure to be filled in with the next event
864
+ * from the queue, or NULL
865
+ * \returns 1 on success or 0 if there was an error while waiting for events;
866
+ * call SDL_GetError() for more information.
708
867
  *
709
- * \param event If not NULL, the next event is removed from the queue and
710
- * stored in that area.
868
+ * \since This function is available since SDL 2.0.0.
869
+ *
870
+ * \sa SDL_PollEvent
871
+ * \sa SDL_PumpEvents
872
+ * \sa SDL_WaitEventTimeout
711
873
  */
712
874
  extern DECLSPEC int SDLCALL SDL_WaitEvent(SDL_Event * event);
713
875
 
714
876
  /**
715
- * \brief Waits until the specified timeout (in milliseconds) for the next
716
- * available event.
877
+ * Wait until the specified timeout (in milliseconds) for the next available
878
+ * event.
879
+ *
880
+ * If `event` is not NULL, the next event is removed from the queue and stored
881
+ * in the SDL_Event structure pointed to by `event`.
717
882
  *
718
- * \return 1, or 0 if there was an error while waiting for events.
883
+ * As this function may implicitly call SDL_PumpEvents(), you can only call
884
+ * this function in the thread that initialized the video subsystem.
719
885
  *
720
- * \param event If not NULL, the next event is removed from the queue and
721
- * stored in that area.
722
- * \param timeout The timeout (in milliseconds) to wait for next event.
886
+ * \param event the SDL_Event structure to be filled in with the next event
887
+ * from the queue, or NULL
888
+ * \param timeout the maximum number of milliseconds to wait for the next
889
+ * available event
890
+ * \returns 1 on success or 0 if there was an error while waiting for events;
891
+ * call SDL_GetError() for more information. This also returns 0 if
892
+ * the timeout elapsed without an event arriving.
893
+ *
894
+ * \since This function is available since SDL 2.0.0.
895
+ *
896
+ * \sa SDL_PollEvent
897
+ * \sa SDL_PumpEvents
898
+ * \sa SDL_WaitEvent
723
899
  */
724
900
  extern DECLSPEC int SDLCALL SDL_WaitEventTimeout(SDL_Event * event,
725
901
  int timeout);
726
902
 
727
903
  /**
728
- * \brief Add an event to the event queue.
904
+ * Add an event to the event queue.
905
+ *
906
+ * The event queue can actually be used as a two way communication channel.
907
+ * Not only can events be read from the queue, but the user can also push
908
+ * their own events onto it. `event` is a pointer to the event structure you
909
+ * wish to push onto the queue. The event is copied into the queue, and the
910
+ * caller may dispose of the memory pointed to after SDL_PushEvent() returns.
911
+ *
912
+ * Note: Pushing device input events onto the queue doesn't modify the state
913
+ * of the device within SDL.
914
+ *
915
+ * This function is thread-safe, and can be called from other threads safely.
916
+ *
917
+ * Note: Events pushed onto the queue with SDL_PushEvent() get passed through
918
+ * the event filter but events added with SDL_PeepEvents() do not.
729
919
  *
730
- * \return 1 on success, 0 if the event was filtered, or -1 if the event queue
731
- * was full or there was some other error.
920
+ * For pushing application-specific events, please use SDL_RegisterEvents() to
921
+ * get an event type that does not conflict with other code that also wants
922
+ * its own custom event types.
923
+ *
924
+ * \param event the SDL_Event to be added to the queue
925
+ * \returns 1 on success, 0 if the event was filtered, or a negative error
926
+ * code on failure; call SDL_GetError() for more information. A
927
+ * common reason for error is the event queue being full.
928
+ *
929
+ * \since This function is available since SDL 2.0.0.
930
+ *
931
+ * \sa SDL_PeepEvents
932
+ * \sa SDL_PollEvent
933
+ * \sa SDL_RegisterEvents
732
934
  */
733
935
  extern DECLSPEC int SDLCALL SDL_PushEvent(SDL_Event * event);
734
936
 
937
+ /**
938
+ * A function pointer used for callbacks that watch the event queue.
939
+ *
940
+ * \param userdata what was passed as `userdata` to SDL_SetEventFilter()
941
+ * or SDL_AddEventWatch, etc
942
+ * \param event the event that triggered the callback
943
+ * \returns 1 to permit event to be added to the queue, and 0 to disallow
944
+ * it. When used with SDL_AddEventWatch, the return value is ignored.
945
+ *
946
+ * \sa SDL_SetEventFilter
947
+ * \sa SDL_AddEventWatch
948
+ */
735
949
  typedef int (SDLCALL * SDL_EventFilter) (void *userdata, SDL_Event * event);
736
950
 
737
951
  /**
738
- * Sets up a filter to process all events before they change internal state and
739
- * are posted to the internal event queue.
952
+ * Set up a filter to process all events before they change internal state and
953
+ * are posted to the internal event queue.
954
+ *
955
+ * If the filter function returns 1 when called, then the event will be added
956
+ * to the internal queue. If it returns 0, then the event will be dropped from
957
+ * the queue, but the internal state will still be updated. This allows
958
+ * selective filtering of dynamically arriving events.
959
+ *
960
+ * **WARNING**: Be very careful of what you do in the event filter function,
961
+ * as it may run in a different thread!
962
+ *
963
+ * On platforms that support it, if the quit event is generated by an
964
+ * interrupt signal (e.g. pressing Ctrl-C), it will be delivered to the
965
+ * application at the next event poll.
966
+ *
967
+ * There is one caveat when dealing with the ::SDL_QuitEvent event type. The
968
+ * event filter is only called when the window manager desires to close the
969
+ * application window. If the event filter returns 1, then the window will be
970
+ * closed, otherwise the window will remain open if possible.
971
+ *
972
+ * Note: Disabled events never make it to the event filter function; see
973
+ * SDL_EventState().
740
974
  *
741
- * The filter is prototyped as:
742
- * \code
743
- * int SDL_EventFilter(void *userdata, SDL_Event * event);
744
- * \endcode
975
+ * Note: If you just want to inspect events without filtering, you should use
976
+ * SDL_AddEventWatch() instead.
745
977
  *
746
- * If the filter returns 1, then the event will be added to the internal queue.
747
- * If it returns 0, then the event will be dropped from the queue, but the
748
- * internal state will still be updated. This allows selective filtering of
749
- * dynamically arriving events.
978
+ * Note: Events pushed onto the queue with SDL_PushEvent() get passed through
979
+ * the event filter, but events pushed onto the queue with SDL_PeepEvents() do
980
+ * not.
750
981
  *
751
- * \warning Be very careful of what you do in the event filter function, as
752
- * it may run in a different thread!
982
+ * \param filter An SDL_EventFilter function to call when an event happens
983
+ * \param userdata a pointer that is passed to `filter`
753
984
  *
754
- * There is one caveat when dealing with the ::SDL_QuitEvent event type. The
755
- * event filter is only called when the window manager desires to close the
756
- * application window. If the event filter returns 1, then the window will
757
- * be closed, otherwise the window will remain open if possible.
985
+ * \since This function is available since SDL 2.0.0.
758
986
  *
759
- * If the quit event is generated by an interrupt signal, it will bypass the
760
- * internal queue and be delivered to the application at the next event poll.
987
+ * \sa SDL_AddEventWatch
988
+ * \sa SDL_EventState
989
+ * \sa SDL_GetEventFilter
990
+ * \sa SDL_PeepEvents
991
+ * \sa SDL_PushEvent
761
992
  */
762
993
  extern DECLSPEC void SDLCALL SDL_SetEventFilter(SDL_EventFilter filter,
763
994
  void *userdata);
764
995
 
765
996
  /**
766
- * Return the current event filter - can be used to "chain" filters.
767
- * If there is no event filter set, this function returns SDL_FALSE.
997
+ * Query the current event filter.
998
+ *
999
+ * This function can be used to "chain" filters, by saving the existing filter
1000
+ * before replacing it with a function that will call that saved filter.
1001
+ *
1002
+ * \param filter the current callback function will be stored here
1003
+ * \param userdata the pointer that is passed to the current event filter will
1004
+ * be stored here
1005
+ * \returns SDL_TRUE on success or SDL_FALSE if there is no event filter set.
1006
+ *
1007
+ * \since This function is available since SDL 2.0.0.
1008
+ *
1009
+ * \sa SDL_SetEventFilter
768
1010
  */
769
1011
  extern DECLSPEC SDL_bool SDLCALL SDL_GetEventFilter(SDL_EventFilter * filter,
770
1012
  void **userdata);
771
1013
 
772
1014
  /**
773
- * Add a function which is called when an event is added to the queue.
1015
+ * Add a callback to be triggered when an event is added to the event queue.
1016
+ *
1017
+ * `filter` will be called when an event happens, and its return value is
1018
+ * ignored.
1019
+ *
1020
+ * **WARNING**: Be very careful of what you do in the event filter function,
1021
+ * as it may run in a different thread!
1022
+ *
1023
+ * If the quit event is generated by a signal (e.g. SIGINT), it will bypass
1024
+ * the internal queue and be delivered to the watch callback immediately, and
1025
+ * arrive at the next event poll.
1026
+ *
1027
+ * Note: the callback is called for events posted by the user through
1028
+ * SDL_PushEvent(), but not for disabled events, nor for events by a filter
1029
+ * callback set with SDL_SetEventFilter(), nor for events posted by the user
1030
+ * through SDL_PeepEvents().
1031
+ *
1032
+ * \param filter an SDL_EventFilter function to call when an event happens.
1033
+ * \param userdata a pointer that is passed to `filter`
1034
+ *
1035
+ * \since This function is available since SDL 2.0.0.
1036
+ *
1037
+ * \sa SDL_DelEventWatch
1038
+ * \sa SDL_SetEventFilter
774
1039
  */
775
1040
  extern DECLSPEC void SDLCALL SDL_AddEventWatch(SDL_EventFilter filter,
776
1041
  void *userdata);
777
1042
 
778
1043
  /**
779
- * Remove an event watch function added with SDL_AddEventWatch()
1044
+ * Remove an event watch callback added with SDL_AddEventWatch().
1045
+ *
1046
+ * This function takes the same input as SDL_AddEventWatch() to identify and
1047
+ * delete the corresponding callback.
1048
+ *
1049
+ * \param filter the function originally passed to SDL_AddEventWatch()
1050
+ * \param userdata the pointer originally passed to SDL_AddEventWatch()
1051
+ *
1052
+ * \since This function is available since SDL 2.0.0.
1053
+ *
1054
+ * \sa SDL_AddEventWatch
780
1055
  */
781
1056
  extern DECLSPEC void SDLCALL SDL_DelEventWatch(SDL_EventFilter filter,
782
1057
  void *userdata);
783
1058
 
784
1059
  /**
785
- * Run the filter function on the current event queue, removing any
786
- * events for which the filter returns 0.
1060
+ * Run a specific filter function on the current event queue, removing any
1061
+ * events for which the filter returns 0.
1062
+ *
1063
+ * See SDL_SetEventFilter() for more information. Unlike SDL_SetEventFilter(),
1064
+ * this function does not change the filter permanently, it only uses the
1065
+ * supplied filter until this function returns.
1066
+ *
1067
+ * \param filter the SDL_EventFilter function to call when an event happens
1068
+ * \param userdata a pointer that is passed to `filter`
1069
+ *
1070
+ * \since This function is available since SDL 2.0.0.
1071
+ *
1072
+ * \sa SDL_GetEventFilter
1073
+ * \sa SDL_SetEventFilter
787
1074
  */
788
1075
  extern DECLSPEC void SDLCALL SDL_FilterEvents(SDL_EventFilter filter,
789
1076
  void *userdata);
@@ -795,24 +1082,45 @@ extern DECLSPEC void SDLCALL SDL_FilterEvents(SDL_EventFilter filter,
795
1082
  #define SDL_ENABLE 1
796
1083
 
797
1084
  /**
798
- * This function allows you to set the state of processing certain events.
799
- * - If \c state is set to ::SDL_IGNORE, that event will be automatically
800
- * dropped from the event queue and will not be filtered.
801
- * - If \c state is set to ::SDL_ENABLE, that event will be processed
802
- * normally.
803
- * - If \c state is set to ::SDL_QUERY, SDL_EventState() will return the
804
- * current processing state of the specified event.
1085
+ * Set the state of processing events by type.
1086
+ *
1087
+ * `state` may be any of the following:
1088
+ *
1089
+ * - `SDL_QUERY`: returns the current processing state of the specified event
1090
+ * - `SDL_IGNORE` (aka `SDL_DISABLE`): the event will automatically be dropped
1091
+ * from the event queue and will not be filtered
1092
+ * - `SDL_ENABLE`: the event will be processed normally
1093
+ *
1094
+ * \param type the type of event; see SDL_EventType for details
1095
+ * \param state how to process the event
1096
+ * \returns `SDL_DISABLE` or `SDL_ENABLE`, representing the processing state
1097
+ * of the event before this function makes any changes to it.
1098
+ *
1099
+ * \since This function is available since SDL 2.0.0.
1100
+ *
1101
+ * \sa SDL_GetEventState
805
1102
  */
806
1103
  extern DECLSPEC Uint8 SDLCALL SDL_EventState(Uint32 type, int state);
807
1104
  /* @} */
808
1105
  #define SDL_GetEventState(type) SDL_EventState(type, SDL_QUERY)
809
1106
 
810
1107
  /**
811
- * This function allocates a set of user-defined events, and returns
812
- * the beginning event number for that set of events.
1108
+ * Allocate a set of user-defined events, and return the beginning event
1109
+ * number for that set of events.
1110
+ *
1111
+ * Calling this function with `numevents` <= 0 is an error and will return
1112
+ * (Uint32)-1.
1113
+ *
1114
+ * Note, (Uint32)-1 means the maximum unsigned 32-bit integer value (or
1115
+ * 0xFFFFFFFF), but is clearer to write.
1116
+ *
1117
+ * \param numevents the number of events to be allocated
1118
+ * \returns the beginning event number, or (Uint32)-1 if there are not enough
1119
+ * user-defined events left.
1120
+ *
1121
+ * \since This function is available since SDL 2.0.0.
813
1122
  *
814
- * If there aren't enough user-defined events left, this function
815
- * returns (Uint32)-1
1123
+ * \sa SDL_PushEvent
816
1124
  */
817
1125
  extern DECLSPEC Uint32 SDLCALL SDL_RegisterEvents(int numevents);
818
1126