gosu 1.5.0 → 2.0.0.pre6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. checksums.yaml +4 -4
  2. data/dependencies/SDL/include/SDL.h +233 -0
  3. data/dependencies/SDL/include/SDL_assert.h +320 -0
  4. data/dependencies/SDL/include/SDL_atomic.h +414 -0
  5. data/dependencies/SDL/include/SDL_audio.h +1500 -0
  6. data/dependencies/SDL/include/{SDL3/SDL_bits.h → SDL_bits.h} +27 -47
  7. data/dependencies/SDL/include/{SDL3/SDL_blendmode.h → SDL_blendmode.h} +55 -59
  8. data/dependencies/SDL/include/SDL_clipboard.h +141 -0
  9. data/dependencies/SDL/include/SDL_config.h +331 -0
  10. data/dependencies/SDL/include/SDL_cpuinfo.h +594 -0
  11. data/dependencies/SDL/include/{SDL3/SDL_egl.h → SDL_egl.h} +8 -11
  12. data/dependencies/SDL/include/SDL_endian.h +348 -0
  13. data/dependencies/SDL/include/SDL_error.h +163 -0
  14. data/dependencies/SDL/include/SDL_events.h +1166 -0
  15. data/dependencies/SDL/include/SDL_filesystem.h +149 -0
  16. data/dependencies/SDL/include/SDL_gamecontroller.h +1074 -0
  17. data/dependencies/SDL/include/SDL_gesture.h +117 -0
  18. data/dependencies/SDL/include/SDL_guid.h +100 -0
  19. data/dependencies/SDL/include/SDL_haptic.h +1341 -0
  20. data/dependencies/SDL/include/SDL_hidapi.h +451 -0
  21. data/dependencies/SDL/include/SDL_hints.h +2613 -0
  22. data/dependencies/SDL/include/SDL_joystick.h +1069 -0
  23. data/dependencies/SDL/include/SDL_keyboard.h +353 -0
  24. data/dependencies/SDL/include/SDL_keycode.h +358 -0
  25. data/dependencies/SDL/include/SDL_loadso.h +115 -0
  26. data/dependencies/SDL/include/{SDL3/SDL_locale.h → SDL_locale.h} +24 -40
  27. data/dependencies/SDL/include/SDL_log.h +404 -0
  28. data/dependencies/SDL/include/SDL_main.h +282 -0
  29. data/dependencies/SDL/include/{SDL3/SDL_messagebox.h → SDL_messagebox.h} +48 -85
  30. data/dependencies/SDL/include/{SDL3/SDL_metal.h → SDL_metal.h} +29 -29
  31. data/dependencies/SDL/include/{SDL3/SDL_misc.h → SDL_misc.h} +12 -13
  32. data/dependencies/SDL/include/SDL_mouse.h +464 -0
  33. data/dependencies/SDL/include/SDL_mutex.h +545 -0
  34. data/dependencies/SDL/include/SDL_name.h +33 -0
  35. data/dependencies/SDL/include/{SDL3/SDL_opengl.h → SDL_opengl.h} +252 -1221
  36. data/dependencies/SDL/include/{SDL3/SDL_opengles.h → SDL_opengles.h} +7 -6
  37. data/dependencies/SDL/include/{SDL3/SDL_opengles2.h → SDL_opengles2.h} +11 -10
  38. data/dependencies/SDL/include/SDL_pixels.h +644 -0
  39. data/dependencies/SDL/include/SDL_platform.h +261 -0
  40. data/dependencies/SDL/include/{SDL3/SDL_power.h → SDL_power.h} +19 -40
  41. data/dependencies/SDL/include/SDL_quit.h +58 -0
  42. data/dependencies/SDL/include/SDL_rect.h +376 -0
  43. data/dependencies/SDL/include/SDL_render.h +1924 -0
  44. data/dependencies/SDL/include/SDL_revision.h +7 -0
  45. data/dependencies/SDL/include/SDL_rwops.h +841 -0
  46. data/dependencies/SDL/include/{SDL3/SDL_scancode.h → SDL_scancode.h} +68 -60
  47. data/dependencies/SDL/include/SDL_sensor.h +322 -0
  48. data/dependencies/SDL/include/SDL_shape.h +155 -0
  49. data/dependencies/SDL/include/SDL_stdinc.h +838 -0
  50. data/dependencies/SDL/include/SDL_surface.h +997 -0
  51. data/dependencies/SDL/include/SDL_system.h +623 -0
  52. data/dependencies/SDL/include/SDL_syswm.h +386 -0
  53. data/dependencies/SDL/include/{SDL3/SDL_test.h → SDL_test.h} +22 -16
  54. data/dependencies/SDL/include/{SDL3/SDL_test_assert.h → SDL_test_assert.h} +34 -27
  55. data/dependencies/SDL/include/{SDL3/SDL_test_common.h → SDL_test_common.h} +52 -109
  56. data/dependencies/SDL/include/{SDL3/SDL_test_compare.h → SDL_test_compare.h} +14 -22
  57. data/dependencies/SDL/include/{SDL3/SDL_test_crc32.h → SDL_test_crc32.h} +30 -27
  58. data/dependencies/SDL/include/{SDL3/SDL_test_font.h → SDL_test_font.h} +49 -50
  59. data/dependencies/SDL/include/{SDL3/SDL_test_fuzzer.h → SDL_test_fuzzer.h} +79 -64
  60. data/dependencies/SDL/include/{SDL3/SDL_test_harness.h → SDL_test_harness.h} +30 -47
  61. data/dependencies/SDL/include/SDL_test_images.h +78 -0
  62. data/dependencies/SDL/include/{SDL3/SDL_platform.h → SDL_test_log.h} +26 -25
  63. data/dependencies/SDL/include/{SDL3/SDL_test_md5.h → SDL_test_md5.h} +28 -21
  64. data/dependencies/SDL/include/{SDL3/SDL_test_memory.h → SDL_test_memory.h} +16 -19
  65. data/dependencies/SDL/include/SDL_test_random.h +115 -0
  66. data/dependencies/SDL/include/SDL_thread.h +464 -0
  67. data/dependencies/SDL/include/SDL_timer.h +222 -0
  68. data/dependencies/SDL/include/SDL_touch.h +150 -0
  69. data/dependencies/SDL/include/{SDL3/SDL_copying.h → SDL_types.h} +9 -2
  70. data/dependencies/SDL/include/SDL_version.h +204 -0
  71. data/dependencies/SDL/include/SDL_video.h +2178 -0
  72. data/dependencies/SDL/include/SDL_vulkan.h +215 -0
  73. data/dependencies/SDL/include/begin_code.h +187 -0
  74. data/dependencies/SDL/include/{SDL3/SDL_close_code.h → close_code.h} +6 -7
  75. data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
  76. data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
  77. data/dependencies/SDL_sound/SDL_sound.c +215 -136
  78. data/dependencies/SDL_sound/SDL_sound.h +725 -0
  79. data/dependencies/SDL_sound/SDL_sound_aiff.c +54 -55
  80. data/dependencies/SDL_sound/SDL_sound_au.c +32 -32
  81. data/dependencies/SDL_sound/SDL_sound_coreaudio.c +41 -24
  82. data/dependencies/SDL_sound/SDL_sound_flac.c +12 -32
  83. data/dependencies/SDL_sound/SDL_sound_internal.h +48 -33
  84. data/dependencies/SDL_sound/SDL_sound_modplug.c +29 -21
  85. data/dependencies/SDL_sound/SDL_sound_mp3.c +13 -35
  86. data/dependencies/SDL_sound/SDL_sound_raw.c +15 -14
  87. data/dependencies/SDL_sound/SDL_sound_shn.c +82 -82
  88. data/dependencies/SDL_sound/SDL_sound_voc.c +30 -30
  89. data/dependencies/SDL_sound/SDL_sound_vorbis.c +25 -34
  90. data/dependencies/SDL_sound/SDL_sound_wav.c +82 -86
  91. data/dependencies/SDL_sound/dr_flac.h +1281 -1845
  92. data/dependencies/SDL_sound/dr_mp3.h +617 -1035
  93. data/dependencies/SDL_sound/libmodplug/fastmix.c +1 -1
  94. data/dependencies/SDL_sound/libmodplug/libmodplug.h +4 -5
  95. data/dependencies/SDL_sound/libmodplug/load_ams.c +3 -6
  96. data/dependencies/SDL_sound/libmodplug/load_dsm.c +1 -2
  97. data/dependencies/SDL_sound/libmodplug/load_mt2.c +2 -2
  98. data/dependencies/SDL_sound/libmodplug/modplug.h +1 -2
  99. data/dependencies/SDL_sound/libmodplug/snd_fx.c +3 -3
  100. data/dependencies/SDL_sound/libmodplug/sndfile.c +0 -3
  101. data/dependencies/SDL_sound/libmodplug/sndmix.c +3 -7
  102. data/dependencies/SDL_sound/stb_vorbis.h +343 -397
  103. data/dependencies/mojoAL/AL/alc.h +2 -2
  104. data/dependencies/mojoAL/mojoal.c +1878 -2113
  105. data/dependencies/stb/stb_image.h +1381 -1192
  106. data/dependencies/stb/stb_image_write.h +129 -329
  107. data/dependencies/stb/stb_truetype.h +60 -304
  108. data/dependencies/utf8proc/utf8proc.c +75 -133
  109. data/dependencies/utf8proc/utf8proc.h +50 -131
  110. data/dependencies/utf8proc/utf8proc_data.h +15658 -16213
  111. data/ext/gosu-ffi/extconf.rb +28 -11
  112. data/ext/gosu-ffi/gosu-ffi.def +0 -3
  113. data/ffi/Gosu.cpp +29 -52
  114. data/ffi/Gosu.h +4 -4
  115. data/ffi/Gosu_Color.cpp +36 -80
  116. data/ffi/Gosu_FFI_internal.h +13 -12
  117. data/ffi/Gosu_Font.cpp +11 -16
  118. data/ffi/Gosu_Font.h +4 -4
  119. data/ffi/Gosu_Image.cpp +36 -69
  120. data/ffi/Gosu_Image.h +5 -16
  121. data/include/Gosu/Bitmap.hpp +1 -1
  122. data/include/Gosu/Color.hpp +4 -5
  123. data/include/Gosu/Graphics.hpp +0 -2
  124. data/include/Gosu/Image.hpp +1 -1
  125. data/include/Gosu/Math.hpp +5 -5
  126. data/include/Gosu/Utility.hpp +1 -27
  127. data/include/Gosu/Version.hpp +2 -2
  128. data/lib/SDL2.dll +0 -0
  129. data/lib/gosu/channel.rb +0 -1
  130. data/lib/gosu/color.rb +13 -36
  131. data/lib/gosu/compat.rb +14 -106
  132. data/lib/gosu/constants.rb +24 -24
  133. data/lib/gosu/ffi.rb +13 -24
  134. data/lib/gosu/font.rb +13 -19
  135. data/lib/gosu/gosu.rb +61 -101
  136. data/lib/gosu/image.rb +34 -72
  137. data/lib/gosu/sample.rb +0 -1
  138. data/lib/gosu/song.rb +0 -1
  139. data/lib/gosu/text_input.rb +1 -15
  140. data/lib/gosu/window.rb +10 -31
  141. data/lib64/SDL2.dll +0 -0
  142. data/rdoc/gosu.rb +0 -2
  143. data/src/Audio.cpp +16 -22
  144. data/src/AudioFileSDLSound.cpp +5 -5
  145. data/src/BinPacker.cpp +4 -5
  146. data/src/Bitmap.cpp +9 -16
  147. data/src/Buffer.cpp +14 -5
  148. data/src/ClipRectStack.hpp +83 -17
  149. data/src/Directories.cpp +1 -1
  150. data/src/DrawOp.hpp +17 -14
  151. data/src/DrawOpQueue.hpp +31 -25
  152. data/src/Font.cpp +1 -1
  153. data/src/GosuGLView.cpp +7 -1
  154. data/src/Graphics.cpp +25 -32
  155. data/src/GraphicsImpl.hpp +24 -0
  156. data/src/Image.cpp +2 -2
  157. data/src/Input.cpp +70 -66
  158. data/src/Macro.cpp +26 -43
  159. data/src/Macro.hpp +16 -22
  160. data/src/Math.cpp +7 -20
  161. data/src/OffScreenTarget.cpp +10 -3
  162. data/src/OpenGLContext.cpp +8 -7
  163. data/src/OpenGLContext.hpp +2 -2
  164. data/src/RenderState.hpp +54 -30
  165. data/src/Resolution.cpp +38 -48
  166. data/src/TexChunk.cpp +2 -2
  167. data/src/TextInput.cpp +9 -9
  168. data/src/Texture.cpp +1 -1
  169. data/src/TiledDrawable.cpp +7 -6
  170. data/src/TrueTypeFontUnix.cpp +9 -12
  171. data/src/Utility.cpp +26 -39
  172. data/src/UtilityWin.cpp +2 -6
  173. data/src/Window.cpp +34 -54
  174. metadata +93 -99
  175. data/dependencies/SDL/include/SDL3/SDL.h +0 -91
  176. data/dependencies/SDL/include/SDL3/SDL_assert.h +0 -710
  177. data/dependencies/SDL/include/SDL3/SDL_asyncio.h +0 -550
  178. data/dependencies/SDL/include/SDL3/SDL_atomic.h +0 -692
  179. data/dependencies/SDL/include/SDL3/SDL_audio.h +0 -2382
  180. data/dependencies/SDL/include/SDL3/SDL_begin_code.h +0 -553
  181. data/dependencies/SDL/include/SDL3/SDL_camera.h +0 -535
  182. data/dependencies/SDL/include/SDL3/SDL_clipboard.h +0 -331
  183. data/dependencies/SDL/include/SDL3/SDL_cpuinfo.h +0 -374
  184. data/dependencies/SDL/include/SDL3/SDL_dialog.h +0 -343
  185. data/dependencies/SDL/include/SDL3/SDL_dlopennote.h +0 -234
  186. data/dependencies/SDL/include/SDL3/SDL_endian.h +0 -645
  187. data/dependencies/SDL/include/SDL3/SDL_error.h +0 -226
  188. data/dependencies/SDL/include/SDL3/SDL_events.h +0 -1651
  189. data/dependencies/SDL/include/SDL3/SDL_filesystem.h +0 -537
  190. data/dependencies/SDL/include/SDL3/SDL_gamepad.h +0 -1657
  191. data/dependencies/SDL/include/SDL3/SDL_gpu.h +0 -4637
  192. data/dependencies/SDL/include/SDL3/SDL_guid.h +0 -106
  193. data/dependencies/SDL/include/SDL3/SDL_haptic.h +0 -1461
  194. data/dependencies/SDL/include/SDL3/SDL_hidapi.h +0 -571
  195. data/dependencies/SDL/include/SDL3/SDL_hints.h +0 -5041
  196. data/dependencies/SDL/include/SDL3/SDL_init.h +0 -508
  197. data/dependencies/SDL/include/SDL3/SDL_intrin.h +0 -410
  198. data/dependencies/SDL/include/SDL3/SDL_iostream.h +0 -1379
  199. data/dependencies/SDL/include/SDL3/SDL_joystick.h +0 -1385
  200. data/dependencies/SDL/include/SDL3/SDL_keyboard.h +0 -615
  201. data/dependencies/SDL/include/SDL3/SDL_keycode.h +0 -348
  202. data/dependencies/SDL/include/SDL3/SDL_loadso.h +0 -145
  203. data/dependencies/SDL/include/SDL3/SDL_log.h +0 -541
  204. data/dependencies/SDL/include/SDL3/SDL_main.h +0 -704
  205. data/dependencies/SDL/include/SDL3/SDL_main_impl.h +0 -149
  206. data/dependencies/SDL/include/SDL3/SDL_mouse.h +0 -813
  207. data/dependencies/SDL/include/SDL3/SDL_mutex.h +0 -1117
  208. data/dependencies/SDL/include/SDL3/SDL_oldnames.h +0 -1339
  209. data/dependencies/SDL/include/SDL3/SDL_pen.h +0 -198
  210. data/dependencies/SDL/include/SDL3/SDL_pixels.h +0 -1441
  211. data/dependencies/SDL/include/SDL3/SDL_platform_defines.h +0 -497
  212. data/dependencies/SDL/include/SDL3/SDL_process.h +0 -441
  213. data/dependencies/SDL/include/SDL3/SDL_properties.h +0 -572
  214. data/dependencies/SDL/include/SDL3/SDL_rect.h +0 -528
  215. data/dependencies/SDL/include/SDL3/SDL_render.h +0 -3034
  216. data/dependencies/SDL/include/SDL3/SDL_revision.h +0 -56
  217. data/dependencies/SDL/include/SDL3/SDL_sensor.h +0 -321
  218. data/dependencies/SDL/include/SDL3/SDL_stdinc.h +0 -6186
  219. data/dependencies/SDL/include/SDL3/SDL_storage.h +0 -686
  220. data/dependencies/SDL/include/SDL3/SDL_surface.h +0 -1769
  221. data/dependencies/SDL/include/SDL3/SDL_system.h +0 -840
  222. data/dependencies/SDL/include/SDL3/SDL_test_log.h +0 -83
  223. data/dependencies/SDL/include/SDL3/SDL_thread.h +0 -602
  224. data/dependencies/SDL/include/SDL3/SDL_time.h +0 -249
  225. data/dependencies/SDL/include/SDL3/SDL_timer.h +0 -454
  226. data/dependencies/SDL/include/SDL3/SDL_touch.h +0 -184
  227. data/dependencies/SDL/include/SDL3/SDL_tray.h +0 -544
  228. data/dependencies/SDL/include/SDL3/SDL_version.h +0 -198
  229. data/dependencies/SDL/include/SDL3/SDL_video.h +0 -3497
  230. data/dependencies/SDL/include/SDL3/SDL_vulkan.h +0 -287
  231. data/dependencies/SDL/lib/x64/libSDL3.dll.a +0 -0
  232. data/dependencies/SDL/lib/x86/libSDL3.dll.a +0 -0
  233. data/dependencies/SDL_sound/SDL3_sound/SDL_sound.h +0 -755
  234. data/lib/SDL3.dll +0 -0
  235. data/lib64/SDL3.dll +0 -0
  236. data/src/ClipRectStack.cpp +0 -38
  237. /data/dependencies/SDL/include/{SDL3/SDL_opengl_glext.h → SDL_opengl_glext.h} +0 -0
  238. /data/dependencies/SDL/include/{SDL3/SDL_opengles2_gl2.h → SDL_opengles2_gl2.h} +0 -0
  239. /data/dependencies/SDL/include/{SDL3/SDL_opengles2_gl2ext.h → SDL_opengles2_gl2ext.h} +0 -0
  240. /data/dependencies/SDL/include/{SDL3/SDL_opengles2_gl2platform.h → SDL_opengles2_gl2platform.h} +0 -0
  241. /data/dependencies/SDL/include/{SDL3/SDL_opengles2_khrplatform.h → SDL_opengles2_khrplatform.h} +0 -0
