gosu 0.15.1 → 0.15.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,6 +7,7 @@
7
7
  #include <cmath>
8
8
  #include <algorithm>
9
9
  #include <vector>
10
+ #include <stdexcept>
10
11
  using namespace std;
11
12
 
12
13
  double Gosu::text_width(const u32string& text,
@@ -0,0 +1,101 @@
1
+ #include <Gosu/Gosu.hpp>
2
+
3
+ namespace Gosu
4
+ {
5
+ class TextInputForWrapper : public Gosu::TextInput
6
+ {
7
+ public:
8
+ TextInputForWrapper();
9
+ std::string filter(std::string text) const override;
10
+ std::function<void (const char *text)> filter_callback;
11
+ std::string filter_result = "";
12
+ };
13
+ } // namespace Gosu
14
+
15
+ Gosu::TextInputForWrapper::TextInputForWrapper() : Gosu::TextInput()
16
+ {
17
+ }
18
+
19
+ std::string Gosu::TextInputForWrapper::filter(std::string text) const
20
+ {
21
+ if (filter_callback != nullptr) {
22
+ filter_callback(text.c_str());
23
+ return filter_result;
24
+ }
25
+ else {
26
+ return text;
27
+ }
28
+ }
29
+
30
+ extern "C" {
31
+ #include <Gosu/TextInput.h>
32
+
33
+ Gosu_TextInput *Gosu_TextInput_create()
34
+ {
35
+ return reinterpret_cast<Gosu_TextInput *>(new Gosu::TextInputForWrapper());
36
+ }
37
+
38
+ const char *Gosu_TextInput_text(Gosu_TextInput *text_input)
39
+ {
40
+ thread_local std::string string;
41
+ string = reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->text();
42
+
43
+ return string.c_str();
44
+ }
45
+
46
+ void Gosu_TextInput_set_text(Gosu_TextInput *text_input, const char *text)
47
+ {
48
+ reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->set_text(text);
49
+ }
50
+
51
+ unsigned Gosu_TextInput_caret_pos(Gosu_TextInput *text_input)
52
+ {
53
+ return reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->caret_pos();
54
+ }
55
+
56
+ void Gosu_TextInput_set_caret_pos(Gosu_TextInput *text_input, unsigned pos)
57
+ {
58
+ return reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->set_caret_pos(pos);
59
+ }
60
+
61
+ unsigned Gosu_TextInput_selection_start(Gosu_TextInput *text_input)
62
+ {
63
+ return reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->selection_start();
64
+ }
65
+
66
+ void Gosu_TextInput_set_selection_start(Gosu_TextInput *text_input, unsigned pos)
67
+ {
68
+ return reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->set_selection_start(pos);
69
+ }
70
+
71
+ void Gosu_TextInput_set_filter(Gosu_TextInput *text_input, void function(void *data, const char *text), void *data)
72
+ {
73
+ reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->filter_callback = [=](const char *text) { function(data, text); };
74
+ }
75
+
76
+ void Gosu_TextInput_set_filter_result(Gosu_TextInput *text_input, const char *result)
77
+ {
78
+ reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->filter_result = result;
79
+ }
80
+
81
+ void Gosu_TextInput_insert_text(Gosu_TextInput *text_input, const char *text)
82
+ {
83
+ reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->insert_text(text);
84
+ }
85
+
86
+ void Gosu_TextInput_delete_backward(Gosu_TextInput *text_input)
87
+ {
88
+ reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->delete_backward();
89
+ }
90
+
91
+ void Gosu_TextInput_delete_forward(Gosu_TextInput *text_input)
92
+ {
93
+ reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->delete_forward();
94
+ }
95
+
96
+ void Gosu_TextInput_destroy(Gosu_TextInput *text_input)
97
+ {
98
+ delete (reinterpret_cast<Gosu::TextInputForWrapper *>(text_input));
99
+ }
100
+
101
+ }
@@ -1,6 +1,7 @@
1
1
  #include "TrueTypeFont.hpp"
2
2
  #include <Gosu/IO.hpp>
3
3
  #include <Gosu/Text.hpp>
4
+ #include <stdexcept>
4
5
 
5
6
  // Disable comma warnings in stb headers.
6
7
  #ifdef __GNUC__
@@ -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
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gosu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.1
4
+ version: 0.15.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Raschke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-21 00:00:00.000000000 Z
11
+ date: 2020-06-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  2D game development library.
@@ -25,30 +25,40 @@ extra_rdoc_files:
25
25
  - COPYING
26
26
  - rdoc/gosu.rb
27
27
  files:
28
+ - ".yardopts"
28
29
  - COPYING
29
30
  - Gosu/Audio.hpp
30
31
  - Gosu/AutoLink.hpp
31
32
  - Gosu/Bitmap.hpp
32
33
  - Gosu/Buttons.hpp
34
+ - Gosu/Channel.h
35
+ - Gosu/Color.h
33
36
  - Gosu/Color.hpp
34
37
  - Gosu/Directories.hpp
38
+ - Gosu/Font.h
35
39
  - Gosu/Font.hpp
36
40
  - Gosu/Fwd.hpp
41
+ - Gosu/Gosu.h
37
42
  - Gosu/Gosu.hpp
38
43
  - Gosu/Graphics.hpp
39
44
  - Gosu/GraphicsBase.hpp
40
45
  - Gosu/IO.hpp
46
+ - Gosu/Image.h
41
47
  - Gosu/Image.hpp
42
48
  - Gosu/ImageData.hpp
43
49
  - Gosu/Input.hpp
44
50
  - Gosu/Inspection.hpp
45
51
  - Gosu/Math.hpp
46
52
  - Gosu/Platform.hpp
53
+ - Gosu/Sample.h
54
+ - Gosu/Song.h
47
55
  - Gosu/Text.hpp
56
+ - Gosu/TextInput.h
48
57
  - Gosu/TextInput.hpp
49
58
  - Gosu/Timing.hpp
50
59
  - Gosu/Utility.hpp
51
60
  - Gosu/Version.hpp
61
+ - Gosu/Window.h
52
62
  - Gosu/Window.hpp
53
63
  - README.md
54
64
  - ext/gosu/extconf.rb
@@ -70,8 +80,11 @@ files:
70
80
  - src/BlockAllocator.cpp
71
81
  - src/BlockAllocator.hpp
72
82
  - src/Channel.cpp
83
+ - src/ChannelWrapper.cpp
73
84
  - src/ClipRectStack.hpp
74
85
  - src/Color.cpp
86
+ - src/ColorWrapper.cpp
87
+ - src/Constants.cpp
75
88
  - src/DirectoriesApple.cpp
76
89
  - src/DirectoriesUnix.cpp
77
90
  - src/DirectoriesWin.cpp
@@ -81,15 +94,18 @@ files:
81
94
  - src/FileUnix.cpp
82
95
  - src/FileWin.cpp
83
96
  - src/Font.cpp
97
+ - src/FontWrapper.cpp
84
98
  - src/GosuGLView.cpp
85
99
  - src/GosuGLView.hpp
86
100
  - src/GosuViewController.cpp
87
101
  - src/GosuViewController.hpp
102
+ - src/GosuWrapper.cpp
88
103
  - src/Graphics.cpp
89
104
  - src/GraphicsImpl.hpp
90
105
  - src/IO.cpp
91
106
  - src/Iconv.hpp
92
107
  - src/Image.cpp
108
+ - src/ImageWrapper.cpp
93
109
  - src/Input.cpp
94
110
  - src/InputUIKit.cpp
95
111
  - src/Inspection.cpp
@@ -109,13 +125,16 @@ files:
109
125
  - src/Resolution.cpp
110
126
  - src/RubyGosu.cxx
111
127
  - src/RubyGosu.h
128
+ - src/SampleWrapper.cpp
112
129
  - src/SndFile.hpp
130
+ - src/SongWrapper.cpp
113
131
  - src/TexChunk.cpp
114
132
  - src/TexChunk.hpp
115
133
  - src/Text.cpp
116
134
  - src/TextBuilder.cpp
117
135
  - src/TextBuilder.hpp
118
136
  - src/TextInput.cpp
137
+ - src/TextInputWrapper.cpp
119
138
  - src/Texture.cpp
120
139
  - src/Texture.hpp
121
140
  - src/TimingApple.cpp
@@ -137,6 +156,7 @@ files:
137
156
  - src/WinUtility.hpp
138
157
  - src/Window.cpp
139
158
  - src/WindowUIKit.cpp
159
+ - src/WindowWrapper.cpp
140
160
  - src/stb_image.h
141
161
  - src/stb_image_write.h
142
162
  - src/stb_truetype.h
@@ -167,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
187
  - !ruby/object:Gem::Version
168
188
  version: '0'
169
189
  requirements: []
170
- rubygems_version: 3.0.6
190
+ rubygems_version: 3.0.3
171
191
  signing_key:
172
192
  specification_version: 4
173
193
  summary: 2D game development library.