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/Bitmap.cpp CHANGED
@@ -31,20 +31,20 @@ void Gosu::Bitmap::resize(int width, int height, Color c)
31
31
 
32
32
  void Gosu::Bitmap::blend_pixel(int x, int y, Color c)
33
33
  {
34
- if (c.alpha() == 0) return;
34
+ if (c.alpha == 0) return;
35
35
 
36
36
  Color out = get_pixel(x, y);
37
- if (out.alpha() == 0) {
37
+ if (out.alpha == 0) {
38
38
  set_pixel(x, y, c);
39
39
  return;
40
40
  }
41
41
 
42
- int inv_alpha = out.alpha() * (255 - c.alpha()) / 255;
42
+ int inv_alpha = out.alpha * (255 - c.alpha) / 255;
43
43
 
44
- out.set_alpha(c.alpha() + inv_alpha);
45
- out.set_red ((c.red() * c.alpha() + out.red() * inv_alpha) / out.alpha());
46
- out.set_green((c.green() * c.alpha() + out.green() * inv_alpha) / out.alpha());
47
- out.set_blue ((c.blue() * c.alpha() + out.blue() * inv_alpha) / out.alpha());
44
+ out.alpha = (c.alpha + inv_alpha);
45
+ out.red = ((c.red * c.alpha + out.red * inv_alpha) / out.alpha);
46
+ out.green = ((c.green * c.alpha + out.green * inv_alpha) / out.alpha);
47
+ out.blue = ((c.blue * c.alpha + out.blue * inv_alpha) / out.alpha);
48
48
 
49
49
  set_pixel(x, y, out);
50
50
  }
@@ -108,9 +108,9 @@ void Gosu::apply_color_key(Bitmap& bitmap, Color key)
108
108
  auto visit = [&](Color c) {
109
109
  if (c != key) {
110
110
  neighbors += 1;
111
- red += c.red();
112
- green += c.green();
113
- blue += c.blue();
111
+ red += c.red;
112
+ green += c.green;
113
+ blue += c.blue;
114
114
  }
115
115
  };
116
116
 
@@ -121,9 +121,9 @@ void Gosu::apply_color_key(Bitmap& bitmap, Color key)
121
121
 
122
122
  Color replacement = Color::NONE;
123
123
  if (neighbors > 0) {
124
- replacement.set_red(red / neighbors);
125
- replacement.set_green(green / neighbors);
126
- replacement.set_blue(blue / neighbors);
124
+ replacement.red = red / neighbors;
125
+ replacement.green = green / neighbors;
126
+ replacement.blue = blue / neighbors;
127
127
  }
128
128
  bitmap.set_pixel(x, y, replacement);
129
129
  }
data/src/BitmapIO.cpp CHANGED
@@ -7,18 +7,8 @@
7
7
  #define STBI_NO_STDIO
8
8
  #define STBI_NO_LINEAR
9
9
 
10
- // Disable comma warnings in stb headers.
11
- #ifdef __GNUC__
12
- #pragma GCC diagnostic push
13
- #pragma GCC diagnostic ignored "-Wcomma"
14
- #endif
15
-
16
10
  #include <stb_image.h>
17
11
 
18
- #ifdef __GNUC__
19
- #pragma GCC diagnostic pop
20
- #endif
21
-
22
12
  static int read_callback(void* user, char* data, int size)
23
13
  {
24
14
  Gosu::Reader* reader = static_cast<Gosu::Reader*>(user);
@@ -82,19 +72,9 @@ Gosu::Bitmap Gosu::load_image_file(Reader input)
82
72
  return bitmap;
83
73
  }
84
74
 
85
- // Disable comma warnings in stb headers.
86
- #ifdef __GNUC__
87
- #pragma GCC diagnostic push
88
- #pragma GCC diagnostic ignored "-Wcomma"
89
- #endif
90
-
91
75
  #define STB_IMAGE_WRITE_IMPLEMENTATION
92
76
  #include <stb_image_write.h>
93
77
 
94
- #ifdef __GNUC__
95
- #pragma GCC diagnostic pop
96
- #endif
97
-
98
78
  void Gosu::save_image_file(const Gosu::Bitmap& bitmap, const std::string& filename)
