gosu 1.3.0 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (223) 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 +104 -70
  87. data/dependencies/SDL_sound/SDL_sound.h +6 -6
  88. data/dependencies/SDL_sound/SDL_sound_aiff.c +32 -32
  89. data/dependencies/SDL_sound/SDL_sound_au.c +14 -14
  90. data/dependencies/SDL_sound/SDL_sound_coreaudio.c +6 -7
  91. data/dependencies/SDL_sound/SDL_sound_flac.c +28 -30
  92. data/dependencies/SDL_sound/SDL_sound_internal.h +21 -14
  93. data/dependencies/SDL_sound/SDL_sound_modplug.c +26 -28
  94. data/dependencies/SDL_sound/SDL_sound_mp3.c +20 -36
  95. data/dependencies/SDL_sound/SDL_sound_raw.c +15 -16
  96. data/dependencies/SDL_sound/SDL_sound_shn.c +11 -10
  97. data/dependencies/SDL_sound/SDL_sound_voc.c +20 -18
  98. data/dependencies/SDL_sound/SDL_sound_vorbis.c +11 -9
  99. data/dependencies/SDL_sound/SDL_sound_wav.c +49 -43
  100. data/dependencies/SDL_sound/dr_flac.h +10925 -4466
  101. data/dependencies/SDL_sound/dr_mp3.h +2802 -844
  102. data/dependencies/SDL_sound/libmodplug/fastmix.c +63 -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 +12 -7
  106. data/dependencies/SDL_sound/libmodplug/load_ams.c +103 -44
  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 +61 -61
  112. data/dependencies/SDL_sound/libmodplug/load_mdl.c +94 -58
  113. data/dependencies/SDL_sound/libmodplug/load_med.c +20 -11
  114. data/dependencies/SDL_sound/libmodplug/load_mod.c +40 -15
  115. data/dependencies/SDL_sound/libmodplug/load_mt2.c +50 -19
  116. data/dependencies/SDL_sound/libmodplug/load_okt.c +59 -28
  117. data/dependencies/SDL_sound/libmodplug/load_psm.c +104 -79
  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 +4 -3
  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 +32 -19
  130. data/dependencies/SDL_sound/libmodplug/sndfile.c +76 -160
  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 +504 -329
  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 +4848 -0
  137. data/dependencies/stb/stb_image.h +208 -73
  138. data/dependencies/stb/stb_image_write.h +57 -23
  139. data/dependencies/stb/stb_truetype.h +345 -279
  140. data/dependencies/utf8proc/utf8proc.c +37 -18
  141. data/dependencies/utf8proc/utf8proc.h +17 -5
  142. data/dependencies/utf8proc/utf8proc_data.h +12012 -10089
  143. data/ext/gosu/extconf.rb +29 -30
  144. data/include/Gosu/Audio.hpp +70 -85
  145. data/include/Gosu/Buttons.hpp +103 -103
  146. data/include/Gosu/Color.hpp +19 -11
  147. data/include/Gosu/Directories.hpp +31 -24
  148. data/include/Gosu/Font.hpp +42 -44
  149. data/include/Gosu/Gosu.hpp +5 -8
  150. data/include/Gosu/Graphics.hpp +58 -71
  151. data/include/Gosu/GraphicsBase.hpp +26 -33
  152. data/include/Gosu/IO.hpp +0 -3
  153. data/include/Gosu/Image.hpp +56 -62
  154. data/include/Gosu/ImageData.hpp +23 -27
  155. data/include/Gosu/Inspection.hpp +1 -4
  156. data/include/Gosu/Math.hpp +0 -3
  157. data/include/Gosu/TextInput.hpp +34 -40
  158. data/include/Gosu/Timing.hpp +2 -8
  159. data/include/Gosu/Version.hpp +2 -2
  160. data/include/Gosu/Window.hpp +71 -70
  161. data/lib/SDL2.dll +0 -0
  162. data/lib/gosu/compat.rb +24 -37
  163. data/lib/gosu.rb +2 -2
  164. data/lib64/SDL2.dll +0 -0
  165. data/src/Audio.cpp +88 -86
  166. data/src/AudioFile.hpp +6 -6
  167. data/src/AudioFileAudioToolbox.cpp +1 -1
  168. data/src/AudioFileSDLSound.cpp +1 -1
  169. data/src/AudioImpl.cpp +0 -7
  170. data/src/AudioImpl.hpp +6 -8
  171. data/src/BitmapIO.cpp +23 -22
  172. data/src/BlockAllocator.cpp +2 -1
  173. data/src/Channel.cpp +22 -20
  174. data/src/Color.cpp +12 -9
  175. data/src/DirectoriesApple.cpp +25 -24
  176. data/src/DirectoriesUnix.cpp +14 -12
  177. data/src/DirectoriesWin.cpp +26 -30
  178. data/src/EmptyImageData.hpp +15 -17
  179. data/src/FileUnix.cpp +1 -1
  180. data/src/FileWin.cpp +1 -1
  181. data/src/Font.cpp +59 -54
  182. data/src/Graphics.cpp +135 -143
  183. data/src/Image.cpp +41 -47
  184. data/src/Input.cpp +1 -1
  185. data/src/InputUIKit.cpp +1 -1
  186. data/src/LargeImageData.cpp +108 -101
  187. data/src/LargeImageData.hpp +17 -15
  188. data/src/Log.hpp +6 -6
  189. data/src/Macro.cpp +35 -37
  190. data/src/Macro.hpp +11 -11
  191. data/src/Math.cpp +8 -1
  192. data/src/Resolution.cpp +12 -7
  193. data/src/RubyGosu.cxx +11 -39
  194. data/src/TexChunk.cpp +50 -41
  195. data/src/TexChunk.hpp +22 -22
  196. data/src/Text.cpp +37 -37
  197. data/src/TextBuilder.cpp +60 -57
  198. data/src/TextBuilder.hpp +20 -20
  199. data/src/TextInput.cpp +127 -135
  200. data/src/TimingApple.cpp +1 -7
  201. data/src/TimingUnix.cpp +0 -6
  202. data/src/TimingWin.cpp +0 -6
  203. data/src/TrueTypeFont.cpp +107 -107
  204. data/src/TrueTypeFont.hpp +39 -38
  205. data/src/TrueTypeFontApple.cpp +19 -22
  206. data/src/TrueTypeFontUnix.cpp +21 -26
  207. data/src/TrueTypeFontWin.cpp +30 -30
  208. data/src/Window.cpp +97 -87
  209. data/src/WindowUIKit.cpp +46 -49
  210. metadata +7 -17
  211. data/dependencies/SDL/include/SDL_config_os2.h +0 -188
  212. data/dependencies/SDL_sound/libmodplug/load_abc.c +0 -4725
  213. data/dependencies/SDL_sound/libmodplug/load_mid.c +0 -1405
  214. data/dependencies/SDL_sound/libmodplug/load_pat.c +0 -1143
  215. data/dependencies/SDL_sound/libmodplug/load_pat.h +0 -25
  216. data/dependencies/al_soft/AL/alext.h +0 -585
  217. data/dependencies/al_soft/AL/efx-creative.h +0 -3
  218. data/dependencies/al_soft/AL/efx-presets.h +0 -402
  219. data/dependencies/al_soft/AL/efx.h +0 -762
  220. data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
  221. data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
  222. data/lib/OpenAL32.dll +0 -0
  223. data/lib64/OpenAL32.dll +0 -0
