gosu 1.4.6 → 1.5.0

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 (320) hide show
  1. checksums.yaml +4 -4
  2. data/COPYING +2 -1
  3. data/dependencies/SDL/include/SDL3/SDL.h +91 -0
  4. data/dependencies/SDL/include/SDL3/SDL_assert.h +710 -0
  5. data/dependencies/SDL/include/SDL3/SDL_asyncio.h +550 -0
  6. data/dependencies/SDL/include/SDL3/SDL_atomic.h +692 -0
  7. data/dependencies/SDL/include/SDL3/SDL_audio.h +2382 -0
  8. data/dependencies/SDL/include/SDL3/SDL_begin_code.h +553 -0
  9. data/dependencies/SDL/include/{SDL_bits.h → SDL3/SDL_bits.h} +47 -27
  10. data/dependencies/SDL/include/{SDL_blendmode.h → SDL3/SDL_blendmode.h} +59 -55
  11. data/dependencies/SDL/include/SDL3/SDL_camera.h +535 -0
  12. data/dependencies/SDL/include/SDL3/SDL_clipboard.h +331 -0
  13. data/dependencies/SDL/include/{close_code.h → SDL3/SDL_close_code.h} +9 -8
  14. data/dependencies/SDL/include/{SDL_types.h → SDL3/SDL_copying.h} +2 -9
  15. data/dependencies/SDL/include/SDL3/SDL_cpuinfo.h +374 -0
  16. data/dependencies/SDL/include/SDL3/SDL_dialog.h +343 -0
  17. data/dependencies/SDL/include/SDL3/SDL_dlopennote.h +234 -0
  18. data/dependencies/SDL/include/{SDL_egl.h → SDL3/SDL_egl.h} +11 -8
  19. data/dependencies/SDL/include/SDL3/SDL_endian.h +645 -0
  20. data/dependencies/SDL/include/SDL3/SDL_error.h +226 -0
  21. data/dependencies/SDL/include/SDL3/SDL_events.h +1651 -0
  22. data/dependencies/SDL/include/SDL3/SDL_filesystem.h +537 -0
  23. data/dependencies/SDL/include/SDL3/SDL_gamepad.h +1657 -0
  24. data/dependencies/SDL/include/SDL3/SDL_gpu.h +4637 -0
  25. data/dependencies/SDL/include/SDL3/SDL_guid.h +106 -0
  26. data/dependencies/SDL/include/SDL3/SDL_haptic.h +1461 -0
  27. data/dependencies/SDL/include/SDL3/SDL_hidapi.h +571 -0
  28. data/dependencies/SDL/include/SDL3/SDL_hints.h +5041 -0
  29. data/dependencies/SDL/include/SDL3/SDL_init.h +508 -0
  30. data/dependencies/SDL/include/SDL3/SDL_intrin.h +410 -0
  31. data/dependencies/SDL/include/SDL3/SDL_iostream.h +1379 -0
  32. data/dependencies/SDL/include/SDL3/SDL_joystick.h +1385 -0
  33. data/dependencies/SDL/include/SDL3/SDL_keyboard.h +615 -0
  34. data/dependencies/SDL/include/SDL3/SDL_keycode.h +348 -0
  35. data/dependencies/SDL/include/SDL3/SDL_loadso.h +145 -0
  36. data/dependencies/SDL/include/{SDL_locale.h → SDL3/SDL_locale.h} +40 -24
  37. data/dependencies/SDL/include/SDL3/SDL_log.h +541 -0
  38. data/dependencies/SDL/include/SDL3/SDL_main.h +704 -0
  39. data/dependencies/SDL/include/SDL3/SDL_main_impl.h +149 -0
  40. data/dependencies/SDL/include/{SDL_messagebox.h → SDL3/SDL_messagebox.h} +85 -48
  41. data/dependencies/SDL/include/{SDL_metal.h → SDL3/SDL_metal.h} +29 -29
  42. data/dependencies/SDL/include/{SDL_misc.h → SDL3/SDL_misc.h} +13 -12
  43. data/dependencies/SDL/include/SDL3/SDL_mouse.h +813 -0
  44. data/dependencies/SDL/include/SDL3/SDL_mutex.h +1117 -0
  45. data/dependencies/SDL/include/SDL3/SDL_oldnames.h +1339 -0
  46. data/dependencies/SDL/include/{SDL_opengl.h → SDL3/SDL_opengl.h} +1247 -278
  47. data/dependencies/SDL/include/{SDL_opengl_glext.h → SDL3/SDL_opengl_glext.h} +5 -1
  48. data/dependencies/SDL/include/{SDL_opengles.h → SDL3/SDL_opengles.h} +6 -7
  49. data/dependencies/SDL/include/{SDL_opengles2.h → SDL3/SDL_opengles2.h} +10 -11
  50. data/dependencies/SDL/include/SDL3/SDL_pen.h +198 -0
  51. data/dependencies/SDL/include/SDL3/SDL_pixels.h +1441 -0
  52. data/dependencies/SDL/include/{SDL_test_log.h → SDL3/SDL_platform.h} +25 -26
  53. data/dependencies/SDL/include/SDL3/SDL_platform_defines.h +497 -0
  54. data/dependencies/SDL/include/{SDL_power.h → SDL3/SDL_power.h} +40 -20
  55. data/dependencies/SDL/include/SDL3/SDL_process.h +441 -0
  56. data/dependencies/SDL/include/SDL3/SDL_properties.h +572 -0
  57. data/dependencies/SDL/include/SDL3/SDL_rect.h +528 -0
  58. data/dependencies/SDL/include/SDL3/SDL_render.h +3034 -0
  59. data/dependencies/SDL/include/SDL3/SDL_revision.h +56 -0
  60. data/dependencies/SDL/include/{SDL_scancode.h → SDL3/SDL_scancode.h} +60 -68
  61. data/dependencies/SDL/include/SDL3/SDL_sensor.h +321 -0
  62. data/dependencies/SDL/include/SDL3/SDL_stdinc.h +6186 -0
  63. data/dependencies/SDL/include/SDL3/SDL_storage.h +686 -0
  64. data/dependencies/SDL/include/SDL3/SDL_surface.h +1769 -0
  65. data/dependencies/SDL/include/SDL3/SDL_system.h +840 -0
  66. data/dependencies/SDL/include/{SDL_test.h → SDL3/SDL_test.h} +16 -22
  67. data/dependencies/SDL/include/{SDL_test_assert.h → SDL3/SDL_test_assert.h} +27 -34
  68. data/dependencies/SDL/include/{SDL_test_common.h → SDL3/SDL_test_common.h} +109 -52
  69. data/dependencies/SDL/include/{SDL_test_compare.h → SDL3/SDL_test_compare.h} +22 -14
  70. data/dependencies/SDL/include/{SDL_test_crc32.h → SDL3/SDL_test_crc32.h} +27 -30
  71. data/dependencies/SDL/include/{SDL_test_font.h → SDL3/SDL_test_font.h} +50 -49
  72. data/dependencies/SDL/include/{SDL_test_fuzzer.h → SDL3/SDL_test_fuzzer.h} +64 -79
  73. data/dependencies/SDL/include/{SDL_test_harness.h → SDL3/SDL_test_harness.h} +47 -30
  74. data/dependencies/SDL/include/SDL3/SDL_test_log.h +83 -0
  75. data/dependencies/SDL/include/{SDL_test_md5.h → SDL3/SDL_test_md5.h} +21 -28
  76. data/dependencies/SDL/include/{SDL_test_memory.h → SDL3/SDL_test_memory.h} +19 -16
  77. data/dependencies/SDL/include/SDL3/SDL_thread.h +602 -0
  78. data/dependencies/SDL/include/SDL3/SDL_time.h +249 -0
  79. data/dependencies/SDL/include/SDL3/SDL_timer.h +454 -0
  80. data/dependencies/SDL/include/SDL3/SDL_touch.h +184 -0
  81. data/dependencies/SDL/include/SDL3/SDL_tray.h +544 -0
  82. data/dependencies/SDL/include/SDL3/SDL_version.h +198 -0
  83. data/dependencies/SDL/include/SDL3/SDL_video.h +3497 -0
  84. data/dependencies/SDL/include/SDL3/SDL_vulkan.h +287 -0
  85. data/dependencies/SDL/lib/x64/libSDL3.dll.a +0 -0
  86. data/dependencies/SDL/lib/x86/libSDL3.dll.a +0 -0
  87. data/dependencies/SDL_sound/SDL3_sound/SDL_sound.h +755 -0
  88. data/dependencies/SDL_sound/SDL_sound.c +136 -215
  89. data/dependencies/SDL_sound/SDL_sound_aiff.c +55 -54
  90. data/dependencies/SDL_sound/SDL_sound_au.c +32 -32
  91. data/dependencies/SDL_sound/SDL_sound_coreaudio.c +24 -41
  92. data/dependencies/SDL_sound/SDL_sound_flac.c +32 -12
  93. data/dependencies/SDL_sound/SDL_sound_internal.h +33 -48
  94. data/dependencies/SDL_sound/SDL_sound_modplug.c +21 -29
  95. data/dependencies/SDL_sound/SDL_sound_mp3.c +35 -13
  96. data/dependencies/SDL_sound/SDL_sound_raw.c +14 -15
  97. data/dependencies/SDL_sound/SDL_sound_shn.c +82 -82
  98. data/dependencies/SDL_sound/SDL_sound_voc.c +30 -30
  99. data/dependencies/SDL_sound/SDL_sound_vorbis.c +34 -25
  100. data/dependencies/SDL_sound/SDL_sound_wav.c +86 -82
  101. data/dependencies/SDL_sound/dr_flac.h +1890 -1301
  102. data/dependencies/SDL_sound/dr_mp3.h +1098 -660
  103. data/dependencies/SDL_sound/libmodplug/fastmix.c +1 -1
  104. data/dependencies/SDL_sound/libmodplug/libmodplug.h +5 -4
  105. data/dependencies/SDL_sound/libmodplug/load_ams.c +6 -3
  106. data/dependencies/SDL_sound/libmodplug/load_dsm.c +2 -1
  107. data/dependencies/SDL_sound/libmodplug/load_mt2.c +2 -2
  108. data/dependencies/SDL_sound/libmodplug/modplug.h +2 -1
  109. data/dependencies/SDL_sound/libmodplug/snd_fx.c +3 -3
  110. data/dependencies/SDL_sound/libmodplug/sndfile.c +3 -0
  111. data/dependencies/SDL_sound/libmodplug/sndmix.c +7 -3
  112. data/dependencies/SDL_sound/stb_vorbis.h +397 -342
  113. data/dependencies/mojoAL/AL/alc.h +2 -2
  114. data/dependencies/mojoAL/mojoal.c +2120 -1885
  115. data/dependencies/stb/stb_image.h +1190 -1379
  116. data/dependencies/stb/stb_image_write.h +329 -129
  117. data/dependencies/stb/stb_truetype.h +304 -60
  118. data/dependencies/utf8proc/utf8proc.c +133 -75
  119. data/dependencies/utf8proc/utf8proc.h +131 -50
  120. data/dependencies/utf8proc/utf8proc_data.h +16213 -15658
  121. data/ext/gosu-ffi/extconf.rb +103 -0
  122. data/ext/gosu-ffi/gosu-ffi.def +467 -0
  123. data/ffi/Gosu.cpp +330 -0
  124. data/ffi/Gosu.h +84 -0
  125. data/ffi/Gosu_Channel.cpp +62 -0
  126. data/ffi/Gosu_Channel.h +17 -0
  127. data/ffi/Gosu_Color.cpp +176 -0
  128. data/ffi/Gosu_Color.h +31 -0
  129. data/ffi/Gosu_Constants.cpp +334 -0
  130. data/ffi/Gosu_FFI.h +34 -0
  131. data/ffi/Gosu_FFI_internal.h +160 -0
  132. data/ffi/Gosu_Font.cpp +97 -0
  133. data/ffi/Gosu_Font.h +32 -0
  134. data/ffi/Gosu_Image.cpp +239 -0
  135. data/ffi/Gosu_Image.h +71 -0
  136. data/ffi/Gosu_Sample.cpp +29 -0
  137. data/ffi/Gosu_Sample.h +14 -0
  138. data/ffi/Gosu_Song.cpp +69 -0
  139. data/ffi/Gosu_Song.h +18 -0
  140. data/ffi/Gosu_TextInput.cpp +94 -0
  141. data/ffi/Gosu_TextInput.h +25 -0
  142. data/ffi/Gosu_Window.cpp +314 -0
  143. data/ffi/Gosu_Window.h +78 -0
  144. data/include/Gosu/Audio.hpp +6 -11
  145. data/include/Gosu/Bitmap.hpp +38 -53
  146. data/include/Gosu/Buffer.hpp +54 -0
  147. data/include/Gosu/Color.hpp +29 -36
  148. data/include/Gosu/Directories.hpp +25 -28
  149. data/include/Gosu/Drawable.hpp +58 -0
  150. data/include/Gosu/Font.hpp +6 -5
  151. data/include/Gosu/Fwd.hpp +4 -6
  152. data/include/Gosu/Gosu.hpp +5 -5
  153. data/include/Gosu/Graphics.hpp +53 -61
  154. data/include/Gosu/GraphicsBase.hpp +1 -11
  155. data/include/Gosu/Image.hpp +12 -15
  156. data/include/Gosu/Math.hpp +50 -72
  157. data/include/Gosu/Transform.hpp +32 -0
  158. data/include/Gosu/Utility.hpp +77 -1
  159. data/include/Gosu/Version.hpp +2 -2
  160. data/include/Gosu/Window.hpp +15 -9
  161. data/lib/SDL3.dll +0 -0
  162. data/lib/gosu/channel.rb +50 -0
  163. data/lib/gosu/color.rb +173 -0
  164. data/lib/gosu/compat.rb +130 -17
  165. data/lib/gosu/constants.rb +386 -0
  166. data/lib/gosu/ffi.rb +269 -0
  167. data/lib/gosu/font.rb +62 -0
  168. data/lib/gosu/gl_tex_info.rb +33 -0
  169. data/lib/gosu/gosu.rb +250 -0
  170. data/lib/gosu/image.rb +179 -0
  171. data/lib/gosu/numeric.rb +17 -0
  172. data/lib/gosu/preview.rb +6 -6
  173. data/lib/gosu/sample.rb +25 -0
  174. data/lib/gosu/song.rb +57 -0
  175. data/lib/gosu/text_input.rb +83 -0
  176. data/lib/gosu/window.rb +249 -0
  177. data/lib/gosu.rb +29 -8
  178. data/lib64/SDL3.dll +0 -0
  179. data/rdoc/gosu.rb +2 -2
  180. data/src/Audio.cpp +30 -24
  181. data/src/AudioFile.hpp +5 -4
  182. data/src/AudioFileAudioToolbox.cpp +8 -8
  183. data/src/AudioFileSDLSound.cpp +12 -15
  184. data/src/BinPacker.cpp +188 -0
  185. data/src/BinPacker.hpp +55 -0
  186. data/src/Bitmap.cpp +172 -143
  187. data/src/BitmapIO.cpp +60 -86
  188. data/src/Buffer.cpp +150 -0
  189. data/src/ClipRectStack.cpp +38 -0
  190. data/src/ClipRectStack.hpp +17 -83
  191. data/src/Color.cpp +75 -80
  192. data/src/Directories.cpp +47 -0
  193. data/src/DirectoriesUIKit.cpp +50 -0
  194. data/src/DrawOp.hpp +20 -18
  195. data/src/DrawOpQueue.hpp +27 -33
  196. data/src/Drawable.cpp +95 -0
  197. data/src/EmptyDrawable.hpp +38 -0
  198. data/src/FPS.cpp +31 -0
  199. data/src/Font.cpp +104 -74
  200. data/src/GosuGLView.cpp +13 -11
  201. data/src/GosuViewController.cpp +2 -10
  202. data/src/Graphics.cpp +86 -145
  203. data/src/GraphicsImpl.hpp +14 -68
  204. data/src/Image.cpp +41 -35
  205. data/src/Input.cpp +73 -78
  206. data/src/Macro.cpp +46 -29
  207. data/src/Macro.hpp +23 -17
  208. data/src/MarkupParser.cpp +5 -5
  209. data/src/Math.cpp +48 -22
  210. data/src/OffScreenTarget.cpp +47 -50
  211. data/src/OffScreenTarget.hpp +13 -11
  212. data/src/OpenGLContext.cpp +116 -0
  213. data/src/OpenGLContext.hpp +41 -0
  214. data/src/RenderState.hpp +49 -71
  215. data/src/Resolution.cpp +65 -53
  216. data/src/TexChunk.cpp +35 -80
  217. data/src/TexChunk.hpp +44 -35
  218. data/src/Text.cpp +1 -1
  219. data/src/TextBuilder.cpp +35 -21
  220. data/src/TextBuilder.hpp +6 -9
  221. data/src/TextInput.cpp +9 -9
  222. data/src/Texture.cpp +62 -80
  223. data/src/Texture.hpp +25 -23
  224. data/src/TiledDrawable.cpp +149 -0
  225. data/src/TiledDrawable.hpp +47 -0
  226. data/src/TimingApple.cpp +1 -1
  227. data/src/Transform.cpp +45 -50
  228. data/src/TransformStack.hpp +16 -16
  229. data/src/TrueTypeFont.cpp +59 -51
  230. data/src/TrueTypeFont.hpp +6 -7
  231. data/src/TrueTypeFontApple.cpp +28 -19
  232. data/src/TrueTypeFontUnix.cpp +39 -32
  233. data/src/TrueTypeFontWin.cpp +30 -30
  234. data/src/Utility.cpp +113 -37
  235. data/src/UtilityWin.cpp +49 -0
  236. data/src/Window.cpp +121 -151
  237. data/src/WindowUIKit.cpp +14 -14
  238. metadata +165 -118
  239. data/dependencies/SDL/include/SDL.h +0 -233
  240. data/dependencies/SDL/include/SDL_assert.h +0 -320
  241. data/dependencies/SDL/include/SDL_atomic.h +0 -415
  242. data/dependencies/SDL/include/SDL_audio.h +0 -1500
  243. data/dependencies/SDL/include/SDL_clipboard.h +0 -141
  244. data/dependencies/SDL/include/SDL_config.h +0 -331
  245. data/dependencies/SDL/include/SDL_cpuinfo.h +0 -594
  246. data/dependencies/SDL/include/SDL_endian.h +0 -348
  247. data/dependencies/SDL/include/SDL_error.h +0 -163
  248. data/dependencies/SDL/include/SDL_events.h +0 -1166
  249. data/dependencies/SDL/include/SDL_filesystem.h +0 -149
  250. data/dependencies/SDL/include/SDL_gamecontroller.h +0 -1074
  251. data/dependencies/SDL/include/SDL_gesture.h +0 -117
  252. data/dependencies/SDL/include/SDL_guid.h +0 -100
  253. data/dependencies/SDL/include/SDL_haptic.h +0 -1341
  254. data/dependencies/SDL/include/SDL_hidapi.h +0 -451
  255. data/dependencies/SDL/include/SDL_hints.h +0 -2569
  256. data/dependencies/SDL/include/SDL_joystick.h +0 -1066
  257. data/dependencies/SDL/include/SDL_keyboard.h +0 -353
  258. data/dependencies/SDL/include/SDL_keycode.h +0 -358
  259. data/dependencies/SDL/include/SDL_loadso.h +0 -115
  260. data/dependencies/SDL/include/SDL_log.h +0 -404
  261. data/dependencies/SDL/include/SDL_main.h +0 -275
  262. data/dependencies/SDL/include/SDL_mouse.h +0 -465
  263. data/dependencies/SDL/include/SDL_mutex.h +0 -471
  264. data/dependencies/SDL/include/SDL_name.h +0 -33
  265. data/dependencies/SDL/include/SDL_pixels.h +0 -644
  266. data/dependencies/SDL/include/SDL_platform.h +0 -261
  267. data/dependencies/SDL/include/SDL_quit.h +0 -58
  268. data/dependencies/SDL/include/SDL_rect.h +0 -376
  269. data/dependencies/SDL/include/SDL_render.h +0 -1919
  270. data/dependencies/SDL/include/SDL_revision.h +0 -7
  271. data/dependencies/SDL/include/SDL_rwops.h +0 -841
  272. data/dependencies/SDL/include/SDL_sensor.h +0 -322
  273. data/dependencies/SDL/include/SDL_shape.h +0 -155
  274. data/dependencies/SDL/include/SDL_stdinc.h +0 -830
  275. data/dependencies/SDL/include/SDL_surface.h +0 -997
  276. data/dependencies/SDL/include/SDL_system.h +0 -623
  277. data/dependencies/SDL/include/SDL_syswm.h +0 -386
  278. data/dependencies/SDL/include/SDL_test_images.h +0 -78
  279. data/dependencies/SDL/include/SDL_test_random.h +0 -115
  280. data/dependencies/SDL/include/SDL_thread.h +0 -464
  281. data/dependencies/SDL/include/SDL_timer.h +0 -222
  282. data/dependencies/SDL/include/SDL_touch.h +0 -150
  283. data/dependencies/SDL/include/SDL_version.h +0 -204
  284. data/dependencies/SDL/include/SDL_video.h +0 -2150
  285. data/dependencies/SDL/include/SDL_vulkan.h +0 -215
  286. data/dependencies/SDL/include/begin_code.h +0 -187
  287. data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
  288. data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
  289. data/dependencies/SDL_sound/SDL_sound.h +0 -725
  290. data/ext/gosu/extconf.rb +0 -119
  291. data/include/Gosu/IO.hpp +0 -254
  292. data/include/Gosu/ImageData.hpp +0 -53
  293. data/include/Gosu/Inspection.hpp +0 -7
  294. data/lib/SDL2.dll +0 -0
  295. data/lib/gosu/patches.rb +0 -66
  296. data/lib/gosu/run.rb +0 -20
  297. data/lib/gosu/swig_patches.rb +0 -110
  298. data/lib64/SDL2.dll +0 -0
  299. data/src/BlockAllocator.cpp +0 -131
  300. data/src/BlockAllocator.hpp +0 -32
  301. data/src/DirectoriesApple.cpp +0 -69
  302. data/src/DirectoriesUnix.cpp +0 -46
  303. data/src/DirectoriesWin.cpp +0 -65
  304. data/src/EmptyImageData.hpp +0 -52
  305. data/src/FileUnix.cpp +0 -99
  306. data/src/FileWin.cpp +0 -88
  307. data/src/IO.cpp +0 -60
  308. data/src/Iconv.hpp +0 -51
  309. data/src/Inspection.cpp +0 -27
  310. data/src/LargeImageData.cpp +0 -215
  311. data/src/LargeImageData.hpp +0 -39
  312. data/src/Log.hpp +0 -19
  313. data/src/RubyGosu.cxx +0 -13100
  314. data/src/RubyGosu.h +0 -49
  315. data/src/WinUtility.cpp +0 -61
  316. data/src/WinUtility.hpp +0 -27
  317. /data/dependencies/SDL/include/{SDL_opengles2_gl2.h → SDL3/SDL_opengles2_gl2.h} +0 -0
  318. /data/dependencies/SDL/include/{SDL_opengles2_gl2ext.h → SDL3/SDL_opengles2_gl2ext.h} +0 -0
  319. /data/dependencies/SDL/include/{SDL_opengles2_gl2platform.h → SDL3/SDL_opengles2_gl2platform.h} +0 -0
  320. /data/dependencies/SDL/include/{SDL_opengles2_khrplatform.h → SDL3/SDL_opengles2_khrplatform.h} +0 -0
