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,289 @@
1
+ #include <Gosu/Gosu.hpp>
2
+
3
+ namespace Gosu
4
+ {
5
+ class WindowForWrapper : public Gosu::Window
6
+ {
7
+ public:
8
+ WindowForWrapper(int width, int height, bool fullscreen, double update_interval, bool resizable);
9
+ void update() override;
10
+ void draw() override;
11
+ void default_button_down(unsigned btn); // Enables fullscreen toggle
12
+ void button_down(Gosu::Button btn) override;
13
+ void button_up(Gosu::Button btn) override;
14
+ void drop(const std::string &filename) override;
15
+ bool needs_redraw() const override;
16
+ bool needs_cursor() const override;
17
+ void close() override;
18
+
19
+ void close_immediately();
20
+
21
+ std::function<void ()> update_callback;
22
+ std::function<void ()> draw_callback;
23
+ std::function<void (unsigned btn)> button_down_callback;
24
+ std::function<void (unsigned btn)> button_up_callback;
25
+ std::function<void (const char *filename)> drop_callback;
26
+ std::function<bool ()> needs_redraw_callback;
27
+ std::function<bool ()> needs_cursor_callback;
28
+ std::function<void ()> close_callback;
29
+ };
30
+ } // namespace Gosu
31
+
32
+ Gosu::WindowForWrapper::WindowForWrapper(int width, int height, bool fullscreen,
33
+ double update_interval, bool resizable)
34
+ : Gosu::Window(width, height, fullscreen, update_interval, resizable)
35
+ {
36
+ }
37
+
38
+ void Gosu::WindowForWrapper::update()
39
+ {
40
+ if (update_callback != nullptr) {
41
+ update_callback();
42
+ }
43
+ }
44
+
45
+ void Gosu::WindowForWrapper::draw()
46
+ {
47
+ if (draw_callback != nullptr) {
48
+ draw_callback();
49
+ }
50
+ }
51
+
52
+ void Gosu::WindowForWrapper::default_button_down(unsigned btn)
53
+ {
54
+ Gosu::Window::button_down(Gosu::ButtonName(btn));
55
+ }
56
+
57
+ void Gosu::WindowForWrapper::button_down(Gosu::Button btn)
58
+ {
59
+ if (button_down_callback != nullptr) {
60
+ button_down_callback(btn.id());
61
+ }
62
+ }
63
+
64
+ void Gosu::WindowForWrapper::button_up(Gosu::Button btn)
65
+ {
66
+ if (button_up_callback != nullptr) {
67
+ button_up_callback(btn.id());
68
+ }
69
+ }
70
+
71
+ void Gosu::WindowForWrapper::drop(const std::string &filename)
72
+ {
73
+ if (drop_callback != nullptr) {
74
+ drop_callback(filename.c_str());
75
+ }
76
+ }
77
+
78
+ bool Gosu::WindowForWrapper::needs_redraw() const
79
+ {
80
+ if (needs_redraw_callback != nullptr) {
81
+ return needs_redraw_callback();
82
+ }
83
+ else {
84
+ return true;
85
+ }
86
+ }
87
+
88
+ bool Gosu::WindowForWrapper::needs_cursor() const
89
+ {
90
+ if (needs_cursor_callback != nullptr) {
91
+ return needs_cursor_callback();
92
+ }
93
+ else {
94
+ return false;
95
+ }
96
+ }
97
+
98
+ void Gosu::WindowForWrapper::close()
99
+ {
100
+ if (close_callback != nullptr) {
101
+ close_callback();
102
+ }
103
+ else {
104
+ Gosu::Window::close();
105
+ }
106
+ }
107
+
108
+ void Gosu::WindowForWrapper::close_immediately()
109
+ {
110
+ Gosu::Window::close();
111
+ }
112
+
113
+ extern "C" {
114
+ #include <Gosu/Window.h>
115
+ #include <Gosu/TextInput.h>
116
+
117
+ // Constructor
118
+ Gosu_Window *Gosu_Window_create(int width, int height, bool fullscreen, double update_interval, bool resizable)
119
+ {
120
+ return reinterpret_cast<Gosu_Window *>(new Gosu::WindowForWrapper(width, height, fullscreen, update_interval, resizable));
121
+ };
122
+
123
+ // Callbacks
124
+ void Gosu_Window_set_draw(Gosu_Window *window, void function(void *data), void *data)
125
+ {
126
+ reinterpret_cast<Gosu::WindowForWrapper *>(window)->draw_callback = [=]() { function(data); };
127
+ }
128
+
129
+ void Gosu_Window_set_update(Gosu_Window *window, void function(void *data), void *data)
130
+ {
131
+ reinterpret_cast<Gosu::WindowForWrapper *>(window)->update_callback = [=]() { function(data); };
132
+ }
133
+
134
+ void Gosu_Window_set_button_down(Gosu_Window *window, void function(void *data, unsigned btn), void *data)
135
+ {
136
+ reinterpret_cast<Gosu::WindowForWrapper *>(window)->button_down_callback = [=](unsigned btn) { function(data, btn); };
137
+ }
138
+
139
+ void Gosu_Window_default_button_down(Gosu_Window *window, unsigned btn)
140
+ {
141
+ reinterpret_cast<Gosu::WindowForWrapper *>(window)->default_button_down(btn);
142
+ }
143
+
144
+ void Gosu_Window_set_button_up(Gosu_Window *window, void function(void *data, unsigned btn), void *data)
145
+ {
146
+ reinterpret_cast<Gosu::WindowForWrapper *>(window)->button_up_callback = [=](unsigned btn) { function(data, btn); };
147
+ }
148
+
149
+ void Gosu_Window_set_drop(Gosu_Window *window, void function(void *data, const char *filename), void *data)
150
+ {
151
+ reinterpret_cast<Gosu::WindowForWrapper *>(window)->drop_callback = [=](const char *filename) { function(data, filename); };
152
+ }
153
+
154
+ void Gosu_Window_set_needs_redraw(Gosu_Window *window, bool function(void *data), void *data)
155
+ {
156
+ reinterpret_cast<Gosu::WindowForWrapper *>(window)->needs_redraw_callback = [=]() -> bool { return function(data); };
157
+ }
158
+
159
+ void Gosu_Window_set_needs_cursor(Gosu_Window *window, bool function(void *data), void *data)
160
+ {
161
+ reinterpret_cast<Gosu::WindowForWrapper *>(window)->needs_cursor_callback = [=]() -> bool { return function(data); };
162
+ }
163
+
164
+ void Gosu_Window_set_close(Gosu_Window *window, void function(void *data), void *data)
165
+ {
166
+ reinterpret_cast<Gosu::WindowForWrapper *>(window)->close_callback = [=]() { function(data); };
167
+ }
168
+
169
+ Gosu_TextInput *Gosu_Window_text_input(Gosu_Window *window)
170
+ {
171
+ Gosu::Window *gosu_window = reinterpret_cast<Gosu::WindowForWrapper *>(window);
172
+ return reinterpret_cast<Gosu_TextInput *>(gosu_window->input().text_input());
173
+ }
174
+
175
+ void Gosu_Window_set_text_input(Gosu_Window *window, Gosu_TextInput *text_input)
176
+ {
177
+ Gosu::Window *gosu_window = reinterpret_cast<Gosu::WindowForWrapper *>(window);
178
+ gosu_window->input().set_text_input(reinterpret_cast<Gosu::TextInput *>(text_input));
179
+ }
180
+
181
+ void Gosu_Window_show(Gosu_Window *window)
182
+ {
183
+ reinterpret_cast<Gosu::WindowForWrapper *>(window)->show();
184
+ }
185
+
186
+ bool Gosu_Window_tick(Gosu_Window *window)
187
+ {
188
+ return reinterpret_cast<Gosu::WindowForWrapper *>(window)->tick();
189
+ }
190
+
191
+ void Gosu_Window_close_immediately(Gosu_Window *window)
192
+ {
193
+ reinterpret_cast<Gosu::WindowForWrapper *>(window)->close_immediately();
194
+ }
195
+
196
+ bool Gosu_Window_is_fullscreen(Gosu_Window *window)
197
+ {
198
+ return reinterpret_cast<Gosu::WindowForWrapper *>(window)->fullscreen();
199
+ }
200
+
201
+ bool Gosu_Window_is_resizable(Gosu_Window *window)
202
+ {
203
+ return reinterpret_cast<Gosu::WindowForWrapper *>(window)->resizable();
204
+ }
205
+
206
+ const char *Gosu_Window_caption(Gosu_Window *window)
207
+ {
208
+ static thread_local std::string caption;
209
+ caption = reinterpret_cast<Gosu::WindowForWrapper *>(window)->caption();
210
+
211
+ return caption.c_str();
212
+ }
213
+
214
+ void Gosu_Window_set_caption(Gosu_Window *window, const char *caption)
215
+ {
216
+ reinterpret_cast<Gosu::WindowForWrapper *>(window)->set_caption(caption);
217
+ }
218
+
219
+ double Gosu_Window_update_interval(Gosu_Window *window)
220
+ {
221
+ return reinterpret_cast<Gosu::WindowForWrapper *>(window)->update_interval();
222
+ }
223
+
224
+ void Gosu_Window_set_update_interval(Gosu_Window *window, double update_interval)
225
+ {
226
+ reinterpret_cast<Gosu::WindowForWrapper *>(window)->set_update_interval(update_interval);
227
+ }
228
+
229
+ void Gosu_Window_set_mouse_x(Gosu_Window *window, double x)
230
+ {
231
+ Gosu::Window *gosu_window = reinterpret_cast<Gosu::WindowForWrapper *>(window);
232
+ gosu_window->input().set_mouse_position(x, gosu_window->input().mouse_x());
233
+ }
234
+
235
+ void Gosu_Window_set_mouse_y(Gosu_Window *window, double y)
236
+ {
237
+ Gosu::Window *gosu_window = reinterpret_cast<Gosu::WindowForWrapper *>(window);
238
+ gosu_window->input().set_mouse_position(gosu_window->input().mouse_x(), y);
239
+ }
240
+
241
+ double Gosu_Window_mouse_x(Gosu_Window *window)
242
+ {
243
+ return reinterpret_cast<Gosu::WindowForWrapper *>(window)->input().mouse_x();
244
+ }
245
+
246
+ double Gosu_Window_mouse_y(Gosu_Window *window)
247
+ {
248
+ return reinterpret_cast<Gosu::WindowForWrapper *>(window)->input().mouse_y();
249
+ }
250
+
251
+ int Gosu_Window_width(Gosu_Window *window)
252
+ {
253
+ return reinterpret_cast<Gosu::WindowForWrapper *>(window)->width();
254
+ }
255
+
256
+ void Gosu_Window_set_width(Gosu_Window *window, int width)
257
+ {
258
+ Gosu::Window *gosu_window = reinterpret_cast<Gosu::WindowForWrapper *>(window);
259
+ gosu_window->resize(width, gosu_window->height(), gosu_window->fullscreen());
260
+ }
261
+
262
+ int Gosu_Window_height(Gosu_Window *window)
263
+ {
264
+ return reinterpret_cast<Gosu::WindowForWrapper *>(window)->height();
265
+ }
266
+
267
+ void Gosu_Window_set_height(Gosu_Window *window, int height)
268
+ {
269
+ Gosu::Window *gosu_window = reinterpret_cast<Gosu::WindowForWrapper *>(window);
270
+ gosu_window->resize(gosu_window->width(), height, gosu_window->fullscreen());
271
+ }
272
+
273
+ void Gosu_Window_resize(Gosu_Window *window, int width, int height, bool fullscreen)
274
+ {
275
+ reinterpret_cast<Gosu::WindowForWrapper *>(window)->resize(width, height, fullscreen);
276
+ }
277
+
278
+ int Gosu_Window_is_button_down(Gosu_Window *window, unsigned btn)
279
+ {
280
+ return reinterpret_cast<Gosu::WindowForWrapper *>(window)->input().down(Gosu::Button(btn));
281
+ }
282
+
283
+ // Destructor
284
+ void Gosu_Window_destroy(Gosu_Window *window)
285
+ {
286
+ delete (reinterpret_cast<Gosu::WindowForWrapper *>(window));
287
+ }
288
+
289
+ }