gosu 1.4.6 → 2.0.0.pre6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. checksums.yaml +4 -4
  2. data/COPYING +2 -1
  3. data/dependencies/SDL/include/SDL_atomic.h +2 -3
  4. data/dependencies/SDL/include/SDL_audio.h +7 -7
  5. data/dependencies/SDL/include/SDL_blendmode.h +1 -1
  6. data/dependencies/SDL/include/SDL_endian.h +3 -3
  7. data/dependencies/SDL/include/SDL_gamecontroller.h +4 -4
  8. data/dependencies/SDL/include/SDL_hints.h +72 -28
  9. data/dependencies/SDL/include/SDL_joystick.h +8 -5
  10. data/dependencies/SDL/include/SDL_keycode.h +1 -1
  11. data/dependencies/SDL/include/SDL_main.h +7 -0
  12. data/dependencies/SDL/include/SDL_mouse.h +6 -7
  13. data/dependencies/SDL/include/SDL_mutex.h +79 -5
  14. data/dependencies/SDL/include/SDL_opengl_glext.h +5 -1
  15. data/dependencies/SDL/include/SDL_power.h +7 -8
  16. data/dependencies/SDL/include/SDL_render.h +5 -0
  17. data/dependencies/SDL/include/SDL_revision.h +2 -2
  18. data/dependencies/SDL/include/SDL_sensor.h +1 -1
  19. data/dependencies/SDL/include/SDL_stdinc.h +19 -11
  20. data/dependencies/SDL/include/SDL_thread.h +2 -2
  21. data/dependencies/SDL/include/SDL_version.h +2 -2
  22. data/dependencies/SDL/include/SDL_video.h +30 -2
  23. data/dependencies/SDL/include/begin_code.h +7 -7
  24. data/dependencies/SDL/include/close_code.h +2 -2
  25. data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
  26. data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
  27. data/dependencies/SDL_sound/SDL_sound.h +1 -1
  28. data/dependencies/SDL_sound/dr_flac.h +48 -23
  29. data/dependencies/SDL_sound/dr_mp3.h +34 -14
  30. data/dependencies/SDL_sound/stb_vorbis.h +3 -2
  31. data/dependencies/mojoAL/mojoal.c +1 -1
  32. data/ext/{gosu → gosu-ffi}/extconf.rb +34 -33
  33. data/ext/gosu-ffi/gosu-ffi.def +464 -0
  34. data/ffi/Gosu.cpp +307 -0
  35. data/ffi/Gosu.h +84 -0
  36. data/ffi/Gosu_Channel.cpp +62 -0
  37. data/ffi/Gosu_Channel.h +17 -0
  38. data/ffi/Gosu_Color.cpp +132 -0
  39. data/ffi/Gosu_Color.h +31 -0
  40. data/ffi/Gosu_Constants.cpp +334 -0
  41. data/ffi/Gosu_FFI.h +34 -0
  42. data/ffi/Gosu_FFI_internal.h +161 -0
  43. data/ffi/Gosu_Font.cpp +92 -0
  44. data/ffi/Gosu_Font.h +32 -0
  45. data/ffi/Gosu_Image.cpp +206 -0
  46. data/ffi/Gosu_Image.h +60 -0
  47. data/ffi/Gosu_Sample.cpp +29 -0
  48. data/ffi/Gosu_Sample.h +14 -0
  49. data/ffi/Gosu_Song.cpp +69 -0
  50. data/ffi/Gosu_Song.h +18 -0
  51. data/ffi/Gosu_TextInput.cpp +94 -0
  52. data/ffi/Gosu_TextInput.h +25 -0
  53. data/ffi/Gosu_Window.cpp +314 -0
  54. data/ffi/Gosu_Window.h +78 -0
  55. data/include/Gosu/Audio.hpp +6 -11
  56. data/include/Gosu/Bitmap.hpp +38 -53
  57. data/include/Gosu/Buffer.hpp +54 -0
  58. data/include/Gosu/Color.hpp +27 -35
  59. data/include/Gosu/Directories.hpp +25 -28
  60. data/include/Gosu/Drawable.hpp +58 -0
  61. data/include/Gosu/Font.hpp +6 -5
  62. data/include/Gosu/Fwd.hpp +4 -6
  63. data/include/Gosu/Gosu.hpp +5 -5
  64. data/include/Gosu/Graphics.hpp +51 -61
  65. data/include/Gosu/GraphicsBase.hpp +1 -11
  66. data/include/Gosu/Image.hpp +11 -14
  67. data/include/Gosu/Math.hpp +50 -72
  68. data/include/Gosu/Transform.hpp +32 -0
  69. data/include/Gosu/Utility.hpp +51 -1
  70. data/include/Gosu/Version.hpp +3 -3
  71. data/include/Gosu/Window.hpp +15 -9
  72. data/lib/SDL2.dll +0 -0
  73. data/lib/gosu/channel.rb +49 -0
  74. data/lib/gosu/color.rb +150 -0
  75. data/lib/gosu/compat.rb +29 -8
  76. data/lib/gosu/constants.rb +386 -0
  77. data/lib/gosu/ffi.rb +258 -0
  78. data/lib/gosu/font.rb +56 -0
  79. data/lib/gosu/gl_tex_info.rb +33 -0
  80. data/lib/gosu/gosu.rb +210 -0
  81. data/lib/gosu/image.rb +141 -0
  82. data/lib/gosu/numeric.rb +17 -0
  83. data/lib/gosu/preview.rb +6 -6
  84. data/lib/gosu/sample.rb +24 -0
  85. data/lib/gosu/song.rb +56 -0
  86. data/lib/gosu/text_input.rb +69 -0
  87. data/lib/gosu/window.rb +228 -0
  88. data/lib/gosu.rb +29 -8
  89. data/lib64/SDL2.dll +0 -0
  90. data/rdoc/gosu.rb +0 -2
  91. data/src/Audio.cpp +12 -12
  92. data/src/AudioFile.hpp +5 -4
  93. data/src/AudioFileAudioToolbox.cpp +8 -8
  94. data/src/AudioFileSDLSound.cpp +7 -10
  95. data/src/BinPacker.cpp +187 -0
  96. data/src/BinPacker.hpp +55 -0
  97. data/src/Bitmap.cpp +166 -144
  98. data/src/BitmapIO.cpp +60 -86
  99. data/src/Buffer.cpp +159 -0
  100. data/src/Color.cpp +75 -80
  101. data/src/Directories.cpp +47 -0
  102. data/src/DirectoriesUIKit.cpp +50 -0
  103. data/src/DrawOp.hpp +9 -4
  104. data/src/DrawOpQueue.hpp +2 -2
  105. data/src/Drawable.cpp +95 -0
  106. data/src/EmptyDrawable.hpp +38 -0
  107. data/src/FPS.cpp +31 -0
  108. data/src/Font.cpp +104 -74
  109. data/src/GosuGLView.cpp +14 -6
  110. data/src/GosuViewController.cpp +2 -10
  111. data/src/Graphics.cpp +60 -126
  112. data/src/GraphicsImpl.hpp +17 -47
  113. data/src/Image.cpp +41 -35
  114. data/src/Input.cpp +7 -8
  115. data/src/Macro.cpp +6 -6
  116. data/src/Macro.hpp +4 -4
  117. data/src/MarkupParser.cpp +5 -5
  118. data/src/Math.cpp +35 -22
  119. data/src/OffScreenTarget.cpp +53 -49
  120. data/src/OffScreenTarget.hpp +13 -11
  121. data/src/OpenGLContext.cpp +117 -0
  122. data/src/OpenGLContext.hpp +41 -0
  123. data/src/RenderState.hpp +21 -19
  124. data/src/Resolution.cpp +23 -21
  125. data/src/TexChunk.cpp +35 -80
  126. data/src/TexChunk.hpp +44 -35
  127. data/src/Text.cpp +1 -1
  128. data/src/TextBuilder.cpp +35 -21
  129. data/src/TextBuilder.hpp +6 -9
  130. data/src/Texture.cpp +62 -80
  131. data/src/Texture.hpp +25 -23
  132. data/src/TiledDrawable.cpp +150 -0
  133. data/src/TiledDrawable.hpp +47 -0
  134. data/src/TimingApple.cpp +1 -1
  135. data/src/Transform.cpp +45 -50
  136. data/src/TransformStack.hpp +16 -16
  137. data/src/TrueTypeFont.cpp +59 -51
  138. data/src/TrueTypeFont.hpp +6 -7
  139. data/src/TrueTypeFontApple.cpp +28 -19
  140. data/src/TrueTypeFontUnix.cpp +27 -23
  141. data/src/TrueTypeFontWin.cpp +30 -30
  142. data/src/Utility.cpp +84 -21
  143. data/src/UtilityWin.cpp +45 -0
  144. data/src/Window.cpp +92 -142
  145. data/src/WindowUIKit.cpp +14 -14
  146. metadata +72 -31
  147. data/include/Gosu/IO.hpp +0 -254
  148. data/include/Gosu/ImageData.hpp +0 -53
  149. data/include/Gosu/Inspection.hpp +0 -7
  150. data/lib/gosu/patches.rb +0 -66
  151. data/lib/gosu/run.rb +0 -20
  152. data/lib/gosu/swig_patches.rb +0 -110
  153. data/src/BlockAllocator.cpp +0 -131
  154. data/src/BlockAllocator.hpp +0 -32
  155. data/src/DirectoriesApple.cpp +0 -69
  156. data/src/DirectoriesUnix.cpp +0 -46
  157. data/src/DirectoriesWin.cpp +0 -65
  158. data/src/EmptyImageData.hpp +0 -52
  159. data/src/FileUnix.cpp +0 -99
  160. data/src/FileWin.cpp +0 -88
  161. data/src/IO.cpp +0 -60
  162. data/src/Iconv.hpp +0 -51
  163. data/src/Inspection.cpp +0 -27
  164. data/src/LargeImageData.cpp +0 -215
  165. data/src/LargeImageData.hpp +0 -39
  166. data/src/Log.hpp +0 -19
  167. data/src/RubyGosu.cxx +0 -13100
  168. data/src/RubyGosu.h +0 -49
  169. data/src/WinUtility.cpp +0 -61
  170. data/src/WinUtility.hpp +0 -27
