sfml3-rb 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.yardopts +9 -0
- data/CHANGELOG.md +43 -17
- data/README.md +97 -29
- data/ext/audio/audio_enums.c +58 -20
- data/ext/audio/listener.c +89 -6
- data/ext/audio/music.c +206 -5
- data/ext/audio/sound.c +175 -5
- data/ext/audio/sound_buffer.c +189 -47
- data/ext/audio/sound_buffer_recorder.c +83 -16
- data/ext/audio/sound_recorder.c +172 -52
- data/ext/audio/sound_source_cone.c +108 -29
- data/ext/audio/sound_stream.c +178 -5
- data/ext/core/exceptions.c +10 -8
- data/ext/core/unicode.c +12 -2
- data/ext/ext.c +4 -0
- data/ext/graphics/blend_mode.c +203 -53
- data/ext/graphics/circle.c +271 -4
- data/ext/graphics/color.c +240 -90
- data/ext/graphics/drawable.c +15 -4
- data/ext/graphics/font.c +138 -25
- data/ext/graphics/glyph.c +31 -8
- data/ext/graphics/image.c +180 -37
- data/ext/graphics/polygon.c +293 -26
- data/ext/graphics/rect.c +211 -54
- data/ext/graphics/rectangle.c +279 -26
- data/ext/graphics/render_state.c +116 -2
- data/ext/graphics/render_texture.c +163 -2
- data/ext/graphics/shader.c +283 -17
- data/ext/graphics/shape.c +252 -26
- data/ext/graphics/sprite.c +216 -25
- data/ext/graphics/stencil_mode.c +148 -39
- data/ext/graphics/target.c +67 -22
- data/ext/graphics/target.h +15 -15
- data/ext/graphics/text.c +306 -6
- data/ext/graphics/texture.c +257 -3
- data/ext/graphics/transform.c +178 -5
- data/ext/graphics/transformable.c +126 -2
- data/ext/graphics/vertex.c +79 -2
- data/ext/graphics/vertex_array.c +128 -16
- data/ext/graphics/vertex_buffer.c +124 -2
- data/ext/graphics/view.c +130 -2
- data/ext/network/ftp.c +249 -10
- data/ext/network/http.c +156 -38
- data/ext/network/ip_address.c +107 -26
- data/ext/network/network_enums.c +248 -141
- data/ext/network/packet.c +273 -39
- data/ext/network/socket_selector.c +91 -19
- data/ext/network/tcp_listener.c +75 -16
- data/ext/network/tcp_socket.c +128 -25
- data/ext/network/udp_socket.c +122 -26
- data/ext/ports.rb +7 -0
- data/ext/system/buffer.c +41 -12
- data/ext/system/clock.c +68 -9
- data/ext/system/input_stream.c +94 -42
- data/ext/system/sleep.c +10 -2
- data/ext/system/time.c +172 -34
- data/ext/system/vec2.c +156 -35
- data/ext/system/vec3.c +166 -35
- data/ext/window/clipboard.c +47 -17
- data/ext/window/context.c +59 -9
- data/ext/window/context_settings.c +116 -38
- data/ext/window/cursor.c +39 -9
- data/ext/window/event.c +163 -42
- data/ext/window/joystick.c +69 -3
- data/ext/window/keyboard.c +168 -116
- data/ext/window/mouse.c +36 -2
- data/ext/window/sensor.c +28 -2
- data/ext/window/touch.c +20 -2
- data/ext/window/video_mode.c +90 -19
- data/ext/window/vulkan.c +34 -6
- data/ext/window/window.c +340 -16
- data/lib/sfml/version.rb +1 -1
- data/sig/audio/audio_enums.rbs +30 -0
- data/sig/audio/listener.rbs +16 -0
- data/sig/audio/music.rbs +56 -0
- data/sig/audio/sound.rbs +51 -0
- data/sig/audio/sound_buffer.rbs +17 -0
- data/sig/audio/sound_buffer_recorder.rbs +14 -0
- data/sig/audio/sound_recorder.rbs +17 -0
- data/sig/audio/sound_source_cone.rbs +14 -0
- data/sig/audio/sound_stream.rbs +51 -0
- data/sig/graphics/blend_mode.rbs +29 -0
- data/sig/graphics/circle.rbs +44 -0
- data/sig/graphics/color.rbs +39 -0
- data/sig/graphics/drawable.rbs +5 -0
- data/sig/graphics/font.rbs +20 -0
- data/sig/graphics/glyph.rbs +7 -0
- data/sig/graphics/image.rbs +22 -0
- data/sig/graphics/polygon.rbs +42 -0
- data/sig/graphics/rect.rbs +33 -0
- data/sig/graphics/rectangle.rbs +42 -0
- data/sig/graphics/render_state.rbs +21 -0
- data/sig/graphics/render_texture.rbs +37 -0
- data/sig/graphics/shader.rbs +39 -0
- data/sig/graphics/shape.rbs +38 -0
- data/sig/graphics/sprite.rbs +34 -0
- data/sig/graphics/stencil_mode.rbs +18 -0
- data/sig/graphics/target.rbs +10 -0
- data/sig/graphics/text.rbs +48 -0
- data/sig/graphics/texture.rbs +34 -0
- data/sig/graphics/transform.rbs +37 -0
- data/sig/graphics/transformable.rbs +25 -0
- data/sig/graphics/vertex.rbs +17 -0
- data/sig/graphics/vertex_array.rbs +17 -0
- data/sig/graphics/vertex_buffer.rbs +22 -0
- data/sig/graphics/view.rbs +24 -0
- data/sig/network/ftp.rbs +46 -0
- data/sig/network/http.rbs +27 -0
- data/sig/network/ip_address.rbs +22 -0
- data/sig/network/network_enums.rbs +95 -0
- data/sig/network/packet.rbs +40 -0
- data/sig/network/socket_selector.rbs +14 -0
- data/sig/network/tcp_listener.rbs +13 -0
- data/sig/network/tcp_socket.rbs +18 -0
- data/sig/network/udp_socket.rbs +17 -0
- data/sig/system/buffer.rbs +11 -0
- data/sig/system/clock.rbs +13 -0
- data/sig/system/input_stream.rbs +7 -0
- data/sig/system/sleep.rbs +3 -0
- data/sig/system/time.rbs +28 -0
- data/sig/system/vec2.rbs +26 -0
- data/sig/system/vec3.rbs +27 -0
- data/sig/window/clipboard.rbs +8 -0
- data/sig/window/context.rbs +11 -0
- data/sig/window/context_settings.rbs +20 -0
- data/sig/window/cursor.rbs +6 -0
- data/sig/window/event.rbs +20 -0
- data/sig/window/joystick.rbs +15 -0
- data/sig/window/keyboard.rbs +10 -0
- data/sig/window/mouse.rbs +9 -0
- data/sig/window/sensor.rbs +8 -0
- data/sig/window/touch.rbs +6 -0
- data/sig/window/video_mode.rbs +16 -0
- data/sig/window/vulkan.rbs +7 -0
- data/sig/window/window.rbs +57 -0
- metadata +66 -2
data/ext/window/window.c
CHANGED
|
@@ -19,20 +19,58 @@
|
|
|
19
19
|
|
|
20
20
|
static VALUE rb_cWindow;
|
|
21
21
|
|
|
22
|
+
/* sfRenderWindow_setMouseCursor requires the Cursor to stay alive for as
|
|
23
|
+
long as it's in use by the window (CSFML/SFML docs), so the wrapper needs
|
|
24
|
+
a place to retain it -- and therefore a dmark, unlike a bare pointer. */
|
|
25
|
+
typedef struct {
|
|
26
|
+
sfRenderWindow* window;
|
|
27
|
+
VALUE rb_cursor;
|
|
28
|
+
} Window;
|
|
29
|
+
|
|
22
30
|
static sfRenderWindow* Window_create(sfVideoMode* mode, const sfChar32* title, uint32_t style,
|
|
23
31
|
sfWindowState state, const sfContextSettings* settings) {
|
|
24
32
|
return sfRenderWindow_createUnicode(*mode, title, style, state, settings);
|
|
25
33
|
}
|
|
26
34
|
|
|
35
|
+
static void Window_mark(void* ptr) {
|
|
36
|
+
Window* window = ptr;
|
|
37
|
+
|
|
38
|
+
rb_gc_mark(window->rb_cursor);
|
|
39
|
+
}
|
|
40
|
+
|
|
27
41
|
static void Window_free(void* ptr) {
|
|
28
|
-
|
|
42
|
+
Window* window = ptr;
|
|
43
|
+
|
|
44
|
+
sfRenderWindow_destroy(window->window);
|
|
45
|
+
free(window);
|
|
29
46
|
}
|
|
30
47
|
|
|
31
48
|
static const rb_data_type_t Window_data_type = {
|
|
32
49
|
.wrap_struct_name = "SFML::Window",
|
|
33
|
-
.function = {.dmark =
|
|
50
|
+
.function = {.dmark = Window_mark, .dfree = Window_free, .dsize = NULL},
|
|
34
51
|
.flags = RUBY_TYPED_FREE_IMMEDIATELY};
|
|
35
52
|
|
|
53
|
+
static VALUE Window_wrap(VALUE klass, sfRenderWindow* c_window) {
|
|
54
|
+
Window* window = malloc(sizeof(Window));
|
|
55
|
+
|
|
56
|
+
if (window == NULL) {
|
|
57
|
+
rb_raise(rb_eNoMemError, "failed to allocate window");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
window->window = c_window;
|
|
61
|
+
window->rb_cursor = Qnil;
|
|
62
|
+
|
|
63
|
+
return TypedData_Wrap_Struct(klass, &Window_data_type, window);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/* call-seq:
|
|
67
|
+
* Window.new(video_mode, title, style = :default, state = :windowed, settings = nil) -> Window
|
|
68
|
+
*
|
|
69
|
+
* Creates a window from +video_mode+ and +title+.
|
|
70
|
+
*
|
|
71
|
+
* @return [Window]
|
|
72
|
+
* @raise [RuntimeError] if window creation fails
|
|
73
|
+
*/
|
|
36
74
|
static VALUE Window_new(int argc, VALUE* argv, VALUE klass) {
|
|
37
75
|
VALUE self, rb_video_mode, rb_title, rb_style, rb_state, rb_settings, title_buffer;
|
|
38
76
|
sfWindowState state = sfWindowed;
|
|
@@ -69,7 +107,7 @@ static VALUE Window_new(int argc, VALUE* argv, VALUE klass) {
|
|
|
69
107
|
rb_raise(rb_eRuntimeError, "failed to create window");
|
|
70
108
|
}
|
|
71
109
|
|
|
72
|
-
self =
|
|
110
|
+
self = Window_wrap(klass, window);
|
|
73
111
|
|
|
74
112
|
rb_obj_call_init(self, argc, argv);
|
|
75
113
|
|
|
@@ -80,6 +118,14 @@ static VALUE Window_new(int argc, VALUE* argv, VALUE klass) {
|
|
|
80
118
|
Window#native_handle returns, or one obtained from a GUI toolkit. The window
|
|
81
119
|
is not owned by the toolkit afterwards: destroying it stays the toolkit's
|
|
82
120
|
job, and closing the Ruby object only tears down the render context. */
|
|
121
|
+
/* call-seq:
|
|
122
|
+
* Window.from_handle(handle, settings = nil) -> Window
|
|
123
|
+
*
|
|
124
|
+
* Creates a window that adopts the existing OS window +handle+.
|
|
125
|
+
*
|
|
126
|
+
* @return [Window]
|
|
127
|
+
* @raise [RuntimeError] if window creation fails
|
|
128
|
+
*/
|
|
83
129
|
static VALUE Window_s_from_handle(int argc, VALUE* argv, VALUE klass) {
|
|
84
130
|
VALUE self, rb_handle, rb_settings;
|
|
85
131
|
sfContextSettings settings;
|
|
@@ -100,7 +146,7 @@ static VALUE Window_s_from_handle(int argc, VALUE* argv, VALUE klass) {
|
|
|
100
146
|
rb_raise(rb_eRuntimeError, "failed to create window from handle");
|
|
101
147
|
}
|
|
102
148
|
|
|
103
|
-
self =
|
|
149
|
+
self = Window_wrap(klass, window);
|
|
104
150
|
|
|
105
151
|
rb_obj_call_init(self, 0, NULL);
|
|
106
152
|
|
|
@@ -111,15 +157,35 @@ static VALUE Window_init(int argc, VALUE* argv, VALUE self) {
|
|
|
111
157
|
return self;
|
|
112
158
|
}
|
|
113
159
|
|
|
160
|
+
/* call-seq: is_open? -> true or false
|
|
161
|
+
*
|
|
162
|
+
* Returns +true+ while the window is open.
|
|
163
|
+
*
|
|
164
|
+
* @return [Boolean]
|
|
165
|
+
*/
|
|
114
166
|
static VALUE Window_is_open(VALUE self) {
|
|
115
167
|
return BOOL2RB(sfRenderWindow_isOpen(Get_Window_Struct(self)));
|
|
116
168
|
}
|
|
117
169
|
|
|
170
|
+
/* call-seq: close! -> self
|
|
171
|
+
*
|
|
172
|
+
* Closes the window.
|
|
173
|
+
*
|
|
174
|
+
* @return [self]
|
|
175
|
+
*/
|
|
118
176
|
static VALUE Window_close(VALUE self) {
|
|
119
177
|
sfRenderWindow_close(Get_Window_Struct(self));
|
|
120
178
|
return self;
|
|
121
179
|
}
|
|
122
180
|
|
|
181
|
+
/* call-seq:
|
|
182
|
+
* clear(color = Color::BLACK) -> self
|
|
183
|
+
*
|
|
184
|
+
* Clears the window to +color+ (black by default).
|
|
185
|
+
*
|
|
186
|
+
* @return [self]
|
|
187
|
+
* @raise [ArgumentError] if given more than one argument
|
|
188
|
+
*/
|
|
123
189
|
static VALUE Window_clear(int argc, VALUE* argv, VALUE self) {
|
|
124
190
|
sfColor color = sfBlack;
|
|
125
191
|
|
|
@@ -137,11 +203,26 @@ static VALUE Window_clear(int argc, VALUE* argv, VALUE self) {
|
|
|
137
203
|
return self;
|
|
138
204
|
}
|
|
139
205
|
|
|
206
|
+
/* call-seq: display -> self
|
|
207
|
+
*
|
|
208
|
+
* Presents everything drawn since the last call to the screen.
|
|
209
|
+
*
|
|
210
|
+
* @return [self]
|
|
211
|
+
*/
|
|
140
212
|
static VALUE Window_display(VALUE self) {
|
|
141
213
|
sfRenderWindow_display(Get_Window_Struct(self));
|
|
142
214
|
return self;
|
|
143
215
|
}
|
|
144
216
|
|
|
217
|
+
/* call-seq:
|
|
218
|
+
* poll_event!(event) -> true or false
|
|
219
|
+
*
|
|
220
|
+
* Pops the next pending event from the queue into +event+, if any, without
|
|
221
|
+
* blocking.
|
|
222
|
+
*
|
|
223
|
+
* @return [Boolean] whether an event was popped
|
|
224
|
+
* @raise [ArgumentError] if +event+ is not an Event
|
|
225
|
+
*/
|
|
145
226
|
static VALUE Window_poll_event(VALUE self, VALUE rb_event) {
|
|
146
227
|
if (!rb_obj_is_kind_of(rb_event, Get_Klass_Event())) {
|
|
147
228
|
raise_invalid_argument_class(Get_Klass_Event());
|
|
@@ -150,6 +231,14 @@ static VALUE Window_poll_event(VALUE self, VALUE rb_event) {
|
|
|
150
231
|
return BOOL2RB(sfRenderWindow_pollEvent(Get_Window_Struct(self), Get_Event_Struct(rb_event)));
|
|
151
232
|
}
|
|
152
233
|
|
|
234
|
+
/* call-seq:
|
|
235
|
+
* wait_event!(event) -> true or false
|
|
236
|
+
*
|
|
237
|
+
* Blocks until an event is available and pops it into +event+.
|
|
238
|
+
*
|
|
239
|
+
* @return [Boolean] whether an event was popped
|
|
240
|
+
* @raise [ArgumentError] if +event+ is not an Event
|
|
241
|
+
*/
|
|
153
242
|
static VALUE Window_wait_event(VALUE self, VALUE rb_event) {
|
|
154
243
|
if (!rb_obj_is_kind_of(rb_event, Get_Klass_Event())) {
|
|
155
244
|
raise_invalid_argument_class(Get_Klass_Event());
|
|
@@ -159,29 +248,69 @@ static VALUE Window_wait_event(VALUE self, VALUE rb_event) {
|
|
|
159
248
|
sfRenderWindow_waitEvent(Get_Window_Struct(self), sfTime_Zero, Get_Event_Struct(rb_event)));
|
|
160
249
|
}
|
|
161
250
|
|
|
251
|
+
/* call-seq: position -> Vector2
|
|
252
|
+
*
|
|
253
|
+
* Returns the window's position in desktop coordinates.
|
|
254
|
+
*
|
|
255
|
+
* @return [Vector2] the window's position, in desktop coordinates
|
|
256
|
+
*/
|
|
162
257
|
static VALUE Window_get_position(VALUE self) {
|
|
163
258
|
return VEC2_C2RB(sfRenderWindow_getPosition(Get_Window_Struct(self)));
|
|
164
259
|
}
|
|
165
260
|
|
|
261
|
+
/* call-seq:
|
|
262
|
+
* position=(value) -> value
|
|
263
|
+
*
|
|
264
|
+
* Moves the window to +value+ in desktop coordinates.
|
|
265
|
+
*
|
|
266
|
+
* @return [Vector2] +value+
|
|
267
|
+
*/
|
|
166
268
|
static VALUE Window_set_position(VALUE self, VALUE rb_arr) {
|
|
167
269
|
sfRenderWindow_setPosition(Get_Window_Struct(self), vec2i_new_from_ruby(rb_arr));
|
|
168
270
|
return self;
|
|
169
271
|
}
|
|
170
272
|
|
|
273
|
+
/* call-seq:
|
|
274
|
+
* frame_rate=(value) -> self
|
|
275
|
+
*
|
|
276
|
+
* Limits the framerate to +value+ frames per second; 0 disables the limit.
|
|
277
|
+
*
|
|
278
|
+
* @return [self]
|
|
279
|
+
*/
|
|
171
280
|
static VALUE Window_set_frame_rate(VALUE self, VALUE rb_limit) {
|
|
172
281
|
sfRenderWindow_setFramerateLimit(Get_Window_Struct(self), NUM2INT(rb_limit));
|
|
173
282
|
return self;
|
|
174
283
|
}
|
|
175
284
|
|
|
285
|
+
/* call-seq:
|
|
286
|
+
* size=(value) -> self
|
|
287
|
+
*
|
|
288
|
+
* Resizes the window's client area to +value+.
|
|
289
|
+
*
|
|
290
|
+
* @return [self]
|
|
291
|
+
*/
|
|
176
292
|
static VALUE Window_set_size(VALUE self, VALUE rb_size) {
|
|
177
293
|
sfRenderWindow_setSize(Get_Window_Struct(self), vec2u_from_rb(rb_size));
|
|
178
294
|
return self;
|
|
179
295
|
}
|
|
180
296
|
|
|
297
|
+
/* call-seq: size -> Vector2
|
|
298
|
+
*
|
|
299
|
+
* Returns the client area size in pixels.
|
|
300
|
+
*
|
|
301
|
+
* @return [Vector2] the client area size, in pixels
|
|
302
|
+
*/
|
|
181
303
|
static VALUE Window_get_size(VALUE self) {
|
|
182
304
|
return VEC2_C2RB(sfRenderWindow_getSize(Get_Window_Struct(self)));
|
|
183
305
|
}
|
|
184
306
|
|
|
307
|
+
/* call-seq:
|
|
308
|
+
* minimum_size=(value) -> value
|
|
309
|
+
*
|
|
310
|
+
* Sets the window's minimum allowed client size.
|
|
311
|
+
*
|
|
312
|
+
* @return [Vector2] +value+
|
|
313
|
+
*/
|
|
185
314
|
static VALUE Window_set_minimum_size(VALUE self, VALUE rb_size) {
|
|
186
315
|
sfVector2u size = vec2u_from_rb(rb_size);
|
|
187
316
|
|
|
@@ -190,6 +319,13 @@ static VALUE Window_set_minimum_size(VALUE self, VALUE rb_size) {
|
|
|
190
319
|
return rb_size;
|
|
191
320
|
}
|
|
192
321
|
|
|
322
|
+
/* call-seq:
|
|
323
|
+
* maximum_size=(value) -> value
|
|
324
|
+
*
|
|
325
|
+
* Sets the window's maximum allowed client size.
|
|
326
|
+
*
|
|
327
|
+
* @return [Vector2] +value+
|
|
328
|
+
*/
|
|
193
329
|
static VALUE Window_set_maximum_size(VALUE self, VALUE rb_size) {
|
|
194
330
|
sfVector2u size = vec2u_from_rb(rb_size);
|
|
195
331
|
|
|
@@ -198,10 +334,24 @@ static VALUE Window_set_maximum_size(VALUE self, VALUE rb_size) {
|
|
|
198
334
|
return rb_size;
|
|
199
335
|
}
|
|
200
336
|
|
|
337
|
+
/* call-seq:
|
|
338
|
+
* active=(value) -> true or false
|
|
339
|
+
*
|
|
340
|
+
* Activates or deactivates this window's OpenGL context as the current one
|
|
341
|
+
* on the calling thread.
|
|
342
|
+
*
|
|
343
|
+
* @return [Boolean] whether activation succeeded
|
|
344
|
+
*/
|
|
201
345
|
static VALUE Window_set_active(VALUE self, VALUE rb_active) {
|
|
202
346
|
return BOOL2RB(sfRenderWindow_setActive(Get_Window_Struct(self), RTEST(rb_active)));
|
|
203
347
|
}
|
|
204
348
|
|
|
349
|
+
/* call-seq: native_handle -> Integer
|
|
350
|
+
*
|
|
351
|
+
* Returns the OS-specific window handle.
|
|
352
|
+
*
|
|
353
|
+
* @return [Integer] the OS-specific window handle
|
|
354
|
+
*/
|
|
205
355
|
static VALUE Window_get_native_handle(VALUE self) {
|
|
206
356
|
return ULL2NUM(
|
|
207
357
|
(unsigned long long)(uintptr_t)sfRenderWindow_getNativeHandle(Get_Window_Struct(self)));
|
|
@@ -211,6 +361,13 @@ static VALUE Window_get_native_handle(VALUE self) {
|
|
|
211
361
|
SFML::Vulkan.function already returns one -- there is no Vulkan object model
|
|
212
362
|
here to wrap them in. Returns the new VkSurfaceKHR, or nil if creation
|
|
213
363
|
failed. */
|
|
364
|
+
/* call-seq:
|
|
365
|
+
* create_vulkan_surface(instance, allocator = nil) -> Integer or nil
|
|
366
|
+
*
|
|
367
|
+
* Creates a Vulkan surface for this window from +instance+.
|
|
368
|
+
*
|
|
369
|
+
* @return [Integer, nil] the new +VkSurfaceKHR+, or +nil+ if creation failed
|
|
370
|
+
*/
|
|
214
371
|
static VALUE Window_create_vulkan_surface(int argc, VALUE* argv, VALUE self) {
|
|
215
372
|
VALUE rb_instance, rb_allocator;
|
|
216
373
|
VkInstance instance;
|
|
@@ -233,21 +390,50 @@ static VALUE Window_create_vulkan_surface(int argc, VALUE* argv, VALUE self) {
|
|
|
233
390
|
return ULL2NUM((unsigned long long)(uintptr_t)surface);
|
|
234
391
|
}
|
|
235
392
|
|
|
393
|
+
/* call-seq:
|
|
394
|
+
* set_icon(size, pixels) -> pixels
|
|
395
|
+
*
|
|
396
|
+
* Sets the window's icon from RGBA32 pixel data (+width * height * 4+
|
|
397
|
+
* bytes, row-major, top-to-bottom).
|
|
398
|
+
*
|
|
399
|
+
* @return [String] +pixels+
|
|
400
|
+
* @raise [ArgumentError] if +pixels+ is shorter than required
|
|
401
|
+
*/
|
|
236
402
|
static VALUE Window_set_icon(VALUE self, VALUE rb_size, VALUE rb_pixels) {
|
|
403
|
+
sfVector2u size = vec2u_from_rb(rb_size);
|
|
404
|
+
size_t expected = (size_t)size.x * size.y * 4;
|
|
405
|
+
|
|
237
406
|
StringValue(rb_pixels);
|
|
238
407
|
|
|
239
|
-
|
|
240
|
-
|
|
408
|
+
if ((size_t)RSTRING_LEN(rb_pixels) < expected) {
|
|
409
|
+
rb_raise(rb_eArgError, "pixel data too short: expected %zu bytes", expected);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
sfRenderWindow_setIcon(Get_Window_Struct(self), size, (const uint8_t*)RSTRING_PTR(rb_pixels));
|
|
241
413
|
|
|
242
414
|
return rb_pixels;
|
|
243
415
|
}
|
|
244
416
|
|
|
417
|
+
/* call-seq: settings -> ContextSettings
|
|
418
|
+
*
|
|
419
|
+
* Returns the context settings this window was created with.
|
|
420
|
+
*
|
|
421
|
+
* @return [ContextSettings] the settings this window's context was created
|
|
422
|
+
* with
|
|
423
|
+
*/
|
|
245
424
|
static VALUE Window_get_settings(VALUE self) {
|
|
246
425
|
return context_settings_to_rb(sfRenderWindow_getSettings(Get_Window_Struct(self)));
|
|
247
426
|
}
|
|
248
427
|
|
|
249
428
|
/* Through the UTF-32 entry point: sfRenderWindow_setTitle decodes the bytes
|
|
250
429
|
with the C locale and mangles anything outside ASCII. */
|
|
430
|
+
/* call-seq:
|
|
431
|
+
* title=(value) -> self
|
|
432
|
+
*
|
|
433
|
+
* Sets the window title.
|
|
434
|
+
*
|
|
435
|
+
* @return [self]
|
|
436
|
+
*/
|
|
251
437
|
static VALUE Window_set_title(VALUE self, VALUE rb_title) {
|
|
252
438
|
VALUE buffer = utf32_from_rb(rb_title);
|
|
253
439
|
|
|
@@ -258,60 +444,136 @@ static VALUE Window_set_title(VALUE self, VALUE rb_title) {
|
|
|
258
444
|
return self;
|
|
259
445
|
}
|
|
260
446
|
|
|
447
|
+
/* call-seq:
|
|
448
|
+
* visible=(value) -> self
|
|
449
|
+
*
|
|
450
|
+
* Shows or hides the window.
|
|
451
|
+
*
|
|
452
|
+
* @return [self]
|
|
453
|
+
*/
|
|
261
454
|
static VALUE Window_set_visible(VALUE self, VALUE rb_visible) {
|
|
262
455
|
sfRenderWindow_setVisible(Get_Window_Struct(self), RTEST(rb_visible));
|
|
263
456
|
return self;
|
|
264
457
|
}
|
|
265
458
|
|
|
459
|
+
/* call-seq:
|
|
460
|
+
* vertical_sync_enabled=(value) -> self
|
|
461
|
+
*
|
|
462
|
+
* Enables or disables vertical synchronization.
|
|
463
|
+
*
|
|
464
|
+
* @return [self]
|
|
465
|
+
*/
|
|
266
466
|
static VALUE Window_set_vertical_sync_enabled(VALUE self, VALUE rb_enable) {
|
|
267
467
|
sfRenderWindow_setVerticalSyncEnabled(Get_Window_Struct(self), RTEST(rb_enable));
|
|
268
468
|
return self;
|
|
269
469
|
}
|
|
270
470
|
|
|
471
|
+
/* call-seq:
|
|
472
|
+
* cursor_visible=(value) -> self
|
|
473
|
+
*
|
|
474
|
+
* Shows or hides the mouse cursor over the window.
|
|
475
|
+
*
|
|
476
|
+
* @return [self]
|
|
477
|
+
*/
|
|
271
478
|
static VALUE Window_set_mouse_cursor_visible(VALUE self, VALUE rb_visible) {
|
|
272
479
|
sfRenderWindow_setMouseCursorVisible(Get_Window_Struct(self), RTEST(rb_visible));
|
|
273
480
|
return self;
|
|
274
481
|
}
|
|
275
482
|
|
|
483
|
+
/* call-seq:
|
|
484
|
+
* cursor_grabbed=(value) -> self
|
|
485
|
+
*
|
|
486
|
+
* Confines or releases the mouse cursor to the window's client area.
|
|
487
|
+
*
|
|
488
|
+
* @return [self]
|
|
489
|
+
*/
|
|
276
490
|
static VALUE Window_set_mouse_cursor_grabbed(VALUE self, VALUE rb_grabbed) {
|
|
277
491
|
sfRenderWindow_setMouseCursorGrabbed(Get_Window_Struct(self), RTEST(rb_grabbed));
|
|
278
492
|
return self;
|
|
279
493
|
}
|
|
280
494
|
|
|
495
|
+
/* call-seq:
|
|
496
|
+
* cursor=(value) -> value
|
|
497
|
+
*
|
|
498
|
+
* Sets the window's mouse cursor. CSFML has no way to clear it back to a
|
|
499
|
+
* system default once set (its C API unconditionally dereferences the
|
|
500
|
+
* cursor pointer, so passing it NULL crashes the process rather than
|
|
501
|
+
* clearing it), so unlike most other assignment-style methods here, +nil+
|
|
502
|
+
* is not accepted.
|
|
503
|
+
*
|
|
504
|
+
* @return [Cursor] +value+
|
|
505
|
+
* @raise [ArgumentError] if +value+ is not a Cursor
|
|
506
|
+
*/
|
|
281
507
|
static VALUE Window_set_mouse_cursor(VALUE self, VALUE rb_cursor) {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
return rb_cursor;
|
|
285
|
-
}
|
|
508
|
+
Window* window;
|
|
509
|
+
TypedData_Get_Struct(self, Window, &Window_data_type, window);
|
|
286
510
|
|
|
287
511
|
if (!rb_obj_is_kind_of(rb_cursor, Get_Klass_Cursor())) {
|
|
288
512
|
raise_invalid_argument_class(Get_Klass_Cursor());
|
|
289
513
|
}
|
|
290
514
|
|
|
291
|
-
sfRenderWindow_setMouseCursor(
|
|
515
|
+
sfRenderWindow_setMouseCursor(window->window, Get_Cursor_Struct(rb_cursor));
|
|
516
|
+
/* Keep the Cursor alive for as long as the window may use it -- see the
|
|
517
|
+
Window_mark comment above. */
|
|
518
|
+
window->rb_cursor = rb_cursor;
|
|
292
519
|
|
|
293
520
|
return rb_cursor;
|
|
294
521
|
}
|
|
295
522
|
|
|
523
|
+
/* call-seq:
|
|
524
|
+
* key_repeat_enabled=(value) -> self
|
|
525
|
+
*
|
|
526
|
+
* Enables or disables key-repeat events.
|
|
527
|
+
*
|
|
528
|
+
* @return [self]
|
|
529
|
+
*/
|
|
296
530
|
static VALUE Window_set_key_repeat_enabled(VALUE self, VALUE rb_enabled) {
|
|
297
531
|
sfRenderWindow_setKeyRepeatEnabled(Get_Window_Struct(self), RTEST(rb_enabled));
|
|
298
532
|
return self;
|
|
299
533
|
}
|
|
300
534
|
|
|
535
|
+
/* call-seq:
|
|
536
|
+
* joystick_threshold=(value) -> value
|
|
537
|
+
*
|
|
538
|
+
* Sets the minimum change in a joystick axis's position required to
|
|
539
|
+
* generate a +"joystick-moved"+ event.
|
|
540
|
+
*
|
|
541
|
+
* @return [Float] +value+
|
|
542
|
+
*/
|
|
301
543
|
static VALUE Window_set_joystick_threshold(VALUE self, VALUE rb_threshold) {
|
|
302
544
|
sfRenderWindow_setJoystickThreshold(Get_Window_Struct(self), NUM2DBL(rb_threshold));
|
|
303
545
|
return rb_threshold;
|
|
304
546
|
}
|
|
305
547
|
|
|
548
|
+
/* call-seq: request_focus -> self
|
|
549
|
+
*
|
|
550
|
+
* Requests focus for this window.
|
|
551
|
+
*
|
|
552
|
+
* @return [self]
|
|
553
|
+
*/
|
|
306
554
|
static VALUE Window_request_focus(VALUE self) {
|
|
307
555
|
sfRenderWindow_requestFocus(Get_Window_Struct(self));
|
|
308
556
|
return self;
|
|
309
557
|
}
|
|
310
558
|
|
|
559
|
+
/* call-seq: focus? -> true or false
|
|
560
|
+
*
|
|
561
|
+
* Returns +true+ if the window currently has focus.
|
|
562
|
+
*
|
|
563
|
+
* @return [Boolean]
|
|
564
|
+
*/
|
|
311
565
|
static VALUE Window_has_focus(VALUE self) {
|
|
312
566
|
return BOOL2RB(sfRenderWindow_hasFocus(Get_Window_Struct(self)));
|
|
313
567
|
}
|
|
314
568
|
|
|
569
|
+
/* call-seq:
|
|
570
|
+
* draw(drawable, state = nil) -> self
|
|
571
|
+
*
|
|
572
|
+
* Draws +drawable+ into the window.
|
|
573
|
+
*
|
|
574
|
+
* @return [self]
|
|
575
|
+
* @raise [ArgumentError] if given no arguments or more than 2
|
|
576
|
+
*/
|
|
315
577
|
static VALUE Window_draw(int argc, VALUE* argv, VALUE self) {
|
|
316
578
|
VALUE rb_drawable, rb_state;
|
|
317
579
|
|
|
@@ -327,6 +589,14 @@ static VALUE Window_draw(int argc, VALUE* argv, VALUE self) {
|
|
|
327
589
|
return self;
|
|
328
590
|
}
|
|
329
591
|
|
|
592
|
+
/* call-seq:
|
|
593
|
+
* view=(value) -> self
|
|
594
|
+
*
|
|
595
|
+
* Sets the window's active view to +value+.
|
|
596
|
+
*
|
|
597
|
+
* @return [self]
|
|
598
|
+
* @raise [ArgumentError] if +value+ is not a View
|
|
599
|
+
*/
|
|
330
600
|
static VALUE Window_set_view(VALUE self, VALUE rb_view) {
|
|
331
601
|
if (!rb_obj_is_kind_of(rb_view, Get_Klass_View())) {
|
|
332
602
|
rb_raise(rb_eArgError, "invalid object, expected a View object");
|
|
@@ -337,10 +607,22 @@ static VALUE Window_set_view(VALUE self, VALUE rb_view) {
|
|
|
337
607
|
return self;
|
|
338
608
|
}
|
|
339
609
|
|
|
610
|
+
/* call-seq: view -> View
|
|
611
|
+
*
|
|
612
|
+
* Returns a copy of the window's currently active view.
|
|
613
|
+
*
|
|
614
|
+
* @return [View] a copy of the window's currently active view
|
|
615
|
+
*/
|
|
340
616
|
static VALUE Window_get_view(VALUE self) {
|
|
341
617
|
return Get_Casting_View(sfView_copy(sfRenderWindow_getView(Get_Window_Struct(self))));
|
|
342
618
|
}
|
|
343
619
|
|
|
620
|
+
/* call-seq: default_view -> View
|
|
621
|
+
*
|
|
622
|
+
* Returns a copy of the window's default view.
|
|
623
|
+
*
|
|
624
|
+
* @return [View] a copy of the window's default view
|
|
625
|
+
*/
|
|
344
626
|
static VALUE Window_get_default_view(VALUE self) {
|
|
345
627
|
return Get_Casting_View(sfView_copy((sfRenderWindow_getDefaultView(Get_Window_Struct(self)))));
|
|
346
628
|
}
|
|
@@ -353,8 +635,50 @@ static VALUE Window_get_default_view(VALUE self) {
|
|
|
353
635
|
#undef RT_METHOD
|
|
354
636
|
#undef RT_HANDLE
|
|
355
637
|
|
|
356
|
-
|
|
357
|
-
|
|
638
|
+
/* Document-class: SFML::Window
|
|
639
|
+
* An OS window with an OpenGL context attached, and (through the methods
|
|
640
|
+
* below) a render target you can draw to.
|
|
641
|
+
*
|
|
642
|
+
* @!method srgb?
|
|
643
|
+
* Returns +true+ if the target's framebuffer is sRGB-capable.
|
|
644
|
+
* @return [Boolean]
|
|
645
|
+
* @!method clear_stencil(value)
|
|
646
|
+
* Clears the stencil buffer to +value+.
|
|
647
|
+
* @return [self]
|
|
648
|
+
* @!method clear_color_and_stencil(color, stencil)
|
|
649
|
+
* Clears the color buffer to +color+ and the stencil buffer to +stencil+.
|
|
650
|
+
* @return [self]
|
|
651
|
+
* @!method viewport(view = nil)
|
|
652
|
+
* Returns the current viewport rectangle in pixels.
|
|
653
|
+
* @return [Rect] the current viewport in pixels; +view+ defaults to the target's current view
|
|
654
|
+
* @!method scissor(view = nil)
|
|
655
|
+
* Returns the current scissor rectangle in pixels.
|
|
656
|
+
* @return [Rect] the current scissor rectangle in pixels; +view+ defaults to the target's current
|
|
657
|
+
* view
|
|
658
|
+
* @!method map_pixel_to_coords(point, view = nil)
|
|
659
|
+
* Converts a pixel position to world coordinates, using the inverse of the view transform.
|
|
660
|
+
* @return [Vector2]
|
|
661
|
+
* @!method map_coords_to_pixel(point, view = nil)
|
|
662
|
+
* Converts a world position to pixel coordinates.
|
|
663
|
+
* @return [Vector2]
|
|
664
|
+
* @!method push_gl_states
|
|
665
|
+
* Saves the current OpenGL state.
|
|
666
|
+
* @return [self]
|
|
667
|
+
* @!method pop_gl_states
|
|
668
|
+
* Restores the OpenGL state saved by #push_gl_states.
|
|
669
|
+
* @return [self]
|
|
670
|
+
* @!method reset_gl_states
|
|
671
|
+
* Resets the OpenGL state to SFML's defaults.
|
|
672
|
+
* @return [self]
|
|
673
|
+
* @!method draw_primitives(vertices, primitive, state = nil)
|
|
674
|
+
* Draws raw vertex data as the given primitive type.
|
|
675
|
+
* @return [self]
|
|
676
|
+
* @!method draw_vertex_buffer_range(buffer, first, count, state = nil)
|
|
677
|
+
* Draws a range of vertices from a vertex buffer.
|
|
678
|
+
* @return [self]
|
|
679
|
+
*/
|
|
680
|
+
void Init_Window(VALUE rb_mSFML) {
|
|
681
|
+
rb_cWindow = rb_define_class_under(rb_mSFML, "Window", rb_cObject);
|
|
358
682
|
|
|
359
683
|
rb_define_singleton_method(rb_cWindow, "new", Window_new, -1);
|
|
360
684
|
rb_define_singleton_method(rb_cWindow, "from_handle", Window_s_from_handle, -1);
|
|
@@ -404,9 +728,9 @@ void Init_Window(VALUE rb_module) {
|
|
|
404
728
|
}
|
|
405
729
|
|
|
406
730
|
void* Get_Window_Struct(VALUE self) {
|
|
407
|
-
|
|
408
|
-
TypedData_Get_Struct(self,
|
|
409
|
-
return ptr;
|
|
731
|
+
Window* ptr;
|
|
732
|
+
TypedData_Get_Struct(self, Window, &Window_data_type, ptr);
|
|
733
|
+
return ptr->window;
|
|
410
734
|
}
|
|
411
735
|
|
|
412
736
|
VALUE Get_Klass_Window() {
|
data/lib/sfml/version.rb
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module SFML
|
|
2
|
+
module SoundStatus
|
|
3
|
+
STOPPED: Integer
|
|
4
|
+
PAUSED: Integer
|
|
5
|
+
PLAYING: Integer
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
module SoundChannel
|
|
9
|
+
UNSPECIFIED: Integer
|
|
10
|
+
MONO: Integer
|
|
11
|
+
FRONT_LEFT: Integer
|
|
12
|
+
FRONT_RIGHT: Integer
|
|
13
|
+
FRONT_CENTER: Integer
|
|
14
|
+
FRONT_LEFT_OF_CENTER: Integer
|
|
15
|
+
FRONT_RIGHT_OF_CENTER: Integer
|
|
16
|
+
LOW_FREQUENCY_EFFECTS: Integer
|
|
17
|
+
BACK_LEFT: Integer
|
|
18
|
+
BACK_RIGHT: Integer
|
|
19
|
+
BACK_CENTER: Integer
|
|
20
|
+
SIDE_LEFT: Integer
|
|
21
|
+
SIDE_RIGHT: Integer
|
|
22
|
+
TOP_CENTER: Integer
|
|
23
|
+
TOP_FRONT_LEFT: Integer
|
|
24
|
+
TOP_FRONT_RIGHT: Integer
|
|
25
|
+
TOP_FRONT_CENTER: Integer
|
|
26
|
+
TOP_BACK_LEFT: Integer
|
|
27
|
+
TOP_BACK_RIGHT: Integer
|
|
28
|
+
TOP_BACK_CENTER: Integer
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module SFML
|
|
2
|
+
module Listener
|
|
3
|
+
def self.global_volume: () -> Float
|
|
4
|
+
def self.global_volume=: (Float value) -> Float
|
|
5
|
+
def self.position: () -> Vector3
|
|
6
|
+
def self.position=: (Vector3 value) -> Vector3
|
|
7
|
+
def self.direction: () -> Vector3
|
|
8
|
+
def self.direction=: (Vector3 value) -> Vector3
|
|
9
|
+
def self.velocity: () -> Vector3
|
|
10
|
+
def self.velocity=: (Vector3 value) -> Vector3
|
|
11
|
+
def self.up_vector: () -> Vector3
|
|
12
|
+
def self.up_vector=: (Vector3 value) -> Vector3
|
|
13
|
+
def self.cone: () -> SoundSourceCone
|
|
14
|
+
def self.cone=: (SoundSourceCone value) -> SoundSourceCone
|
|
15
|
+
end
|
|
16
|
+
end
|
data/sig/audio/music.rbs
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
module SFML
|
|
2
|
+
class Music
|
|
3
|
+
def self.from_file: (String path) -> Music
|
|
4
|
+
def self.from_memory: (String data) -> Music
|
|
5
|
+
def self.from_stream: (untyped stream) -> Music
|
|
6
|
+
|
|
7
|
+
def duration: () -> Time
|
|
8
|
+
def channel_count: () -> Integer
|
|
9
|
+
def sample_rate: () -> Integer
|
|
10
|
+
def channel_map: () -> Array[Symbol]
|
|
11
|
+
def loop_points: () -> [Time, Time]
|
|
12
|
+
def loop_points=: ([Time, Time] value) -> [Time, Time]
|
|
13
|
+
|
|
14
|
+
def play: () -> self
|
|
15
|
+
def pause: () -> self
|
|
16
|
+
def stop: () -> self
|
|
17
|
+
def status: () -> (:stopped | :paused | :playing)
|
|
18
|
+
def looping?: () -> bool
|
|
19
|
+
def looping=: (bool value) -> bool
|
|
20
|
+
def pitch: () -> Float
|
|
21
|
+
def pitch=: (Float value) -> Float
|
|
22
|
+
def pan: () -> Float
|
|
23
|
+
def pan=: (Float value) -> Float
|
|
24
|
+
def volume: () -> Float
|
|
25
|
+
def volume=: (Float value) -> Float
|
|
26
|
+
def spatialization_enabled?: () -> bool
|
|
27
|
+
def spatialization_enabled=: (bool value) -> bool
|
|
28
|
+
def position: () -> Vector3
|
|
29
|
+
def position=: (Vector3 value) -> Vector3
|
|
30
|
+
def direction: () -> Vector3
|
|
31
|
+
def direction=: (Vector3 value) -> Vector3
|
|
32
|
+
def velocity: () -> Vector3
|
|
33
|
+
def velocity=: (Vector3 value) -> Vector3
|
|
34
|
+
def cone: () -> SoundSourceCone
|
|
35
|
+
def cone=: (SoundSourceCone value) -> SoundSourceCone
|
|
36
|
+
def doppler_factor: () -> Float
|
|
37
|
+
def doppler_factor=: (Float value) -> Float
|
|
38
|
+
def directional_attenuation_factor: () -> Float
|
|
39
|
+
def directional_attenuation_factor=: (Float value) -> Float
|
|
40
|
+
def relative_to_listener?: () -> bool
|
|
41
|
+
def relative_to_listener=: (bool value) -> bool
|
|
42
|
+
def min_distance: () -> Float
|
|
43
|
+
def min_distance=: (Float value) -> Float
|
|
44
|
+
def max_distance: () -> Float
|
|
45
|
+
def max_distance=: (Float value) -> Float
|
|
46
|
+
def min_gain: () -> Float
|
|
47
|
+
def min_gain=: (Float value) -> Float
|
|
48
|
+
def max_gain: () -> Float
|
|
49
|
+
def max_gain=: (Float value) -> Float
|
|
50
|
+
def attenuation: () -> Float
|
|
51
|
+
def attenuation=: (Float value) -> Float
|
|
52
|
+
def playing_offset: () -> Time
|
|
53
|
+
def playing_offset=: (Time value) -> Time
|
|
54
|
+
def effect_processor=: (Proc proc) -> Proc
|
|
55
|
+
end
|
|
56
|
+
end
|