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/Macro.cpp CHANGED
@@ -2,7 +2,6 @@
2
2
  #include <Gosu/Image.hpp>
3
3
  #include <Gosu/Utility.hpp>
4
4
  #include "DrawOpQueue.hpp"
5
- #include <optional>
6
5
  #include <stdexcept>
7
6
 
8
7
  struct Gosu::Macro::Impl : private Gosu::Noncopyable
@@ -18,16 +17,14 @@ struct Gosu::Macro::Impl : private Gosu::Noncopyable
18
17
  double b1, double b2, double& x1, double& x2)
19
18
  {
20
19
  const double det = a11 * a22 - a21 * a12;
21
- if (det == 0) {
22
- return false;
23
- }
20
+ if (det == 0) return false;
24
21
  x1 = (a22 * b1 - a12 * b2) / det;
25
22
  x2 = (a11 * b2 - a21 * b1) / det;
26
23
  return true;
27
24
  }
28
25
 
29
- std::optional<Transform> find_transform(double x1, double y1, double x2, double y2, //
30
- double x3, double y3, double x4, double y4) const
26
+ Transform find_transform_for_target(double x1, double y1, double x2, double y2, //
27
+ double x3, double y3, double x4, double y4) const
31
28
  {
32
29
  // Transformation logic follows a discussion on the ImageMagick mailing
33
30
  // list (on which ImageMagick's perspective_transform.pl is based).
@@ -67,9 +64,7 @@ struct Gosu::Macro::Impl : private Gosu::Noncopyable
67
64
 
68
65
  // Solve:
69
66
  double qx, qy;
70
- if (!solve_2x2(a11, a12, a21, a22, b1, b2, qx, qy)) {
71
- return std::nullopt;
72
- }
67
+ if (!solve_2x2(a11, a12, a21, a22, b1, b2, qx, qy)) return Transform{{0}};
73
68
 
74
69
  // Updating the last two rows with the computed solution yields
75
70
 
@@ -93,7 +88,7 @@ struct Gosu::Macro::Impl : private Gosu::Noncopyable
93
88
  // 0, 0, 0, 0, 0, 0, 1, 0 | qx
94
89
  // 0, 0, 0, 0, 0, 0, 0, 1 | qy
95
90
 
96
- // Normalize and reorder rows, so we can read off the solution:
91
+ // Normalize and reorder rows so we can read off the solution:
97
92
 
98
93
  // 1, 0, 0, 0, 0, 0, 0, 0 | (x2-x1) / w + qx x2
99
94
  // 0, 1, 0, 0, 0, 0, 0, 0 | (x3-x1) / h + qy x3
@@ -114,10 +109,10 @@ struct Gosu::Macro::Impl : private Gosu::Noncopyable
114
109
  c[6] = qx;
115
110
  c[7] = qy;
116
111
 
117
- Transform result = { { c[0], c[3], 0, c[6], //
118
- c[1], c[4], 0, c[7], //
119
- 0, 0, 1, 0, //
120
- c[2], c[5], 0, 1 } };
112
+ Transform result = {{c[0], c[3], 0, c[6], //
113
+ c[1], c[4], 0, c[7], //
114
+ 0, 0, 1, 0, //
115
+ c[2], c[5], 0, 1}};
121
116
  return result;
122
117
  }
123
118
 
@@ -129,35 +124,29 @@ struct Gosu::Macro::Impl : private Gosu::Noncopyable
129
124
  // transformation only has to be performed once.
130
125
 
131
126
  #ifndef GOSU_IS_OPENGLES
132
- const std::optional<Transform> transform
133
- = find_transform(x1, y1, x2, y2, x3, y3, x4, y4);
134
- if (!transform.has_value()) {
135
- return;
136
- }
137
-
138
127
  glEnable(GL_BLEND);
139
128
  glMatrixMode(GL_MODELVIEW);
140
129
 