data/src/TextInput.cpp CHANGED
@@ -4,7 +4,7 @@
4
4
  #include <cctype>
5
5
 
6
6
  #ifndef GOSU_IS_IPHONE
7
- #include <SDL3/SDL.h>
7
+ #include <SDL.h>
8
8
  #endif
9
9
 
10
10
  struct Gosu::TextInput::Impl : private Gosu::Noncopyable
@@ -191,28 +191,28 @@ bool Gosu::TextInput::feed_sdl_event(void* event)
191
191
 
192
192
  switch (e->type) {
193
193
  // Direct text input or completed IME composition.
194
- case SDL_EVENT_TEXT_INPUT: {
194
+ case SDL_TEXTINPUT: {
195
195
  m_impl->insert_text(filter(e->text.text));
196
196
  return true;
197
197
  }
198
198
  // IME composition in progress.
199
- case SDL_EVENT_TEXT_EDITING: {
199
+ case SDL_TEXTEDITING: {
200
200
  m_impl->composition = e->edit.text;
201
201
  return true;
202
202
  }
203
203
  // Emulate "standard" Windows/Linux keyboard behavior.
204
- case SDL_EVENT_KEY_DOWN: {
204
+ case SDL_KEYDOWN: {
205
205
  // ...but not if the IME is currently compositing.
206
206
  if (!m_impl->composition.empty()) return false;
207
207
 
208
208
  #ifdef GOSU_IS_MAC
209
- bool words = (e->key.mod & (SDL_KMOD_LALT | SDL_KMOD_RALT));
210
- bool command_down = (e->key.mod & (SDL_KMOD_LGUI | SDL_KMOD_RGUI));
209
+ bool words = (e->key.keysym.mod & (KMOD_LALT | KMOD_RALT));
210
+ bool command_down = (e->key.keysym.mod & (KMOD_LGUI | KMOD_RGUI));
211
211
  #else
212
- bool words = (e->key.mod & (SDL_KMOD_LCTRL | SDL_KMOD_RCTRL));
212
+ bool words = (e->key.keysym.mod & (KMOD_LCTRL | KMOD_RCTRL));
213
213
  #endif
214
- bool shift_down = (e->key.mod & (SDL_KMOD_LSHIFT | SDL_KMOD_RSHIFT));
215
- SDL_Keycode key = e->key.key;
214
+ bool shift_down = (e->key.keysym.mod & (KMOD_LSHIFT | KMOD_RSHIFT));
215
+ SDL_Keycode key = e->key.keysym.sym;
216
216
 
217
217
  switch (key) {
218
218
  case SDLK_LEFT:
data/src/Texture.cpp CHANGED
@@ -75,7 +75,7 @@ std::unique_ptr<Gosu::TexChunk> Gosu::Texture::try_alloc(const Bitmap& bitmap, i
75
75
 
76
76
  void Gosu::Texture::insert(const Gosu::Bitmap& bitmap, int x, int y)
77
77
  {
78
- if (!Rect::covering(*this).contains(Rect::xywh(x, y, bitmap.width(), bitmap.height()))) {
78
+ if (!Rect::covering(*this).contains(Rect { x, y, bitmap.width(), bitmap.height() })) {
79
79
  throw std::invalid_argument("Gosu::Texture::insert: Rect exceeds bounds");
80
80
  }
81
81
 
@@ -1,5 +1,6 @@
1
1
  #include <Gosu/Bitmap.hpp>
2
2
  #include <Gosu/Graphics.hpp>
3
+ #include <Gosu/Math.hpp>
3
4
  #include "GraphicsImpl.hpp"
4
5
  #include "TiledDrawable.hpp"
5
6
  #include <cmath>
@@ -63,7 +64,7 @@ Gosu::TiledDrawable::TiledDrawable(const TiledDrawable& parent, const Rect& rect
63
64
  {
64
65
  for (const Tile& tile : parent.m_tiles) {
65
66
  // rect is the source area on the parent, tile_rect is this tile's area on the parent.
66
- Rect tile_rect = Rect::xywh(tile.x, tile.y, tile.data->width(), tile.data->height());
67
+ Rect tile_rect { tile.x, tile.y, tile.data->width(), tile.data->height() };
67
68
  // The x/y source position on the tile...
68
69
  int x = 0, y = 0;
69
70
  // ...must be adjusted while clipping.
@@ -73,15 +74,15 @@ Gosu::TiledDrawable::TiledDrawable(const TiledDrawable& parent, const Rect& rect
73
74
  m_tiles.push_back(Tile {
74
75
  .x = tile.x - rect.x,
75
76
  .y = tile.y - rect.y,
76
- .data = tile.data->subimage(Rect::xywh(x, y, tile_rect.width, tile_rect.height)),
77
+ .data = tile.data->subimage(Rect { x, y, tile_rect.width, tile_rect.height }),
77
78
  });
78
79
  }
79
80
  }
80
81
  }
81
82
 
82
83
  void Gosu::TiledDrawable::draw(double x1, double y1, Color c1, double x2, double y2, Color c2,
83
- double x3, double y3, Color c3, double x4, double y4, Color c4,
84
- ZPos z, BlendMode mode) const
84
+ double x3, double y3, Color c3, double x4, double y4, Color c4,
85
+ ZPos z, BlendMode mode) const
85
86
  {
86
87
  normalize_coordinates(x1, y1, x2, y2, x3, y3, c3, x4, y4, c4);
87
88
 
@@ -138,9 +139,9 @@ Gosu::Bitmap Gosu::TiledDrawable::to_bitmap() const
138
139
 
139
140
  void Gosu::TiledDrawable::insert(const Bitmap& bitmap, int x, int y)
140
141
  {
141
- const Rect target_rect = Rect::xywh(x, y, bitmap.width(), bitmap.height());
142
+ const Rect target_rect { x, y, bitmap.width(), bitmap.height() };
142
143
  for (const Tile& tile : m_tiles) {
143
- Rect tile_rect = Rect::xywh(tile.x, tile.y, tile.data->width(), tile.data->height());
144
+ Rect tile_rect { tile.x, tile.y, tile.data->width(), tile.data->height() };
144
145
  tile_rect.clip_to(target_rect);
145
146
  if (!tile_rect.empty()) {
146
147
  tile.data->insert(bitmap, x - tile.x, y - tile.y);
@@ -33,10 +33,11 @@ const std::uint8_t* Gosu::ttf_data_by_name(const std::string& font_name, unsigne
33
33
  if (FcFontSet* fonts = FcFontList(config, pattern, props)) {
34
34
  // Among all matching fonts, find the variant that is the best fit for our font_flags.
35
35
  std::string best_filename;
36
- int best_diff = 0;
36
+ int best_diff;
37
37
 
38
38
  for (int i = 0; i < fonts->nfont; ++i) {
39
- int weight = 0, slant = 0;
39
+ int weight, slant;
40
+
40
41
  FcPatternGetInteger(fonts->fonts[i], FC_WEIGHT, 0, &weight);
41
42
  FcPatternGetInteger(fonts->fonts[i], FC_SLANT, 0, &slant);
42
43
 
@@ -56,19 +57,15 @@ const std::uint8_t* Gosu::ttf_data_by_name(const std::string& font_name, unsigne
56
57
  diff += abs(slant - FC_SLANT_ROMAN);
57
58
  }
58
59
 
59
- FcChar8* filename = nullptr;
60
- if (FcPatternGetString(fonts->fonts[i], FC_FILE, 0, &filename) != FcResultMatch
61
- || filename == nullptr) {
62
- continue;
63
- }
64
-
65
60
  // Penalize OTF fonts since we are not really good at handling these.
66
- if (has_extension(reinterpret_cast<char*>(filename), ".otf")) {
61
+ FcChar8* file;
62
+ FcPatternGetString(fonts->fonts[i], FC_FILE, 0, &file);
63
+ if (has_extension(reinterpret_cast<char*>(file), ".otf")) {
67
64
  diff += 10000;
68
65
  }
69
66
 
70
67
  if (best_filename.empty() || diff < best_diff) {
71
- best_filename = reinterpret_cast<char*>(filename);
68
+ best_filename = reinterpret_cast<char*>(file);
72
69
  best_diff = diff;
73
70
  }
74
71
  }
@@ -97,8 +94,8 @@ static const std::uint8_t* ttf_data_of_default_sans_serif_font()
97
94
  FcResult match_result;
98
95
  pattern = FcFontMatch(nullptr, pattern, &match_result);
99
96
  if (match_result == FcResultMatch) {
100
- FcChar8* filename = nullptr;
101
- if (FcPatternGetString(pattern, FC_FILE, 0, &filename) == FcResultMatch && filename) {
97
+ FcChar8* filename;
98
+ if (FcPatternGetString(pattern, FC_FILE, 0, &filename) == FcResultMatch) {
102
99
  ttf_ptr = Gosu::ttf_data_from_file(reinterpret_cast<char*>(filename));
103
100
  }
104
101
  }
data/src/Utility.cpp CHANGED
@@ -3,38 +3,6 @@
3
3
  #include <memory>
4
4
  #include <stdexcept>
5
5
  #include <utf8proc.h>
6
- #include <utility>
7
-
8
- Gosu::Cleanup::Cleanup(std::function<void()> action)
9
- : m_action(std::move(action))
10
- {
11
- }
12
-
13
- Gosu::Cleanup::~Cleanup()
14
- {
15
- perform();
16
- }
17
-
18
- Gosu::Cleanup::Cleanup(Cleanup&& rhs) noexcept
19
- : m_action(std::exchange(rhs.m_action, nullptr))
20
- {
21
- }
22
-
23
- void Gosu::Cleanup::perform()
24
- {
25
- if (m_action) {
26
- m_action();
27
- m_action = nullptr;
28
- }
29
- }
30
-
31
- Gosu::Cleanup Gosu::finally(std::function<void()> action)
32
- {
33
- if (action == nullptr) {
34
- throw std::invalid_argument("Gosu::finally must be called with an action");
35
- }
36
- return Cleanup(std::move(action));
37
- }
38
6
 
39
7
  std::u32string Gosu::utf8_to_composed_utc4(std::string_view utf8)
40
8
  {
@@ -128,32 +96,51 @@ std::vector<std::string> Gosu::user_languages()
128
96
  }
129
97
 
130
98
  #else
131
- #include <SDL3/SDL.h>
99
+ #include <SDL.h>
100
+ #if SDL_VERSION_ATLEAST(2, 0, 14)
101
+
132
102
  std::vector<std::string> Gosu::user_languages()
133
103
  {
134
104
  std::vector<std::string> user_languages;
135
105
 
136
- int locale_count = 0;
137
- std::unique_ptr<SDL_Locale*[], decltype(&SDL_free)> locales(
138
- SDL_GetPreferredLocales(&locale_count), SDL_free);
106
+ std::unique_ptr<SDL_Locale, decltype(SDL_free)*> locales(SDL_GetPreferredLocales(), SDL_free);
139
107
  // GCOV_EXCL_START: There is no portable way to let SDL_GetPreferredLocales fail.
140
108
  if (!locales) {
141
109
  return user_languages;
142
110
  }
143
111
  // GCOV_EXCL_END
144
112
 
145
- for (int i = 0; i < locale_count; ++i) {
146
- const SDL_Locale* locale = locales[i];
113
+ for (const SDL_Locale* locale = locales.get(); locale->language != nullptr; ++locale) {
147
114
  std::string language = locale->language;
148
115
  if (locale->country) {
149
116
  language += '_';
150
117
  language += locale->country;
151
118
  }
152
- user_languages.push_back(std::move(language));
119
+ user_languages.emplace_back(std::move(language));
153
120
  }
154
121
 
155
122
  return user_languages;
156
123
  }
124
+
125
+ #else
126
+ #include <cstdlib>
127
+ #include <regex>
128
+
129
+ std::vector<std::string> Gosu::user_languages()
130
+ {
131
+ static const std::regex language_regex("[a-z]{2}_[A-Z]{2}([^A-Z].*)?");
132
+
133
+ const char* locale = std::getenv("LANG");
134
+
135
+ if (locale && std::regex_match(locale, language_regex)) {
136
+ // Trim off anything after the language code.
137
+ return { std::string(locale, locale + 5) };
138
+ }
139
+
140
+ return {};
141
+ }
142
+
143
+ #endif
157
144
  #endif
158
145
 
159
146
  bool Gosu::Rect::overlaps(const Rect& other) const
data/src/UtilityWin.cpp CHANGED
@@ -37,12 +37,8 @@ std::string Gosu::utf16_to_utf8(const std::wstring& utf16)
37
37
  + std::to_string(GetLastError()));
38
38
  }
39
39
  std::string utf8(result, '\0');
40
- result = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, utf16.c_str(), utf16.size(),
41
- utf8.data(), utf8.size(), nullptr, nullptr);
42
- if (result == 0) {
43
- throw std::runtime_error("Could not convert UTF-16 to UTF-8, GetLastError() = "
44
- + std::to_string(GetLastError()));
45
- }
40
+ WideCharToMultiByte(CP_UTF8, MB_ERR_INVALID_CHARS, utf16.c_str(), utf16.size(), utf8.data(),
41
+ utf8.size(), nullptr, nullptr);
46
42
  return utf8;
47
43
  }
48
44
 
data/src/Window.cpp CHANGED
@@ -18,11 +18,6 @@ struct Gosu::Window::Impl : private Gosu::Noncopyable
18
18
  bool resizable = false;
19
19
  bool resizing = false;
20
20
 
21
- // We remember the last size in windowed mode so that we can restore it when leaving fullscreen.
22
- // (In fullscreen, the logical resolution follows the desktop and would otherwise be lost.)
23
- int windowed_width = 0;
24
- int windowed_height = 0;
25
-
26
21
  // A single `bool open` is not good enough to support the tick() method: When close() is called
27
22
  // from outside the window's call graph, the next call to tick() must return false (transition
28
23
  // from CLOSING to CLOSED), but the call after that must show the window again (transition from
@@ -87,12 +82,6 @@ void Gosu::Window::resize(int width, int height, bool fullscreen)
87
82
  {
88
83
  m_impl->fullscreen = fullscreen;
89
84
 
90
- // Remember the windowed size so we can restore it when leaving fullscreen mode later.
91
- if (!fullscreen) {
92
- m_impl->windowed_width = width;
93
- m_impl->windowed_height = height;
94
- }
95
-
96
85
  int actual_width = width;
97
86
  int actual_height = height;
98
87
  double scale_factor = 1.0;
@@ -139,12 +128,12 @@ void Gosu::Window::resize(int width, int height, bool fullscreen)
139
128
  }
140
129
  }
141
130
 
142
- SDL_SetWindowFullscreen(sdl_window(), fullscreen);
131
+ SDL_SetWindowFullscreen(sdl_window(), fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
143
132
  if (!m_impl->resizing) {
144
133
  SDL_SetWindowSize(sdl_window(), actual_width, actual_height);
145
134
  }
146
135
 
147
- SDL_GetWindowSizeInPixels(sdl_window(), &actual_width, &actual_height);
136
+ SDL_GL_GetDrawableSize(sdl_window(), &actual_width, &actual_height);
148
137
 
149
138
  if (!m_impl->viewport) {
150
139
  m_impl->viewport = std::make_unique<Viewport>(actual_width, actual_height);
@@ -169,7 +158,7 @@ bool Gosu::Window::resizable() const
169
158
  void Gosu::Window::set_resizable(bool resizable)
170
159
  {
171
160
  m_impl->resizable = resizable;
172
- SDL_SetWindowResizable(sdl_window(), resizable);
161
+ SDL_SetWindowResizable(sdl_window(), resizable ? SDL_TRUE : SDL_FALSE);
173
162
  }
174
163
 
175
164
  // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
@@ -181,7 +170,7 @@ bool Gosu::Window::borderless() const
181
170
  // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
182
171
  void Gosu::Window::set_borderless(bool borderless)
183
172
  {
184
- SDL_SetWindowBordered(sdl_window(), !borderless);
173
+ SDL_SetWindowBordered(sdl_window(), borderless ? SDL_FALSE : SDL_TRUE);
185
174
  }
186
175
 
187
176
  double Gosu::Window::update_interval() const
@@ -261,7 +250,7 @@ bool Gosu::Window::tick()
261
250
  SDL_ShowWindow(sdl_window());
262
251
  m_impl->state = Impl::OPEN;
263
252
 
264
- SDL_SetEventEnabled(SDL_EVENT_DROP_FILE, true);
253
+ SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
265
254
 
266
255
  // Enable vsync.
267
256
  const OpenGLContext current_context(true);
@@ -271,46 +260,48 @@ bool Gosu::Window::tick()
271
260
  // -> When first showing the window, update the physical size of Graphics (=glViewport).
272
261
  // Fixes https://github.com/gosu/gosu/issues/318
273
262
  int width, height;
274
- SDL_GetWindowSizeInPixels(sdl_window(), &width, &height);
263
+ SDL_GL_GetDrawableSize(sdl_window(), &width, &height);
275
264
  viewport().set_physical_resolution(width, height);
276
265
  }
277
266
 
278
267
  SDL_Event e;
279
268
  while (SDL_PollEvent(&e)) {
280
269
  switch (e.type) {
281
- case SDL_EVENT_WINDOW_RESIZED: {
282
- if (m_impl->resizable && (width() != e.window.data1 || height() != e.window.data2)) {
283
- m_impl->resizing = true;
284
- resize(e.window.data1, e.window.data2, fullscreen());
285
- m_impl->resizing = false;
270
+ case SDL_WINDOWEVENT: {
271
+ switch (e.window.event) {
272
+ case SDL_WINDOWEVENT_SIZE_CHANGED: {
273
+ if (m_impl->resizable
274
+ && (width() != e.window.data1 || height() != e.window.data2)) {
275
+ m_impl->resizing = true;
276
+ resize(e.window.data1, e.window.data2, fullscreen());
277
+ m_impl->resizing = false;
278
+ }
279
+ break;
280
+ }
281
+ case SDL_WINDOWEVENT_FOCUS_GAINED: {
282
+ gain_focus();
283
+ break;
284
+ }
285
+ case SDL_WINDOWEVENT_FOCUS_LOST: {
286
+ lose_focus();
287
+ break;
288
+ }
289
+ default: {
290
+ break;
291
+ }
286
292
  }
287
293
  break;
288
294
  }
289
- case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED: {
290
- // The logical window size stays the same, but the pixel density changed.
291
- // Example: the window is moved to a display with a different scaling factor.
292
- // => Update the viewport (and thus glViewport) without going through a full resize().
293
- viewport().set_physical_resolution(e.window.data1, e.window.data2);
294
- break;
295
- }
296
- case SDL_EVENT_WINDOW_FOCUS_GAINED: {
297
- gain_focus();
298
- break;
299
- }
300
- case SDL_EVENT_WINDOW_FOCUS_LOST: {
301
- lose_focus();
302
- break;
303
- }
304
- case SDL_EVENT_QUIT: {
295
+ case SDL_QUIT: {
305
296
  close();
306
297
  break;
307
298
  }
308
- case SDL_EVENT_DROP_FILE: {
309
- const char* dropped_file = e.drop.data;
299
+ case SDL_DROPFILE: {
300
+ std::shared_ptr<char> dropped_file { e.drop.file, SDL_free };
310
301
  if (dropped_file == nullptr) {
311
302
  break;
312
303
  }
313
- drop(dropped_file);
304
+ drop(dropped_file.get());
314
305
  break;
315
306
  }
316
307
  default: {
@@ -326,12 +317,7 @@ bool Gosu::Window::tick()
326
317
 
327
318
  update();
328
319
 
329
- if (needs_cursor()) {
330
- SDL_ShowCursor();
331
- }
332
- else {
333
- SDL_HideCursor();
334
- }
320
+ SDL_ShowCursor(needs_cursor());
335
321
 
336
322
  if (needs_redraw()) {
337
323
  const OpenGLContext current_context(true);
@@ -381,13 +367,7 @@ void Gosu::Window::button_down(Button button)
381
367
  }
382
368
 
383
369
  if (toggle_fullscreen) {
384
- if (fullscreen()) {
385
- // Restore the previous windowed size instead of the current (desktop) resolution.
386
- resize(m_impl->windowed_width, m_impl->windowed_height, false);
387
- }
388
- else {
389
- resize(width(), height(), true);
390
- }
370
+ resize(width(), height(), !fullscreen());
391
371
  }
392
372
  }
393
373