gosu 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) 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 +19 -11
  140. data/include/Gosu/Font.hpp +40 -44
  141. data/include/Gosu/Graphics.hpp +58 -71
  142. data/include/Gosu/GraphicsBase.hpp +26 -33
  143. data/include/Gosu/Image.hpp +56 -62
  144. data/include/Gosu/ImageData.hpp +23 -27
  145. data/include/Gosu/Inspection.hpp +1 -4
  146. data/include/Gosu/TextInput.hpp +34 -40
  147. data/include/Gosu/Version.hpp +1 -1
  148. data/include/Gosu/Window.hpp +71 -70
  149. data/lib/SDL2.dll +0 -0
  150. data/lib/gosu/compat.rb +24 -37
  151. data/lib/gosu.rb +2 -2
  152. data/lib64/SDL2.dll +0 -0
  153. data/src/Audio.cpp +86 -86
  154. data/src/AudioFile.hpp +6 -6
  155. data/src/AudioFileAudioToolbox.cpp +1 -1
  156. data/src/AudioFileSDLSound.cpp +1 -1
  157. data/src/AudioImpl.hpp +5 -5
  158. data/src/BitmapIO.cpp +0 -20
  159. data/src/BlockAllocator.cpp +2 -1
  160. data/src/Channel.cpp +22 -20
  161. data/src/Color.cpp +12 -9
  162. data/src/EmptyImageData.hpp +15 -17
  163. data/src/FileUnix.cpp +1 -1
  164. data/src/FileWin.cpp +1 -1
  165. data/src/Font.cpp +48 -53
  166. data/src/Graphics.cpp +135 -143
  167. data/src/Image.cpp +41 -42
  168. data/src/Input.cpp +1 -1
  169. data/src/InputUIKit.cpp +1 -1
  170. data/src/LargeImageData.cpp +108 -101
  171. data/src/LargeImageData.hpp +17 -15
  172. data/src/Log.hpp +6 -6
  173. data/src/Macro.cpp +35 -37
  174. data/src/Macro.hpp +11 -11
  175. data/src/Math.cpp +8 -1
  176. data/src/Resolution.cpp +12 -7
  177. data/src/RubyGosu.cxx +5 -5
  178. data/src/TexChunk.cpp +50 -41
  179. data/src/TexChunk.hpp +22 -22
  180. data/src/Text.cpp +37 -37
  181. data/src/TextBuilder.cpp +60 -57
  182. data/src/TextBuilder.hpp +20 -20
  183. data/src/TextInput.cpp +127 -135
  184. data/src/TrueTypeFont.cpp +107 -107
  185. data/src/TrueTypeFont.hpp +39 -38
  186. data/src/TrueTypeFontApple.cpp +19 -22
  187. data/src/TrueTypeFontUnix.cpp +21 -26
  188. data/src/TrueTypeFontWin.cpp +30 -30
  189. data/src/Window.cpp +95 -86
  190. data/src/WindowUIKit.cpp +46 -49
  191. metadata +7 -17
  192. data/dependencies/SDL/include/SDL_config_os2.h +0 -188
  193. data/dependencies/SDL_sound/libmodplug/load_abc.c +0 -4725
  194. data/dependencies/SDL_sound/libmodplug/load_mid.c +0 -1405
  195. data/dependencies/SDL_sound/libmodplug/load_pat.c +0 -1143
  196. data/dependencies/SDL_sound/libmodplug/load_pat.h +0 -25
  197. data/dependencies/al_soft/AL/alext.h +0 -585
  198. data/dependencies/al_soft/AL/efx-creative.h +0 -3
  199. data/dependencies/al_soft/AL/efx-presets.h +0 -402
  200. data/dependencies/al_soft/AL/efx.h +0 -762
  201. data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
  202. data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
  203. data/lib/OpenAL32.dll +0 -0
  204. data/lib64/OpenAL32.dll +0 -0
data/src/Text.cpp CHANGED
@@ -1,17 +1,17 @@
1
+ #include <Gosu/Text.hpp>
1
2
  #include "GraphicsImpl.hpp"
2
3
  #include "MarkupParser.hpp"
3
4
  #include "TextBuilder.hpp"
4
5
  #include "TrueTypeFont.hpp"
