gosu 1.1.1.1 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (219) hide show
  1. checksums.yaml +4 -4
  2. data/dependencies/SDL/include/SDL.h +108 -14
  3. data/dependencies/SDL/include/SDL_assert.h +81 -50
  4. data/dependencies/SDL/include/SDL_atomic.h +135 -35
  5. data/dependencies/SDL/include/SDL_audio.h +960 -355
  6. data/dependencies/SDL/include/SDL_bits.h +11 -6
  7. data/dependencies/SDL/include/SDL_blendmode.h +91 -14
  8. data/dependencies/SDL/include/SDL_clipboard.h +30 -7
  9. data/dependencies/SDL/include/SDL_config.h +277 -27
  10. data/dependencies/SDL/include/SDL_config_android.h +13 -38
  11. data/dependencies/SDL/include/SDL_config_iphoneos.h +21 -62
  12. data/dependencies/SDL/include/SDL_config_macosx.h +23 -92
  13. data/dependencies/SDL/include/SDL_config_minimal.h +1 -4
  14. data/dependencies/SDL/include/SDL_config_pandora.h +15 -22
  15. data/dependencies/SDL/include/SDL_config_psp.h +16 -37
  16. data/dependencies/SDL/include/SDL_config_windows.h +28 -91
  17. data/dependencies/SDL/include/SDL_config_winrt.h +33 -61
  18. data/dependencies/SDL/include/SDL_config_wiz.h +28 -56
  19. data/dependencies/SDL/include/SDL_copying.h +1 -1
  20. data/dependencies/SDL/include/SDL_cpuinfo.h +331 -71
  21. data/dependencies/SDL/include/SDL_egl.h +906 -280
  22. data/dependencies/SDL/include/SDL_endian.h +101 -47
  23. data/dependencies/SDL/include/SDL_error.h +70 -19
  24. data/dependencies/SDL/include/SDL_events.h +387 -79
  25. data/dependencies/SDL/include/SDL_filesystem.h +73 -64
  26. data/dependencies/SDL/include/SDL_gamecontroller.h +585 -125
  27. data/dependencies/SDL/include/SDL_gesture.h +36 -6
  28. data/dependencies/SDL/include/SDL_haptic.h +304 -210
  29. data/dependencies/SDL/include/SDL_hidapi.h +451 -0
  30. data/dependencies/SDL/include/SDL_hints.h +1286 -897
  31. data/dependencies/SDL/include/SDL_joystick.h +577 -130
  32. data/dependencies/SDL/include/SDL_keyboard.h +162 -63
  33. data/dependencies/SDL/include/SDL_keycode.h +7 -5
  34. data/dependencies/SDL/include/SDL_loadso.h +42 -8
  35. data/dependencies/SDL/include/SDL_locale.h +34 -32
  36. data/dependencies/SDL/include/SDL_log.h +212 -19
  37. data/dependencies/SDL/include/SDL_main.h +72 -17
  38. data/dependencies/SDL/include/SDL_messagebox.h +70 -23
  39. data/dependencies/SDL/include/SDL_metal.h +27 -32
  40. data/dependencies/SDL/include/SDL_misc.h +19 -15
  41. data/dependencies/SDL/include/SDL_mouse.h +262 -110
  42. data/dependencies/SDL/include/SDL_mutex.h +286 -66
  43. data/dependencies/SDL/include/SDL_name.h +1 -1
  44. data/dependencies/SDL/include/SDL_opengl.h +1 -1
  45. data/dependencies/SDL/include/SDL_opengles.h +1 -1
  46. data/dependencies/SDL/include/SDL_opengles2.h +2 -2
  47. data/dependencies/SDL/include/SDL_pixels.h +199 -34
  48. data/dependencies/SDL/include/SDL_platform.h +39 -2
  49. data/dependencies/SDL/include/SDL_power.h +23 -10
  50. data/dependencies/SDL/include/SDL_quit.h +1 -1
  51. data/dependencies/SDL/include/SDL_rect.h +78 -28
  52. data/dependencies/SDL/include/SDL_render.h +1204 -472
  53. data/dependencies/SDL/include/SDL_revision.h +2 -2
  54. data/dependencies/SDL/include/SDL_rwops.h +605 -33
  55. data/dependencies/SDL/include/SDL_scancode.h +1 -1
  56. data/dependencies/SDL/include/SDL_sensor.h +76 -42
  57. data/dependencies/SDL/include/SDL_shape.h +38 -27
  58. data/dependencies/SDL/include/SDL_stdinc.h +96 -24
  59. data/dependencies/SDL/include/SDL_surface.h +571 -139
  60. data/dependencies/SDL/include/SDL_system.h +339 -101
  61. data/dependencies/SDL/include/SDL_syswm.h +50 -20
  62. data/dependencies/SDL/include/SDL_test.h +1 -1
  63. data/dependencies/SDL/include/SDL_test_assert.h +2 -2
  64. data/dependencies/SDL/include/SDL_test_common.h +23 -6
  65. data/dependencies/SDL/include/SDL_test_compare.h +1 -1
  66. data/dependencies/SDL/include/SDL_test_crc32.h +1 -1
  67. data/dependencies/SDL/include/SDL_test_font.h +3 -3
  68. data/dependencies/SDL/include/SDL_test_fuzzer.h +28 -26
  69. data/dependencies/SDL/include/SDL_test_harness.h +6 -6
  70. data/dependencies/SDL/include/SDL_test_images.h +1 -1
  71. data/dependencies/SDL/include/SDL_test_log.h +1 -1
  72. data/dependencies/SDL/include/SDL_test_md5.h +1 -1
  73. data/dependencies/SDL/include/SDL_test_memory.h +1 -1
  74. data/dependencies/SDL/include/SDL_test_random.h +2 -2
  75. data/dependencies/SDL/include/SDL_thread.h +226 -128
  76. data/dependencies/SDL/include/SDL_timer.h +129 -22
  77. data/dependencies/SDL/include/SDL_touch.h +48 -8
  78. data/dependencies/SDL/include/SDL_types.h +1 -1
  79. data/dependencies/SDL/include/SDL_version.h +72 -46
  80. data/dependencies/SDL/include/SDL_video.h +1266 -460
  81. data/dependencies/SDL/include/SDL_vulkan.h +100 -161
  82. data/dependencies/SDL/include/begin_code.h +22 -1
  83. data/dependencies/SDL/include/close_code.h +1 -1
  84. data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
  85. data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
  86. data/dependencies/SDL_sound/SDL_sound.c +83 -7
  87. data/dependencies/SDL_sound/SDL_sound.h +4 -4
  88. data/dependencies/SDL_sound/SDL_sound_aiff.c +9 -12
  89. data/dependencies/SDL_sound/SDL_sound_au.c +7 -7
  90. data/dependencies/SDL_sound/SDL_sound_coreaudio.c +3 -3
  91. data/dependencies/SDL_sound/SDL_sound_flac.c +1 -1
  92. data/dependencies/SDL_sound/SDL_sound_internal.h +17 -10
  93. data/dependencies/SDL_sound/SDL_sound_modplug.c +25 -27
  94. data/dependencies/SDL_sound/SDL_sound_mp3.c +5 -17
  95. data/dependencies/SDL_sound/SDL_sound_raw.c +11 -11
  96. data/dependencies/SDL_sound/SDL_sound_shn.c +8 -7
  97. data/dependencies/SDL_sound/SDL_sound_voc.c +6 -4
  98. data/dependencies/SDL_sound/SDL_sound_vorbis.c +6 -11
  99. data/dependencies/SDL_sound/SDL_sound_wav.c +35 -29
  100. data/dependencies/SDL_sound/dr_flac.h +618 -220
  101. data/dependencies/SDL_sound/dr_mp3.h +263 -94
  102. data/dependencies/SDL_sound/libmodplug/fastmix.c +58 -64
  103. data/dependencies/SDL_sound/libmodplug/libmodplug.h +25 -103
  104. data/dependencies/SDL_sound/libmodplug/load_669.c +14 -17
  105. data/dependencies/SDL_sound/libmodplug/load_amf.c +11 -7
  106. data/dependencies/SDL_sound/libmodplug/load_ams.c +65 -22
  107. data/dependencies/SDL_sound/libmodplug/load_dbm.c +8 -4
  108. data/dependencies/SDL_sound/libmodplug/load_dmf.c +55 -25
  109. data/dependencies/SDL_sound/libmodplug/load_far.c +9 -13
  110. data/dependencies/SDL_sound/libmodplug/load_gdm.c +448 -0
  111. data/dependencies/SDL_sound/libmodplug/load_it.c +45 -49
  112. data/dependencies/SDL_sound/libmodplug/load_mdl.c +80 -53
  113. data/dependencies/SDL_sound/libmodplug/load_med.c +20 -12
  114. data/dependencies/SDL_sound/libmodplug/load_mod.c +40 -15
  115. data/dependencies/SDL_sound/libmodplug/load_mt2.c +29 -17
  116. data/dependencies/SDL_sound/libmodplug/load_okt.c +12 -8
  117. data/dependencies/SDL_sound/libmodplug/load_psm.c +101 -78
  118. data/dependencies/SDL_sound/libmodplug/load_ptm.c +18 -17
  119. data/dependencies/SDL_sound/libmodplug/load_s3m.c +9 -7
  120. data/dependencies/SDL_sound/libmodplug/load_stm.c +3 -2
  121. data/dependencies/SDL_sound/libmodplug/load_ult.c +2 -2
  122. data/dependencies/SDL_sound/libmodplug/load_umx.c +315 -35
  123. data/dependencies/SDL_sound/libmodplug/load_xm.c +25 -21
  124. data/dependencies/SDL_sound/libmodplug/mmcmp.c +295 -149
  125. data/dependencies/SDL_sound/libmodplug/modplug.c +7 -123
  126. data/dependencies/SDL_sound/libmodplug/modplug.h +32 -29
  127. data/dependencies/SDL_sound/libmodplug/snd_dsp.c +0 -1
  128. data/dependencies/SDL_sound/libmodplug/snd_flt.c +2 -2
  129. data/dependencies/SDL_sound/libmodplug/snd_fx.c +24 -18
  130. data/dependencies/SDL_sound/libmodplug/sndfile.c +55 -156
  131. data/dependencies/SDL_sound/libmodplug/sndmix.c +7 -12
  132. data/dependencies/SDL_sound/libmodplug/tables.h +10 -15
  133. data/dependencies/SDL_sound/stb_vorbis.h +508 -325
  134. data/dependencies/{al_soft → mojoAL}/AL/al.h +38 -30
  135. data/dependencies/{al_soft → mojoAL}/AL/alc.h +27 -56
  136. data/dependencies/mojoAL/mojoal.c +4594 -0
  137. data/ext/gosu/extconf.rb +29 -30
  138. data/include/Gosu/Audio.hpp +70 -85
  139. data/include/Gosu/Color.hpp +63 -107
  140. data/include/Gosu/Font.hpp +44 -48
  141. data/include/Gosu/Fwd.hpp +1 -1
  142. data/include/Gosu/Graphics.hpp +64 -75
  143. data/include/Gosu/GraphicsBase.hpp +32 -39
  144. data/include/Gosu/Image.hpp +56 -62
  145. data/include/Gosu/ImageData.hpp +23 -27
  146. data/include/Gosu/Inspection.hpp +1 -4
  147. data/include/Gosu/Math.hpp +4 -16
  148. data/include/Gosu/Platform.hpp +1 -51
  149. data/include/Gosu/Text.hpp +37 -40
  150. data/include/Gosu/TextInput.hpp +34 -40
  151. data/include/Gosu/Utility.hpp +10 -8
  152. data/include/Gosu/Version.hpp +1 -1
  153. data/include/Gosu/Window.hpp +73 -70
  154. data/lib/SDL2.dll +0 -0
  155. data/lib/gosu/compat.rb +28 -37
  156. data/lib/gosu/swig_patches.rb +31 -3
  157. data/lib/gosu.rb +2 -2
  158. data/lib64/SDL2.dll +0 -0
  159. data/rdoc/gosu.rb +9 -1
  160. data/src/Audio.cpp +88 -86
  161. data/src/AudioFile.hpp +6 -6
  162. data/src/AudioFileAudioToolbox.cpp +1 -1
  163. data/src/AudioFileSDLSound.cpp +1 -1
  164. data/src/AudioImpl.hpp +5 -5
  165. data/src/Bitmap.cpp +13 -13
  166. data/src/BitmapIO.cpp +0 -20
  167. data/src/BlockAllocator.cpp +2 -1
  168. data/src/Channel.cpp +22 -20
  169. data/src/Color.cpp +62 -55
  170. data/src/EmptyImageData.hpp +16 -18
  171. data/src/FileUnix.cpp +1 -1
  172. data/src/FileWin.cpp +1 -1
  173. data/src/Font.cpp +52 -57
  174. data/src/GosuViewController.cpp +2 -0
  175. data/src/Graphics.cpp +135 -143
  176. data/src/Image.cpp +42 -42
  177. data/src/Input.cpp +1 -1
  178. data/src/InputUIKit.cpp +1 -1
  179. data/src/LargeImageData.cpp +120 -113
  180. data/src/LargeImageData.hpp +18 -16
  181. data/src/Log.hpp +6 -6
  182. data/src/Macro.cpp +35 -37
  183. data/src/Macro.hpp +11 -11
  184. data/src/Math.cpp +8 -1
  185. data/src/RenderState.hpp +5 -5
  186. data/src/Resolution.cpp +12 -7
  187. data/src/RubyGosu.cxx +471 -502
  188. data/src/RubyGosu.h +3 -2
  189. data/src/TexChunk.cpp +50 -41
  190. data/src/TexChunk.hpp +22 -22
  191. data/src/Text.cpp +58 -59
  192. data/src/TextBuilder.cpp +60 -57
  193. data/src/TextBuilder.hpp +20 -20
  194. data/src/TextInput.cpp +127 -135
  195. data/src/TrueTypeFont.cpp +108 -108
  196. data/src/TrueTypeFont.hpp +39 -38
  197. data/src/TrueTypeFontApple.cpp +27 -23
  198. data/src/TrueTypeFontUnix.cpp +21 -26
  199. data/src/TrueTypeFontWin.cpp +30 -30
  200. data/src/Utility.cpp +82 -23
  201. data/src/WinUtility.hpp +2 -1
  202. data/src/Window.cpp +103 -86
  203. data/src/WindowUIKit.cpp +48 -51
  204. metadata +8 -20
  205. data/dependencies/SDL/include/SDL_config_os2.h +0 -188
  206. data/dependencies/SDL_sound/libmodplug/load_abc.c +0 -4725
  207. data/dependencies/SDL_sound/libmodplug/load_mid.c +0 -1405
  208. data/dependencies/SDL_sound/libmodplug/load_pat.c +0 -1143
  209. data/dependencies/SDL_sound/libmodplug/load_pat.h +0 -25
  210. data/dependencies/al_soft/AL/alext.h +0 -585
  211. data/dependencies/al_soft/AL/efx-creative.h +0 -3
  212. data/dependencies/al_soft/AL/efx-presets.h +0 -402
  213. data/dependencies/al_soft/AL/efx.h +0 -762
  214. data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
  215. data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
  216. data/lib/OpenAL32.dll +0 -0
  217. data/lib64/OpenAL32.dll +0 -0
  218. data/src/UtilityApple.cpp +0 -16
  219. data/src/UtilityWin.cpp +0 -17