data/src/Window.cpp CHANGED
@@ -3,72 +3,13 @@
3
3
 
4
4
  #if defined(GOSU_IS_WIN)
5
5
  #define NOMINMAX
6
- #include <windows.h>
6
+ #include <windows.h> // for SetThreadAffinityMask()
7
7
  #endif
8
8
 
9
9
  #include <Gosu/Gosu.hpp>
10
10
  #include "GraphicsImpl.hpp"
11
- #include <SDL.h>
11
+ #include "OpenGLContext.hpp"
12
12
  #include <algorithm>
13
- #include <stdexcept>
14
-
15
- namespace Gosu
16
- {
17
- namespace FPS
18
- {
19
- void register_frame();
20
- }
21
-
22
- [[noreturn]] static void throw_sdl_error(const std::string& operation)
23
- {
24
- const char* error = SDL_GetError();
25
- throw std::runtime_error{operation + ": " + (error ? error : "(unknown error)")};
26
- }
27
-
28
- SDL_Window* shared_window()
29
- {
30
- // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
31
- static SDL_Window* window = nullptr;
32
- if (window == nullptr) {
33
- if (SDL_Init(SDL_INIT_VIDEO) < 0) {
34
- throw_sdl_error("Could not initialize SDL Video");
35
- }
36
-
37
- Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN | SDL_WINDOW_ALLOW_HIGHDPI;
38
-
39
- window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 64, 64,
40
- flags);
41
- if (window == nullptr) {
42
- throw_sdl_error("Could not create window");
43
- }
44
- SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
45
- }
46
- return window;
47
- }
48
-
49
- static SDL_GLContext shared_gl_context()
50
- {
51
- static SDL_GLContext context = nullptr;
52
- if (context == nullptr) {
53
- #ifdef GOSU_IS_OPENGLES
54
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
55
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
56
- #endif
57
-
58
- context = SDL_GL_CreateContext(shared_window());
59
-
60
- if (context == nullptr) {
61
- throw_sdl_error("Could not create OpenGL context");
62
- }
63
- }
64
- return context;
65
- }
66
-
67
- void ensure_current_context() //
68
- {
69
- SDL_GL_MakeCurrent(shared_window(), shared_gl_context());
70
- }
71
- }
72
13
 