130
+ Transform transform = find_transform_for_target(x1, y1, x2, y2, x3, y3, x4, y4);
131
+
141
132
  for (const auto& vertex_array : vertex_arrays) {
142
133
  glPushMatrix();
143
- const auto pop_matrix = finally([] { glPopMatrix(); });
144
-
145
134
  vertex_array.render_state.apply();
146
- glMultMatrixd(transform->matrix.data());
147
- glInterleavedArrays(GL_T2F_C4UB_V3F, 0, vertex_array.vertices.data());
148
- glDrawArrays(GL_QUADS, 0, (GLsizei)vertex_array.vertices.size());
135
+ glMultMatrixd(transform.matrix.data());
136
+ glInterleavedArrays(GL_T2F_C4UB_V3F, 0, &vertex_array.vertices[0]);
137
+ glDrawArrays(GL_QUADS, 0, (GLsizei) vertex_array.vertices.size());
138
+ glPopMatrix();
149
139
  }
150
140
  #endif
151
141
  }
152
142
  };
153
143
 
154
144
  Gosu::Macro::Macro(DrawOpQueue& queue, int width, int height)
145
+ : pimpl(new Impl)
155
146
  {
156
- auto impl = std::make_shared<Impl>();
157
- impl->width = width;
158
- impl->height = height;
159
- queue.compile_to(impl->vertex_arrays);
160
- pimpl = std::move(impl);
147
+ pimpl->width = width;
148
+ pimpl->height = height;
149
+ queue.compile_to(pimpl->vertex_arrays);
161
150
  }
162
151
 
163
152
  int Gosu::Macro::width() const
@@ -172,17 +161,15 @@ int Gosu::Macro::height() const
172
161
 
173
162
  void Gosu::Macro::draw(double x1, double y1, Color c1, double x2, double y2, Color c2, //
174
163
  double x3, double y3, Color c3, double x4, double y4, Color c4, //
175
- ZPos z, BlendMode) const
164
+ ZPos z, BlendMode mode) const
176
165
  {
177
166
  if (c1 != Color::WHITE || c2 != Color::WHITE || c3 != Color::WHITE || c4 != Color::WHITE) {
178
- throw std::invalid_argument("Macros cannot be tinted with colors");
167
+ throw std::invalid_argument{"Macros cannot be tinted with colors"};
179
168
  }
180
169
 
181
170
  normalize_coordinates(x1, y1, x2, y2, x3, y3, c3, x4, y4, c4);
182
171
 
183
- // Capture pimpl, not this: The GL block only runs when the queue is flushed, and this Macro
184
- // may have been destroyed by then.
185
- gl(z, [=, impl = pimpl] { impl->draw_vertex_arrays(x1, y1, x2, y2, x3, y3, x4, y4); });
172
+ Gosu::gl(z, [=, this] { pimpl->draw_vertex_arrays(x1, y1, x2, y2, x3, y3, x4, y4); });
186
173
  }
187
174
 
188
175
  const Gosu::GLTexInfo* Gosu::Macro::gl_tex_info() const
@@ -192,16 +179,12 @@ const Gosu::GLTexInfo* Gosu::Macro::gl_tex_info() const
192
179
 
193
180
  Gosu::Bitmap Gosu::Macro::to_bitmap() const
194
181
  {
195
- Viewport viewport(pimpl->width, pimpl->height);
196
- const auto current = viewport.make_current();
197
-
198
182
  const auto render_this = [this] {
199
- draw(0, 0, Color::WHITE, pimpl->width, 0, Color::WHITE, //
200
- 0, pimpl->height, Color::WHITE, pimpl->width, pimpl->height, Color::WHITE, //
201
- 0, BM_DEFAULT);
183
+ draw(0, 0, Color::WHITE, pimpl->width, 0, Color::WHITE, 0, pimpl->height, Color::WHITE,
184
+ pimpl->width, pimpl->height, Color::WHITE, 0, BM_DEFAULT);
202
185
  };
203
186
 
204
- return render(pimpl->width, pimpl->height, render_this).drawable().to_bitmap();
187
+ return Gosu::render(pimpl->width, pimpl->height, render_this).drawable().to_bitmap();
205
188
  }
206
189
 
207
190
  std::unique_ptr<Gosu::Drawable> Gosu::Macro::subimage(const Rect&) const
@@ -211,5 +194,5 @@ std::unique_ptr<Gosu::Drawable> Gosu::Macro::subimage(const Rect&) const
211
194
 