5
- #include <Gosu/Text.hpp>
6
6
  #include <algorithm>
7
7
  #include <cmath>
8
8
  #include <stdexcept>
9
9
  #include <vector>
10
10
 
11
- double Gosu::text_width(const std::u32string& text,
11
+ double Gosu::text_width(const std::u32string& text, //
12
12
  const std::string& font_name, double font_height, unsigned font_flags)
13
13
  {
14
- if (font_height <= 0) throw std::invalid_argument{"font_height must be > 0"};
14
+ if (font_height <= 0) throw std::invalid_argument{"font_height must be > 0"};
15
15
  if (font_flags >= FF_COMBINATIONS) throw std::invalid_argument{"Invalid font_flags"};
16
16
 
17
17
  TrueTypeFont& font = font_by_name(font_name, font_flags);
@@ -21,60 +21,60 @@ double Gosu::text_width(const std::u32string& text,
21
21
  double Gosu::draw_text(Bitmap& bitmap, double x, double y, Color c, const std::u32string& text,
22
22
  const std::string& font_name, double font_height, unsigned font_flags)
23
23
  {
24
- if (font_height <= 0) throw std::invalid_argument("font_height must be > 0");
24
+ if (font_height <= 0) throw std::invalid_argument("font_height must be > 0");
25
25
  if (font_flags >= FF_COMBINATIONS) throw std::invalid_argument("Invalid font_flags");
26
26
 
27
27
  TrueTypeFont& font = font_by_name(font_name, font_flags);
28
28
  return font.draw_text(text, font_height, &bitmap, x, y, c);
29
29
  }
30
30
 
31
- Gosu::Bitmap Gosu::layout_text(const std::string& text, const std::string& font_name,
32
- double font_height, double line_spacing,
33
- int width, Alignment align, unsigned font_flags)
31
+ Gosu::Bitmap Gosu::layout_text(const std::string& text, const std::string& font_name, //
32
+ double font_height, double line_spacing, int width, //
33
+ Alignment align, unsigned font_flags)
34
34
  {
35
35
  // Escape all markup and delegate to layout_markup.
36
- return layout_markup(escape_markup(text), font_name,
37
- font_height, line_spacing,
38
- width, align, font_flags);
36
+ return layout_markup(escape_markup(text), font_name, font_height, line_spacing, width, align,
37
+ font_flags);
39
38
  }
40
39
 
41
- Gosu::Bitmap Gosu::layout_markup(const std::string& markup, const std::string& font_name,
42
- double font_height, double line_spacing,
43
- int width, Alignment align, unsigned font_flags)
40
+ Gosu::Bitmap Gosu::layout_markup(const std::string& markup, const std::string& font_name, //
41
+ double font_height, double line_spacing, int width, //
42
+ Alignment align, unsigned font_flags)
44
43
  {
45
- if (font_height <= 0) throw std::invalid_argument{"font_height must be > 0"};
46
- if (line_spacing < -font_height) throw std::invalid_argument{"line_spacing must be ≥ -font_height"};
44
+ if (font_height <= 0) throw std::invalid_argument{"font_height must be > 0"};
45
+ if (line_spacing < -font_height) throw std::invalid_argument{"line_spacing < -font_height"};
47
46
  if (font_flags >= FF_COMBINATIONS) throw std::invalid_argument{"Invalid font_flags"};
48
-
47
+
49
48
  if (width >= 0) {
50
49
  TextBuilder text_builder{font_name, static_cast<int>(font_height),
51
50
  static_cast<int>(line_spacing), width, align};
52
-
51
+
53
52
  // Feed all formatted substrings to the TextBuilder, which will construct the result.
54
53
  // Split the input string into words, because this method implements word-wrapping.
55
54
  MarkupParser parser{font_flags, true, [&text_builder](std::vector<FormattedString> word) {
56
- text_builder.feed_word(move(word));
57
- }};
55
+ text_builder.feed_word(move(word));
56
+ }};
58
57
  parser.parse(markup);
59
-
60
- return text_builder.move_into_bitmap();
58
+
59
+ return std::move(text_builder).move_into_bitmap();
61
60
  }
62
61
  else {
63
62
  std::vector<std::vector<FormattedString>> lines;
64
-
63
+
65
64
  // Split the text into lines (split_words = false) since this method does not wrap lines.
66
65
  MarkupParser parser{font_flags, false, [&lines](std::vector<FormattedString>&& line) {
67
- // Remove trailing \n characters from each line to avoid errors from Gosu::text_width().
68
- if (!line.back().text.empty() && line.back().text.back() == '\n') {
69
- line.back().text.pop_back();
70
- }
71
-
72
- lines.emplace_back(line);
73
- }};
66
+ // Remove trailing \n characters from each line to avoid errors from
67
+ // Gosu::text_width().
68
+ if (!line.back().text.empty() && line.back().text.back() == '\n') {
69
+ line.back().text.pop_back();
70
+ }
71
+
72
+ lines.emplace_back(line);
73
+ }};
74
74
  parser.parse(markup);
75
-
75
+
76
76
  if (lines.empty()) return Bitmap();
77
-
77
+
78
78
  // Measure every part of every line.
79
79
  std::vector<double> line_widths;
80
80
  double max_width = 0;
@@ -85,10 +85,10 @@ Gosu::Bitmap Gosu::layout_markup(const std::string& markup, const std::string& f
85
85
  }
86
86
  max_width = std::max(max_width, line_widths.back());
87
87
  }
