gosu 0.14.5 → 0.15.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/COPYING +1 -1
  4. data/Gosu/Channel.h +25 -0
  5. data/Gosu/Color.h +38 -0
  6. data/Gosu/Font.h +36 -0
  7. data/Gosu/Gosu.h +79 -0
  8. data/Gosu/Image.h +54 -0
  9. data/Gosu/Sample.h +19 -0
  10. data/Gosu/Song.h +24 -0
  11. data/Gosu/TextInput.h +30 -0
  12. data/Gosu/Version.hpp +2 -2
  13. data/Gosu/Window.h +61 -0
  14. data/Gosu/Window.hpp +3 -2
  15. data/README.md +1 -1
  16. data/ext/gosu/extconf.rb +3 -0
  17. data/lib/gosu/compat.rb +12 -7
  18. data/lib/gosu/patches.rb +8 -2
  19. data/lib/gosu/swig_patches.rb +20 -9
  20. data/rdoc/gosu.rb +28 -7
  21. data/src/ChannelWrapper.cpp +50 -0
  22. data/src/ColorWrapper.cpp +126 -0
  23. data/src/Constants.cpp +287 -0
  24. data/src/Font.cpp +1 -0
  25. data/src/FontWrapper.cpp +74 -0
  26. data/src/GosuWrapper.cpp +232 -0
  27. data/src/Graphics.cpp +4 -1
  28. data/src/GraphicsImpl.hpp +0 -1
  29. data/src/ImageWrapper.cpp +168 -0
  30. data/src/LargeImageData.cpp +1 -0
  31. data/src/MarkupParser.cpp +11 -3
  32. data/src/RubyGosu.cxx +185 -121
  33. data/src/RubyGosu.h +2 -2
  34. data/src/SampleWrapper.cpp +30 -0
  35. data/src/SongWrapper.cpp +52 -0
  36. data/src/TexChunk.cpp +29 -19
  37. data/src/Text.cpp +2 -0
  38. data/src/TextBuilder.cpp +3 -3
  39. data/src/TextInputWrapper.cpp +101 -0
  40. data/src/TrueTypeFont.cpp +1 -0
  41. data/src/Window.cpp +62 -28
  42. data/src/WindowUIKit.cpp +8 -4
  43. data/src/WindowWrapper.cpp +289 -0
  44. data/src/stb_image.h +153 -56
  45. data/src/stb_image_write.h +111 -60
  46. data/src/stb_truetype.h +74 -39
  47. data/src/stb_vorbis.c +55 -15
  48. data/src/utf8proc.c +47 -29
  49. data/src/utf8proc.h +46 -24
  50. data/src/utf8proc_data.h +10043 -9609
  51. metadata +23 -4