212
195
  void Gosu::Macro::insert(const Bitmap&, int, int)
213
196
  {
214
- throw std::logic_error("Gosu::Macro cannot be updated with a Gosu::Bitmap yet");
197
+ throw std::logic_error{"Gosu::Macro cannot be updated with a Gosu::Bitmap yet"};
215
198
  }
data/src/Macro.hpp CHANGED
@@ -2,35 +2,29 @@
2
2
 
3
3
  #include <Gosu/Fwd.hpp>
4
4
  #include <Gosu/Drawable.hpp>
5
+ #include "GraphicsImpl.hpp"
5
6
  #include <memory>
6
7
 
7
- namespace Gosu
8
+ class Gosu::Macro : public Gosu::Drawable
8
9
  {
9
- class DrawOpQueue;
10
+ struct Impl;
11
+ std::shared_ptr<Impl> pimpl;
10
12
 
11
- class Macro : public Drawable
12
- {
13
- // This is a shared_ptr so that enqueued DrawOps can keep the macro data alive even after
14
- // the Macro object itself has been destroyed.
15
- struct Impl;
16
- std::shared_ptr<const Impl> pimpl;
13
+ public:
14
+ Macro(DrawOpQueue& queue, int width, int height);
17
15
 
18
- public:
19
- Macro(DrawOpQueue& queue, int width, int height);
16
+ int width() const override;
17
+ int height() const override;
20
18
 
21
- int width() const override;
22
- int height() const override;
19
+ void draw(double x1, double y1, Color c1, double x2, double y2, Color c2, //
20
+ double x3, double y3, Color c3, double x4, double y4, Color c4, //
21
+ ZPos z, BlendMode mode) const override;
23
22
 
24
- void draw(double x1, double y1, Color c1, double x2, double y2, Color c2, //
25
- double x3, double y3, Color c3, double x4, double y4, Color c4, //
26
- ZPos z, BlendMode mode) const override;
23
+ const Gosu::GLTexInfo* gl_tex_info() const override;
27
24
 
28
- const GLTexInfo* gl_tex_info() const override;
25
+ Gosu::Bitmap to_bitmap() const override;
29
26
 
30
- Bitmap to_bitmap() const override;
27
+ std::unique_ptr<Drawable> subimage(const Rect&) const override;
31
28
 
32
- std::unique_ptr<Drawable> subimage(const Rect&) const override;
33
-
34
- void insert(const Bitmap&, int x, int y) override;
35
- };
36
- }
29
+ void insert(const Bitmap&, int x, int y) override;
30
+ };
data/src/Math.cpp CHANGED
@@ -1,23 +1,21 @@
1
1
  #include <Gosu/Math.hpp>
2
- #include <algorithm>
3
2
  #include <cmath>
4
3
  #include <limits> // for std::numeric_limits::quiet_NaN
5
4
  #include <random>
6
- #include <stdexcept>
7
5
 
8
6
  double Gosu::random(double min, double max)