data/src/TrueTypeFont.hpp CHANGED
@@ -1,11 +1,10 @@
1
1
  #pragma once
2
2
 
3
3
  #include <Gosu/Bitmap.hpp>
4
- #include <Gosu/IO.hpp>
4
+ #include <cstdint>
5
5
  #include <functional>
6
6
  #include <memory>
7
7
  #include <string>
8
- #include <vector>
9
8
 
10
9
  namespace Gosu
11
10
  {
@@ -16,7 +15,7 @@ namespace Gosu
16
15
 
17
16
  public:
18
17
  /// The caller must ensure that the ttf_data pointer will outlive this object.
19
- TrueTypeFont(const unsigned char* ttf_data, std::shared_ptr<TrueTypeFont> fallback);
18
+ TrueTypeFont(const std::uint8_t* ttf_data, std::shared_ptr<TrueTypeFont> fallback);
20
19
 
21
20
  /// Returns the right edge of a string when rendered onto a bitmap at the given position,
22
21
  /// and with the given height.
@@ -25,7 +24,7 @@ namespace Gosu
25
24
  Bitmap* bitmap, double x, double y, Color c);
26
25
 
27
26
  /// Returns true if the supplied buffer seems to be a font of the given name.
28
- static bool matches(const unsigned char* ttf_data, //
27
+ static bool matches(const std::uint8_t* ttf_data, //
29
28
  const std::string& font_name, unsigned font_flags);
30
29
  };