99
79
  {
100
80
  int ok;
@@ -1,9 +1,10 @@
1
+ #include <Gosu/Utility.hpp>
1
2
  #include "BlockAllocator.hpp"
2
3
  #include <stdexcept>
3
4
  #include <vector>
4
5
  using namespace std;
5
6
 
6
- struct Gosu::BlockAllocator::Impl
7
+ struct Gosu::BlockAllocator::Impl : Gosu::Noncopyable
7
8
  {
8
9
  unsigned width, height;
9
10
 
data/src/Channel.cpp CHANGED
@@ -1,8 +1,8 @@
1
1
  #include <Gosu/Audio.hpp>
2
2
  #include "AudioImpl.hpp"
3
- using namespace std;
3
+ #include <algorithm>
4
4
 
5
- // Returns the current state of a source
5
+ /// Returns the current state of a source.
6
6
  static ALint state(int& channel)
7
7
  {
8
8
  ALint state;
@@ -14,41 +14,43 @@ static ALint state(int& channel)
14
14
  }
15
15
 
16
16
  Gosu::Channel::Channel()
17
- : channel(NO_CHANNEL), token(0)
17
+ : m_channel{NO_CHANNEL},
18
+ m_token{0}
18
19
  {
19
20
  }
20
21
 
21
22
  Gosu::Channel::Channel(int channel, int token)
22
- : channel(channel), token(token)
23
+ : m_channel{channel},
24
+ m_token{token}
23
25
  {
24
26
  }
25
27
 
26
28
  int Gosu::Channel::current_channel() const
27
29
  {
28
- if (channel != NO_CHANNEL && channel_expired(channel, token)) {
29
- channel = NO_CHANNEL;
30
+ if (m_channel != NO_CHANNEL && channel_expired(m_channel, m_token)) {
31
+ m_channel = NO_CHANNEL;
30
32
  }
31
- return channel;
33
+ return m_channel;
32
34
  }
33
35
 
34
36
  bool Gosu::Channel::playing() const
35
37
  {
36
38
  if (current_channel() == NO_CHANNEL) return false;
37
-
38
- return state(channel) == AL_PLAYING;
39
+
40
+ return state(m_channel) == AL_PLAYING;
39
41
  }
40
42
 
41
43
  bool Gosu::Channel::paused() const
42
44
  {
43
45
  if (current_channel() == NO_CHANNEL) return false;
44
46
 
45
- return state(channel) == AL_PAUSED;
47
+ return state(m_channel) == AL_PAUSED;
46
48
  }
47
49
 
48
50
  void Gosu::Channel::pause()
49
51
  {
50
52
  if (playing()) {
51
- ALuint source = al_source_for_channel(channel);
53
+ ALuint source = al_source_for_channel(m_channel);
52
54
  alSourcePause(source);
53
55
  }
54
56
  }
@@ -56,7 +58,7 @@ void Gosu::Channel::pause()
56
58
  void Gosu::Channel::resume()
57
59
  {
58
60
  if (paused()) {
59
- ALuint source = al_source_for_channel(channel);
61
+ ALuint source = al_source_for_channel(m_channel);
60
62
  alSourcePlay(source);
61
63
  }
62
64
  }
@@ -65,31 +67,31 @@ void Gosu::Channel::stop()
65
67
  {
66
68
  if (current_channel() == NO_CHANNEL) return;
67
69
 
68
- ALuint source = al_source_for_channel(channel);
70
+ ALuint source = al_source_for_channel(m_channel);
69
71
  alSourceStop(source);
70
- channel = NO_CHANNEL;
72
+ m_channel = NO_CHANNEL;
71
73
  }
72
74
 
73
75
  void Gosu::Channel::set_volume(double volume)
74
76
  {
75
77
  if (current_channel() == NO_CHANNEL) return;
76
78
 
77
- ALuint source = al_source_for_channel(channel);
78
- alSourcef(source, AL_GAIN, max(volume, 0.0));
79
+ ALuint source = al_source_for_channel(m_channel);
80
+ alSourcef(source, AL_GAIN, static_cast<ALfloat>(std::max(volume, 0.0)));
79
81
  }
80
82
 
81
83
  void Gosu::Channel::set_pan(double pan)
82
84
  {
83
85
  if (current_channel() == NO_CHANNEL) return;
84
86
 
85
- ALuint source = al_source_for_channel(channel);
86
- alSource3f(source, AL_POSITION, pan * 10, 0, 0);
87
+ ALuint source = al_source_for_channel(m_channel);
88
+ alSource3f(source, AL_POSITION, static_cast<ALfloat>(pan * 10), 0, 0);
87
89
  }
88
90
 
89
91
  void Gosu::Channel::set_speed(double speed)
90
92
  {
91
93
  if (current_channel() == NO_CHANNEL) return;
92
94
 
93
- ALuint source = al_source_for_channel(channel);
94
- alSourcef(source, AL_PITCH, speed);
95
+ ALuint source = al_source_for_channel(m_channel);
96
+ alSourcef(source, AL_PITCH, static_cast<ALfloat>(speed));
95
97
  }
data/src/Color.cpp CHANGED
@@ -1,35 +1,38 @@
1
1
  #include <Gosu/Color.hpp>
2
2
  #include <Gosu/Math.hpp>
3
- #include <cmath>
4
3
  #include <algorithm>
4
+ #include <cmath>
5
5
 
6
6
  namespace
7
7
  {
8
- struct HSV { double h, s, v; };
9
-
8
+ struct HSV
9
+ {
10
+ double h, s, v;
11
+ };
12
+
10
13
  HSV color_to_hsv(const Gosu::Color& c)
11
14
  {
12
- double r = c.red() / 255.0;
13
- double g = c.green() / 255.0;
14
- double b = c.blue() / 255.0;
15
-
15
+ double r = c.red / 255.0;
16
+ double g = c.green / 255.0;
17
+ double b = c.blue / 255.0;
18
+
16
19
  double min = std::min(std::min(r, g), b);
17
20
  double max = std::max(std::max(r, g), b);
18
21
  double delta = max - min;
19
22
 
20
23
  if (max == 0) {
21
- HSV hsv = { 0, 0, 0 };
24
+ HSV hsv = {0, 0, 0};
22
25
  return hsv;
23
26
  }
24
-
25
- HSV hsv;
27
+
28
+ HSV hsv{};
26
29
 
27
30
  // Value.
28
31
  hsv.v = max;
29
-
32
+
30
33
  // Saturation.
31
34
  hsv.s = delta / max;
32
-
35
+
33
36
  // Hue.
34
37
  if (delta == 0) {
35
38
  hsv.h = 0;
@@ -44,44 +47,39 @@ namespace
44
47
  hsv.h = (r - g) / delta + 4;
45
48
  }
46
49
  hsv.h *= 60;
47
-
50
+
48
51
  return hsv;
49
52
  }
50
53
  }
51
54
 
52
55
  Gosu::Color Gosu::Color::from_hsv(double h, double s, double v)
53
- {
54
- return from_ahsv(255, h, s, v);
55
- }
56
-
57
- Gosu::Color Gosu::Color::from_ahsv(Channel alpha, double h, double s, double v)
58
56
  {
59
57
  // Normalize hue so that is always in the [0, 360) range and wraps around.
60
58
  h = normalize_angle(h);
61
59
  // Clamp s and v for consistency with the Ruby/Gosu ARGB getters/setters.
62
- s = clamp(s, 0.0, 1.0);
63
- v = clamp(v, 0.0, 1.0);
64
-
60
+ s = std::clamp(s, 0.0, 1.0);
61
+ v = std::clamp(v, 0.0, 1.0);
62
+
65
63
  int sector = static_cast<int>(h / 60);
66
64
  double factorial = h / 60 - sector;
67
-
68
- double p = v * (1 - s);
69
- double q = v * (1 - s * factorial);
70
- double t = v * (1 - s * (1 - factorial));
71
-
65
+
66
+ Channel p = static_cast<Channel>(255 * v * (1 - s));
67
+ Channel q = static_cast<Channel>(255 * v * (1 - s * factorial));
68
+ Channel t = static_cast<Channel>(255 * v * (1 - s * (1 - factorial)));
69
+
72
70
  switch (sector) {
73
71
  case 0:
74
- return Color(alpha, v * 255, t * 255, p * 255);
72
+ return Color{static_cast<Channel>(255 * v), t, p};
75
73
  case 1:
76
- return Color(alpha, q * 255, v * 255, p * 255);
74
+ return Color{q, static_cast<Channel>(255 * v), p};
77
75
  case 2:
78
- return Color(alpha, p * 255, v * 255, t * 255);
76
+ return Color{p, static_cast<Channel>(255 * v), t};
79
77
  case 3:
80
- return Color(alpha, p * 255, q * 255, v * 255);
78
+ return Color{p, q, static_cast<Channel>(255 * v)};
81
79
  case 4:
82
- return Color(alpha, t * 255, p * 255, v * 255);
80
+ return Color{t, p, static_cast<Channel>(255 * v)};
83
81
  default: // sector 5
84
- return Color(alpha, v * 255, p * 255, q * 255);
82
+ return Color{static_cast<Channel>(255 * v), p, q};
85
83
  }
86
84
  }
87
85
 
@@ -92,7 +90,7 @@ double Gosu::Color::hue() const
92
90
 
93
91
  void Gosu::Color::set_hue(double h)
94
92
  {
95
- *this = from_ahsv(alpha(), h, saturation(), value());
93
+ *this = from_hsv(h, saturation(), value()).with_alpha(alpha);
96
94
  }
97
95
 
98
96
  double Gosu::Color::saturation() const
@@ -102,7 +100,7 @@ double Gosu::Color::saturation() const
102
100
 
103
101
  void Gosu::Color::set_saturation(double s)
104
102
  {
105
- *this = from_ahsv(alpha(), hue(), s, value());
103
+ *this = from_hsv(hue(), s, value()).with_alpha(alpha);
106
104
  }
107
105
 
108
106
  double Gosu::Color::value() const
@@ -112,33 +110,42 @@ double Gosu::Color::value() const
112
110
 
113
111
  void Gosu::Color::set_value(double v)
114
112
  {
115
- *this = from_ahsv(alpha(), hue(), saturation(), v);
113
+ *this = from_hsv(hue(), saturation(), v).with_alpha(alpha);
116
114
  }
117
115
 
118
- Gosu::Color Gosu::interpolate(Color a, Color b, double weight)
116
+ Gosu::Color Gosu::lerp(Color a, Color b, double t)
119
117
  {
120
- return Color(clamp<long>(round(interpolate(a.alpha(), b.alpha(), weight)), 0, 255),
121
- clamp<long>(round(interpolate(a.red(), b.red(), weight)), 0, 255),
122
- clamp<long>(round(interpolate(a.green(), b.green(), weight)), 0, 255),
123
- clamp<long>(round(interpolate(a.blue(), b.blue(), weight)), 0, 255));
118
+ const auto lerp_channel = [](Color::Channel a, Color::Channel b, double t) {
119
+ return static_cast<Color::Channel>(std::clamp(std::round(lerp(a, b, t)), 0.0, 255.0));
120
+ };
121
+
122
+ Color result;
123
+ result.red = lerp_channel(a.red, b.red, t);
124
+ result.green = lerp_channel(a.green, b.green, t);
125
+ result.blue = lerp_channel(a.blue, b.blue, t);
126
+ result.alpha = lerp_channel(a.alpha, b.alpha, t);
127
+ return result;
124
128
  }
125
129
 
126
130
  Gosu::Color Gosu::multiply(Color a, Color b)
127
131
  {
128
- return Color(round(a.alpha() * b.alpha() / 255.0),
129
- round(a.red() * b.red() / 255.0),
130
- round(a.green() * b.green() / 255.0),
131
- round(a.blue() * b.blue() / 255.0));
132
+ Color result;
133
+ result.red = static_cast<Color::Channel>(std::round(a.red * b.red / 255.0));
134
+ result.green = static_cast<Color::Channel>(std::round(a.green * b.green / 255.0));
135
+ result.blue = static_cast<Color::Channel>(std::round(a.blue * b.blue / 255.0));
136
+ result.alpha = static_cast<Color::Channel>(std::round(a.alpha * b.alpha / 255.0));
137
+ return result;
132
138
  }
133
139
 
134
- const Gosu::Color Gosu::Color::NONE (0x00000000);
135
- const Gosu::Color Gosu::Color::BLACK (0xff000000);
136
- const Gosu::Color Gosu::Color::GRAY (0xff808080);
137
- const Gosu::Color Gosu::Color::WHITE (0xffffffff);
138
- const Gosu::Color Gosu::Color::AQUA (0xff00ffff);
139
- const Gosu::Color Gosu::Color::RED (0xffff0000);
140
- const Gosu::Color Gosu::Color::GREEN (0xff00ff00);
141
- const Gosu::Color Gosu::Color::BLUE (0xff0000ff);
142
- const Gosu::Color Gosu::Color::YELLOW (0xffffff00);
143
- const Gosu::Color Gosu::Color::FUCHSIA (0xffff00ff);
144
- const Gosu::Color Gosu::Color::CYAN (0xff00ffff);
140
+ const Gosu::Color Gosu::Color::NONE{0x00'000000};
141
+ const Gosu::Color Gosu::Color::BLACK{0, 0, 0};
142
+ const Gosu::Color Gosu::Color::GRAY{128, 128, 128};
143
+ const Gosu::Color Gosu::Color::WHITE{255, 255, 255};
144
+
145
+ const Gosu::Color Gosu::Color::AQUA{0, 255, 255};
146
+ const Gosu::Color Gosu::Color::RED{255, 0, 0};
147
+ const Gosu::Color Gosu::Color::GREEN{0, 255, 0};
148
+ const Gosu::Color Gosu::Color::BLUE{0, 0, 255};
149
+ const Gosu::Color Gosu::Color::YELLOW{255, 255, 0};
150
+ const Gosu::Color Gosu::Color::FUCHSIA{255, 0, 255};
151
+ const Gosu::Color Gosu::Color::CYAN{0, 255, 255};
@@ -8,43 +8,41 @@ namespace Gosu
8
8
  class EmptyImageData : public ImageData
9
9
  {
10
10
  public:
11
- int width() const override
11
+ int width() const override //
12
12
  {
13
13
  return 0;
14
14
  }
15
-
16
- int height() const override
15
+
16
+ int height() const override //
17
17
  {
18
18
  return 0;
19
19
  }
20
-
21
- void draw(double, double, Color,
22
- double, double, Color,
23
- double, double, Color,
24
- double, double, Color,
25
- ZPos, AlphaMode) const override
20
+
21
+ void draw(double, double, Color, double, double, Color, //
22
+ double, double, Color, double, double, Color, //
23
+ ZPos, BlendMode) const override
26
24
  {
27
25
  }
28
-
29
- GLTexInfo* gl_tex_info() const override
26
+
27
+ GLTexInfo* gl_tex_info() const override //
30
28
  {
31
29
  return nullptr;
32
30
  }
33
-
34
- Bitmap to_bitmap() const override
31
+
32
+ Bitmap to_bitmap() const override //
35
33
  {
36
34
  return Bitmap();
37
35
  }
38
-
39
- virtual std::unique_ptr<ImageData> subimage(int, int, int, int) const override
36
+
37
+ std::unique_ptr<ImageData> subimage(int, int, int, int) const override //
40
38
  {
41
39
  return nullptr;
42
40
  }
43
-
44
- virtual void insert(const Bitmap&, int x, int y) override
41
+
42
+ void insert(const Bitmap&, int x, int y) override //
45
43
  {
46
44
  }
47
-
45
+
48
46
  static const std::shared_ptr<EmptyImageData>& instance_ptr()
49
47
  {
50
48
  static std::shared_ptr<EmptyImageData> instance = std::make_shared<EmptyImageData>();
data/src/FileUnix.cpp CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
  using namespace std;
18
18
 
19
- struct Gosu::File::Impl
19
+ struct Gosu::File::Impl : Gosu::Noncopyable
20
20
  {
21
21
  int fd = -1;
22
22
  void* mapping = MAP_FAILED;
data/src/FileWin.cpp CHANGED
@@ -9,7 +9,7 @@ using namespace std;
9
9
 
10
10
  // TODO: Error checking
11
11
 
12
- struct Gosu::File::Impl
12
+ struct Gosu::File::Impl : Gosu::Noncopyable
13
13
  {
14
14
  HANDLE handle = INVALID_HANDLE_VALUE;
15
15