@@ -0,0 +1,232 @@
1
+ #include <Gosu/Gosu.hpp>
2
+
3
+ extern "C" {
4
+ #include <Gosu/Gosu.h>
5
+
6
+ void Gosu_gl_z(double z, void function(void *data), void *data)
7
+ {
8
+ std::function<void ()> callback;
9
+ callback = [=]() { function(data); };
10
+
11
+ Gosu::Graphics::gl(z, callback);
12
+ }
13
+
14
+ void Gosu_gl(void function(void *data), void *data)
15
+ {
16
+ std::function<void ()> callback;
17
+ callback = [=]() { function(data); };
18
+
19
+ Gosu::Graphics::gl(callback);
20
+ }
21
+
22
+ Gosu_Image *Gosu_render(int width, int height, void function(void *data), void *data, unsigned image_flags)
23
+ {
24
+ std::function<void ()> callback;
25
+ callback = [=]() { function(data); };
26
+
27
+ return reinterpret_cast<Gosu_Image *>(new Gosu::Image(Gosu::Graphics::render(width, height, callback, image_flags)));
28
+ }
29
+
30
+ Gosu_Image *Gosu_record(int width, int height, void function(void *data), void *data)
31
+ {
32
+ std::function<void ()> callback;
33
+ callback = [=]() { function(data); };
34
+ return reinterpret_cast<Gosu_Image *>(new Gosu::Image(Gosu::Graphics::record(width, height, callback)));
35
+ }
36
+
37
+ void Gosu_flush()
38
+ {
39
+ Gosu::Graphics::flush();
40
+ }
41
+
42
+ void Gosu_transform(double m0, double m1, double m2, double m3, double m4, double m5, double m6,
43
+ double m7, double m8, double m9, double m10, double m11, double m12, double m13,
44
+ double m14, double m15, void function(void *data), void *data)
45
+ {
46
+ Gosu::Transform transform = {
47
+ m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15};
48
+ std::function<void ()> callback;
49
+ callback = [=]() { function(data); };
50
+
51
+ Gosu::Graphics::transform(transform, callback);
52
+ }
53
+
54
+ void Gosu_translate(double x, double y, void function(void *data), void *data)
55
+ {
56
+ std::function<void ()> callback;
57
+ callback = [=]() { function(data); };
58
+
59
+ Gosu::Graphics::transform(Gosu::translate(x, y), callback);
60
+ }
61
+
62
+ void Gosu_scale(double scale_x, double scale_y, double around_x, double around_y, void function(void *data), void *data)
63
+ {
64
+ std::function<void ()> callback;
65
+ callback = [=]() { function(data); };
66
+
67
+ Gosu::Graphics::transform(Gosu::scale(scale_x, scale_y, around_x, around_y), callback);
68
+ }
69
+
70
+ void Gosu_rotate(double angle, double around_x, double around_y, void function(void *data), void *data)
71
+ {
72
+ std::function<void ()> callback;
73
+ callback = [=]() { function(data); };
74
+
75
+ Gosu::Graphics::transform(Gosu::rotate(angle, around_x, around_y), callback);
76
+ }
77
+
78
+ void Gosu_clip_to(double x, double y, double width, double height, void function(void *data), void *data)
79
+ {
80
+ std::function<void ()> callback;
81
+ callback = [=]() { function(data); };
82
+
83
+ Gosu::Graphics::clip_to(x, y, width, height, callback);
84
+ }
85
+
86
+ void Gosu_draw_line(double x1, double y1, unsigned c1,
87
+ double x2, double y2, unsigned c2,
88
+ double z, unsigned mode)
89
+ {
90
+ Gosu::Graphics::draw_line(x1, y1, c1, x2, y2, c2, z, (Gosu::AlphaMode)mode);
91
+ }
92
+
93
+ void Gosu_draw_triangle(double x1, double y1, unsigned c1,
94
+ double x2, double y2, unsigned c2,
95
+ double x3, double y3, unsigned c3,
96
+ double z, unsigned mode)
97
+ {
98
+ Gosu::Graphics::draw_triangle(x1, y1, c1,
99
+ x2, y2, c2,
100
+ x3, y3, c3,
101
+ z, (Gosu::AlphaMode)mode);
102
+ }
103
+
104
+ void Gosu_draw_rect(double x, double y, double width, double height, unsigned c, double z, unsigned mode)
105
+ {
106
+ Gosu::Graphics::draw_rect(x, y, width, height, c, z, (Gosu::AlphaMode)mode);
107
+ }
108
+
109
+ void Gosu_draw_quad(double x1, double y1, unsigned c1,
110
+ double x2, double y2, unsigned c2,
111
+ double x3, double y3, unsigned c3,
112
+ double x4, double y4, unsigned c4,
113
+ double z, unsigned mode)
114
+ {
115
+ Gosu::Graphics::draw_quad(x1, y1, c1,
116
+ x2, y2, c2,
117
+ x3, y3, c3,
118
+ x4, y4, c4,
119
+ z, (Gosu::AlphaMode)mode);
120
+ }
121
+
122
+ double Gosu_distance(double x1, double y1, double x2, double y2)
123
+ {
124
+ return Gosu::distance(x1, y1, x2, y2);
125
+ }
126
+
127
+ double Gosu_angle(double from_x, double from_y, double to_x, double to_y)
128
+ {
129
+ return Gosu::angle(from_x, from_y, to_x, to_y);
130
+ }
131
+
132
+ double Gosu_angle_diff(double from, double to)
133
+ {
134
+ return Gosu::angle_diff(from, to);
135
+ }
136
+
137
+ double Gosu_offset_x(double angle, double radius)
138
+ {
139
+ return Gosu::offset_x(angle, radius);
140
+ }
141
+
142
+ double Gosu_offset_y(double angle, double radius)
143
+ {
144
+ return Gosu::offset_y(angle, radius);
145
+ }
146
+
147
+ double Gosu_random(double min, double max)
148
+ {
149
+ return Gosu::random(min, max);
150
+ }
151
+
152
+ unsigned Gosu_available_width(Gosu_Window *window)
153
+ {
154
+ Gosu::Window *gosu_window = nullptr;
155
+ if (window != nullptr) {
156
+ gosu_window = reinterpret_cast<Gosu::Window *>(window);
157
+ }
158
+ return Gosu::available_width(gosu_window);
159
+ }
160
+
161
+ unsigned Gosu_available_height(Gosu_Window *window)
162
+ {
163
+ Gosu::Window *gosu_window = nullptr;
164
+ if (window != nullptr) {
165
+ gosu_window = reinterpret_cast<Gosu::Window *>(window);
166
+ }
167
+ return Gosu::available_height(gosu_window);
168
+ }
169
+
170
+ unsigned Gosu_screen_width(Gosu_Window *window)
171
+ {
172
+ Gosu::Window *gosu_window = nullptr;
173
+ if (window != nullptr) {
174
+ gosu_window = reinterpret_cast<Gosu::Window *>(window);
175
+ }
176
+ return Gosu::screen_width(gosu_window);
177
+ }
178
+
179
+ unsigned Gosu_screen_height(Gosu_Window *window)
180
+ {
181
+ Gosu::Window *gosu_window = nullptr;
182
+ if (window != nullptr) {
183
+ gosu_window = reinterpret_cast<Gosu::Window *>(window);
184
+ }
185
+ return Gosu::screen_height(gosu_window);
186
+ }
187
+
188
+ int Gosu_button_down(int btn)
189
+ {
190
+ return Gosu::Input::down((Gosu::ButtonName)btn);
191
+ }
192
+
193
+ const char *Gosu_button_id_to_char(int id)
194
+ {
195
+ static thread_local std::string button;
196
+ button = Gosu::Input::id_to_char((Gosu::Button)id);
197
+
198
+ return button.c_str();
199
+ }
200
+
201
+ unsigned Gosu_button_char_to_id(const char *btn)
202
+ {
203
+ return Gosu::Input::char_to_id(btn).id();
204
+ }
205
+
206
+ int Gosu_fps()
207
+ {
208
+ return Gosu::fps();
209
+ }
210
+
211
+ const char *Gosu_language()
212
+ {
213
+ static thread_local std::string language;
214
+ language = Gosu::language();
215
+
216
+ return language.c_str();
217
+ }
218
+
219
+ long Gosu_milliseconds()
220
+ {
221
+ return Gosu::milliseconds();
222
+ }
223
+
224
+ const char *Gosu_default_font_name()
225
+ {
226
+ static thread_local std::string name;
227
+ name = Gosu::default_font_name();
228
+
229
+ return name.c_str();
230
+ }
231
+
232
+ }
data/src/Graphics.cpp CHANGED
@@ -68,7 +68,7 @@ struct Gosu::Graphics::Impl
68
68
  {
69
69
  glPushAttrib(GL_ALL_ATTRIB_BITS);
70
70
  glDisable(GL_BLEND);
71
- // Reset the colour to white to avoid surprises.
71
+ // Reset the color to white to avoid surprises.
72
72
  // https://www.libgosu.org/cgi-bin/mwf/topic_show.pl?pid=9115#pid9115
73
73
  glColor4ubv(reinterpret_cast<const GLubyte*>(&Color::WHITE));
74
74
  while (glGetError() != GL_NO_ERROR);
@@ -287,13 +287,16 @@ Gosu::Image Gosu::Graphics::render(int width, int height, const function<void ()
287
287
 
288
288
  // This is the actual render-to-texture step.
289
289
  Image result = OffScreenTarget(width, height, image_flags).render([&] {
290
+ glPushAttrib(GL_ALL_ATTRIB_BITS);
290
291
  glClearColor(0, 0, 0, 0);
291
292
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
293
+ glEnable(GL_BLEND);
292
294
  queues.emplace_back(QM_RENDER_TO_TEXTURE);
293
295
  f();
294
296
  queues.back().perform_draw_ops_and_code();
295
297
  queues.pop_back();
296
298
  glFlush();
299
+ glPopAttrib();
297
300
  });
298
301
 
299
302
  // Restore previous matrix and glViewport.
data/src/GraphicsImpl.hpp CHANGED
@@ -110,7 +110,6 @@ namespace Gosu
110
110
  void ensure_current_context();
111
111
 
112
112
  inline std::string escape_markup(const std::string& text) {
113
- // Escape all markup and delegate to layout_markup.
114
113
  auto markup = text;
115
114
  for (std::string::size_type pos = 0; pos < markup.length(); ++pos) {
116
115
  if (markup[pos] == '&') {
@@ -0,0 +1,168 @@
1
+ #include <Gosu/Gosu.hpp>
2
+ #include <stdio.h>
3
+ #include <cstring>
4
+
5
+ extern "C" {
6
+ #include <Gosu/Image.h>
7
+
8
+ // Constructors
9
+ Gosu_Image *Gosu_Image_create(const char *filename, unsigned image_flags)
10
+ {
11
+ return reinterpret_cast<Gosu_Image *>(new Gosu::Image(filename, image_flags));
12
+ };
13
+
14
+ Gosu_Image *Gosu_Image_create_from_markup(const char *markup, const char *font, double font_height,
15
+ int width, double spacing, unsigned align, unsigned font_flags, unsigned image_flags)
16
+ {
17
+ Gosu::Bitmap bitmap = Gosu::layout_markup(markup, font, font_height, spacing, width,
18
+ (Gosu::Alignment)align, font_flags);
19
+ return reinterpret_cast<Gosu_Image *>(new Gosu::Image(bitmap, image_flags));
20
+ }
21
+
22
+ Gosu_Image *Gosu_Image_create_from_text(const char *text, const char *font, double font_height,
23
+ int width, double spacing, unsigned align, unsigned font_flags, unsigned image_flags)
24
+ {
25
+ Gosu::Bitmap bitmap = Gosu::layout_text(text, font, font_height, spacing, width,
26
+ (Gosu::Alignment)align, font_flags);
27
+ return reinterpret_cast<Gosu_Image *>(new Gosu::Image(bitmap, image_flags));
28
+ }
29
+
30
+ Gosu_Image *Gosu_Image_create_from_blob(unsigned char *blob, int byte_count, int columns, int rows, unsigned image_flags)
31
+ {
32
+ std::size_t size = columns * rows * 4;
33
+ Gosu::Bitmap bitmap(columns, rows, Gosu::Color::NONE);
34
+
35
+ if (byte_count == size) {
36
+ // 32 bit per pixel, assume R8G8B8A8
37
+ std::memcpy(bitmap.data(), blob, size);
38
+ }
39
+ else if (byte_count == size * sizeof(float)) {
40
+ // 128 bit per channel, assume float/float/float/float
41
+ const float *in = reinterpret_cast<const float *>(blob);
42
+ Gosu::Color::Channel *out = reinterpret_cast<Gosu::Color::Channel *>(bitmap.data());
43
+ for (int i = size; i > 0; --i) {
44
+ *(out++) = static_cast<Gosu::Color::Channel>(*(in++) * 255);
45
+ }
46
+ }
47
+ else {
48
+ return nullptr; // abort?
49
+ }
50
+
51
+ return reinterpret_cast<Gosu_Image *>(new Gosu::Image(bitmap, image_flags));
52
+ }
53
+
54
+ Gosu_Image *Gosu_Image_create_from_subimage(Gosu_Image *image, int left, int top, int width, int height)
55
+ {
56
+ Gosu::Image *gosu_image = reinterpret_cast<Gosu::Image *>(image);
57
+ std::unique_ptr<Gosu::ImageData> image_data = gosu_image->data().subimage(left, top, width, height);
58
+
59
+ return reinterpret_cast<Gosu_Image *>(image_data.get() ? new Gosu::Image(std::move(image_data)) : nullptr);
60
+ }
61
+
62
+ void Gosu_Image_create_from_tiles(const char *source, int tile_width, int tile_height, void function(void *data, Gosu_Image *image), void *data, unsigned image_flags)
63
+ {
64
+ std::vector<Gosu::Image> gosu_images = Gosu::load_tiles(source, tile_width, tile_height, image_flags);
65
+
66
+ for (Gosu::Image &img : gosu_images) {
67
+ function(data, reinterpret_cast<Gosu_Image *>(new Gosu::Image(img)));
68
+ }
69
+ }
70
+
71
+ void Gosu_Image_create_tiles_from_image(Gosu_Image *image, int tile_width, int tile_height, void function(void *data, Gosu_Image *image), void *data, unsigned image_flags)
72
+ {
73
+ std::vector<Gosu::Image> gosu_images = Gosu::load_tiles(reinterpret_cast<Gosu::Image *>(image)->data().to_bitmap(), tile_width, tile_height, image_flags);
74
+
75
+ for (Gosu::Image &img : gosu_images) {
76
+ function(data, reinterpret_cast<Gosu_Image *>(new Gosu::Image(img)));
77
+ }
78
+ }
79
+
80
+ // Properties
81
+ unsigned Gosu_Image_width(Gosu_Image *image)
82
+ {
83
+ return reinterpret_cast<Gosu::Image *>(image)->width();
84
+ }
85
+
86
+ unsigned Gosu_Image_height(Gosu_Image *image)
87
+ {
88
+ return reinterpret_cast<Gosu::Image *>(image)->height();
89
+ }
90
+
91
+ Gosu_GLTexInfo *Gosu_Image_gl_tex_info_create(Gosu_Image *image)
92
+ {
93
+ Gosu::Image *gosu_image = reinterpret_cast<Gosu::Image *>(image);
94
+ Gosu::GLTexInfo *gosu_texture_info = new Gosu::GLTexInfo(*gosu_image->data().gl_tex_info());
95
+ if (gosu_texture_info) {
96
+ return reinterpret_cast<Gosu_GLTexInfo *>(gosu_texture_info);
97
+ }
98
+ else {
99
+ return nullptr;
100
+ }
101
+ }
102
+
103
+ void Gosu_Image_gl_tex_info_destroy(Gosu_GLTexInfo *gl_tex_info)
104
+ {
105
+ delete (reinterpret_cast<Gosu::GLTexInfo *>(gl_tex_info));
106
+ }
107
+
108
+ // Rendering
109
+ void Gosu_Image_draw(Gosu_Image *image, double x, double y, double z, double scale_x, double scale_y, unsigned color, unsigned mode)
110
+ {
111
+ reinterpret_cast<Gosu::Image *>(image)->draw(x, y, z, scale_x, scale_y, color, (Gosu::AlphaMode)mode);
112
+ }
113
+
114
+ void Gosu_Image_draw_rot(Gosu_Image *image, double x, double y, double z,
115
+ double angle, double center_x, double center_y,
116
+ double scale_x, double scale_y, unsigned color, unsigned mode)
117
+ {
118
+ reinterpret_cast<Gosu::Image *>(image)->draw_rot(x, y, z,
119
+ angle, center_x, center_y,
120
+ scale_x, scale_y,
121
+ color, (Gosu::AlphaMode)mode);
122
+ }
123
+
124
+ void Gosu_Image_draw_as_quad(Gosu_Image *image,
125
+ double x1, double y1, unsigned color1,
126
+ double x2, double y2, unsigned color2,
127
+ double x3, double y3, unsigned color3,
128
+ double x4, double y4, unsigned color4,
129
+ double z, unsigned mode)
130
+ {
131
+ Gosu::Image *gosu_image = reinterpret_cast<Gosu::Image *>(image);
132
+ gosu_image->data().draw(
133
+ x1, y1, color1,
134
+ x2, y2, color2,
135
+ x3, y3, color3,
136
+ x4, y4, color4,
137
+ z, (Gosu::AlphaMode)mode);
138
+ }
139
+
140
+ // Image operations
141
+ void Gosu_Image_insert(Gosu_Image *image, Gosu_Image *source, int x, int y)
142
+ {
143
+ Gosu::Bitmap bmp;
144
+ bmp = reinterpret_cast<Gosu::Image *>(source)->data().to_bitmap();
145
+ reinterpret_cast<Gosu::Image *>(image)->data().insert(bmp, x, y);
146
+ }
147
+
148
+ unsigned char *Gosu_Image_to_blob(Gosu_Image *image)
149
+ {
150
+ Gosu::Image *gosu_image = reinterpret_cast<Gosu::Image *>(image);
151
+ static thread_local Gosu::Bitmap bitmap;
152
+ bitmap = gosu_image->data().to_bitmap();
153
+
154
+ return reinterpret_cast<unsigned char *>(bitmap.data());
155
+ }
156
+
157
+ void Gosu_Image_save(Gosu_Image *image, const char *filename)
158
+ {
159
+ Gosu::save_image_file(reinterpret_cast<Gosu::Image *>(image)->data().to_bitmap(), filename);
160
+ }
161
+
162
+ // Destructor
163
+ void Gosu_Image_destroy(Gosu_Image *image)
164
+ {
165
+ delete (reinterpret_cast<Gosu::Image *>(image));
166
+ }
167
+
168
+ }
@@ -3,6 +3,7 @@
3
3
  #include <Gosu/Graphics.hpp>
4
4
  #include <Gosu/Math.hpp>
5
5
  #include <cmath>
6
+ #include <stdexcept>
6
7
  using namespace std;
7
8
 
8
9
  Gosu::LargeImageData::LargeImageData(const Bitmap& source, int tile_width, int tile_height,
data/src/MarkupParser.cpp CHANGED
@@ -119,17 +119,25 @@ bool Gosu::MarkupParser::parse_markup()
119
119
 
120
120
  bool Gosu::MarkupParser::parse_escape_entity()
121
121
  {
122
+ auto translate_to = [this](char ch) {
123
+ if (word_state == ADDING_WHITESPACE) {
124
+ flush_to_consumer();
125
+ word_state = ADDING_WORD;
126
+ }
127
+ add_composed_substring(u32string(1, ch));
128
+ };
129
+
122
130
  // These are not entities (images) but escapes for markup characters.
123
131
  if (match_and_skip("&lt;")) {
124
- add_composed_substring(u32string(1, '<'));
132
+ translate_to('<');
125
133
  return true;
126
134
  }
127
135
  if (match_and_skip("&gt;")) {
128
- add_composed_substring(u32string(1, '>'));
136
+ translate_to('>');
129
137
  return true;
130
138
  }
131
139
  if (match_and_skip("&amp;")) {
132
- add_composed_substring(u32string(1, '&'));
140
+ translate_to('&');
133
141
  return true;
134
142
  }
135
143