9
7
  {
10
- if (!std::isfinite(min) || !std::isfinite(max)) {
8
+ if (std::isnan(min) || std::isnan(max)) {
11
9
  return std::numeric_limits<double>::quiet_NaN();
12
10
  }
13
- if (min >= max) {
14
- throw std::invalid_argument("Gosu::random: min >= max");
11
+
12
+ if (min == max) {
13
+ return min;
15
14
  }
16
15
 
17
- thread_local std::mt19937_64 generator(std::random_device { }());
16
+ thread_local std::mt19937_64 generator(std::random_device {}());
18
17
  std::uniform_real_distribution<double> distribution(min, max);
19
18
  const double result = distribution(generator);
20
-
21
19
  // Make sure that we do not return "max" even when uniform_real_distribution is buggy.
22
20
  // See "Notes": https://en.cppreference.com/w/cpp/numeric/random/uniform_real_distribution
23
21
  return result == max ? min : result;
@@ -25,12 +23,12 @@ double Gosu::random(double min, double max)
25
23
 
26
24
  double Gosu::offset_x(double angle, double radius)
27
25
  {
28
- return +std::sin(degrees_to_radians(angle)) * radius;
26
+ return +std::sin(angle / 180 * std::numbers::pi) * radius;
29
27
  }
30
28
 
31
29
  double Gosu::offset_y(double angle, double radius)
32
30
  {
33
- return -std::cos(degrees_to_radians(angle)) * radius;
31
+ return -std::cos(angle / 180 * std::numbers::pi) * radius;
34
32
  }
35
33
 
36
34
  double Gosu::angle(double from_x, double from_y, double to_x, double to_y, double fallback)
@@ -66,23 +64,12 @@ double Gosu::normalize_angle(double angle)
66
64
 
67
65
  int Gosu::wrap(int value, int min, int max)
68
66
  {
69
- if (min >= max) {
70
- throw std::invalid_argument("Gosu::wrap: min >= max");
71
- }
72
-
73
67
  int result = (value - min) % (max - min);
74
68
  return result < 0 ? result + max : result + min;
75
69
  }
76
70
 
77
71
  double Gosu::wrap(double value, double min, double max)
78
72
  {
79
- if (!std::isfinite(value) || !std::isfinite(min) || !std::isfinite(max)) {
80
- return std::numeric_limits<double>::quiet_NaN();
81
- }
82
- if (min >= max) {
83
- throw std::invalid_argument("Gosu::wrap: min >= max");
84
- }
85
-
86
73
  double result = std::fmod(value - min, max - min);
87
74
  return result < 0 ? result + max : result + min;
88
75
  }
@@ -4,7 +4,7 @@
4
4
  #include "OpenGLContext.hpp"
5
5
  #include "Texture.hpp"
6
6
  #ifndef GOSU_IS_IPHONE
7
- #include <SDL3/SDL.h> // for SDL_GL_GetProcAddress
7
+ #include <SDL.h> // for SDL_GL_GetProcAddress
8
8
  #endif
9
9
 
10
10
  #ifdef GOSU_IS_OPENGLES
@@ -90,7 +90,14 @@ Gosu::Image Gosu::OffScreenTarget::render(const std::function<void ()>& f)
90
90
  throw std::runtime_error("Incomplete framebuffer");
91
91
  }
92
92
 
93
- auto reset_framebuffer = finally([] { glBindFramebuffer(GOSU_GL_CONST(GL_FRAMEBUFFER), 0); });
94
- f();
93
+ try {
94
+ f();
95
+
96
+ } catch (...) {
97
+ glBindFramebuffer(GOSU_GL_CONST(GL_FRAMEBUFFER), 0);
98
+ throw;
99
+ }
100
+ glBindFramebuffer(GOSU_GL_CONST(GL_FRAMEBUFFER), 0);
101
+
95
102
  return Image(std::make_unique<TexChunk>(m_texture, Rect::covering(*m_texture), nullptr));
96
103
  }
@@ -44,9 +44,8 @@ namespace
44
44
  #endif
45
45
 
46
46
  window = //
47
- SDL_CreateWindow("", 64, 64,
48
- SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN
49
- | SDL_WINDOW_HIGH_PIXEL_DENSITY);
47
+ SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 64, 64,
48
+ SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN | SDL_WINDOW_ALLOW_HIGHDPI);
50
49
  if (!window) {
51
50
  throw_sdl_error("Could not create SDL window");
52
51
  }
@@ -83,14 +82,16 @@ Gosu::OpenGLContext::OpenGLContext(bool for_rendering_to_window)
83
82
  // Explicitly make the context current every time for_rendering_to_window is set, so that we set
84
83
  // the current SDL_Window even if we are somehow nested into something else.