31
30
 
@@ -49,15 +48,15 @@ namespace Gosu
49
48
  /// 3. As a last resort, Gosu could implement faux bold and faux italics. I think faux
50
49
  /// underlines are a must anyway, since no font provides a dedicated TTF file for that.
51
50
  /// These options are not mutually exclusive.
52
- const unsigned char* ttf_data_from_file(const std::string& filename);
51
+ const std::uint8_t* ttf_data_from_file(const std::string& filename);
53
52
 
54
53
  /// This method loads a system font with the given flags.
55
54
  /// This method has a different implementation on each platform.
56
55
  /// In case of failure, this method returns nullptr.
57
- const unsigned char* ttf_data_by_name(const std::string& font_name, unsigned font_flags);
56
+ const std::uint8_t* ttf_data_by_name(const std::string& font_name, unsigned font_flags);
58
57
 
59
58
  /// Returns the TTF data of a font that supports as many glyphs as possible.
60
59
  /// This method has a different implementation on each platform.
61
60
  /// In case of failure, this method must not return nullptr, but raise an exception.
62
- const unsigned char* ttf_fallback_data();
61
+ const std::uint8_t* ttf_fallback_data();
63
62
  }
@@ -2,50 +2,55 @@
2
2
  #if defined(GOSU_IS_MAC)