73
14
  struct Gosu::Window::Impl : private Gosu::Noncopyable
74
15
  {
@@ -86,14 +27,15 @@ struct Gosu::Window::Impl : private Gosu::Noncopyable
86
27
  CLOSED,
87
28
  OPEN,
88
29
  CLOSING
89
- } state = CLOSED;
30
+ } state
31
+ = CLOSED;
90
32
 
91
- std::unique_ptr<Graphics> graphics;
33
+ std::unique_ptr<Viewport> viewport;
92
34
  std::unique_ptr<Input> input;
93
35
  };
94
36
 
95
37
  Gosu::Window::Window(int width, int height, unsigned window_flags, double update_interval)
96
- : m_impl(new Impl)
38
+ : m_impl(new Impl)
97
39
  {
98
40
  set_borderless(window_flags & WF_BORDERLESS);
99
41
  set_resizable(window_flags & WF_RESIZABLE);
@@ -103,13 +45,11 @@ Gosu::Window::Window(int width, int height, unsigned window_flags, double update
103
45
  // Fixes https://github.com/gosu/gosu/issues/369
104
46
  // (This will implicitly create graphics() and input(), and make the OpenGL context current.)
105
47
  resize(width, height, false);
106
- SDL_SetWindowPosition(shared_window(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
48
+ SDL_SetWindowPosition(sdl_window(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
107
49
 
108
50
  // Really enable fullscreen if desired.
109
51
  resize(width, height, (window_flags & WF_FULLSCREEN));
110
52
 
111
- SDL_GL_SetSwapInterval(1);
112
-
113
53
  m_impl->update_interval = update_interval;
114
54
 
115
55
  input().on_button_down = [this](Button button) { button_down(button); };
@@ -120,17 +60,17 @@ Gosu::Window::Window(int width, int height, unsigned window_flags, double update
120
60
 
121
61
  Gosu::Window::~Window()
122
62
  {
123
- SDL_HideWindow(shared_window());
63
+ SDL_HideWindow(sdl_window());
124
64
  }
125
65
 
126
66
  int Gosu::Window::width() const
127
67
  {
128
- return graphics().width();
68
+ return viewport().width();
129
69
  }
130
70
 
131
71
  int Gosu::Window::height() const
132
72
  {
133
- return graphics().height();
73
+ return viewport().height();
134
74
  }
135
75
 
136
76
  bool Gosu::Window::fullscreen() const
@@ -188,25 +128,23 @@ void Gosu::Window::resize(int width, int height, bool fullscreen)
188
128
  }
189
129
  }
190
130
 
191
- SDL_SetWindowFullscreen(shared_window(), fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
131
+ SDL_SetWindowFullscreen(sdl_window(), fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
192
132
  if (!m_impl->resizing) {
193
- SDL_SetWindowSize(shared_window(), actual_width, actual_height);
133
+ SDL_SetWindowSize(sdl_window(), actual_width, actual_height);
194
134
  }
195
135
 
196
- SDL_GL_GetDrawableSize(shared_window(), &actual_width, &actual_height);
136
+ SDL_GL_GetDrawableSize(sdl_window(), &actual_width, &actual_height);
197
137
 
198
- ensure_current_context();
199
-
200
- if (!m_impl->graphics) {
201
- m_impl->graphics.reset(new Graphics(actual_width, actual_height));
138
+ if (!m_impl->viewport) {
139
+ m_impl->viewport = std::make_unique<Viewport>(actual_width, actual_height);
202
140
  }
203
141
  else {
204
- m_impl->graphics->set_physical_resolution(actual_width, actual_height);
142
+ m_impl->viewport->set_physical_resolution(actual_width, actual_height);
205
143
  }
206
- m_impl->graphics->set_resolution(width, height, black_bar_width, black_bar_height);
144
+ m_impl->viewport->set_resolution(width, height, black_bar_width, black_bar_height);
207
145
 
208
146
  if (!m_impl->input) {
209
- m_impl->input.reset(new Input(shared_window()));
147
+ m_impl->input = std::make_unique<Input>(sdl_window());
210
148
  }
211
149
  m_impl->input->set_mouse_factors(1 / scale_factor, 1 / scale_factor, black_bar_width,
212
150
  black_bar_height);
@@ -220,19 +158,19 @@ bool Gosu::Window::resizable() const
220
158
  void Gosu::Window::set_resizable(bool resizable)
221
159
  {
222
160
  m_impl->resizable = resizable;
223
- SDL_SetWindowResizable(shared_window(), resizable ? SDL_TRUE : SDL_FALSE);
161
+ SDL_SetWindowResizable(sdl_window(), resizable ? SDL_TRUE : SDL_FALSE);
224
162
  }
225
163
 
226
164
  // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
227
165
  bool Gosu::Window::borderless() const
228
166
  {
229
- return SDL_GetWindowFlags(shared_window()) & SDL_WINDOW_BORDERLESS;
167
+ return SDL_GetWindowFlags(sdl_window()) & SDL_WINDOW_BORDERLESS;
230
168
  }
231
169
 
232
170
  // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
233
171
  void Gosu::Window::set_borderless(bool borderless)
234
172
  {
235
- SDL_SetWindowBordered(shared_window(), borderless ? SDL_FALSE : SDL_TRUE);
173
+ SDL_SetWindowBordered(sdl_window(), borderless ? SDL_FALSE : SDL_TRUE);
236
174
  }
237
175
 
238
176
  double Gosu::Window::update_interval() const
@@ -248,14 +186,14 @@ void Gosu::Window::set_update_interval(double update_interval)
248
186
  // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
249
187
  std::string Gosu::Window::caption() const
250
188
  {
251
- const char* title = SDL_GetWindowTitle(shared_window());
189
+ const char* title = SDL_GetWindowTitle(sdl_window());
252
190
  return title ? title : "";
253
191
  }
254
192
 
255
193
  // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
256
194
  void Gosu::Window::set_caption(const std::string& caption)
257
195
  {
258
- SDL_SetWindowTitle(shared_window(), caption.c_str());
196
+ SDL_SetWindowTitle(sdl_window(), caption.c_str());
259
197
  }
260
198
 
261
199
  void Gosu::Window::show()
@@ -285,13 +223,17 @@ void Gosu::Window::show()
285
223
  }
286
224
  } catch (...) {
287
225
  #ifdef GOSU_IS_WIN
288
- if (previous_affinity) SetThreadAffinityMask(GetCurrentThread(), previous_affinity);
226
+ if (previous_affinity) {
227
+ SetThreadAffinityMask(GetCurrentThread(), previous_affinity);
228
+ }
289
229
  #endif
290
230
  throw;
291
231
  }
292
232
 
293
233
  #ifdef GOSU_IS_WIN
294
- if (previous_affinity) SetThreadAffinityMask(GetCurrentThread(), previous_affinity);
234
+ if (previous_affinity) {
235
+ SetThreadAffinityMask(GetCurrentThread(), previous_affinity);
236
+ }
295
237
  #endif
296
238
 
297
239
  m_impl->state = Impl::CLOSED;
@@ -305,59 +247,67 @@ bool Gosu::Window::tick()
305
247
  }
306
248
 
307
249
  if (m_impl->state == Impl::CLOSED) {
308
- SDL_ShowWindow(shared_window());
250
+ SDL_ShowWindow(sdl_window());
309
251
  m_impl->state = Impl::OPEN;
310
252
 
253
+ SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
254
+
255
+ // Enable vsync.
256
+ const OpenGLContext current_context(true);
257
+ SDL_GL_SetSwapInterval(1);
258
+
311
259
  // SDL_GL_GetDrawableSize returns different values before and after showing the window.
312
260
  // -> When first showing the window, update the physical size of Graphics (=glViewport).
313
261
  // Fixes https://github.com/gosu/gosu/issues/318
314
262
  int width, height;
315
- SDL_GL_GetDrawableSize(shared_window(), &width, &height);
316
- graphics().set_physical_resolution(width, height);
263
+ SDL_GL_GetDrawableSize(sdl_window(), &width, &height);
264
+ viewport().set_physical_resolution(width, height);
317
265
  }
318
266
 
319
267
  SDL_Event e;
320
268
  while (SDL_PollEvent(&e)) {
321
269
  switch (e.type) {
322
- case SDL_WINDOWEVENT: {
323
- switch (e.window.event) {
324
- case SDL_WINDOWEVENT_SIZE_CHANGED: {
325
- if (m_impl->resizable &&
326
- (width() != e.window.data1 || height() != e.window.data2)) {
327
- m_impl->resizing = true;
328
- resize(e.window.data1, e.window.data2, fullscreen());
329
- m_impl->resizing = false;
330
- }
331
- break;
332
- }
333
- case SDL_WINDOWEVENT_FOCUS_GAINED: {
334
- gain_focus();
335
- break;
336
- }
337
- case SDL_WINDOWEVENT_FOCUS_LOST: {
338
- lose_focus();
339
- break;
340
- }
341
- default: {
342
- break;
343
- }
270
+ case SDL_WINDOWEVENT: {
271
+ switch (e.window.event) {
272
+ case SDL_WINDOWEVENT_SIZE_CHANGED: {
273
+ if (m_impl->resizable
274
+ && (width() != e.window.data1 || height() != e.window.data2)) {
275
+ m_impl->resizing = true;
276
+ resize(e.window.data1, e.window.data2, fullscreen());
277
+ m_impl->resizing = false;
344
278
  }
345
279
  break;
346
280
  }
347
- case SDL_QUIT: {
348
- close();
281
+ case SDL_WINDOWEVENT_FOCUS_GAINED: {
282
+ gain_focus();
349
283
  break;
350
284
  }
351
- case SDL_DROPFILE: {
352
- std::shared_ptr<char> dropped_file{e.drop.file, SDL_free};
353
- if (dropped_file == nullptr) break;
354
- drop(dropped_file.get());
285
+ case SDL_WINDOWEVENT_FOCUS_LOST: {
286
+ lose_focus();
355
287
  break;
356
288
  }
357
289
  default: {
358
- input().feed_sdl_event(&e);
359
290
  break;
360
291
  }
292
+ }
293
+ break;
294
+ }
295
+ case SDL_QUIT: {
296
+ close();
297
+ break;
298
+ }
299
+ case SDL_DROPFILE: {
300
+ std::shared_ptr<char> dropped_file { e.drop.file, SDL_free };
301
+ if (dropped_file == nullptr) {
302
+ break;
303
+ }
304
+ drop(dropped_file.get());
305
+ break;
306
+ }
307
+ default: {
308
+ input().feed_sdl_event(&e);
309
+ break;
310
+ }
361
311
  }
362
312
  }
363
313
 
@@ -370,13 +320,13 @@ bool Gosu::Window::tick()
370
320
  SDL_ShowCursor(needs_cursor());
371
321
 
372
322
  if (needs_redraw()) {
373
- ensure_current_context();
374
- graphics().frame([&] {
323
+ const OpenGLContext current_context(true);
324
+ viewport().frame([&] {
375
325
  draw();
376
- FPS::register_frame();
326
+ register_frame();
377
327
  });
378
328
 
379
- SDL_GL_SwapWindow(shared_window());
329
+ SDL_GL_SwapWindow(sdl_window());
380
330
  }
381
331
 
382
332
  if (m_impl->state == Impl::CLOSING) {
@@ -389,7 +339,7 @@ bool Gosu::Window::tick()
389
339
  void Gosu::Window::close()
390
340
  {
391
341
  m_impl->state = Impl::CLOSING;
392
- SDL_HideWindow(shared_window());
342
+ SDL_HideWindow(sdl_window());
393
343
  }
394
344
 
395
345
  void Gosu::Window::button_down(Button button)
@@ -398,26 +348,21 @@ void Gosu::Window::button_down(Button button)
398
348
 
399
349
  // Default shortcuts for toggling fullscreen mode, see: https://github.com/gosu/gosu/issues/361
400
350
 
351
+ const bool control_down = Input::down(KB_LEFT_CONTROL) || Input::down(KB_RIGHT_CONTROL);
352
+ const bool alt_down = Input::down(KB_LEFT_ALT) || Input::down(KB_RIGHT_ALT);
353
+ const bool shift_down = Input::down(KB_LEFT_SHIFT) || Input::down(KB_RIGHT_SHIFT);
354
+ const bool meta_down = Input::down(KB_LEFT_META) || Input::down(KB_RIGHT_META);
355
+
401
356
  #ifdef GOSU_IS_MAC
402
357
  // cmd+F and cmd+ctrl+F are both common shortcuts for toggling fullscreen mode on macOS.
403
- toggle_fullscreen = button == KB_F &&
404
- (Input::down(KB_LEFT_META) || Input::down(KB_RIGHT_META)) &&
405
- !Input::down(KB_LEFT_SHIFT) && !Input::down(KB_RIGHT_SHIFT) &&
406
- !Input::down(KB_LEFT_ALT) && !Input::down(KB_RIGHT_ALT);
358
+ toggle_fullscreen = button == KB_F && meta_down && !control_down && !alt_down && !shift_down;
407
359
  #else
408
360
  // Alt+Enter and Alt+Return toggle fullscreen mode on all other platforms.
409
- toggle_fullscreen = (button == KB_RETURN || button == KB_ENTER) &&
410
- (Input::down(KB_LEFT_ALT) || Input::down(KB_RIGHT_ALT)) &&
411
- !Input::down(KB_LEFT_CONTROL) && !Input::down(KB_RIGHT_CONTROL) &&
412
- !Input::down(KB_LEFT_META) && !Input::down(KB_RIGHT_META) &&
413
- !Input::down(KB_LEFT_SHIFT) && !Input::down(KB_RIGHT_SHIFT);
361
+ const bool enter_or_return = (button == KB_RETURN || button == KB_ENTER);
362
+ toggle_fullscreen = enter_or_return && alt_down && !control_down && !shift_down && !meta_down;
414
363
  #endif
415
364
  // F11 is supported as a shortcut for fullscreen mode on all platforms.
416
- if (!toggle_fullscreen && button == KB_F11 && !Input::down(KB_LEFT_ALT) &&
417
- !Input::down(KB_RIGHT_ALT) && !Input::down(KB_LEFT_CONTROL) &&
418
- !Input::down(KB_RIGHT_CONTROL) && !Input::down(KB_LEFT_META) &&
419
- !Input::down(KB_RIGHT_META) && !Input::down(KB_LEFT_SHIFT) &&
420
- !Input::down(KB_RIGHT_SHIFT)) {
365
+ if (button == KB_F11 && !meta_down && !control_down && !alt_down && !shift_down) {
421
366
  toggle_fullscreen = true;
422
367
  }
423
368
 
@@ -426,14 +371,14 @@ void Gosu::Window::button_down(Button button)
426
371
  }
427
372
  }
428
373
 
429
- const Gosu::Graphics& Gosu::Window::graphics() const
374
+ const Gosu::Viewport& Gosu::Window::viewport() const
430
375
  {
431
- return *m_impl->graphics;
376
+ return *m_impl->viewport;
432
377
  }
433
378
 
434
- Gosu::Graphics& Gosu::Window::graphics()
379
+ Gosu::Viewport& Gosu::Window::viewport()
435
380
  {
436
- return *m_impl->graphics;
381
+ return *m_impl->viewport;
437
382
  }
438
383
 
439
384
  const Gosu::Input& Gosu::Window::input() const
@@ -446,4 +391,9 @@ Gosu::Input& Gosu::Window::input()
446
391
  return *m_impl->input;
447
392
  }
448
393
 
394
+ SDL_Window* Gosu::Window::sdl_window() const // NOLINT(*-convert-member-functions-to-static)
395
+ {
396
+ return OpenGLContext::shared_sdl_window();
397
+ }
398
+
449
399
  #endif
data/src/WindowUIKit.cpp CHANGED
@@ -8,7 +8,7 @@ struct Gosu::Window::Impl : private Gosu::Noncopyable
8
8
  {
9
9
  UIWindow* window;
10
10
  GosuViewController* controller;
11
- std::unique_ptr<Graphics> graphics;
11
+ std::unique_ptr<Viewport> viewport;
12
12
  std::unique_ptr<Input> input;
13
13
 
14
14
  double update_interval;
@@ -23,11 +23,11 @@ Gosu::Window::Window(int width, int height, unsigned window_flags, double update
23
23
  m_impl->controller.gosuWindow = this;
24
24
  m_impl->window.rootViewController = m_impl->controller;
25
25
 
26
- // It is important to (implicitly) load the view before creating the Graphics instance.
26
+ // It is important to (implicitly) load the view before creating the Viewport instance.
27
27
  [m_impl->controller view];
28
28
 
29
- m_impl->graphics.reset(new Graphics(screen_width(), screen_height()));
30
- m_impl->graphics->set_resolution(width, height);
29
+ m_impl->viewport = std::make_unique<Viewport>(screen_width(), screen_height());
30
+ m_impl->viewport->set_resolution(width, height);
31
31
 
32
32
  m_impl->input.reset(new Input((__bridge void*) m_impl->controller.view, update_interval));
33
33
  m_impl->input->set_mouse_factors(1.0 * width / available_width(),
@@ -48,12 +48,12 @@ Gosu::Window::~Window() = default;
48
48
 
49
49
  int Gosu::Window::width() const
50
50
  {
51
- return graphics().width();
51
+ return viewport().width();
52
52
  }
53
53
 
54
54
  int Gosu::Window::height() const
55
55
  {
56
- return graphics().height();
56
+ return viewport().height();
57
57
  }
58
58
 
59
59
  bool Gosu::Window::fullscreen() const
@@ -104,14 +104,14 @@ void Gosu::Window::set_caption(const std::string& caption)
104
104
  m_impl->caption = caption;
105
105
  }
106
106
 
107
- const Gosu::Graphics& Gosu::Window::graphics() const
107
+ const Gosu::Viewport& Gosu::Window::viewport() const
108
108
  {
109
- return *m_impl->graphics;
109
+ return *m_impl->viewport;
110
110
  }
111
111
 
112
- Gosu::Graphics& Gosu::Window::graphics()
112
+ Gosu::Viewport& Gosu::Window::viewport()
113
113
  {
114
- return *m_impl->graphics;
114
+ return *m_impl->viewport;
115
115
  }
116
116
 
117
117
  const Gosu::Input& Gosu::Window::input() const
@@ -147,24 +147,24 @@ void* Gosu::Window::uikit_window() const
147
147
  return (__bridge void*) m_impl->window;
148
148
  }
149
149
 
150
- int Gosu::screen_width(Window*)
150
+ int Gosu::screen_width(const Window*)
151
151
  {
152
152
  return available_width() * [UIScreen mainScreen].scale;
153
153
  }
154
154
 
155
- int Gosu::screen_height(Window*)
155
+ int Gosu::screen_height(const Window*)
156
156
  {
157
157
  return available_height() * [UIScreen mainScreen].scale;
158
158
  }
159
159
 
160
- int Gosu::available_width(Window*)
160
+ int Gosu::available_width(const Window*)
161
161
  {
162
162
  static CGSize screen_size = [UIScreen mainScreen].bounds.size;
163
163
  static CGFloat width = MAX(screen_size.width, screen_size.height);
164
164
  return width;
165
165
  }
166
166
 
167
- int Gosu::available_height(Window*)
167
+ int Gosu::available_height(const Window*)
168
168
  {
169
169
  static CGSize screen_size = [UIScreen mainScreen].bounds.size;
170
170
  static CGFloat height = MIN(screen_size.width, screen_size.height);