85
84
  if (for_rendering_to_window) {
86
- if (!SDL_GL_MakeCurrent(window.window, window.gl_context)) {
85
+ if (SDL_GL_MakeCurrent(window.window, window.gl_context) != 0) {
87
86
  throw_sdl_error("Could not set current GL context for rendering to the window");
88
87
  }
89
88
  }
90
89
  else if (current_nesting_depth == 0) {
91
- // On other platforms, make the context current together with its (hidden) window.
92
- // A context without a Window is broken under Linux with SDL3 (cannot find extensions).
93
- if (!SDL_GL_MakeCurrent(window.window, window.gl_context)) {
90
+ // Making a GL context current on a background thread, but with a window, causes a deadlock
91
+ // on macOS because SDL tries to use dispatch_sync onto the main thread.
92
+ // -> Try without a window first (for macOS), then with a window (for other platforms).
93
+ if (SDL_GL_MakeCurrent(nullptr, window.gl_context) != 0
94
+ && SDL_GL_MakeCurrent(window.window, window.gl_context) != 0) {
94
95
  throw_sdl_error("Could not set current GL context");
95
96
  }
96
97
  }
@@ -8,8 +8,8 @@
8
8
  #include <OpenGLES/ES1/gl.h>
9
9
  #include <OpenGLES/ES1/glext.h>
10
10
  #else
11
- #include <SDL3/SDL.h>
12
- #include <SDL3/SDL_opengl.h>
11
+ #include <SDL.h>
12
+ #include <SDL_opengl.h>
13
13
  #endif
14
14
 
15
15
  #include <mutex>
data/src/RenderState.hpp CHANGED
@@ -1,22 +1,32 @@
1
1
  #pragma once
2
2
 
3
3
  #include <Gosu/Transform.hpp>
4
- #include "ClipRectStack.hpp"
5
4
  #include "GraphicsImpl.hpp"
6
5
  #include "OpenGLContext.hpp"
7
6
  #include "Texture.hpp"
8
- #include <optional>
9
7
 
10
8
  // Properties that potentially need to be changed between each draw operation.
11
9
  // This does not include the color or vertex data of the actual quads.
12
10
  struct Gosu::RenderState
13
11
  {
14
12
  std::shared_ptr<Texture> texture;
15
- const Transform* transform = nullptr;
16
- std::optional<Rect> clip_rect;
17
- BlendMode mode = BM_DEFAULT;
13
+ const Transform* transform;
14
+ ClipRect clip_rect;
15
+ BlendMode mode;
18
16
 
19
- bool operator==(const RenderState&) const = default;
17
+ RenderState()
18
+ : transform(0), mode(BM_DEFAULT)
19
+ {
20
+ clip_rect.width = NO_CLIPPING;
21
+ }
22
+
23
+ bool operator==(const RenderState& rhs) const
24
+ {
25
+ return texture == rhs.texture &&
26
+ transform == rhs.transform &&
27
+ clip_rect == rhs.clip_rect &&
28
+ mode == rhs.mode;
29
+ }
20
30
 
21
31
  void apply_texture() const
22
32
  {
@@ -44,12 +54,12 @@ struct Gosu::RenderState
44
54
 
45
55
  void apply_clip_rect() const
46
56
  {
47
- if (clip_rect.has_value()) {
48
- glEnable(GL_SCISSOR_TEST);
49
- glScissor(clip_rect->x, clip_rect->y, clip_rect->width, clip_rect->height);
57
+ if (clip_rect.width == NO_CLIPPING) {
58
+ glDisable(GL_SCISSOR_TEST);
50
59
  }
51
60
  else {
52
- glDisable(GL_SCISSOR_TEST);
61
+ glEnable(GL_SCISSOR_TEST);
62
+ glScissor(clip_rect.x, clip_rect.y, clip_rect.width, clip_rect.height);
53
63
  }
54
64
  }
55
65
 
@@ -66,8 +76,12 @@ struct Gosu::RenderState
66
76
 
67
77
  // Manages the OpenGL rendering state. It caches the current state, only forwarding the
68
78
  // changes to OpenGL if the new state is really different.
69
- class Gosu::RenderStateManager : private Gosu::RenderState, private Gosu::Noncopyable
79
+ class Gosu::RenderStateManager : private Gosu::RenderState
70
80
  {
81
+ // Not copyable
82
+ RenderStateManager(const RenderStateManager&);
83
+ RenderStateManager& operator=(const RenderStateManager&);
84
+
71
85
  void apply_transform() const
72
86
  {
73
87
  glMatrixMode(GL_MODELVIEW);
@@ -96,8 +110,10 @@ public:
96
110
 
97
111
  ~RenderStateManager()
98
112
  {
99
- set_clip_rect(std::nullopt);
100
- set_texture(nullptr);
113
+ ClipRect no_clipping;
114
+ no_clipping.width = NO_CLIPPING;
115
+ set_clip_rect(no_clipping);
116
+ set_texture(std::shared_ptr<Texture>());
101
117
  // Return to previous MV matrix
102
118
  glMatrixMode(GL_MODELVIEW);
103
119
  glPopMatrix();
@@ -111,11 +127,9 @@ public:
111
127
  set_alpha_mode(rs.mode);
112
128
  }
113
129
 
114
- void set_texture(const std::shared_ptr<Texture>& new_texture)
130
+ void set_texture(std::shared_ptr<Texture> new_texture)
115
131
  {
116
- if (new_texture == texture) {
117
- return;
118
- }
132
+ if (new_texture == texture) return;
119
133
 
120
134
  if (new_texture) {
121
135
  if (!texture) {
@@ -132,36 +146,46 @@ public:
132
146
 
133
147
  void set_transform(const Transform* new_transform)
134
148
  {
135
- if (new_transform == transform) {
136
- return;
137
- }
149
+ if (new_transform == transform) return;
138
150
 
139
151
  transform = new_transform;
140
152
  apply_transform();
141
153
  }
142
154
 
143
- void set_clip_rect(const std::optional<Rect>& new_clip_rect)
155
+ void set_clip_rect(const ClipRect& new_clip_rect)
144
156
  {
145
- if (clip_rect == new_clip_rect) {
146
- return;
157
+ if (new_clip_rect.width == NO_CLIPPING) {
158
+ // Disable clipping
159
+ if (clip_rect.width != NO_CLIPPING) {
160
+ glDisable(GL_SCISSOR_TEST);
161
+ clip_rect.width = NO_CLIPPING;
162
+ }
163
+ }
164
+ else {
165
+ // Enable clipping if off
166
+ if (clip_rect.width == NO_CLIPPING) {
167
+ glEnable(GL_SCISSOR_TEST);
168
+ clip_rect = new_clip_rect;
169
+ glScissor(clip_rect.x, clip_rect.y, clip_rect.width, clip_rect.height);
170
+ }
171
+ // Adjust clipping if necessary
172
+ else if (!(clip_rect == new_clip_rect)) {
173
+ clip_rect = new_clip_rect;
174
+ glScissor(clip_rect.x, clip_rect.y, clip_rect.width, clip_rect.height);
175
+ }
147
176
  }
148
-
149
- clip_rect = new_clip_rect;
150
- apply_clip_rect();
151
177
  }
152
178
 
153
179
  void set_alpha_mode(BlendMode new_mode)
154
180
  {
155
- if (new_mode == mode) {
156
- return;
157
- }
181
+ if (new_mode == mode) return;
158
182
 
159
183
  mode = new_mode;
160
184
  apply_alpha_mode();
161
185
  }
162
186
 
163
187
  // The cached values may have been messed with. Reset them again.
164
- void enforce_after_untrusted_gl() const
188
+ void enforce_after_untrusted_gL() const
165
189
  {
166
190
  apply_texture();
167
191
  apply_transform();
data/src/Resolution.cpp CHANGED
@@ -3,9 +3,9 @@
3
3
 
4
4
  #include <Gosu/Window.hpp>
5
5
  #include "GraphicsImpl.hpp"
6
- #include <SDL3/SDL.h>
6
+ #include <SDL.h>
7
7
 
8
- static const SDL_DisplayMode& display_mode(const Gosu::Window* window)
8
+ static SDL_DisplayMode display_mode(const Gosu::Window* window)
9
9
  {
10
10
  static const struct VideoSubsystem : Gosu::Noncopyable
11
11
  {
@@ -13,13 +13,10 @@ static const SDL_DisplayMode& display_mode(const Gosu::Window* window)
13
13
  ~VideoSubsystem() { SDL_QuitSubSystem(SDL_INIT_VIDEO); };
14
14
  } subsystem;
15
15
 
16
- SDL_DisplayID index
17
- = window ? SDL_GetDisplayForWindow(window->sdl_window()) : SDL_GetPrimaryDisplay();
18
- const SDL_DisplayMode* result = SDL_GetDesktopDisplayMode(index);
19
- if (result == nullptr) {
20
- throw std::runtime_error("SDL_GetDesktopDisplayMode: " + std::string(SDL_GetError()));
21
- }
22
- return *result;
16
+ int index = window ? SDL_GetWindowDisplayIndex(window->sdl_window()) : 0;
17
+ SDL_DisplayMode result;
18
+ SDL_GetDesktopDisplayMode(index, &result);
19
+ return result;
23
20
  }
24
21
 
25
22
  int Gosu::screen_width(const Window* window)
@@ -37,43 +34,44 @@ int Gosu::screen_height(const Window* window)
37
34
 
38
35
  static SDL_Rect max_window_size(const Gosu::Window* window)
39
36
  {
40
- static const struct VideoSubsystem : Gosu::Noncopyable
41
- {
42
- VideoSubsystem() { SDL_InitSubSystem(SDL_INIT_VIDEO); };
43
- ~VideoSubsystem() { SDL_QuitSubSystem(SDL_INIT_VIDEO); };
44
- } subsystem;
45
-
46
37
  // The extra size that a window needs depends on its style.
47
38
  // This logic must be kept in sync with SDL_cocoawindow.m to be 100% accurate.
48
- NSUInteger style
49
- = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable;
50
-
51
- // SDL_GetDisplayUsableBounds gives the maximum size of a borderless window (the screen minus
52
- // the menu bar and dock).
53
- SDL_DisplayID display
54
- = window ? SDL_GetDisplayForWindow(window->sdl_window()) : SDL_GetPrimaryDisplay();
55
- SDL_Rect result;
56
- if (!SDL_GetDisplayUsableBounds(display, &result)) {
57
- throw std::runtime_error("SDL_GetDisplayUsableBounds: " + std::string(SDL_GetError()));
39
+ NSUInteger style;
40
+ if (window && window->borderless()) {
41
+ style = NSWindowStyleMaskBorderless;
42
+ }
43
+ else {
44
+ style = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable |
45
+ NSWindowStyleMaskMiniaturizable;
46
+ }
47
+ if (window && window->resizable()) {
48
+ style |= NSWindowStyleMaskResizable;
58
49
  }
59
50
 
60
- // Now subtract the decorations that a default-styled Cocoa window would add.
61
- NSRect content =
62
- [NSWindow contentRectForFrameRect:NSMakeRect(0, 0, result.w, result.h) styleMask:style];
63
- result.w = content.size.width;
64
- result.h = content.size.height;
51
+ auto index = window ? SDL_GetWindowDisplayIndex(window->sdl_window()) : 0;
52
+ NSRect screen_frame = NSScreen.screens[index].visibleFrame;
53
+ NSRect content_rect = [NSWindow contentRectForFrameRect:screen_frame styleMask:style];
54
+
55
+ SDL_Rect result;
56
+ result.x = 0;
57
+ result.y = 0;
58
+ result.w = content_rect.size.width;
59
+ result.h = content_rect.size.height;
65
60
  return result;
66
61
  }
67
62
  #endif
68
63
 
64
+ // TODO: Remove this implementation and remove ifdef for GOSU_IS_X once WIN_GetWindowBordersSize is patched
69
65
  #ifdef GOSU_IS_WIN
66
+ #include <SDL_syswm.h>
70
67
  #include <dwmapi.h>
71
68
  #include <windows.h>
69
+ #pragma comment(lib, "Dwmapi.lib")
72
70
 
73
71
  static SDL_Rect max_window_size(const Gosu::Window* window)
74
72
  {
75
- // Replicate SDL's WIN_GetWindowBordersSize implementation because the original includes the
76
- // size of the drop shadow, which doesn't make sense as they don't actually take up space.
73
+ // Replicate SDL's WIN_GetWindowBordersSize implementation (https://github.com/libsdl-org/SDL/blob/9f71a809e9bd6fbb5fa401a45c1537fc26abc1b4/src/video/windows/SDL_windowswindow.c#L514-L554)
74
+ // until it's patched to ignore the window drop shadow (window border is 1px but with drop shadow it's reported as 8px)
77
75
  // REF: https://github.com/libsdl-org/SDL/issues/3835
78
76
 
79
77
  static const struct VideoSubsystem : Gosu::Noncopyable
@@ -82,20 +80,15 @@ static SDL_Rect max_window_size(const Gosu::Window* window)
82
80
  ~VideoSubsystem() { SDL_QuitSubSystem(SDL_INIT_VIDEO); };
83
81
  } subsystem;
84
82
 
85
- SDL_DisplayID display
86
- = window ? SDL_GetDisplayForWindow(window->sdl_window()) : SDL_GetPrimaryDisplay();
83
+ int index = window ? SDL_GetWindowDisplayIndex(window->sdl_window()) : 0;
87
84
  SDL_Rect rect;
88
- if (!SDL_GetDisplayUsableBounds(display, &rect)) {
89
- throw std::runtime_error("SDL_GetDisplayUsableBounds: " + std::string(SDL_GetError()));
90
- }
85
+ SDL_GetDisplayUsableBounds(index, &rect);
91
86
 
92
- // Note: We only subtract the window border when a window is given - but the main use case of
93
- // available_width/available_height is to determine the available space for a new window!
94
- // TODO: Replace DWM with a better API (AdjustWindowRectExForDpi?)
95
87
  if (window) {
96
- HWND hwnd = static_cast<HWND>(
97
- SDL_GetPointerProperty(SDL_GetWindowProperties(window->sdl_window()),
98
- SDL_PROP_WINDOW_WIN32_HWND_POINTER, nullptr));
88
+ SDL_SysWMinfo info;
89
+ SDL_VERSION(&info.version);
90
+ SDL_GetWindowWMInfo(window->sdl_window(), &info);
91
+ HWND hwnd = info.info.win.window;
99
92
 
100
93
  RECT rcClient, rcWindow;
101
94
  POINT ptDiff;
@@ -152,12 +145,9 @@ static SDL_Rect max_window_size(const Gosu::Window* window)
152
145
  ~VideoSubsystem() { SDL_QuitSubSystem(SDL_INIT_VIDEO); };
153
146
  } subsystem;
154
147
 
155
- SDL_DisplayID index
156
- = window ? SDL_GetDisplayForWindow(window->sdl_window()) : SDL_GetPrimaryDisplay();
148
+ int index = window ? SDL_GetWindowDisplayIndex(window->sdl_window()) : 0;
157
149
  SDL_Rect rect;
158
- if (!SDL_GetDisplayUsableBounds(index, &rect)) {
159
- throw std::runtime_error("SDL_GetDisplayUsableBounds: " + std::string(SDL_GetError()));
160
- }
150
+ SDL_GetDisplayUsableBounds(index, &rect);
161
151
 
162
152
  if (window) {
163
153
  int top, left, bottom, right;
data/src/TexChunk.cpp CHANGED
@@ -59,7 +59,7 @@ std::unique_ptr<Gosu::Drawable> Gosu::TexChunk::subimage(const Rect& rect) const
59
59
  if (!Rect::covering(*this).contains(rect)) {
60
60
  throw std::invalid_argument("Gosu::TexChunk::subimage cannot exceed parent size");
61
61
  }
62
- Rect nested_rect = Rect::xywh(m_rect.x + rect.x, m_rect.y + rect.y, rect.width, rect.height);
62
+ const Rect nested_rect { m_rect.x + rect.x, m_rect.y + rect.y, rect.width, rect.height };
63
63
  return std::make_unique<TexChunk>(m_texture, nested_rect, m_rect_handle);
64
64
  }
65
65
 
@@ -73,7 +73,7 @@ void Gosu::TexChunk::insert(const Bitmap& bitmap, int x, int y)
73
73
  Bitmap clipped_bitmap;
74
74
  const Bitmap* source = &bitmap;
75
75
 
76
- Rect target_rect = Rect::xywh(x, y, bitmap.width(), bitmap.height());
76
+ Rect target_rect { x, y, bitmap.width(), bitmap.height() };
77
77
  int offset_x = 0, offset_y = 0;
78
78
  // If inserting the bitmap at the given position exceeds the boundaries of the space allocated
79
79
  // for this image on the texture, we need to clip the bitmap and insert the clipped version