@@ -1,22 +1,18 @@
1
1
  #include <Gosu/Platform.hpp>
2
2
  #if defined(GOSU_IS_X)
3
3
 
4
- #include "TrueTypeFont.hpp"
5
- #include "Log.hpp"
6
-
7
4
  #include <Gosu/IO.hpp>
8
5
  #include <Gosu/Text.hpp>
9
6
  #include <Gosu/Utility.hpp>
10
-
7
+ #include "Log.hpp"
8
+ #include "TrueTypeFont.hpp"
11
9
  #include <fontconfig/fontconfig.h>
12
-
13
10
  #include <map>
14
- using namespace std;
15
11
 
16
- const unsigned char* Gosu::ttf_data_by_name(const string& font_name, unsigned font_flags)
12
+ const unsigned char* Gosu::ttf_data_by_name(const std::string& font_name, unsigned font_flags)
17
13
  {
18
14
  // TODO: Make this cache thread-safe.
19
- static map<pair<string, unsigned>, const unsigned char*> ttf_file_cache;
15
+ static std::map<std::pair<std::string, unsigned>, const unsigned char*> ttf_file_cache;
20
16
 
21
17
  auto& ttf_ptr = ttf_file_cache[make_pair(font_name, font_flags)];
22
18
  if (ttf_ptr) return ttf_ptr;
@@ -26,27 +22,27 @@ const unsigned char* Gosu::ttf_data_by_name(const string& font_name, unsigned fo
26
22
  static FcConfig* config = FcInitLoadConfigAndFonts();
27
23
  if (config) {
28
24
  FcPattern* pattern;
29
- // Our search pattern does not include weight or slant so that we can compromise on these.
30
- pattern = FcPatternBuild(nullptr,
31
- FC_FAMILY, FcTypeString, font_name.empty() ? "sans-serif" : font_name.c_str(),
32
- FC_OUTLINE, FcTypeBool, FcTrue, // exclude bitmap fonts
33
- nullptr);
25
+ // Our search pattern does not include weight or slant so that we can compromise on these.
26
+ pattern = FcPatternBuild(nullptr, FC_FAMILY, FcTypeString,
27
+ font_name.empty() ? "sans-serif" : font_name.c_str(), FC_OUTLINE,
28
+ FcTypeBool, FcTrue, // exclude bitmap fonts
29
+ nullptr);
34
30
 
35
31
  FcObjectSet* props = FcObjectSetBuild(FC_FILE, FC_WEIGHT, FC_SLANT, nullptr);
36
32
 
37
33
  if (FcFontSet* fonts = FcFontList(config, pattern, props)) {
38
34
  log("Looking for the best candidate among %d matching fonts", (int) fonts->nfont);
39
-
35
+
40
36
  // Among all matching fonts, find the variant that is the best fit for our font_flags.
41
- string best_filename;
37
+ std::string best_filename;
42
38
  int best_diff;
43
-
39
+
44
40
  for (int i = 0; i < fonts->nfont; ++i) {
45
41
  int weight, slant;
46
-
42
+
47
43
  FcPatternGetInteger(fonts->fonts[i], FC_WEIGHT, 0, &weight);
48
44
  FcPatternGetInteger(fonts->fonts[i], FC_SLANT, 0, &slant);
49
-
45
+
50
46
  // Difference between found font weight/slant and desired weight/slant.
51
47
  // Lower is better, so find the font with the lowest diff.
52
48
  int diff = 0;
@@ -62,14 +58,14 @@ const unsigned char* Gosu::ttf_data_by_name(const string& font_name, unsigned fo
62
58
  else {
63
59
  diff += abs(slant - FC_SLANT_ROMAN);
64
60
  }
65
-
61
+
66
62
  // Penalize OTF fonts since we are not really good at handling these.
67
- FcChar8 *file;
63
+ FcChar8* file;
68
64
  FcPatternGetString(fonts->fonts[i], FC_FILE, 0, &file);
69
65
  if (has_extension(reinterpret_cast<char*>(file), ".otf")) {
70
66
  diff += 10000;
71
67
  }
72
-
68
+
73
69
  if (best_filename.empty() || diff < best_diff) {
74
70
  best_filename = reinterpret_cast<char*>(file);
75
71
  best_diff = diff;
@@ -79,10 +75,10 @@ const unsigned char* Gosu::ttf_data_by_name(const string& font_name, unsigned fo
79
75
  log("Loading best candidate '%s'", best_filename.c_str());
80
76
  ttf_ptr = ttf_data_from_file(best_filename.c_str());
81
77
  }
82
-
78
+
83
79
  FcFontSetDestroy(fonts);
84
80
  }
85
-
81
+
86
82
  FcObjectSetDestroy(props);
87
83
  FcPatternDestroy(pattern);
88
84
  }
@@ -126,7 +122,7 @@ const unsigned char* Gosu::ttf_fallback_data()
126
122
  // Unifont has pretty good Unicode coverage, but looks extremely ugly.
127
123
  static const unsigned char* unifont = ttf_data_by_name("Unifont", 0);
128
124
  if (unifont) return unifont;
129
-
125
+
130
126
  // If none of the fonts above work, try to use the default sans-serif font.
131
127
  static const unsigned char* default_font = ttf_data_of_default_sans_serif_font();
132
128
  if (default_font) return default_font;
@@ -135,7 +131,7 @@ const unsigned char* Gosu::ttf_fallback_data()
135
131
  return ttf_data_from_file("/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf");
136
132
  }
137
133
 
138
- string Gosu::default_font_name()
134
+ std::string Gosu::default_font_name()
139
135
  {
140
136
  // Liberation Sans was designed to have the same metrics as Arial, which is the default
141
137
  // font on macOS and Windows.
@@ -143,4 +139,3 @@ string Gosu::default_font_name()
143
139
  }
144
140
 
145
141
  #endif
146
-
@@ -1,54 +1,54 @@
1
1
  #include <Gosu/Platform.hpp>
2
2
  #if defined(GOSU_IS_WIN)
3
3
 
4
- #include "TrueTypeFont.hpp"
5
4
  #include "Log.hpp"
5
+ #include "TrueTypeFont.hpp"
6
6
 
7
7
  #define _WIN32_WINNT 0x0500
8
- #include <windows.h>
9
-
10
- #include "WinUtility.hpp"
11
-
12
8
  #include <Gosu/IO.hpp>
13
9
  #include <Gosu/Text.hpp>
14
10
  #include <Gosu/Utility.hpp>
15
-
11
+ #include "WinUtility.hpp"
16
12
  #include <cstdlib>
17
13
  #include <cwchar>
18
14
  #include <map>
19
15
  #include <memory>
20
- using namespace std;
16
+ #include <windows.h>
21
17
 
22
- const unsigned char* Gosu::ttf_data_by_name(const string& font_name, unsigned font_flags)
18
+ const unsigned char* Gosu::ttf_data_by_name(const std::string& font_name, unsigned font_flags)
23
19
  {
24
20
  // TODO: Make this cache thread-safe.
25
- static map<pair<string, unsigned>, shared_ptr<Buffer>> ttf_file_cache;
26
-
21
+ static std::map<std::pair<std::string, unsigned>, std::shared_ptr<Buffer>> ttf_file_cache;
22
+
27
23
  auto& buffer_ptr = ttf_file_cache[make_pair(font_name, font_flags)];
28
24
  if (buffer_ptr) return static_cast<const unsigned char*>(buffer_ptr->data());
29
25
 
30
26
  log("Trying to find a font named '%s', flags=%x", font_name.c_str(), font_flags);
31
27
 
32
- LOGFONT logfont = {
33
- 0, 0, 0, 0,
34
- (font_flags & Gosu::FF_BOLD) ? FW_BOLD : FW_NORMAL,
35
- static_cast<BYTE>((font_flags & Gosu::FF_ITALIC) ? TRUE : FALSE),
36
- static_cast<BYTE>((font_flags & Gosu::FF_UNDERLINE) ? TRUE : FALSE),
37
- 0 /* no strikethrough */,
38
- ANSI_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
39
- DEFAULT_PITCH
40
- };
41
-
42
- wstring wfont_name = utf8_to_utf16(font_name);
43
- wcsncpy(logfont.lfFaceName, wfont_name.c_str(), LF_FACESIZE);
28
+ LOGFONT logfont = {0,
29
+ 0,
30
+ 0,
31
+ 0,
32
+ (font_flags & Gosu::FF_BOLD) ? FW_BOLD : FW_NORMAL,
33
+ static_cast<BYTE>((font_flags & Gosu::FF_ITALIC) ? TRUE : FALSE),
34
+ static_cast<BYTE>((font_flags & Gosu::FF_UNDERLINE) ? TRUE : FALSE),
35
+ 0 /* no strikethrough */,
36
+ ANSI_CHARSET,
37
+ OUT_OUTLINE_PRECIS,
38
+ CLIP_DEFAULT_PRECIS,
39
+ ANTIALIASED_QUALITY,
40
+ DEFAULT_PITCH};
41
+
42
+ std::wstring wfont_name = utf8_to_utf16(font_name);
43
+ std::wcsncpy(logfont.lfFaceName, wfont_name.c_str(), LF_FACESIZE);
44
44
  logfont.lfFaceName[LF_FACESIZE - 1] = 0;
45
-
45
+
46
46
  if (HFONT font = CreateFontIndirect(&logfont)) {
47
47
  if (HDC hdc = GetDC(0)) {
48
48
  HFONT last_font = (HFONT) SelectObject(hdc, (HGDIOBJ) font);
49
49
  auto ttf_buffer_size = GetFontData(hdc, 0, 0, nullptr, 0);
50
50
  if (ttf_buffer_size != GDI_ERROR) {
51
- auto buffer = make_shared<Gosu::Buffer>();
51
+ auto buffer = std::make_shared<Gosu::Buffer>();
52
52
  buffer->resize(ttf_buffer_size);
53
53
  if (GetFontData(hdc, 0, 0, buffer->data(), buffer->size()) != GDI_ERROR) {
54
54
  auto data = static_cast<const unsigned char*>(buffer->data());
@@ -75,18 +75,18 @@ const unsigned char* Gosu::ttf_fallback_data()
75
75
  // Prefer Arial Unicode MS as a fallback because it covers a lot of Unicode.
76
76
  static const unsigned char* arial_unicode = ttf_data_by_name("Arial Unicode MS", 0);
77
77
  if (arial_unicode) return arial_unicode;
78
-
78
+
79
79
  // Otherwise, just try to find *any* font.
80
80
  static const unsigned char* any_font = ttf_data_by_name("", 0);
81
81
  if (any_font) return any_font;
82
-
83
- static const char* windir = getenv("WINDIR");
84
- if (windir) return ttf_data_from_file(string(windir) + "/Fonts/arial.ttf");
85
-
82
+
83
+ static const char* windir = std::getenv("WINDIR");
84
+ if (windir) return ttf_data_from_file(std::string(windir) + "/Fonts/arial.ttf");
85
+
86
86
  return ttf_data_from_file("C:/Windows/Fonts/arial.ttf");
87
87
  }
88
88
 
89
- string Gosu::default_font_name()
89
+ std::string Gosu::default_font_name()
90
90
  {
91
91
  return "Arial";
92
92
  }
data/src/Window.cpp CHANGED
@@ -2,16 +2,16 @@
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;
14
+ #include <thread>
15
15
 
16
16
  namespace Gosu
17
17
  {
@@ -20,14 +20,15 @@ namespace Gosu
20
20
  void register_frame();
21
21
  }
22
22
 
23
- static void throw_sdl_error(const string& operation)
23
+ [[noreturn]] static void throw_sdl_error(const std::string& operation)
24
24
  {
25
25
  const char* error = SDL_GetError();
26
- throw runtime_error(operation + ": " + (error ? error : "(unknown error)"));
26
+ throw std::runtime_error{operation + ": " + (error ? error : "(unknown error)")};
27
27
  }
28
28
 
29
29
  SDL_Window* shared_window()
30
30
  {
31
+ // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
31
32
  static SDL_Window* window = nullptr;
32
33
  if (window == nullptr) {
33
34
  if (SDL_Init(SDL_INIT_VIDEO) < 0) {
@@ -36,8 +37,8 @@ namespace Gosu
36
37
 
37
38
  Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN | SDL_WINDOW_ALLOW_HIGHDPI;
38
39
 
39
- window =
40
- SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 64, 64, flags);
40
+ window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 64, 64,
41
+ flags);
41
42
  if (window == nullptr) {
42
43
  throw_sdl_error("Could not create window");
43
44
  }
@@ -50,10 +51,10 @@ namespace Gosu
50
51
  {
51
52
  static SDL_GLContext context = nullptr;
52
53
  if (context == nullptr) {
53
- #ifdef GOSU_IS_OPENGLES
54
+ #ifdef GOSU_IS_OPENGLES
54
55
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
55
56
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
56
- #endif
57
+ #endif
57
58
 
58
59
  context = SDL_GL_CreateContext(shared_window());
59
60
 
@@ -64,36 +65,41 @@ namespace Gosu
64
65
  return context;
65
66
  }
66
67
 
67
- void ensure_current_context()
68
+ void ensure_current_context() //
68
69
  {
69
70
  SDL_GL_MakeCurrent(shared_window(), shared_gl_context());
70
71
  }
71
72
  }
72
73
 
73
- struct Gosu::Window::Impl
74
+ struct Gosu::Window::Impl : Gosu::Noncopyable
74
75
  {
75
- bool fullscreen;
76
- double update_interval;
77
- bool resizable;
76
+ bool fullscreen = false;
77
+ double update_interval = 0;
78
+ bool resizable = false;
78
79
  bool resizing = false;
79
80
 
80
81
  // A single `bool open` is not good enough to support the tick() method: When close() is called
81
82
  // 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;
83
+ // from CLOSING to CLOSED), but the call after that must show the window again (transition from
84
+ // CLOSED to OPEN).
85
+ enum
86
+ {
87
+ CLOSED,
88
+ OPEN,
89
+ CLOSING
90
+ } state = CLOSED;
85
91
 
86
- unique_ptr<Graphics> graphics;
87
- unique_ptr<Input> input;
92
+ std::unique_ptr<Graphics> graphics;
93
+ std::unique_ptr<Input> input;
88
94
  };
89
95
 
90
96
  Gosu::Window::Window(int width, int height, unsigned window_flags, double update_interval)
91
- : pimpl(new Impl)
97
+ : m_impl(new Impl)
92
98
  {
93
99
  set_borderless(window_flags & WF_BORDERLESS);
94
100
  set_resizable(window_flags & WF_RESIZABLE);
95
101
 
96
- // Even in fullscreen mode, temporarily show the window in windowed mode to centre it.
102
+ // Even in fullscreen mode, temporarily show the window in windowed mode to center it.
97
103
  // This ensures that the window will be centered correctly when exiting fullscreen mode.
98
104
  // Fixes https://github.com/gosu/gosu/issues/369
99
105
  // (This will implicitly create graphics() and input(), and make the OpenGL context current.)
@@ -105,11 +111,11 @@ Gosu::Window::Window(int width, int height, unsigned window_flags, double update
105
111
 
106
112
  SDL_GL_SetSwapInterval(1);
107
113
 
108
- pimpl->update_interval = update_interval;
114
+ m_impl->update_interval = update_interval;
109
115
 
110
116
  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); };
117
+ input().on_button_up = [this](Button button) { button_up(button); };
118
+ input().on_gamepad_connected = [this](int index) { gamepad_connected(index); };
113
119
  input().on_gamepad_disconnected = [this](int index) { gamepad_disconnected(index); };
114
120
  }
115
121
 
@@ -130,12 +136,12 @@ int Gosu::Window::height() const
130
136
 
131
137
  bool Gosu::Window::fullscreen() const
132
138
  {
133
- return pimpl->fullscreen;
139
+ return m_impl->fullscreen;
134
140
  }
135
141
 
136
142
  void Gosu::Window::resize(int width, int height, bool fullscreen)
137
143
  {
138
- pimpl->fullscreen = fullscreen;
144
+ m_impl->fullscreen = fullscreen;
139
145
 
140
146
  int actual_width = width;
141
147
  int actual_height = height;
@@ -144,19 +150,19 @@ void Gosu::Window::resize(int width, int height, bool fullscreen)
144
150
  double black_bar_height = 0;
145
151
 
146
152
  if (fullscreen) {
147
- actual_width = Gosu::screen_width(this);
153
+ actual_width = Gosu::screen_width(this);
148
154
  actual_height = Gosu::screen_height(this);
149
155
 
150
156
  if (resizable()) {
151
157
  // Resizable fullscreen windows stubbornly follow the desktop resolution.
152
- width = actual_width;
158
+ width = actual_width;
153
159
  height = actual_height;
154
160
  }
155
161
  else {
156
162
  // Scale the window to fill the desktop resolution.
157
163
  double scale_x = 1.0 * actual_width / width;
158
164
  double scale_y = 1.0 * actual_height / height;
159
- scale_factor = min(scale_x, scale_y);
165
+ scale_factor = std::min(scale_x, scale_y);
160
166
  // Add black bars to preserve the aspect ratio, if necessary.
161
167
  if (scale_x < scale_y) {
162
168
  black_bar_height = (actual_height / scale_x - height) / 2;
@@ -167,24 +173,24 @@ void Gosu::Window::resize(int width, int height, bool fullscreen)
167
173
  }
168
174
  }
169
175
  else {
170
- int max_width = Gosu::available_width(this);
176
+ int max_width = Gosu::available_width(this);
171
177
  int max_height = Gosu::available_height(this);
172
178
 
173
179
  if (resizable()) {
174
180
  // 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);
181
+ width = actual_width = std::min(width, max_width);
182
+ height = actual_height = std::min(height, max_height);
177
183
  }
178
184
  else if (width > max_width || height > max_height) {
179
185
  // 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;
186
+ scale_factor = std::min(1.0 * max_width / width, 1.0 * max_height / height);
187
+ actual_width = static_cast<int>(width * scale_factor);
188
+ actual_height = static_cast<int>(height * scale_factor);
183
189
  }
184
190
  }
185
191
 
186
192
  SDL_SetWindowFullscreen(shared_window(), fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
187
- if (!pimpl->resizing) {
193
+ if (!m_impl->resizing) {
188
194
  SDL_SetWindowSize(shared_window(), actual_width, actual_height);
189
195
  }
190
196
 
@@ -192,37 +198,39 @@ void Gosu::Window::resize(int width, int height, bool fullscreen)
192
198
 
193
199
  ensure_current_context();
194
200
 
195
- if (!pimpl->graphics) {
196
- pimpl->graphics.reset(new Graphics(actual_width, actual_height));
201
+ if (!m_impl->graphics) {
202
+ m_impl->graphics.reset(new Graphics(actual_width, actual_height));
197
203
  }
198
204
  else {
199
- pimpl->graphics->set_physical_resolution(actual_width, actual_height);
205
+ m_impl->graphics->set_physical_resolution(actual_width, actual_height);
200
206
  }
201
- pimpl->graphics->set_resolution(width, height, black_bar_width, black_bar_height);
207
+ m_impl->graphics->set_resolution(width, height, black_bar_width, black_bar_height);
202
208
 
203
- if (!pimpl->input) {
204
- pimpl->input.reset(new Input(shared_window()));
209
+ if (!m_impl->input) {
210
+ m_impl->input.reset(new Input(shared_window()));
205
211
  }
206
- pimpl->input->set_mouse_factors(1 / scale_factor, 1 / scale_factor,
207
- black_bar_width, black_bar_height);
212
+ m_impl->input->set_mouse_factors(1 / scale_factor, 1 / scale_factor, black_bar_width,
213
+ black_bar_height);
208
214
  }
209
215
 
210
216
  bool Gosu::Window::resizable() const
211
217
  {
212
- return pimpl->resizable;
218
+ return m_impl->resizable;
213
219
  }
214
220
 
215
221
  void Gosu::Window::set_resizable(bool resizable)
216
222
  {
217
- pimpl->resizable = resizable;
223
+ m_impl->resizable = resizable;
218
224
  SDL_SetWindowResizable(shared_window(), resizable ? SDL_TRUE : SDL_FALSE);
219
225
  }
220
226
 
227
+ // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
221
228
  bool Gosu::Window::borderless() const
222
229
  {
223
230
  return SDL_GetWindowFlags(shared_window()) & SDL_WINDOW_BORDERLESS;
224
231
  }
225
232
 
233
+ // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
226
234
  void Gosu::Window::set_borderless(bool borderless)
227
235
  {
228
236
  SDL_SetWindowBordered(shared_window(), borderless ? SDL_FALSE : SDL_TRUE);
@@ -230,21 +238,23 @@ void Gosu::Window::set_borderless(bool borderless)
230
238
 
231
239
  double Gosu::Window::update_interval() const
232
240
  {
233
- return pimpl->update_interval;
241
+ return m_impl->update_interval;
234
242
  }
235
243
 
236
244
  void Gosu::Window::set_update_interval(double update_interval)
237
245
  {
238
- pimpl->update_interval = update_interval;
246
+ m_impl->update_interval = update_interval;
239
247
  }
240
248
 
241
- string Gosu::Window::caption() const
249
+ // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
250
+ std::string Gosu::Window::caption() const
242
251
  {
243
252
  const char* title = SDL_GetWindowTitle(shared_window());
244
253
  return title ? title : "";
245
254
  }
246
255
 
247
- void Gosu::Window::set_caption(const string& caption)
256
+ // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
257
+ void Gosu::Window::set_caption(const std::string& caption)
248
258
  {
249
259
  SDL_SetWindowTitle(shared_window(), caption.c_str());
250
260
  }
@@ -263,17 +273,18 @@ void Gosu::Window::show()
263
273
  try {
264
274
  while (tick()) {
265
275
  // Sleep to keep this loop from eating 100% CPU.
266
- unsigned long tick_time = milliseconds() - time_before_tick;
267
- if (tick_time < update_interval()) {
268
- sleep(update_interval() - tick_time);
276
+ long tick_time = milliseconds() - time_before_tick;
277
+ long sleep_time = static_cast<long>(update_interval() - tick_time);
278
+ if (sleep_time >= 1) {
279
+ std::this_thread::sleep_for(std::chrono::milliseconds{sleep_time});
269
280
  }
270
281
 
271
282
  time_before_tick = milliseconds();
272
283
  }
273
284
  } catch (...) {
274
- #ifdef GOSU_IS_WIN
285
+ #ifdef GOSU_IS_WIN
275
286
  if (previous_affinity) SetThreadAffinityMask(GetCurrentThread(), previous_affinity);
276
- #endif
287
+ #endif
277
288
  throw;
278
289
  }
279
290
 
@@ -281,19 +292,19 @@ void Gosu::Window::show()
281
292
  if (previous_affinity) SetThreadAffinityMask(GetCurrentThread(), previous_affinity);
282
293
  #endif
283
294
 
284
- pimpl->state = Impl::CLOSED;
295
+ m_impl->state = Impl::CLOSED;
285
296
  }
286
297
 
287
298
  bool Gosu::Window::tick()
288
299
  {
289
- if (pimpl->state == Impl::CLOSING) {
290
- pimpl->state = Impl::CLOSED;
300
+ if (m_impl->state == Impl::CLOSING) {
301
+ m_impl->state = Impl::CLOSED;
291
302
  return false;
292
303
  }
293
304
 
294
- if (pimpl->state == Impl::CLOSED) {
305
+ if (m_impl->state == Impl::CLOSED) {
295
306
  SDL_ShowWindow(shared_window());
296
- pimpl->state = Impl::OPEN;
307
+ m_impl->state = Impl::OPEN;
297
308
 
298
309
  // SDL_GL_GetDrawableSize returns different values before and after showing the window.
299
310
  // -> When first showing the window, update the physical size of Graphics (=glViewport).
@@ -305,15 +316,15 @@ bool Gosu::Window::tick()
305
316
 
306
317
  SDL_Event e;
307
318
  while (SDL_PollEvent(&e)) {
308
-
309
319
  switch (e.type) {
310
320
  case SDL_WINDOWEVENT: {
311
321
  switch (e.window.event) {
312
322
  case SDL_WINDOWEVENT_SIZE_CHANGED: {
313
- if (pimpl->resizable && (width() != e.window.data1 || height() != e.window.data2)) {
314
- pimpl->resizing = true;
323
+ if (m_impl->resizable &&
324
+ (width() != e.window.data1 || height() != e.window.data2)) {
325
+ m_impl->resizing = true;
315
326
  resize(e.window.data1, e.window.data2, fullscreen());
316
- pimpl->resizing = false;
327
+ m_impl->resizing = false;
317
328
  }
318
329
  break;
319
330
  }
@@ -336,10 +347,9 @@ bool Gosu::Window::tick()
336
347
  break;
337
348
  }
338
349
  case SDL_DROPFILE: {
339
- char* dropped_filedir = e.drop.file;
340
- if (dropped_filedir == nullptr) break;
341
- drop(string(dropped_filedir));
342
- SDL_free(dropped_filedir);
350
+ std::shared_ptr<char> dropped_file{e.drop.file, SDL_free};
351
+ if (dropped_file == nullptr) break;
352
+ drop(dropped_file.get());
343
353
  break;
344
354
  }
345
355
  default: {
@@ -367,16 +377,16 @@ bool Gosu::Window::tick()
367
377
  SDL_GL_SwapWindow(shared_window());
368
378
  }
369
379
 
370
- if (pimpl->state == Impl::CLOSING) {
371
- pimpl->state = Impl::CLOSED;
380
+ if (m_impl->state == Impl::CLOSING) {
381
+ m_impl->state = Impl::CLOSED;
372
382
  }
373
383
 
374
- return pimpl->state == Impl::OPEN;
384
+ return m_impl->state == Impl::OPEN;
375
385
  }
376
386
 
377
387
  void Gosu::Window::close()
378
388
  {
379
- pimpl->state = Impl::CLOSING;
389
+ m_impl->state = Impl::CLOSING;
380
390
  SDL_HideWindow(shared_window());
381
391
  }
382
392
 
@@ -389,23 +399,23 @@ void Gosu::Window::button_down(Button button)
389
399
  #ifdef GOSU_IS_MAC
390
400
  // cmd+F and cmd+ctrl+F are both common shortcuts for toggling fullscreen mode on macOS.
391
401
  toggle_fullscreen = button == KB_F &&
392
- (Input::down(KB_LEFT_META) || Input::down(KB_RIGHT_META)) &&
393
- !Input::down(KB_LEFT_SHIFT) && !Input::down(KB_RIGHT_SHIFT) &&
394
- !Input::down(KB_LEFT_ALT) && !Input::down(KB_RIGHT_ALT);
402
+ (Input::down(KB_LEFT_META) || Input::down(KB_RIGHT_META)) &&
403
+ !Input::down(KB_LEFT_SHIFT) && !Input::down(KB_RIGHT_SHIFT) &&
404
+ !Input::down(KB_LEFT_ALT) && !Input::down(KB_RIGHT_ALT);
395
405
  #else
396
406
  // Alt+Enter and Alt+Return toggle fullscreen mode on all other platforms.
397
407
  toggle_fullscreen = (button == KB_RETURN || button == KB_ENTER) &&
398
- (Input::down(KB_LEFT_ALT) || Input::down(KB_RIGHT_ALT)) &&
399
- !Input::down(KB_LEFT_CONTROL) && !Input::down(KB_RIGHT_CONTROL) &&
400
- !Input::down(KB_LEFT_META) && !Input::down(KB_RIGHT_META) &&
401
- !Input::down(KB_LEFT_SHIFT) && !Input::down(KB_RIGHT_SHIFT);
408
+ (Input::down(KB_LEFT_ALT) || Input::down(KB_RIGHT_ALT)) &&
409
+ !Input::down(KB_LEFT_CONTROL) && !Input::down(KB_RIGHT_CONTROL) &&
410
+ !Input::down(KB_LEFT_META) && !Input::down(KB_RIGHT_META) &&
411
+ !Input::down(KB_LEFT_SHIFT) && !Input::down(KB_RIGHT_SHIFT);
402
412
  #endif
403
413
  // F11 is supported as a shortcut for fullscreen mode on all platforms.
404
- if (!toggle_fullscreen && button == KB_F11 &&
405
- !Input::down(KB_LEFT_ALT) && !Input::down(KB_RIGHT_ALT) &&
406
- !Input::down(KB_LEFT_CONTROL) && !Input::down(KB_RIGHT_CONTROL) &&
407
- !Input::down(KB_LEFT_META) && !Input::down(KB_RIGHT_META) &&
408
- !Input::down(KB_LEFT_SHIFT) && !Input::down(KB_RIGHT_SHIFT)) {
414
+ if (!toggle_fullscreen && button == KB_F11 && !Input::down(KB_LEFT_ALT) &&
415
+ !Input::down(KB_RIGHT_ALT) && !Input::down(KB_LEFT_CONTROL) &&
416
+ !Input::down(KB_RIGHT_CONTROL) && !Input::down(KB_LEFT_META) &&
417
+ !Input::down(KB_RIGHT_META) && !Input::down(KB_LEFT_SHIFT) &&
418
+ !Input::down(KB_RIGHT_SHIFT)) {
409
419
  toggle_fullscreen = true;
410
420
  }
411
421
 
@@ -416,22 +426,22 @@ void Gosu::Window::button_down(Button button)
416
426
 
417
427
  const Gosu::Graphics& Gosu::Window::graphics() const
418
428
  {
419
- return *pimpl->graphics;
429
+ return *m_impl->graphics;
420
430
  }
421
431
 
422
432
  Gosu::Graphics& Gosu::Window::graphics()
423
433
  {
424
- return *pimpl->graphics;
434
+ return *m_impl->graphics;
425
435
  }
426
436
 
427
437
  const Gosu::Input& Gosu::Window::input() const
428
438
  {
429
- return *pimpl->input;
439
+ return *m_impl->input;
430
440
  }
431
441
 
432
442
  Gosu::Input& Gosu::Window::input()
433
443
  {
434
- return *pimpl->input;
444
+ return *m_impl->input;
435
445
  }
436
446
 
437
447
  #endif