3
3
 
4
4
  #include <Gosu/Text.hpp>
5
- #include "Log.hpp"
6
5
  #include "TrueTypeFont.hpp"
7
6
  #include <CoreText/CoreText.h>
8
7
  #include <Foundation/Foundation.h>
9
8
  #include <map>
10
9
 
11
- const unsigned char* Gosu::ttf_data_by_name(const std::string& font_name, unsigned font_flags)
10
+ const std::uint8_t* Gosu::ttf_data_by_name(const std::string& font_name, unsigned font_flags)
12
11
  {
13
- // TODO: Make this cache thread-safe.
14
- static std::map<std::pair<std::string, unsigned>, const unsigned char*> ttf_file_cache;
12
+ static std::map<std::pair<std::string, unsigned>, const std::uint8_t*> ttf_file_cache;
13
+ static std::recursive_mutex mutex;
14
+ std::scoped_lock lock(mutex);
15
15
 
16
16
  auto& ttf_ptr = ttf_file_cache[make_pair(font_name, font_flags)];
17
- if (ttf_ptr) return ttf_ptr;
18
-
19
- log("Trying to find a font named '%s', flags=%x", font_name.c_str(), font_flags);
17
+ if (ttf_ptr) {
18
+ return ttf_ptr;
19
+ }
20
20
 
21
21
  unsigned symbolic_traits = 0;
22
- if (font_flags & Gosu::FF_BOLD) symbolic_traits |= kCTFontTraitBold;
23
- if (font_flags & Gosu::FF_ITALIC) symbolic_traits |= kCTFontTraitItalic;
22
+ if (font_flags & Gosu::FF_BOLD) {
23
+ symbolic_traits |= kCTFontTraitBold;
24
+ }
25
+ if (font_flags & Gosu::FF_ITALIC) {
26
+ symbolic_traits |= kCTFontTraitItalic;
27
+ }
24
28
 
25
29
  NSDictionary* attributes = @{
26
- ((__bridge id) kCTFontNameAttribute): [NSString stringWithUTF8String:font_name.c_str()],
27
- ((__bridge id) kCTFontTraitsAttribute):
28
- @{((__bridge id) kCTFontSymbolicTrait): @(symbolic_traits)}
30
+ ((__bridge id)kCTFontNameAttribute) : [NSString stringWithUTF8String:font_name.c_str()],
31
+ ((__bridge id)kCTFontTraitsAttribute) :
32
+ @ { ((__bridge id)kCTFontSymbolicTrait) : @(symbolic_traits) }
29
33
  };
30
34
  CTFontDescriptorRef descriptor =
31
- // NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
32
- CTFontDescriptorCreateWithAttributes((__bridge CFDictionaryRef) attributes);
35
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
36
+ CTFontDescriptorCreateWithAttributes((__bridge CFDictionaryRef)attributes);
33
37
 
34
38
  if (descriptor) {
35
39
  CTFontRef font = CTFontCreateWithFontDescriptorAndOptions(descriptor, 20, nullptr, 0);
36
40
  if (font) {
41
+ // GCOV_EXCL_START: This does not seem to happen anymore on recent macOS versions.
37
42
  if ((CTFontGetSymbolicTraits(font) & symbolic_traits) != symbolic_traits) {
38
43
  // For some reason the initial call to CTFontCreateWithFontDescriptorAndOptions does
39
44
  // not respect the requested font traits. Explicitly requesting the traits again
40
45
  // seems to help. Tested on macOS 11.2.2.
41
46
  CTFontRef correct_font = CTFontCreateCopyWithSymbolicTraits(
42
- font, 0.0, nullptr, symbolic_traits, symbolic_traits);
47
+ font, 0.0, nullptr, symbolic_traits, symbolic_traits);
43
48
  CFRelease(font);
44
49
  font = correct_font;
45
50
  }
51
+ // GCOV_EXCL_END
46
52
  NSURL* url = CFBridgingRelease(CTFontCopyAttribute(font, kCTFontURLAttribute));
47
53
  if (url && url.fileSystemRepresentation) {
48
- log("Loading file '%s'", url.fileSystemRepresentation);
49
54
  ttf_ptr = ttf_data_from_file(url.fileSystemRepresentation);
50
55
  }
51
56
  CFRelease(font);
@@ -56,13 +61,17 @@ const unsigned char* Gosu::ttf_data_by_name(const std::string& font_name, unsign
56
61
  return ttf_ptr;
57
62
  }
58
63
 
59
- const unsigned char* Gosu::ttf_fallback_data()
64
+ const std::uint8_t* Gosu::ttf_fallback_data()
60
65
  {
61
66
  // Prefer Arial Unicode MS as a fallback because it covers a lot of Unicode.
62
- static const unsigned char* arial_unicode = ttf_data_by_name("Arial Unicode MS", 0);
63
- if (arial_unicode) return arial_unicode;
67
+ static const std::uint8_t* arial_unicode = ttf_data_by_name("Arial Unicode MS", 0);
68
+ if (arial_unicode) {
69
+ return arial_unicode;
70
+ }
64
71
 
72
+ // GCOV_EXCL_START: We do not want to delete system fonts in order to test this line.
65
73
  return ttf_data_from_file("/Library/Fonts/Arial.ttf");
74
+ // GCOV_EXCL_END
66
75
  }
67
76
 
68
77
  std::string Gosu::default_font_name()
@@ -1,23 +1,23 @@
1
1
  #include <Gosu/Platform.hpp>
2
2
  #if defined(GOSU_IS_X)
3
3
 
4
- #include <Gosu/IO.hpp>
5
4
  #include <Gosu/Text.hpp>
6
5
  #include <Gosu/Utility.hpp>
7
- #include "Log.hpp"
8
6
  #include "TrueTypeFont.hpp"
9
7
  #include <fontconfig/fontconfig.h>
10
8
  #include <map>
9
+ #include <mutex>
11
10
 
12
- const unsigned char* Gosu::ttf_data_by_name(const std::string& font_name, unsigned font_flags)
11
+ const std::uint8_t* Gosu::ttf_data_by_name(const std::string& font_name, unsigned font_flags)
13
12
  {
14
- // TODO: Make this cache thread-safe.
15
- static std::map<std::pair<std::string, unsigned>, const unsigned char*> ttf_file_cache;
13
+ static std::map<std::pair<std::string, unsigned>, const std::uint8_t*> ttf_file_cache;
14
+ static std::recursive_mutex mutex;
15
+ std::scoped_lock lock(mutex);
16
16
 
17
17
  auto& ttf_ptr = ttf_file_cache[make_pair(font_name, font_flags)];
18
- if (ttf_ptr) return ttf_ptr;
19
-
20
- log("Trying to find a font named '%s', flags=%x", font_name.c_str(), font_flags);
18
+ if (ttf_ptr) {
19
+ return ttf_ptr;
20
+ }
21
21
 
22
22
  static FcConfig* config = FcInitLoadConfigAndFonts();
23
23
  if (config) {
@@ -31,15 +31,12 @@ const unsigned char* Gosu::ttf_data_by_name(const std::string& font_name, unsign
31
31
  FcObjectSet* props = FcObjectSetBuild(FC_FILE, FC_WEIGHT, FC_SLANT, nullptr);
32
32
 
33
33
  if (FcFontSet* fonts = FcFontList(config, pattern, props)) {
34
- log("Looking for the best candidate among %d matching fonts", (int) fonts->nfont);
35
-
36
34
  // Among all matching fonts, find the variant that is the best fit for our font_flags.
37
35
  std::string best_filename;
38
- int best_diff;
36
+ int best_diff = 0;
39
37
 
40
38
  for (int i = 0; i < fonts->nfont; ++i) {
41
- int weight, slant;
42
-
39
+ int weight = 0, slant = 0;
43
40
  FcPatternGetInteger(fonts->fonts[i], FC_WEIGHT, 0, &weight);
44
41
  FcPatternGetInteger(fonts->fonts[i], FC_SLANT, 0, &slant);
45
42
 
@@ -59,20 +56,23 @@ const unsigned char* Gosu::ttf_data_by_name(const std::string& font_name, unsign
59
56
  diff += abs(slant - FC_SLANT_ROMAN);
60
57
  }
61
58
 
59
+ FcChar8* filename = nullptr;
60
+ if (FcPatternGetString(fonts->fonts[i], FC_FILE, 0, &filename) != FcResultMatch
61
+ || filename == nullptr) {
62
+ continue;
63
+ }
64
+
62
65
  // Penalize OTF fonts since we are not really good at handling these.
63
- FcChar8* file;
64
- FcPatternGetString(fonts->fonts[i], FC_FILE, 0, &file);
65
- if (has_extension(reinterpret_cast<char*>(file), ".otf")) {
66
+ if (has_extension(reinterpret_cast<char*>(filename), ".otf")) {
66
67
  diff += 10000;
67
68
  }
68
69
 
69
70
  if (best_filename.empty() || diff < best_diff) {
70
- best_filename = reinterpret_cast<char*>(file);
71
+ best_filename = reinterpret_cast<char*>(filename);
71
72
  best_diff = diff;
72
73
  }
73
74
  }
74
75
  if (!best_filename.empty()) {
75
- log("Loading best candidate '%s'", best_filename.c_str());
76
76
  ttf_ptr = ttf_data_from_file(best_filename.c_str());
77
77
  }
78
78
 
@@ -86,9 +86,9 @@ const unsigned char* Gosu::ttf_data_by_name(const std::string& font_name, unsign
86
86
  return ttf_ptr;
87
87
  }
88
88
 
89
- static const unsigned char* ttf_data_of_default_sans_serif_font()
89
+ static const std::uint8_t* ttf_data_of_default_sans_serif_font()
90
90
  {
91
- const unsigned char* ttf_ptr = nullptr;
91
+ const std::uint8_t* ttf_ptr = nullptr;
92
92
 
93
93
  // At this point, we already have an open FcConfig, and can pass nullptr to these functions.
94
94
  FcPattern* pattern = FcNameParse(reinterpret_cast<const FcChar8*>("sans-serif"));
@@ -97,9 +97,8 @@ static const unsigned char* ttf_data_of_default_sans_serif_font()
97
97
  FcResult match_result;
98
98
  pattern = FcFontMatch(nullptr, pattern, &match_result);
99
99
  if (match_result == FcResultMatch) {
100
- FcChar8* filename;
101
- if (FcPatternGetString(pattern, FC_FILE, 0, &filename) == FcResultMatch) {
102
- Gosu::log("Found the default sans-serif font: '%s'", filename);
100
+ FcChar8* filename = nullptr;
101
+ if (FcPatternGetString(pattern, FC_FILE, 0, &filename) == FcResultMatch && filename) {
103
102
  ttf_ptr = Gosu::ttf_data_from_file(reinterpret_cast<char*>(filename));
104
103
  }
105
104
  }
@@ -108,24 +107,32 @@ static const unsigned char* ttf_data_of_default_sans_serif_font()
108
107
  return ttf_ptr;
109
108
  }
110
109
 
111
- const unsigned char* Gosu::ttf_fallback_data()
110
+ const std::uint8_t* Gosu::ttf_fallback_data()
112
111
  {
113
112
  // Prefer Arial Unicode MS as a fallback because it covers a lot of Unicode in a single file.
114
113
  // This is also the fallback font on Windows and macOS.
115
- static const unsigned char* arial_unicode = ttf_data_by_name("Arial Unicode MS", 0);
116
- if (arial_unicode) return arial_unicode;
114
+ static const std::uint8_t* arial_unicode = ttf_data_by_name("Arial Unicode MS", 0);
115
+ if (arial_unicode) {
116
+ return arial_unicode;
117
+ }
117
118
 
118
119
  // DejaVu has at least some Unicode coverage (though no CJK).
119
- static const unsigned char* deja_vu = ttf_data_by_name("DejaVu", 0);
120
- if (deja_vu) return deja_vu;
120
+ static const std::uint8_t* deja_vu = ttf_data_by_name("DejaVu", 0);
121
+ if (deja_vu) {
122
+ return deja_vu;
123
+ }
121
124
 
122
125
  // Unifont has pretty good Unicode coverage, but looks extremely ugly.
123
- static const unsigned char* unifont = ttf_data_by_name("Unifont", 0);
124
- if (unifont) return unifont;
126
+ static const std::uint8_t* unifont = ttf_data_by_name("Unifont", 0);
127
+ if (unifont) {
128
+ return unifont;
129
+ }
125
130
 
126
131
  // If none of the fonts above work, try to use the default sans-serif font.
127
- static const unsigned char* default_font = ttf_data_of_default_sans_serif_font();
128
- if (default_font) return default_font;
132
+ static const std::uint8_t* default_font = ttf_data_of_default_sans_serif_font();
133
+ if (default_font) {
134
+ return default_font;
135
+ }
129
136
 
130
137
  // If nothing else works, try to load a file from this hardcoded path.
131
138
  return ttf_data_from_file("/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf");
@@ -1,31 +1,30 @@
1
1
  #include <Gosu/Platform.hpp>
2
2
  #if defined(GOSU_IS_WIN)
3
3
 
4
- #include "Log.hpp"
5
4
  #include "TrueTypeFont.hpp"
6
5
 
7
- #define _WIN32_WINNT 0x0500
8
- #include <Gosu/IO.hpp>
6
+ #include <Gosu/Buffer.hpp>
9
7
  #include <Gosu/Text.hpp>
10
8
  #include <Gosu/Utility.hpp>
11
- #include "WinUtility.hpp"
12
9
  #include <cstdlib>
13
10
  #include <cwchar>
14
11
  #include <map>
15
12
  #include <memory>
13
+ #include <mutex>
16
14
  #include <windows.h>
17
15
 
18
- const unsigned char* Gosu::ttf_data_by_name(const std::string& font_name, unsigned font_flags)
16
+ const std::uint8_t* Gosu::ttf_data_by_name(const std::string& font_name, unsigned font_flags)
19
17
  {
20
- // TODO: Make this cache thread-safe.
21
18
  static std::map<std::pair<std::string, unsigned>, std::shared_ptr<Buffer>> ttf_file_cache;
19
+ static std::recursive_mutex mutex;
20
+ std::scoped_lock lock(mutex);
22
21
 
23
22
  auto& buffer_ptr = ttf_file_cache[make_pair(font_name, font_flags)];
24
- if (buffer_ptr) return static_cast<const unsigned char*>(buffer_ptr->data());
25
-
26
- log("Trying to find a font named '%s', flags=%x", font_name.c_str(), font_flags);
23
+ if (buffer_ptr) {
24
+ return static_cast<const std::uint8_t*>(buffer_ptr->data());
25
+ }
27
26
 
28
- LOGFONT logfont = {0,
27
+ LOGFONTW logfont { 0,
29
28
  0,
30
29
  0,
31
30
  0,
@@ -37,51 +36,52 @@ const unsigned char* Gosu::ttf_data_by_name(const std::string& font_name, unsign
37
36
  OUT_OUTLINE_PRECIS,
38
37
  CLIP_DEFAULT_PRECIS,
39
38
  ANTIALIASED_QUALITY,
40
- DEFAULT_PITCH};
39
+ DEFAULT_PITCH };
41
40
 
42
41
  std::wstring wfont_name = utf8_to_utf16(font_name);
43
42
  std::wcsncpy(logfont.lfFaceName, wfont_name.c_str(), LF_FACESIZE);
44
43
  logfont.lfFaceName[LF_FACESIZE - 1] = 0;
45
44
 
46
- if (HFONT font = CreateFontIndirect(&logfont)) {
45
+ if (HFONT font = CreateFontIndirectW(&logfont)) {
47
46
  if (HDC hdc = GetDC(0)) {
48
- HFONT last_font = (HFONT) SelectObject(hdc, (HGDIOBJ) font);
47
+ HFONT last_font = (HFONT)SelectObject(hdc, (HGDIOBJ)font);
49
48
  auto ttf_buffer_size = GetFontData(hdc, 0, 0, nullptr, 0);
50
49
  if (ttf_buffer_size != GDI_ERROR) {
51
- auto buffer = std::make_shared<Gosu::Buffer>();
52
- buffer->resize(ttf_buffer_size);
50
+ auto buffer = std::make_shared<Gosu::Buffer>(ttf_buffer_size);
53
51
  if (GetFontData(hdc, 0, 0, buffer->data(), buffer->size()) != GDI_ERROR) {
54
- auto data = static_cast<const unsigned char*>(buffer->data());
55
- if (font_name.empty() || TrueTypeFont::matches(data, font_name, font_flags)) {
52
+ if (font_name.empty()
53
+ || TrueTypeFont::matches(buffer->data(), font_name, font_flags)) {
56
54
  buffer_ptr = buffer;
57
- log("Found a matching file (%d bytes)", (int) buffer->size());
58
- }
59
- else {
60
- log("Internal font name did not match; discarding result");
61
55
  }
62
56
  }
63
57
  }
64
- SelectObject(hdc, (HGDIOBJ) last_font);
58
+ SelectObject(hdc, (HGDIOBJ)last_font);
65
59
  ReleaseDC(0, hdc);
66
60
  }
67
- DeleteObject((HGDIOBJ) font);
61
+ DeleteObject((HGDIOBJ)font);
68
62
  }
69
63
 
70
- return buffer_ptr ? static_cast<const unsigned char*>(buffer_ptr->data()) : nullptr;
64
+ return buffer_ptr ? buffer_ptr->data() : nullptr;
71
65
  }
72
66
 
73
- const unsigned char* Gosu::ttf_fallback_data()
67
+ const std::uint8_t* Gosu::ttf_fallback_data()
74
68
  {
75
69
  // Prefer Arial Unicode MS as a fallback because it covers a lot of Unicode.
76
- static const unsigned char* arial_unicode = ttf_data_by_name("Arial Unicode MS", 0);
77
- if (arial_unicode) return arial_unicode;
70
+ static const std::uint8_t* arial_unicode = ttf_data_by_name("Arial Unicode MS", 0);
71
+ if (arial_unicode) {
72
+ return arial_unicode;
73
+ }
78
74
 
79
75
  // Otherwise, just try to find *any* font.
80
- static const unsigned char* any_font = ttf_data_by_name("", 0);
81
- if (any_font) return any_font;
76
+ static const std::uint8_t* any_font = ttf_data_by_name("", 0);
77
+ if (any_font) {
78
+ return any_font;
79
+ }
82
80
 
83
81
  static const char* windir = std::getenv("WINDIR");
84
- if (windir) return ttf_data_from_file(std::string(windir) + "/Fonts/arial.ttf");
82
+ if (windir) {
83
+ return ttf_data_from_file(std::string(windir) + "/Fonts/arial.ttf");
84
+ }
85
85
 
86
86
  return ttf_data_from_file("C:/Windows/Fonts/arial.ttf");
87
87
  }
data/src/Utility.cpp CHANGED
@@ -1,25 +1,54 @@
1
1
  #include <Gosu/Platform.hpp>
2
2
  #include <Gosu/Utility.hpp>
3
-
4
- #include <utf8proc.h>
5
-
6
- #include <cstring>
7
3
  #include <memory>
8
4
  #include <stdexcept>
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
+ }
9
17
 
10
- std::u32string Gosu::utf8_to_composed_utc4(const std::string& utf8)
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
+
39
+ std::u32string Gosu::utf8_to_composed_utc4(std::string_view utf8)
11
40
  {
12
41
  std::u32string utc4;
13
42
  utc4.reserve(utf8.size());
14
43
 
15
44
  const auto* current_byte = reinterpret_cast<const utf8proc_uint8_t*>(utf8.data());
16
- auto remaining_length = utf8.length();
45
+ auto remaining_length = static_cast<utf8proc_ssize_t>(utf8.length());
17
46
 
18
47
  // First convert from UTF-8 to UTC-4.
19
48
  utf8proc_int32_t codepoint;
20
49
  while (remaining_length) {
21
50
  auto bytes_read = utf8proc_iterate(current_byte, remaining_length, &codepoint);
22
- if (bytes_read == -1) {
51
+ if (bytes_read < 0) {
23
52
  // Not looking good, skip this byte and retry.
24
53
  current_byte += 1;
25
54
  remaining_length -= 1;
@@ -33,12 +62,15 @@ std::u32string Gosu::utf8_to_composed_utc4(const std::string& utf8)
33
62
 
34
63
  // Now compose characters in-place.
35
64
  auto* utc4_data = reinterpret_cast<utf8proc_int32_t*>(utc4.data());
65
+ auto utc4_length = static_cast<utf8proc_ssize_t>(utc4.length());
36
66
  auto options = static_cast<utf8proc_option_t>(UTF8PROC_NLF2LF | UTF8PROC_COMPOSE);
37
- auto new_length = utf8proc_normalize_utf32(utc4_data, utc4.length(), options);
67
+ auto new_length = utf8proc_normalize_utf32(utc4_data, utc4_length, options);
68
+ // GCOV_EXCL_START: No code path in utf8proc_normalize_utf32 currently returns an error.
38
69
  if (new_length < 0) {
39
- throw std::runtime_error{"Could not normalize '" + utf8 +
40
- "': " + utf8proc_errmsg(new_length)};
70
+ throw std::runtime_error("Could not normalize '" + std::string(utf8)
71
+ + "': " + utf8proc_errmsg(new_length));
41
72
  }
73
+ // GCOV_EXCL_END
42
74
  utc4.resize(new_length);
43
75
 
44
76
  return utc4;
@@ -46,8 +78,13 @@ std::u32string Gosu::utf8_to_composed_utc4(const std::string& utf8)
46
78
 
47
79
  bool Gosu::has_extension(std::string_view filename, std::string_view extension)
48
80
  {
81
+ /// To avoid extra code paths later, we cut off all leading dots.
82
+ if (extension.starts_with('.')) {
83
+ extension.remove_prefix(1);
84
+ }
85
+
49
86
  std::size_t ext_len = extension.length();
50
- if (ext_len > filename.length()) {
87
+ if (ext_len >= filename.length()) {
51
88
  return false;
52
89
  }
53
90
 
@@ -57,13 +94,14 @@ bool Gosu::has_extension(std::string_view filename, std::string_view extension)
57
94
  --filename_iter;
58
95
  --ext_iter;
59
96
 
60
- if (std::tolower(static_cast<int>(*filename_iter)) !=
61
- std::tolower(static_cast<int>(*ext_iter))) {
97
+ if (std::tolower(static_cast<int>(*filename_iter))
98
+ != std::tolower(static_cast<int>(*ext_iter))) {
62
99
  return false;
63
100
  }
64
101
  }
65
-
66
- return true;
102
+ // We have verified the part after the dot, now make sure that the preceding character is a dot.
103
+ --filename_iter;
104
+ return *filename_iter == '.';
67
105
  }
68
106
 
69
107
  #ifdef GOSU_IS_IPHONE
@@ -72,7 +110,7 @@ bool Gosu::has_extension(std::string_view filename, std::string_view extension)
72
110
 
73
111
  std::vector<std::string> Gosu::user_languages()
74
112
  {
75
- static const std::regex language_regex{"([a-z]{2})-([A-Z]{2})([^A-Z].*)?"};
113
+ static const std::regex language_regex("([a-z]{2})-([A-Z]{2})([^A-Z].*)?");
76
114
 
77
115
  std::vector<std::string> user_languages;
78
116
 
@@ -90,45 +128,83 @@ std::vector<std::string> Gosu::user_languages()
90
128
  }
91
129
 
92
130
  #else
93
- #include <SDL.h>
94
- #if SDL_VERSION_ATLEAST(2, 0, 14)
95
-
131
+ #include <SDL3/SDL.h>
96
132
  std::vector<std::string> Gosu::user_languages()
97
133
  {
98
134
  std::vector<std::string> user_languages;
99
135
 
100
- std::unique_ptr<SDL_Locale, decltype(SDL_free)*> locales{SDL_GetPreferredLocales(), SDL_free};
101
- if (!locales) return user_languages;
136
+ int locale_count = 0;
137
+ std::unique_ptr<SDL_Locale*[], decltype(&SDL_free)> locales(
138
+ SDL_GetPreferredLocales(&locale_count), SDL_free);
139
+ // GCOV_EXCL_START: There is no portable way to let SDL_GetPreferredLocales fail.
140
+ if (!locales) {
141
+ return user_languages;
142
+ }
143
+ // GCOV_EXCL_END
102
144
 
103
- for (const SDL_Locale* locale = locales.get(); locale->language != nullptr; ++locale) {
145
+ for (int i = 0; i < locale_count; ++i) {
146
+ const SDL_Locale* locale = locales[i];
104
147
  std::string language = locale->language;
105
148
  if (locale->country) {
106
- language += "_";
149
+ language += '_';
107
150
  language += locale->country;
108
151
  }
109
- user_languages.emplace_back(std::move(language));
152
+ user_languages.push_back(std::move(language));
110
153
  }
111
154
 
112
155
  return user_languages;
113
156
  }
157
+ #endif
114
158
 
115
- #else
116
- #include <cstdlib>
117
- #include <regex>
159
+ bool Gosu::Rect::overlaps(const Rect& other) const
160
+ {
161
+ return x < other.right() && other.x < right() && y < other.bottom() && other.y < bottom();
162
+ }
118
163
 
119
- std::vector<std::string> Gosu::user_languages()
164
+ bool Gosu::Rect::contains(const Rect& other) const
120
165
  {
121
- static const std::regex language_regex{"[a-z]{2}_[A-Z]{2}([^A-Z].*)?"};
166
+ return x <= other.x && other.right() <= right() && y <= other.y && other.bottom() <= bottom();
167
+ }
122
168
 
123
- const char* locale = std::getenv("LANG");
169
+ void Gosu::Rect::clip_to(const Rect& bounding_box, int* adjust_x, int* adjust_y)
170
+ {
171
+ // Cut off the area on the left that exceeds the bounding box, if any.
172
+ const int extra_pixels_left = bounding_box.x - x;
173
+ if (extra_pixels_left > 0) {
174
+ x += extra_pixels_left;
175
+ width -= extra_pixels_left;
176
+ if (adjust_x) {
177
+ *adjust_x += extra_pixels_left;
178
+ }
179
+ }
124
180
 
125
- if (locale && std::regex_match(locale, language_regex)) {
126
- // Trim off anything after the language code.
127
- return {std::string{locale, locale + 5}};
181
+ // Cut off the area on the right that exceeds the bounding box, if any.
182
+ const int extra_pixels_right = right() - bounding_box.right();
183
+ if (extra_pixels_right > 0) {
184
+ width -= extra_pixels_right;
128
185
  }
129
186
 
130
- return {};
131
- }
187
+ // Cut off the area at the top that exceeds the bounding box, if any.
188
+ const int extra_pixels_top = bounding_box.y - y;
189
+ if (extra_pixels_top > 0) {
190
+ y += extra_pixels_top;
191
+ height -= extra_pixels_top;
192
+ if (adjust_y) {
193
+ *adjust_y += extra_pixels_top;
194
+ }
195
+ }
132
196
 
133
- #endif
134
- #endif
197
+ // Cut off the area at the bottom that exceeds the bounding box, if any.
198
+ const int extra_pixels_bottom = bottom() - bounding_box.bottom();
199
+ if (extra_pixels_bottom > 0) {
200
+ height -= extra_pixels_bottom;
201
+ }
202
+
203
+ // Leave 0 instead of negative values for width/height when the rect was clipped away.
204
+ if (width < 0) {
205
+ width = 0;
206
+ }
207
+ if (height < 0) {
208
+ height = 0;
209
+ }
210
+ }