88
-
88
+
89
89
  double height = lines.size() * font_height + (lines.size() - 1.0) * line_spacing;
90
90
  Bitmap result{static_cast<int>(std::ceil(max_width)), static_cast<int>(std::ceil(height))};
91
-
91
+
92
92
  // Render every part of every line.
93
93
  double y = 0;
94
94
  for (int i = 0; i < lines.size(); ++i) {
@@ -99,14 +99,14 @@ Gosu::Bitmap Gosu::layout_markup(const std::string& markup, const std::string& f
99
99
  else if (align == AL_RIGHT) {
100
100
  x = result.width() - line_widths[i];
101
101
  }
102
-
102
+
103
103
  for (auto& part : lines[i]) {
104
- x = draw_text(result, x, y, part.color, part.text,
105
- font_name, font_height, part.flags);
104
+ x = draw_text(result, x, y, part.color, part.text, font_name, font_height,
105
+ part.flags);
106
106
  }
107
107
  y += (font_height + line_spacing);
108
108
  }
109
-
109
+
110
110
  return result;
111
111
  }
112
112
  }
data/src/TextBuilder.cpp CHANGED
@@ -1,17 +1,15 @@
1
1
  #include "TextBuilder.hpp"
2
2
  #include <Gosu/Text.hpp>
3
-
4
- #include <utf8proc.h>
5
-
6
3
  #include <cassert>
7
4
  #include <cmath>
8
- using namespace std;
5
+ #include <utf8proc.h>
9
6
 