data/src/Window.cpp CHANGED
@@ -2,16 +2,15 @@
2
2
  #if !defined(GOSU_IS_IPHONE)
3
3
 
4
4
  #if defined(GOSU_IS_WIN)
5
+ #define NOMINMAX
5
6
  #include <windows.h>
6
7
  #endif
7
8
 
8
9
  #include <Gosu/Gosu.hpp>
9
10
  #include "GraphicsImpl.hpp"
10
11
  #include <SDL.h>
11
- #include <cstdlib>
12
12
  #include <algorithm>
13
13
  #include <stdexcept>
14
- using namespace std;
15
14
 
16
15
  namespace Gosu
17
16
  {
@@ -20,14 +19,15 @@ namespace Gosu
20
19
  void register_frame();
21
20
  }
22
21
 
23
- static void throw_sdl_error(const string& operation)
22
+ [[noreturn]] static void throw_sdl_error(const std::string& operation)
24
23
  {
25
24
  const char* error = SDL_GetError();
26
- throw runtime_error(operation + ": " + (error ? error : "(unknown error)"));
25
+ throw std::runtime_error{operation + ": " + (error ? error : "(unknown error)")};
27
26
  }
28
27
 
29
28
  SDL_Window* shared_window()
30
29
  {
30
+ // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
31
31
  static SDL_Window* window = nullptr;
32
32
  if (window == nullptr) {
33
33
  if (SDL_Init(SDL_INIT_VIDEO) < 0) {
@@ -36,8 +36,8 @@ namespace Gosu
36
36
 
37
37
  Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN | SDL_WINDOW_ALLOW_HIGHDPI;
38
38
 
39
- window =
40
- SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 64, 64, flags);
39
+ window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 64, 64,
40
+ flags);
41
41
  if (window == nullptr) {
42
42
  throw_sdl_error("Could not create window");
43
43
  }
@@ -50,10 +50,10 @@ namespace Gosu
50
50
  {
51
51
  static SDL_GLContext context = nullptr;
52
52
  if (context == nullptr) {
53
- #ifdef GOSU_IS_OPENGLES
53
+ #ifdef GOSU_IS_OPENGLES
54
54
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
55
55
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
56
- #endif
56
+ #endif
57
57
 
58
58
  context = SDL_GL_CreateContext(shared_window());
59
59
 
@@ -64,36 +64,41 @@ namespace Gosu
64
64
  return context;
65
65
  }
66
66
 
67
- void ensure_current_context()
67
+ void ensure_current_context() //
68
68
  {
69
69
  SDL_GL_MakeCurrent(shared_window(), shared_gl_context());
70
70
  }
71
71
  }
72
72
 
73
- struct Gosu::Window::Impl
73
+ struct Gosu::Window::Impl : Gosu::Noncopyable
74
74
  {
75
- bool fullscreen;
76
- double update_interval;
77
- bool resizable;
75
+ bool fullscreen = false;
76
+ double update_interval = 0;
77
+ bool resizable = false;
78
78
  bool resizing = false;
79
79
 
80
80
  // A single `bool open` is not good enough to support the tick() method: When close() is called
81
81
  // from outside the window's call graph, the next call to tick() must return false (transition
82
- // from CLOSING to CLOSED), but the call after that must return show the window again
83
- // (transition from CLOSED to OPEN).
84
- enum { CLOSED, OPEN, CLOSING } state = CLOSED;
82
+ // from CLOSING to CLOSED), but the call after that must show the window again (transition from
83
+ // CLOSED to OPEN).
84
+ enum
85
+ {
86
+ CLOSED,
87
+ OPEN,
88
+ CLOSING
89
+ } state = CLOSED;
85
90
 
86
- unique_ptr<Graphics> graphics;
87
- unique_ptr<Input> input;
91
+ std::unique_ptr<Graphics> graphics;
92
+ std::unique_ptr<Input> input;
88
93
  };
89
94
 
90
95
  Gosu::Window::Window(int width, int height, unsigned window_flags, double update_interval)
91
- : pimpl(new Impl)
96
+ : m_impl(new Impl)
92
97
  {
93
98
  set_borderless(window_flags & WF_BORDERLESS);
94
99
  set_resizable(window_flags & WF_RESIZABLE);
95
100
 
96
- // Even in fullscreen mode, temporarily show the window in windowed mode to centre it.
101
+ // Even in fullscreen mode, temporarily show the window in windowed mode to center it.
97
102
  // This ensures that the window will be centered correctly when exiting fullscreen mode.
98
103
  // Fixes https://github.com/gosu/gosu/issues/369
99
104
  // (This will implicitly create graphics() and input(), and make the OpenGL context current.)
@@ -105,11 +110,11 @@ Gosu::Window::Window(int width, int height, unsigned window_flags, double update
105
110
 
106
111
  SDL_GL_SetSwapInterval(1);
107
112
 
108
- pimpl->update_interval = update_interval;
113
+ m_impl->update_interval = update_interval;
109
114
 
110
115
  input().on_button_down = [this](Button button) { button_down(button); };
111
- input().on_button_up = [this](Button button) { button_up(button); };
112
- input().on_gamepad_connected = [this](int index) { gamepad_connected(index); };
116
+ input().on_button_up = [this](Button button) { button_up(button); };
117
+ input().on_gamepad_connected = [this](int index) { gamepad_connected(index); };
113
118
  input().on_gamepad_disconnected = [this](int index) { gamepad_disconnected(index); };
114
119
  }
115
120
 
@@ -130,12 +135,12 @@ int Gosu::Window::height() const
130
135
 
131
136
  bool Gosu::Window::fullscreen() const
132
137
  {
133
- return pimpl->fullscreen;
138
+ return m_impl->fullscreen;
134
139
  }
135
140
 
136
141
  void Gosu::Window::resize(int width, int height, bool fullscreen)
137
142
  {
138
- pimpl->fullscreen = fullscreen;
143
+ m_impl->fullscreen = fullscreen;
139
144
 
140
145
  int actual_width = width;
141
146
  int actual_height = height;
@@ -144,19 +149,19 @@ void Gosu::Window::resize(int width, int height, bool fullscreen)
144
149
  double black_bar_height = 0;
145
150
 
146
151
  if (fullscreen) {
147
- actual_width = Gosu::screen_width(this);
152
+ actual_width = Gosu::screen_width(this);
148
153
  actual_height = Gosu::screen_height(this);
149
154
 
150
155
  if (resizable()) {
151
156
  // Resizable fullscreen windows stubbornly follow the desktop resolution.
152
- width = actual_width;
157
+ width = actual_width;
153
158
  height = actual_height;
154
159
  }
155
160
  else {
156
161
  // Scale the window to fill the desktop resolution.
157
162
  double scale_x = 1.0 * actual_width / width;
158
163
  double scale_y = 1.0 * actual_height / height;
159
- scale_factor = min(scale_x, scale_y);
164
+ scale_factor = std::min(scale_x, scale_y);
160
165
  // Add black bars to preserve the aspect ratio, if necessary.
161
166
  if (scale_x < scale_y) {
162
167
  black_bar_height = (actual_height / scale_x - height) / 2;
@@ -167,24 +172,24 @@ void Gosu::Window::resize(int width, int height, bool fullscreen)
167
172
  }
168
173
  }
169
174
  else {
170
- int max_width = Gosu::available_width(this);
175
+ int max_width = Gosu::available_width(this);
171
176
  int max_height = Gosu::available_height(this);
172
177
 
173
178
  if (resizable()) {
174
179
  // If the window is resizable, limit its size, without preserving the aspect ratio.
175
- width = actual_width = min(width, max_width);
176
- height = actual_height = min(height, max_height);
180
+ width = actual_width = std::min(width, max_width);
181
+ height = actual_height = std::min(height, max_height);
177
182
  }
178
183
  else if (width > max_width || height > max_height) {
179
184
  // If the window cannot fit on the screen, shrink its contents.
180
- scale_factor = min(1.0 * max_width / width, 1.0 * max_height / height);
181
- actual_width = width * scale_factor;
182
- actual_height = height * scale_factor;
185
+ scale_factor = std::min(1.0 * max_width / width, 1.0 * max_height / height);
186
+ actual_width = static_cast<int>(width * scale_factor);
187
+ actual_height = static_cast<int>(height * scale_factor);
183
188
  }
184
189
  }
185
190
 
186
191
  SDL_SetWindowFullscreen(shared_window(), fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
187
- if (!pimpl->resizing) {
192
+ if (!m_impl->resizing) {
188
193
  SDL_SetWindowSize(shared_window(), actual_width, actual_height);
189
194
  }
190
195
 
@@ -192,37 +197,39 @@ void Gosu::Window::resize(int width, int height, bool fullscreen)
192
197
 
193
198
  ensure_current_context();
194
199
 
195
- if (!pimpl->graphics) {
196
- pimpl->graphics.reset(new Graphics(actual_width, actual_height));
200
+ if (!m_impl->graphics) {
201
+ m_impl->graphics.reset(new Graphics(actual_width, actual_height));
197
202
  }
198
203
  else {
199
- pimpl->graphics->set_physical_resolution(actual_width, actual_height);
204
+ m_impl->graphics->set_physical_resolution(actual_width, actual_height);
200
205
  }
201
- pimpl->graphics->set_resolution(width, height, black_bar_width, black_bar_height);
206
+ m_impl->graphics->set_resolution(width, height, black_bar_width, black_bar_height);
202
207
 
203
- if (!pimpl->input) {
204
- pimpl->input.reset(new Input(shared_window()));
208
+ if (!m_impl->input) {
209
+ m_impl->input.reset(new Input(shared_window()));
205
210
  }
206
- pimpl->input->set_mouse_factors(1 / scale_factor, 1 / scale_factor,
207
- black_bar_width, black_bar_height);
211
+ m_impl->input->set_mouse_factors(1 / scale_factor, 1 / scale_factor, black_bar_width,
212
+ black_bar_height);
208
213
  }
209
214
 
210
215
  bool Gosu::Window::resizable() const
211
216
  {
212
- return pimpl->resizable;
217
+ return m_impl->resizable;
213
218
  }
214
219
 
215
220
  void Gosu::Window::set_resizable(bool resizable)
216
221
  {
217
- pimpl->resizable = resizable;
222
+ m_impl->resizable = resizable;
218
223
  SDL_SetWindowResizable(shared_window(), resizable ? SDL_TRUE : SDL_FALSE);
219
224
  }
220
225
 
226
+ // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
221
227
  bool Gosu::Window::borderless() const
222
228
  {
223
229
  return SDL_GetWindowFlags(shared_window()) & SDL_WINDOW_BORDERLESS;
224
230
  }
225
231
 
232
+ // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
226
233
  void Gosu::Window::set_borderless(bool borderless)
227
234
  {
228
235
  SDL_SetWindowBordered(shared_window(), borderless ? SDL_FALSE : SDL_TRUE);
@@ -230,21 +237,23 @@ void Gosu::Window::set_borderless(bool borderless)
230
237
 
231
238
  double Gosu::Window::update_interval() const
232
239
  {
233
- return pimpl->update_interval;
240
+ return m_impl->update_interval;
234
241
  }
235
242
 
236
243
  void Gosu::Window::set_update_interval(double update_interval)
237
244
  {
238
- pimpl->update_interval = update_interval;
245
+ m_impl->update_interval = update_interval;
239
246
  }
240
247
 
241
- string Gosu::Window::caption() const
248
+ // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
249
+ std::string Gosu::Window::caption() const
242
250
  {
243
251
  const char* title = SDL_GetWindowTitle(shared_window());
244
252
  return title ? title : "";
245
253
  }
246
254
 
247
- void Gosu::Window::set_caption(const string& caption)
255
+ // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
256
+ void Gosu::Window::set_caption(const std::string& caption)
248
257
  {
249
258
  SDL_SetWindowTitle(shared_window(), caption.c_str());
250
259
  }
@@ -264,16 +273,17 @@ void Gosu::Window::show()
264
273
  while (tick()) {
265
274
  // Sleep to keep this loop from eating 100% CPU.
266
275
  unsigned long tick_time = milliseconds() - time_before_tick;
267
- if (tick_time < update_interval()) {
268
- sleep(update_interval() - tick_time);
276
+ double sleep_time = update_interval() - tick_time;
277
+ if (sleep_time >= 1) {
278
+ sleep(static_cast<unsigned long>(sleep_time));
269
279
  }
270
280
 
271
281
  time_before_tick = milliseconds();
272
282
  }
273
283
  } catch (...) {
274
- #ifdef GOSU_IS_WIN
284
+ #ifdef GOSU_IS_WIN
275
285
  if (previous_affinity) SetThreadAffinityMask(GetCurrentThread(), previous_affinity);
276
- #endif
286
+ #endif
277
287
  throw;
278
288
  }
279
289
 
@@ -281,19 +291,19 @@ void Gosu::Window::show()
281
291
  if (previous_affinity) SetThreadAffinityMask(GetCurrentThread(), previous_affinity);
282
292
  #endif
283
293
 
284
- pimpl->state = Impl::CLOSED;
294
+ m_impl->state = Impl::CLOSED;
285
295
  }
286
296
 
287
297
  bool Gosu::Window::tick()
288
298
  {
289
- if (pimpl->state == Impl::CLOSING) {
290
- pimpl->state = Impl::CLOSED;
299
+ if (m_impl->state == Impl::CLOSING) {
300
+ m_impl->state = Impl::CLOSED;
291
301
  return false;
292
302
  }
293
303
 
294
- if (pimpl->state == Impl::CLOSED) {
304
+ if (m_impl->state == Impl::CLOSED) {
295
305
  SDL_ShowWindow(shared_window());
296
- pimpl->state = Impl::OPEN;
306
+ m_impl->state = Impl::OPEN;
297
307
 
298
308
  // SDL_GL_GetDrawableSize returns different values before and after showing the window.
299
309
  // -> When first showing the window, update the physical size of Graphics (=glViewport).
@@ -305,18 +315,26 @@ bool Gosu::Window::tick()
305
315
 
306
316
  SDL_Event e;
307
317
  while (SDL_PollEvent(&e)) {
308
-
309
318
  switch (e.type) {
310
319
  case SDL_WINDOWEVENT: {
311
320
  switch (e.window.event) {
312
321
  case SDL_WINDOWEVENT_SIZE_CHANGED: {
313
- if (pimpl->resizable && (width() != e.window.data1 || height() != e.window.data2)) {
314
- pimpl->resizing = true;
322
+ if (m_impl->resizable &&
323
+ (width() != e.window.data1 || height() != e.window.data2)) {
324
+ m_impl->resizing = true;
315
325
  resize(e.window.data1, e.window.data2, fullscreen());
316
- pimpl->resizing = false;
326
+ m_impl->resizing = false;
317
327
  }
318
328
  break;
319
329
  }
330
+ case SDL_WINDOWEVENT_FOCUS_GAINED: {
331
+ gain_focus();
332
+ break;
333
+ }
334
+ case SDL_WINDOWEVENT_FOCUS_LOST: {
335
+ lose_focus();
336
+ break;
337
+ }
320
338
  default: {
321
339
  break;
322
340
  }
@@ -328,10 +346,9 @@ bool Gosu::Window::tick()
328
346
  break;
329
347
  }
330
348
  case SDL_DROPFILE: {
331
- char* dropped_filedir = e.drop.file;
332
- if (dropped_filedir == nullptr) break;
333
- drop(string(dropped_filedir));
334
- SDL_free(dropped_filedir);
349
+ std::shared_ptr<char> dropped_file{e.drop.file, SDL_free};
350
+ if (dropped_file == nullptr) break;
351
+ drop(dropped_file.get());
335
352
  break;
336
353
  }
337
354
  default: {
@@ -359,16 +376,16 @@ bool Gosu::Window::tick()
359
376
  SDL_GL_SwapWindow(shared_window());
360
377
  }
361
378
 
362
- if (pimpl->state == Impl::CLOSING) {
363
- pimpl->state = Impl::CLOSED;
379
+ if (m_impl->state == Impl::CLOSING) {
380
+ m_impl->state = Impl::CLOSED;
364
381
  }
365
382
 
366
- return pimpl->state == Impl::OPEN;
383
+ return m_impl->state == Impl::OPEN;
367
384
  }
368
385
 
369
386
  void Gosu::Window::close()
370
387
  {
371
- pimpl->state = Impl::CLOSING;
388
+ m_impl->state = Impl::CLOSING;
372
389
  SDL_HideWindow(shared_window());
373
390
  }
374
391
 
@@ -381,23 +398,23 @@ void Gosu::Window::button_down(Button button)
381
398
  #ifdef GOSU_IS_MAC
382
399
  // cmd+F and cmd+ctrl+F are both common shortcuts for toggling fullscreen mode on macOS.
383
400
  toggle_fullscreen = button == KB_F &&
384
- (Input::down(KB_LEFT_META) || Input::down(KB_RIGHT_META)) &&
385
- !Input::down(KB_LEFT_SHIFT) && !Input::down(KB_RIGHT_SHIFT) &&
386
- !Input::down(KB_LEFT_ALT) && !Input::down(KB_RIGHT_ALT);
401
+ (Input::down(KB_LEFT_META) || Input::down(KB_RIGHT_META)) &&
402
+ !Input::down(KB_LEFT_SHIFT) && !Input::down(KB_RIGHT_SHIFT) &&
403
+ !Input::down(KB_LEFT_ALT) && !Input::down(KB_RIGHT_ALT);
387
404
  #else
388
405
  // Alt+Enter and Alt+Return toggle fullscreen mode on all other platforms.
389
406
  toggle_fullscreen = (button == KB_RETURN || button == KB_ENTER) &&
390
- (Input::down(KB_LEFT_ALT) || Input::down(KB_RIGHT_ALT)) &&
391
- !Input::down(KB_LEFT_CONTROL) && !Input::down(KB_RIGHT_CONTROL) &&
392
- !Input::down(KB_LEFT_META) && !Input::down(KB_RIGHT_META) &&
393
- !Input::down(KB_LEFT_SHIFT) && !Input::down(KB_RIGHT_SHIFT);
407
+ (Input::down(KB_LEFT_ALT) || Input::down(KB_RIGHT_ALT)) &&
408
+ !Input::down(KB_LEFT_CONTROL) && !Input::down(KB_RIGHT_CONTROL) &&
409
+ !Input::down(KB_LEFT_META) && !Input::down(KB_RIGHT_META) &&
410
+ !Input::down(KB_LEFT_SHIFT) && !Input::down(KB_RIGHT_SHIFT);
394
411
  #endif
395
412
  // F11 is supported as a shortcut for fullscreen mode on all platforms.
396
- if (!toggle_fullscreen && button == KB_F11 &&
397
- !Input::down(KB_LEFT_ALT) && !Input::down(KB_RIGHT_ALT) &&
398
- !Input::down(KB_LEFT_CONTROL) && !Input::down(KB_RIGHT_CONTROL) &&
399
- !Input::down(KB_LEFT_META) && !Input::down(KB_RIGHT_META) &&
400
- !Input::down(KB_LEFT_SHIFT) && !Input::down(KB_RIGHT_SHIFT)) {
413
+ if (!toggle_fullscreen && button == KB_F11 && !Input::down(KB_LEFT_ALT) &&
414
+ !Input::down(KB_RIGHT_ALT) && !Input::down(KB_LEFT_CONTROL) &&
415
+ !Input::down(KB_RIGHT_CONTROL) && !Input::down(KB_LEFT_META) &&
416
+ !Input::down(KB_RIGHT_META) && !Input::down(KB_LEFT_SHIFT) &&
417
+ !Input::down(KB_RIGHT_SHIFT)) {
401
418
  toggle_fullscreen = true;
402
419
  }
403
420
 
@@ -408,22 +425,22 @@ void Gosu::Window::button_down(Button button)
408
425
 
409
426
  const Gosu::Graphics& Gosu::Window::graphics() const
410
427
  {
411
- return *pimpl->graphics;
428
+ return *m_impl->graphics;
412
429
  }
413
430
 
414
431
  Gosu::Graphics& Gosu::Window::graphics()
415
432
  {
416
- return *pimpl->graphics;
433
+ return *m_impl->graphics;
417
434
  }
418
435
 
419
436
  const Gosu::Input& Gosu::Window::input() const
420
437
  {
421
- return *pimpl->input;
438
+ return *m_impl->input;
422
439
  }
423
440
 
424
441
  Gosu::Input& Gosu::Window::input()
425
442
  {
426
- return *pimpl->input;
443
+ return *m_impl->input;
427
444
  }
428
445
 
429
446
  #endif
data/src/WindowUIKit.cpp CHANGED
@@ -4,51 +4,48 @@
4
4
  #include "GosuViewController.hpp"
5
5
  #include <Gosu/Gosu.hpp>
6
6
 
7
- using namespace std;
8
-
9
- struct Gosu::Window::Impl
7
+ struct Gosu::Window::Impl : Gosu::Noncopyable
10
8
  {
11
9
  UIWindow* window;
12
10
  GosuViewController* controller;
13
- unique_ptr<Graphics> graphics;
14
- unique_ptr<Input> input;
15
-
11
+ std::unique_ptr<Graphics> graphics;
12
+ std::unique_ptr<Input> input;
13
+
16
14
  double update_interval;
17
- string caption;
15
+ std::string caption;
18
16
  };
19
17
 
20
18
  Gosu::Window::Window(int width, int height, unsigned window_flags, double update_interval)
21
- : pimpl(new Impl)
22
- {
23
- pimpl->window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
24
- pimpl->controller = [GosuViewController new];
25
- pimpl->controller.gosuWindow = this;
26
- pimpl->window.rootViewController = pimpl->controller;
27
-
28
- // It is important to load the view before creating the Graphics instance.
29
- [pimpl->controller loadView];
30
-
31
- pimpl->graphics.reset(new Graphics(screen_width(), screen_height()));
32
- pimpl->graphics->set_resolution(width, height);
33
-
34
- pimpl->input.reset(new Input((__bridge void*) pimpl->controller.view, update_interval));
35
- pimpl->input->set_mouse_factors(1.0 * width / available_width(), 1.0 * height / available_height());
36
-
37
- pimpl->input->on_touch_began = [this](Gosu::Touch touch) { touch_began(touch); };
38
- pimpl->input->on_touch_moved = [this](Gosu::Touch touch) { touch_moved(touch); };
39
- pimpl->input->on_touch_ended = [this](Gosu::Touch touch) { touch_ended(touch); };
40
- pimpl->input->on_touch_cancelled = [this](Gosu::Touch touch) { touch_cancelled(touch); };
41
-
19
+ : m_impl{new Impl}
20
+ {
21
+ m_impl->window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
22
+ m_impl->controller = [GosuViewController new];
23
+ m_impl->controller.gosuWindow = this;
24
+ m_impl->window.rootViewController = m_impl->controller;
25
+
26
+ // It is important to (implicitly) load the view before creating the Graphics instance.
27
+ [m_impl->controller view];
28
+
29
+ m_impl->graphics.reset(new Graphics(screen_width(), screen_height()));
30
+ m_impl->graphics->set_resolution(width, height);
31
+
32
+ m_impl->input.reset(new Input((__bridge void*) m_impl->controller.view, update_interval));
33
+ m_impl->input->set_mouse_factors(1.0 * width / available_width(),
34
+ 1.0 * height / available_height());
35
+
36
+ m_impl->input->on_touch_began = [this](Gosu::Touch touch) { touch_began(touch); };
37
+ m_impl->input->on_touch_moved = [this](Gosu::Touch touch) { touch_moved(touch); };
38
+ m_impl->input->on_touch_ended = [this](Gosu::Touch touch) { touch_ended(touch); };
39
+ m_impl->input->on_touch_cancelled = [this](Gosu::Touch touch) { touch_cancelled(touch); };
40
+
42
41
  // Now let the controller know about our Input instance.
43
- [pimpl->controller trackTextInput:*pimpl->input];
44
-
45
- pimpl->update_interval = update_interval;
46
- }
42
+ [m_impl->controller trackTextInput:*m_impl->input];
47
43
 
48
- Gosu::Window::~Window()
49
- {
44
+ m_impl->update_interval = update_interval;
50
45
  }
51
46
 
47
+ Gosu::Window::~Window() = default;
48
+
52
49
  int Gosu::Window::width() const
53
50
  {
54
51
  return graphics().width();
@@ -69,7 +66,7 @@ bool Gosu::Window::resizable() const
69
66
  return false;
70
67
  }
71
68
 
72
- void Gosu::Window::set_resizable(bool resizable)
69
+ void Gosu::Window::set_resizable(bool)
73
70
  {
74
71
  }
75
72
 
@@ -78,53 +75,53 @@ bool Gosu::Window::borderless() const
78
75
  return true;
79
76
  }
80
77
 
81
- void Gosu::Window::set_borderless(bool borderless)
78
+ void Gosu::Window::set_borderless(bool)
82
79
  {
83
80
  }
84
81
 
85
- void Gosu::Window::resize(int width, int height, bool fullscreen)
82
+ void Gosu::Window::resize(int, int, bool)
86
83
  {
87
- throw logic_error("Cannot resize windows on iOS");
84
+ throw std::logic_error{"Cannot resize windows on iOS"};
88
85
  }
89
86
 
90
87
  double Gosu::Window::update_interval() const
91
88
  {
92
- return pimpl->update_interval;
89
+ return m_impl->update_interval;
93
90
  }
94
91
 
95
- void Gosu::Window::set_update_interval(double update_interval)
92
+ void Gosu::Window::set_update_interval(double)
96
93
  {
97
- throw logic_error("Cannot change the update interval on iOS");
94
+ throw std::logic_error{"Cannot change the update interval on iOS"};
98
95
  }
99
96
 
100
- string Gosu::Window::caption() const
97
+ std::string Gosu::Window::caption() const
101
98
  {
102
- return pimpl->caption;
99
+ return m_impl->caption;
103
100
  }
104
101
 
105
- void Gosu::Window::set_caption(const string& caption)
102
+ void Gosu::Window::set_caption(const std::string& caption)
106
103
  {
107
- pimpl->caption = caption;
104
+ m_impl->caption = caption;
108
105
  }
109
106
 
110
107
  const Gosu::Graphics& Gosu::Window::graphics() const
111
108
  {
112
- return *pimpl->graphics;
109
+ return *m_impl->graphics;
113
110
  }
114
111
 
115
112
  Gosu::Graphics& Gosu::Window::graphics()
116
113
  {
117
- return *pimpl->graphics;
114
+ return *m_impl->graphics;
118
115
  }
119
116
 
120
117
  const Gosu::Input& Gosu::Window::input() const
121
118
  {
122
- return *pimpl->input;
119
+ return *m_impl->input;
123
120
  }
124
121
 
125
122
  Gosu::Input& Gosu::Window::input()
126
123
  {
127
- return *pimpl->input;
124
+ return *m_impl->input;
128
125
  }
129
126
 
130
127
  void Gosu::Window::show()
@@ -138,7 +135,7 @@ bool Gosu::Window::tick()
138
135
 
139
136
  void Gosu::Window::close()
140
137
  {
141
- throw logic_error("Cannot close windows manually on iOS");
138
+ throw std::logic_error{"Cannot close windows manually on iOS"};
142
139
  }
143
140
 
144
141
  void Gosu::Window::button_down(Button button)
@@ -147,7 +144,7 @@ void Gosu::Window::button_down(Button button)
147
144
 
148
145
  void* Gosu::Window::uikit_window() const
149
146
  {
150
- return (__bridge void*) pimpl->window;
147
+ return (__bridge void*) m_impl->window;
151
148
  }
152
149
 
153
150
  int Gosu::screen_width(Window*)