10
- Gosu::WordInfo::WordInfo(const string& font_name, double font_height, vector<FormattedString> parts)
7
+ Gosu::WordInfo::WordInfo(const std::string& font_name, double font_height,
8
+ std::vector<FormattedString> parts)
11
9
  {
12
- assert (!parts.empty());
13
-
14
- auto* properties = utf8proc_get_property(parts.front().text.front());
10
+ assert(!parts.empty());
11
+
12
+ const auto* properties = utf8proc_get_property(parts.front().text.front());
15
13
 
16
14
  // Also check the BiDi class to filter out non-breaking spaces.
17
15
  is_whitespace = properties->category == UTF8PROC_CATEGORY_ZS &&
@@ -20,119 +18,124 @@ Gosu::WordInfo::WordInfo(const string& font_name, double font_height, vector<For
20
18
  is_end_of_line = parts.back().text.back() == '\n';
21
19
  // Remove the trailing backspace character to avoid errors from Gosu::text_width().
22
20
  if (is_end_of_line) parts.back().text.pop_back();
23
-
21
+
24
22
  width = 0;
25
23
  for (const auto& part : parts) {
26
- assert (is_end_of_line || !part.text.empty());
27
-
24
+ assert(is_end_of_line || !part.text.empty());
25
+
28
26
  width += text_width(part.text, font_name, font_height, part.flags);
29
27
  }
30
-
28
+
31
29
  this->parts = move(parts);
32
30
  }
33
31
 
34
32
  void Gosu::TextBuilder::flush_current_line(EndOfLineReason reason)
35
33
  {
36
- if (current_line.empty()) {
34
+ if (m_current_line.empty()) {
37
35
  if (reason == END_OF_PARAGRAPH) allocate_next_line();
38
36
  return;
39
37
  }
40
-
38
+
41
39
  allocate_next_line();
42
-
40
+
43
41
  // Remove trailing whitespace so that justifying the text across the line works.
44
- if (current_line.back().is_whitespace) current_line.pop_back();
45
-
42
+ if (m_current_line.back().is_whitespace) m_current_line.pop_back();
43
+
46
44
  // Shouldn't happen because the first word on a line should never be whitespace.
47
- assert (!current_line.empty());
48
-
45
+ assert(!m_current_line.empty());
46
+
49
47
  double words_width = 0, whitespace_width = 0;
50
- for (const auto& word : current_line) {
48
+ for (const auto& word : m_current_line) {
51
49
  (word.is_whitespace ? whitespace_width : words_width) += word.width;
52
50
  }
53
-
51
+
54
52
  double x = 0;
55
- if (align == AL_RIGHT) {
56
- x = result.width() - words_width - whitespace_width;
53
+ if (m_align == AL_RIGHT) {
54
+ x = m_result.width() - words_width - whitespace_width;
57
55
  }
58
- else if (align == AL_CENTER) {
59
- x = (result.width() - words_width - whitespace_width) / 2.0;
56
+ else if (m_align == AL_CENTER) {
57
+ x = (m_result.width() - words_width - whitespace_width) / 2.0;
60
58
  }
61
-
59
+
62
60
  double whitespace_factor = 1.0;
63
- if (align == AL_JUSTIFY && whitespace_width != 0 && reason == LINE_TOO_LONG) {
64
- whitespace_factor = (result.width() - words_width) / whitespace_width;
61
+ if (m_align == AL_JUSTIFY && whitespace_width != 0 && reason == LINE_TOO_LONG) {
62
+ whitespace_factor = (m_result.width() - words_width) / whitespace_width;
65
63
  }
66
-
67
- double y = (used_lines - 1) * (font_height + line_spacing);
68
-
69
- for (const auto& word : current_line) {
64
+
65
+ double y = (m_used_lines - 1) * (m_font_height + m_line_spacing);
66
+
67
+ for (const auto& word : m_current_line) {
70
68
  if (word.is_whitespace) {
71
69
  x += word.width * whitespace_factor;
72
70
  }
73
71
  else {
74
72
  for (const auto& part : word.parts) {
75
- draw_text(result, x, y, part.color, part.text, font_name, font_height, part.flags);
73
+ draw_text(m_result, x, y, part.color, part.text, m_font_name, m_font_height,
74
+ part.flags);
76
75
  }
77
76
  x += word.width;
78
77
  }
79
78
  }
80
-
81
- current_line.clear();
82
- current_line_width = 0;
79
+
80
+ m_current_line.clear();
81
+ m_current_line_width = 0;
83
82
  }
84
83
 
85
84
  void Gosu::TextBuilder::allocate_next_line()
86
85
  {
87
- if (used_lines == allocated_lines) {
88
- allocated_lines += 10;
86
+ if (m_used_lines == m_allocated_lines) {
87
+ m_allocated_lines += 10;
89
88
  resize_to_allocated_lines();
90
89
  }
91
-
92
- ++used_lines;
90
+
91
+ ++m_used_lines;
93
92
  }
94
93
 
95
94
  void Gosu::TextBuilder::resize_to_allocated_lines()
96
95
  {
97
- double new_height = font_height * allocated_lines + line_spacing * max(0, allocated_lines - 1);
98
- result.resize(result.width(), ceil(new_height));
96
+ double new_height =
97
+ m_font_height * m_allocated_lines + m_line_spacing * std::max(0, m_allocated_lines - 1);
98
+ m_result.resize(m_result.width(), ceil(new_height));
99
99
  }
100
100
 
101
- Gosu::TextBuilder::TextBuilder(const string& font_name, int font_height, int line_spacing,
101
+ Gosu::TextBuilder::TextBuilder(const std::string& font_name, int font_height, int line_spacing,
102
102
  int width, Alignment align)
103
- : font_name(font_name), font_height(font_height), line_spacing(line_spacing), align(align)
103
+ : m_font_name{font_name},
104
+ m_font_height{font_height * 1.0},
105
+ m_line_spacing{line_spacing * 1.0},
106
+ m_align{align}
104
107
  {
105
108
  // This class uses result.width() to remember its destination width, so store it in there.
106
- result.resize(width, 0);
109
+ m_result.resize(width, 0);
107
110
  }
108
111
 
109
- Gosu::Bitmap Gosu::TextBuilder::move_into_bitmap()
112
+ Gosu::Bitmap Gosu::TextBuilder::move_into_bitmap() &&
110
113
  {
111
114
  flush_current_line(END_OF_TEXT);
112
-
115
+
113
116
  // Shrink to fit the currently used height.
114
- allocated_lines = used_lines;
117
+ m_allocated_lines = m_used_lines;
115
118
  resize_to_allocated_lines();
116
- return move(result);
119
+ return std::move(m_result);
117
120
  }
118
121
 
119
- void Gosu::TextBuilder::feed_word(vector<FormattedString>&& word)
122
+ void Gosu::TextBuilder::feed_word(std::vector<FormattedString>&& word)
120
123
  {
121
- WordInfo new_word(font_name, font_height, word);
122
-
123
- if (current_line_width + new_word.width > result.width()) {
124
+ WordInfo new_word(m_font_name, m_font_height, word);
125
+
126
+ if (m_current_line_width + new_word.width > m_result.width()) {
124
127
  // Can't fit it on the same line as before, so flush the last line before adding the word to
125
128
  // the next line.
126
129
  flush_current_line(LINE_TOO_LONG);
127
-
130
+
128
131
  if (new_word.is_whitespace) {
129
132
  // Do not wrap trailing whitespace onto the start of the next line - discard this word.
130
133
  return;
131
134
  }
132
135
  }
133
-
134
- current_line.emplace_back(new_word);
135
- current_line_width += new_word.width;
136
+
137
+ m_current_line.emplace_back(new_word);
138
+ m_current_line_width += new_word.width * 1.0;
136
139
 
137
140
  if (new_word.is_end_of_line) {
138
141
  flush_current_line(END_OF_PARAGRAPH);
data/src/TextBuilder.hpp CHANGED
@@ -12,44 +12,44 @@ namespace Gosu
12
12
  bool is_whitespace;
13
13
  bool is_end_of_line;
14
14
  double width;
15
-
15
+
16
16
  WordInfo(const std::string& font_name, double font_height,
17
17
  std::vector<FormattedString> parts);
18
18
  };
19
-
19
+
20
20
  class TextBuilder
21
21
  {
22
22
  // Parameters.
23
- std::string font_name;
24
- double font_height;
25
- double line_spacing;
26
- Alignment align;
27
-
28
- enum EndOfLineReason {
23
+ std::string m_font_name;
24
+ double m_font_height;
25
+ double m_line_spacing;
26
+ Alignment m_align;
27
+
28
+ enum EndOfLineReason
29
+ {
29
30
  LINE_TOO_LONG,
30
31
  END_OF_PARAGRAPH,
31
32
  END_OF_TEXT
32
33
  };
33
-
34
+
34
35
  // Input.
35
- std::vector<WordInfo> current_line;
36
- int current_line_width = 0;
36
+ std::vector<WordInfo> m_current_line;
37
+ int m_current_line_width = 0;
37
38
  void flush_current_line(EndOfLineReason reason);
38
39
 
39
40
  // Output.
40
- Bitmap result;
41
- int used_lines = 0;
42
- int allocated_lines = 0;
41
+ Bitmap m_result;
42
+ int m_used_lines = 0;
43
+ int m_allocated_lines = 0;
43
44
  void allocate_next_line();
44
45
  void resize_to_allocated_lines();
45
-
46
+
46
47
  public:
47
- TextBuilder(const std::string& font_name, int font_height, int line_spacing,
48
- int width, Alignment align);
49
-
48
+ TextBuilder(const std::string& font_name, int font_height, int line_spacing, int width,
49
+ Alignment align);
50
+
50
51
  void feed_word(std::vector<FormattedString>&& word);
51
52
 
52
- Bitmap move_into_bitmap();
53
+ Bitmap move_into_bitmap() &&;
53
54
  };
54
55
  }
55
-