sfml3-rb 0.3.0 → 0.3.1
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/CHANGELOG.md +25 -0
- data/README.md +36 -13
- data/TODO.md +18 -11
- data/ext/audio/music.c +6 -0
- data/ext/audio/sound.c +43 -4
- data/ext/audio/sound_buffer.c +8 -0
- data/ext/audio/sound_buffer_recorder.c +8 -3
- data/ext/audio/sound_recorder.c +21 -11
- data/ext/audio/sound_source_cone.c +18 -3
- data/ext/audio/sound_stream.c +25 -15
- data/ext/ext.c +4 -0
- data/ext/graphics/blend_mode.c +16 -8
- data/ext/graphics/circle.c +30 -13
- data/ext/graphics/color.c +17 -8
- data/ext/graphics/drawable.c +3 -2
- data/ext/graphics/font.c +6 -0
- data/ext/graphics/glyph.c +7 -0
- data/ext/graphics/image.c +25 -4
- data/ext/graphics/polygon.c +31 -11
- data/ext/graphics/rect.c +16 -8
- data/ext/graphics/rectangle.c +30 -11
- data/ext/graphics/render_state.c +8 -10
- data/ext/graphics/render_texture.c +27 -11
- data/ext/graphics/render_window.c +55 -0
- data/ext/graphics/render_window.h +10 -0
- data/ext/graphics/shader.c +6 -0
- data/ext/graphics/shape.c +23 -16
- data/ext/graphics/sprite.c +34 -10
- data/ext/graphics/stencil_mode.c +16 -8
- data/ext/graphics/target.c +60 -27
- data/ext/graphics/target.h +22 -8
- data/ext/graphics/text.c +33 -13
- data/ext/graphics/texture.c +34 -3
- data/ext/graphics/transformable.c +11 -20
- data/ext/graphics/vertex.c +18 -3
- data/ext/graphics/vertex_array.c +18 -9
- data/ext/graphics/vertex_buffer.c +30 -10
- data/ext/graphics/view.c +16 -10
- data/ext/network/ftp.c +30 -3
- data/ext/network/http.c +23 -6
- data/ext/network/ip_address.c +25 -14
- data/ext/network/packet.c +8 -3
- data/ext/network/socket_selector.c +8 -3
- data/ext/network/tcp_listener.c +8 -3
- data/ext/network/tcp_socket.c +8 -3
- data/ext/network/udp_socket.c +8 -3
- data/ext/system/buffer.c +13 -11
- data/ext/system/clock.c +11 -5
- data/ext/system/input_stream.c +21 -11
- data/ext/system/time.c +17 -13
- data/ext/system/vec2.c +17 -11
- data/ext/system/vec3.c +18 -11
- data/ext/window/context.c +14 -11
- data/ext/window/context_settings.c +16 -4
- data/ext/window/cursor.c +6 -0
- data/ext/window/event.c +15 -25
- data/ext/window/mouse.c +28 -11
- data/ext/window/touch.c +12 -10
- data/ext/window/video_mode.c +16 -25
- data/ext/window/window.c +110 -435
- data/ext/window/window.h +4 -4
- data/ext/window/window_base.c +251 -0
- data/ext/window/window_base.h +43 -0
- data/ext/window/window_base.inc +236 -0
- data/lib/sfml/version.rb +1 -1
- data/sig/audio/sound.rbs +1 -1
- data/sig/audio/sound_buffer_recorder.rbs +1 -1
- data/sig/audio/sound_recorder.rbs +1 -1
- data/sig/audio/sound_source_cone.rbs +1 -1
- data/sig/audio/sound_stream.rbs +1 -1
- data/sig/graphics/blend_mode.rbs +1 -1
- data/sig/graphics/circle.rbs +1 -1
- data/sig/graphics/color.rbs +5 -5
- data/sig/graphics/image.rbs +1 -1
- data/sig/graphics/polygon.rbs +1 -1
- data/sig/graphics/rect.rbs +5 -5
- data/sig/graphics/rectangle.rbs +1 -1
- data/sig/graphics/render_state.rbs +2 -2
- data/sig/graphics/render_target.rbs +18 -0
- data/sig/graphics/render_texture.rbs +4 -2
- data/sig/graphics/render_window.rbs +7 -0
- data/sig/graphics/shape.rbs +1 -1
- data/sig/graphics/sprite.rbs +2 -2
- data/sig/graphics/stencil_mode.rbs +2 -2
- data/sig/graphics/target.rbs +1 -3
- data/sig/graphics/text.rbs +4 -4
- data/sig/graphics/texture.rbs +1 -1
- data/sig/graphics/transformable.rbs +1 -1
- data/sig/graphics/vertex.rbs +4 -4
- data/sig/graphics/vertex_array.rbs +1 -1
- data/sig/graphics/vertex_buffer.rbs +4 -4
- data/sig/graphics/view.rbs +0 -1
- data/sig/network/ftp.rbs +1 -1
- data/sig/network/http.rbs +2 -2
- data/sig/network/ip_address.rbs +1 -1
- data/sig/network/packet.rbs +1 -1
- data/sig/network/socket_selector.rbs +1 -1
- data/sig/network/tcp_listener.rbs +1 -1
- data/sig/network/tcp_socket.rbs +1 -1
- data/sig/network/udp_socket.rbs +1 -1
- data/sig/sfml/version.rbs +3 -0
- data/sig/system/buffer.rbs +1 -1
- data/sig/system/clock.rbs +1 -1
- data/sig/system/input_stream.rbs +1 -1
- data/sig/system/time.rbs +4 -4
- data/sig/system/vec2.rbs +4 -4
- data/sig/system/vec3.rbs +4 -4
- data/sig/window/context.rbs +1 -1
- data/sig/window/context_settings.rbs +1 -1
- data/sig/window/event.rbs +1 -1
- data/sig/window/mouse.rbs +2 -2
- data/sig/window/touch.rbs +1 -1
- data/sig/window/video_mode.rbs +1 -1
- data/sig/window/window.rbs +2 -25
- data/sig/window/window_base.rbs +33 -0
- metadata +11 -2
data/ext/window/window.c
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
#include "graphics/render_state.h"
|
|
6
6
|
#include "graphics/target.h"
|
|
7
7
|
#include "graphics/view.h"
|
|
8
|
+
#include "window/window_base.h"
|
|
8
9
|
#include "window/video_mode.h"
|
|
9
10
|
#include "window/event.h"
|
|
10
11
|
#include "window/input_enums.h"
|
|
@@ -19,60 +20,28 @@
|
|
|
19
20
|
|
|
20
21
|
static VALUE rb_cWindow;
|
|
21
22
|
|
|
22
|
-
/*
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
static void Window_mark(void* ptr) {
|
|
36
|
-
Window* window = ptr;
|
|
37
|
-
|
|
38
|
-
rb_gc_mark(window->rb_cursor);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
static void Window_free(void* ptr) {
|
|
42
|
-
Window* window = ptr;
|
|
43
|
-
|
|
44
|
-
sfRenderWindow_destroy(window->window);
|
|
45
|
-
free(window);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
static const rb_data_type_t Window_data_type = {
|
|
49
|
-
.wrap_struct_name = "SFML::Window",
|
|
50
|
-
.function = {.dmark = Window_mark, .dfree = Window_free, .dsize = NULL},
|
|
51
|
-
.flags = RUBY_TYPED_FREE_IMMEDIATELY};
|
|
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
|
-
}
|
|
23
|
+
/* Window overrides every WindowBase method with the sfRenderWindow_ entry
|
|
24
|
+
point: its handle is an sfRenderWindow*, and CSFML keys its functions off the
|
|
25
|
+
concrete type, so inheriting the sfWindowBase_ bodies would be wrong. The
|
|
26
|
+
generated bodies live in window_base.inc. */
|
|
27
|
+
#define WB_FN(name) sfRenderWindow_##name
|
|
28
|
+
#define WB_METHOD(name) Window_##name
|
|
29
|
+
#define WB_HANDLE(self) Get_Window_Struct(self)
|
|
30
|
+
#include "window/window_base.inc"
|
|
31
|
+
#undef WB_FN
|
|
32
|
+
#undef WB_METHOD
|
|
33
|
+
#undef WB_HANDLE
|
|
65
34
|
|
|
66
35
|
/* call-seq:
|
|
67
36
|
* Window.new(video_mode, title, style = :default, state = :windowed, settings = nil) -> Window
|
|
68
37
|
*
|
|
69
|
-
* Creates a window from +video_mode+ and +title+.
|
|
38
|
+
* Creates a window with an OpenGL context from +video_mode+ and +title+.
|
|
70
39
|
*
|
|
71
40
|
* @return [Window]
|
|
72
41
|
* @raise [RuntimeError] if window creation fails
|
|
73
42
|
*/
|
|
74
|
-
static VALUE
|
|
75
|
-
VALUE
|
|
43
|
+
static VALUE Window_initialize(int argc, VALUE* argv, VALUE self) {
|
|
44
|
+
VALUE rb_video_mode, rb_title, rb_style, rb_state, rb_settings, title_buffer;
|
|
76
45
|
sfWindowState state = sfWindowed;
|
|
77
46
|
sfContextSettings settings;
|
|
78
47
|
const sfContextSettings* settings_ptr = NULL;
|
|
@@ -99,17 +68,16 @@ static VALUE Window_new(int argc, VALUE* argv, VALUE klass) {
|
|
|
99
68
|
}
|
|
100
69
|
|
|
101
70
|
title_buffer = utf32_from_rb(rb_title);
|
|
102
|
-
window =
|
|
103
|
-
|
|
71
|
+
window = sfRenderWindow_createUnicode(*Get_Mode_Struct(rb_video_mode), UTF32_PTR(title_buffer),
|
|
72
|
+
style, state, settings_ptr);
|
|
104
73
|
RB_GC_GUARD(title_buffer);
|
|
105
74
|
|
|
106
75
|
if (window == NULL) {
|
|
107
76
|
rb_raise(rb_eRuntimeError, "failed to create window");
|
|
108
77
|
}
|
|
109
78
|
|
|
110
|
-
self =
|
|
111
|
-
|
|
112
|
-
rb_obj_call_init(self, argc, argv);
|
|
79
|
+
Get_Window_Data(self)->handle = window;
|
|
80
|
+
Get_Window_Data(self)->kind = SFML_WINDOW_KIND_WINDOW;
|
|
113
81
|
|
|
114
82
|
return self;
|
|
115
83
|
}
|
|
@@ -121,13 +89,11 @@ static VALUE Window_new(int argc, VALUE* argv, VALUE klass) {
|
|
|
121
89
|
/* call-seq:
|
|
122
90
|
* Window.from_handle(handle, settings = nil) -> Window
|
|
123
91
|
*
|
|
124
|
-
* Creates a window that adopts the existing OS window +handle+.
|
|
125
|
-
*
|
|
126
92
|
* @return [Window]
|
|
127
93
|
* @raise [RuntimeError] if window creation fails
|
|
128
94
|
*/
|
|
129
95
|
static VALUE Window_s_from_handle(int argc, VALUE* argv, VALUE klass) {
|
|
130
|
-
VALUE
|
|
96
|
+
VALUE rb_handle, rb_settings;
|
|
131
97
|
sfContextSettings settings;
|
|
132
98
|
const sfContextSettings* settings_ptr = NULL;
|
|
133
99
|
sfRenderWindow* window;
|
|
@@ -146,36 +112,7 @@ static VALUE Window_s_from_handle(int argc, VALUE* argv, VALUE klass) {
|
|
|
146
112
|
rb_raise(rb_eRuntimeError, "failed to create window from handle");
|
|
147
113
|
}
|
|
148
114
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
rb_obj_call_init(self, 0, NULL);
|
|
152
|
-
|
|
153
|
-
return self;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
static VALUE Window_init(int argc, VALUE* argv, VALUE self) {
|
|
157
|
-
return self;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/* call-seq: is_open? -> true or false
|
|
161
|
-
*
|
|
162
|
-
* Returns +true+ while the window is open.
|
|
163
|
-
*
|
|
164
|
-
* @return [Boolean]
|
|
165
|
-
*/
|
|
166
|
-
static VALUE Window_is_open(VALUE self) {
|
|
167
|
-
return BOOL2RB(sfRenderWindow_isOpen(Get_Window_Struct(self)));
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/* call-seq: close! -> self
|
|
171
|
-
*
|
|
172
|
-
* Closes the window.
|
|
173
|
-
*
|
|
174
|
-
* @return [self]
|
|
175
|
-
*/
|
|
176
|
-
static VALUE Window_close(VALUE self) {
|
|
177
|
-
sfRenderWindow_close(Get_Window_Struct(self));
|
|
178
|
-
return self;
|
|
115
|
+
return Window_wrap_handle(klass, window, SFML_WINDOW_KIND_WINDOW);
|
|
179
116
|
}
|
|
180
117
|
|
|
181
118
|
/* call-seq:
|
|
@@ -214,62 +151,6 @@ static VALUE Window_display(VALUE self) {
|
|
|
214
151
|
return self;
|
|
215
152
|
}
|
|
216
153
|
|
|
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
|
-
*/
|
|
226
|
-
static VALUE Window_poll_event(VALUE self, VALUE rb_event) {
|
|
227
|
-
if (!rb_obj_is_kind_of(rb_event, Get_Klass_Event())) {
|
|
228
|
-
raise_invalid_argument_class(Get_Klass_Event());
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
return BOOL2RB(sfRenderWindow_pollEvent(Get_Window_Struct(self), Get_Event_Struct(rb_event)));
|
|
232
|
-
}
|
|
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
|
-
*/
|
|
242
|
-
static VALUE Window_wait_event(VALUE self, VALUE rb_event) {
|
|
243
|
-
if (!rb_obj_is_kind_of(rb_event, Get_Klass_Event())) {
|
|
244
|
-
raise_invalid_argument_class(Get_Klass_Event());
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
return BOOL2RB(
|
|
248
|
-
sfRenderWindow_waitEvent(Get_Window_Struct(self), sfTime_Zero, Get_Event_Struct(rb_event)));
|
|
249
|
-
}
|
|
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
|
-
*/
|
|
257
|
-
static VALUE Window_get_position(VALUE self) {
|
|
258
|
-
return VEC2_C2RB(sfRenderWindow_getPosition(Get_Window_Struct(self)));
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/* call-seq:
|
|
262
|
-
* position=(value) -> value
|
|
263
|
-
*
|
|
264
|
-
* Moves the window to +value+ in desktop coordinates.
|
|
265
|
-
*
|
|
266
|
-
* @return [Vector2] +value+
|
|
267
|
-
*/
|
|
268
|
-
static VALUE Window_set_position(VALUE self, VALUE rb_arr) {
|
|
269
|
-
sfRenderWindow_setPosition(Get_Window_Struct(self), vec2i_new_from_ruby(rb_arr));
|
|
270
|
-
return self;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
154
|
/* call-seq:
|
|
274
155
|
* frame_rate=(value) -> self
|
|
275
156
|
*
|
|
@@ -282,63 +163,11 @@ static VALUE Window_set_frame_rate(VALUE self, VALUE rb_limit) {
|
|
|
282
163
|
return self;
|
|
283
164
|
}
|
|
284
165
|
|
|
285
|
-
/* call-seq:
|
|
286
|
-
* size=(value) -> self
|
|
287
|
-
*
|
|
288
|
-
* Resizes the window's client area to +value+.
|
|
289
|
-
*
|
|
290
|
-
* @return [self]
|
|
291
|
-
*/
|
|
292
|
-
static VALUE Window_set_size(VALUE self, VALUE rb_size) {
|
|
293
|
-
sfRenderWindow_setSize(Get_Window_Struct(self), vec2u_from_rb(rb_size));
|
|
294
|
-
return self;
|
|
295
|
-
}
|
|
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
|
-
*/
|
|
303
|
-
static VALUE Window_get_size(VALUE self) {
|
|
304
|
-
return VEC2_C2RB(sfRenderWindow_getSize(Get_Window_Struct(self)));
|
|
305
|
-
}
|
|
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
|
-
*/
|
|
314
|
-
static VALUE Window_set_minimum_size(VALUE self, VALUE rb_size) {
|
|
315
|
-
sfVector2u size = vec2u_from_rb(rb_size);
|
|
316
|
-
|
|
317
|
-
sfRenderWindow_setMinimumSize(Get_Window_Struct(self), &size);
|
|
318
|
-
|
|
319
|
-
return rb_size;
|
|
320
|
-
}
|
|
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
|
-
*/
|
|
329
|
-
static VALUE Window_set_maximum_size(VALUE self, VALUE rb_size) {
|
|
330
|
-
sfVector2u size = vec2u_from_rb(rb_size);
|
|
331
|
-
|
|
332
|
-
sfRenderWindow_setMaximumSize(Get_Window_Struct(self), &size);
|
|
333
|
-
|
|
334
|
-
return rb_size;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
166
|
/* call-seq:
|
|
338
167
|
* active=(value) -> true or false
|
|
339
168
|
*
|
|
340
|
-
* Activates or deactivates this window's OpenGL context as the current one
|
|
341
|
-
*
|
|
169
|
+
* Activates or deactivates this window's OpenGL context as the current one on
|
|
170
|
+
* the calling thread.
|
|
342
171
|
*
|
|
343
172
|
* @return [Boolean] whether activation succeeded
|
|
344
173
|
*/
|
|
@@ -346,116 +175,6 @@ static VALUE Window_set_active(VALUE self, VALUE rb_active) {
|
|
|
346
175
|
return BOOL2RB(sfRenderWindow_setActive(Get_Window_Struct(self), RTEST(rb_active)));
|
|
347
176
|
}
|
|
348
177
|
|
|
349
|
-
/* call-seq: native_handle -> Integer
|
|
350
|
-
*
|
|
351
|
-
* Returns the OS-specific window handle.
|
|
352
|
-
*
|
|
353
|
-
* @return [Integer] the OS-specific window handle
|
|
354
|
-
*/
|
|
355
|
-
static VALUE Window_get_native_handle(VALUE self) {
|
|
356
|
-
return ULL2NUM(
|
|
357
|
-
(unsigned long long)(uintptr_t)sfRenderWindow_getNativeHandle(Get_Window_Struct(self)));
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
/* Vulkan handles cross this binding as Integers, the same way
|
|
361
|
-
SFML::Vulkan.function already returns one -- there is no Vulkan object model
|
|
362
|
-
here to wrap them in. Returns the new VkSurfaceKHR, or nil if creation
|
|
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
|
-
*/
|
|
371
|
-
static VALUE Window_create_vulkan_surface(int argc, VALUE* argv, VALUE self) {
|
|
372
|
-
VALUE rb_instance, rb_allocator;
|
|
373
|
-
VkInstance instance;
|
|
374
|
-
VkSurfaceKHR surface;
|
|
375
|
-
const VkAllocationCallbacks* allocator = NULL;
|
|
376
|
-
|
|
377
|
-
rb_scan_args(argc, argv, "11", &rb_instance, &rb_allocator);
|
|
378
|
-
|
|
379
|
-
instance = (VkInstance)(uintptr_t)NUM2ULL(rb_instance);
|
|
380
|
-
|
|
381
|
-
if (!NIL_P(rb_allocator)) {
|
|
382
|
-
allocator = (const VkAllocationCallbacks*)(uintptr_t)NUM2ULL(rb_allocator);
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
if (!sfRenderWindow_createVulkanSurface(Get_Window_Struct(self), &instance, &surface,
|
|
386
|
-
allocator)) {
|
|
387
|
-
return Qnil;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
return ULL2NUM((unsigned long long)(uintptr_t)surface);
|
|
391
|
-
}
|
|
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
|
-
*/
|
|
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
|
-
|
|
406
|
-
StringValue(rb_pixels);
|
|
407
|
-
|
|
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));
|
|
413
|
-
|
|
414
|
-
return rb_pixels;
|
|
415
|
-
}
|
|
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
|
-
*/
|
|
424
|
-
static VALUE Window_get_settings(VALUE self) {
|
|
425
|
-
return context_settings_to_rb(sfRenderWindow_getSettings(Get_Window_Struct(self)));
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
/* Through the UTF-32 entry point: sfRenderWindow_setTitle decodes the bytes
|
|
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
|
-
*/
|
|
437
|
-
static VALUE Window_set_title(VALUE self, VALUE rb_title) {
|
|
438
|
-
VALUE buffer = utf32_from_rb(rb_title);
|
|
439
|
-
|
|
440
|
-
sfRenderWindow_setUnicodeTitle(Get_Window_Struct(self), UTF32_PTR(buffer));
|
|
441
|
-
|
|
442
|
-
RB_GC_GUARD(buffer);
|
|
443
|
-
|
|
444
|
-
return self;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
/* call-seq:
|
|
448
|
-
* visible=(value) -> self
|
|
449
|
-
*
|
|
450
|
-
* Shows or hides the window.
|
|
451
|
-
*
|
|
452
|
-
* @return [self]
|
|
453
|
-
*/
|
|
454
|
-
static VALUE Window_set_visible(VALUE self, VALUE rb_visible) {
|
|
455
|
-
sfRenderWindow_setVisible(Get_Window_Struct(self), RTEST(rb_visible));
|
|
456
|
-
return self;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
178
|
/* call-seq:
|
|
460
179
|
* vertical_sync_enabled=(value) -> self
|
|
461
180
|
*
|
|
@@ -468,102 +187,14 @@ static VALUE Window_set_vertical_sync_enabled(VALUE self, VALUE rb_enable) {
|
|
|
468
187
|
return self;
|
|
469
188
|
}
|
|
470
189
|
|
|
471
|
-
/* call-seq:
|
|
472
|
-
* cursor_visible=(value) -> self
|
|
473
|
-
*
|
|
474
|
-
* Shows or hides the mouse cursor over the window.
|
|
475
|
-
*
|
|
476
|
-
* @return [self]
|
|
477
|
-
*/
|
|
478
|
-
static VALUE Window_set_mouse_cursor_visible(VALUE self, VALUE rb_visible) {
|
|
479
|
-
sfRenderWindow_setMouseCursorVisible(Get_Window_Struct(self), RTEST(rb_visible));
|
|
480
|
-
return self;
|
|
481
|
-
}
|
|
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
|
-
*/
|
|
490
|
-
static VALUE Window_set_mouse_cursor_grabbed(VALUE self, VALUE rb_grabbed) {
|
|
491
|
-
sfRenderWindow_setMouseCursorGrabbed(Get_Window_Struct(self), RTEST(rb_grabbed));
|
|
492
|
-
return self;
|
|
493
|
-
}
|
|
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
|
-
*/
|
|
507
|
-
static VALUE Window_set_mouse_cursor(VALUE self, VALUE rb_cursor) {
|
|
508
|
-
Window* window;
|
|
509
|
-
TypedData_Get_Struct(self, Window, &Window_data_type, window);
|
|
510
|
-
|
|
511
|
-
if (!rb_obj_is_kind_of(rb_cursor, Get_Klass_Cursor())) {
|
|
512
|
-
raise_invalid_argument_class(Get_Klass_Cursor());
|
|
513
|
-
}
|
|
514
|
-
|
|
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;
|
|
519
|
-
|
|
520
|
-
return rb_cursor;
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
/* call-seq:
|
|
524
|
-
* key_repeat_enabled=(value) -> self
|
|
525
|
-
*
|
|
526
|
-
* Enables or disables key-repeat events.
|
|
527
|
-
*
|
|
528
|
-
* @return [self]
|
|
529
|
-
*/
|
|
530
|
-
static VALUE Window_set_key_repeat_enabled(VALUE self, VALUE rb_enabled) {
|
|
531
|
-
sfRenderWindow_setKeyRepeatEnabled(Get_Window_Struct(self), RTEST(rb_enabled));
|
|
532
|
-
return self;
|
|
533
|
-
}
|
|
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
|
-
*/
|
|
543
|
-
static VALUE Window_set_joystick_threshold(VALUE self, VALUE rb_threshold) {
|
|
544
|
-
sfRenderWindow_setJoystickThreshold(Get_Window_Struct(self), NUM2DBL(rb_threshold));
|
|
545
|
-
return rb_threshold;
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
/* call-seq: request_focus -> self
|
|
549
|
-
*
|
|
550
|
-
* Requests focus for this window.
|
|
551
|
-
*
|
|
552
|
-
* @return [self]
|
|
553
|
-
*/
|
|
554
|
-
static VALUE Window_request_focus(VALUE self) {
|
|
555
|
-
sfRenderWindow_requestFocus(Get_Window_Struct(self));
|
|
556
|
-
return self;
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
/* call-seq: focus? -> true or false
|
|
190
|
+
/* call-seq: settings -> ContextSettings
|
|
560
191
|
*
|
|
561
|
-
* Returns
|
|
192
|
+
* Returns the context settings this window was created with.
|
|
562
193
|
*
|
|
563
|
-
* @return [
|
|
194
|
+
* @return [ContextSettings] the settings this window's context was created with
|
|
564
195
|
*/
|
|
565
|
-
static VALUE
|
|
566
|
-
return
|
|
196
|
+
static VALUE Window_get_settings(VALUE self) {
|
|
197
|
+
return context_settings_to_rb(sfRenderWindow_getSettings(Get_Window_Struct(self)));
|
|
567
198
|
}
|
|
568
199
|
|
|
569
200
|
/* call-seq:
|
|
@@ -589,8 +220,7 @@ static VALUE Window_draw(int argc, VALUE* argv, VALUE self) {
|
|
|
589
220
|
return self;
|
|
590
221
|
}
|
|
591
222
|
|
|
592
|
-
/* call-seq:
|
|
593
|
-
* view=(value) -> self
|
|
223
|
+
/* call-seq: view=(value) -> self
|
|
594
224
|
*
|
|
595
225
|
* Sets the window's active view to +value+.
|
|
596
226
|
*
|
|
@@ -636,9 +266,79 @@ static VALUE Window_get_default_view(VALUE self) {
|
|
|
636
266
|
#undef RT_HANDLE
|
|
637
267
|
|
|
638
268
|
/* Document-class: SFML::Window
|
|
639
|
-
*
|
|
640
|
-
*
|
|
269
|
+
* A renderable OS window with an OpenGL context attached. It derives from
|
|
270
|
+
* SFML::WindowBase; SFML::RenderWindow is the same object under the name that
|
|
271
|
+
* includes SFML::RenderTarget.
|
|
641
272
|
*
|
|
273
|
+
* @!method is_open?
|
|
274
|
+
* Returns +true+ while the window is open.
|
|
275
|
+
* @return [Boolean]
|
|
276
|
+
* @!method close!
|
|
277
|
+
* Closes the window.
|
|
278
|
+
* @return [self]
|
|
279
|
+
* @!method poll_event!(event)
|
|
280
|
+
* Pops the next pending event into +event+, if any, without blocking.
|
|
281
|
+
* @return [Boolean] whether an event was popped
|
|
282
|
+
* @!method wait_event!(event)
|
|
283
|
+
* Blocks until an event is available and pops it into +event+.
|
|
284
|
+
* @return [Boolean] whether an event was popped
|
|
285
|
+
* @!method position
|
|
286
|
+
* Returns the window's position in desktop coordinates.
|
|
287
|
+
* @return [Vector2]
|
|
288
|
+
* @!method position=(value)
|
|
289
|
+
* Moves the window to +value+.
|
|
290
|
+
* @return [Vector2] +value+
|
|
291
|
+
* @!method size
|
|
292
|
+
* Returns the client area size in pixels.
|
|
293
|
+
* @return [Vector2]
|
|
294
|
+
* @!method size=(value)
|
|
295
|
+
* Resizes the window's client area.
|
|
296
|
+
* @return [self]
|
|
297
|
+
* @!method minimum_size=(value)
|
|
298
|
+
* Sets the window's minimum allowed client size.
|
|
299
|
+
* @return [Vector2] +value+
|
|
300
|
+
* @!method maximum_size=(value)
|
|
301
|
+
* Sets the window's maximum allowed client size.
|
|
302
|
+
* @return [Vector2] +value+
|
|
303
|
+
* @!method title=(value)
|
|
304
|
+
* Sets the window title.
|
|
305
|
+
* @return [self]
|
|
306
|
+
* @!method set_icon(size, pixels)
|
|
307
|
+
* Sets the window's icon from RGBA32 pixel data.
|
|
308
|
+
* @return [String] +pixels+
|
|
309
|
+
* @!method visible=(value)
|
|
310
|
+
* Shows or hides the window.
|
|
311
|
+
* @return [self]
|
|
312
|
+
* @!method cursor_visible=(value)
|
|
313
|
+
* Shows or hides the mouse cursor over the window.
|
|
314
|
+
* @return [self]
|
|
315
|
+
* @!method cursor_grabbed=(value)
|
|
316
|
+
* Confines or releases the mouse cursor to the window's client area.
|
|
317
|
+
* @return [self]
|
|
318
|
+
* @!method mouse_cursor=(value)
|
|
319
|
+
* Sets the window's mouse cursor.
|
|
320
|
+
* @return [Cursor] +value+
|
|
321
|
+
* @!method cursor=(value)
|
|
322
|
+
* Sets the window's mouse cursor.
|
|
323
|
+
* @return [Cursor] +value+
|
|
324
|
+
* @!method key_repeat_enabled=(value)
|
|
325
|
+
* Enables or disables key-repeat events.
|
|
326
|
+
* @return [self]
|
|
327
|
+
* @!method joystick_threshold=(value)
|
|
328
|
+
* Sets the minimum joystick axis change that generates a move event.
|
|
329
|
+
* @return [Float] +value+
|
|
330
|
+
* @!method request_focus
|
|
331
|
+
* Requests focus for this window.
|
|
332
|
+
* @return [self]
|
|
333
|
+
* @!method focus?
|
|
334
|
+
* Returns +true+ if the window currently has focus.
|
|
335
|
+
* @return [Boolean]
|
|
336
|
+
* @!method native_handle
|
|
337
|
+
* Returns the OS-specific window handle.
|
|
338
|
+
* @return [Integer]
|
|
339
|
+
* @!method create_vulkan_surface(instance, allocator = nil)
|
|
340
|
+
* Creates a Vulkan surface for this window.
|
|
341
|
+
* @return [Integer, nil] the new +VkSurfaceKHR+, or +nil+ if creation failed
|
|
642
342
|
* @!method srgb?
|
|
643
343
|
* Returns +true+ if the target's framebuffer is sRGB-capable.
|
|
644
344
|
* @return [Boolean]
|
|
@@ -678,61 +378,36 @@ static VALUE Window_get_default_view(VALUE self) {
|
|
|
678
378
|
* @return [self]
|
|
679
379
|
*/
|
|
680
380
|
void Init_Window(VALUE rb_mSFML) {
|
|
681
|
-
rb_cWindow = rb_define_class_under(rb_mSFML, "Window",
|
|
381
|
+
rb_cWindow = rb_define_class_under(rb_mSFML, "Window", Get_Klass_WindowBase());
|
|
382
|
+
|
|
383
|
+
rb_define_alloc_func(rb_cWindow, Window_alloc);
|
|
682
384
|
|
|
683
|
-
rb_define_singleton_method(rb_cWindow, "new", Window_new, -1);
|
|
684
385
|
rb_define_singleton_method(rb_cWindow, "from_handle", Window_s_from_handle, -1);
|
|
685
386
|
|
|
387
|
+
// methods generated from window_base.inc, overridden with sfRenderWindow_*
|
|
388
|
+
Window_define_methods(rb_cWindow);
|
|
389
|
+
|
|
686
390
|
// methods
|
|
687
|
-
rb_define_method(rb_cWindow, "initialize",
|
|
688
|
-
rb_define_method(rb_cWindow, "is_open?", Window_is_open, 0);
|
|
689
|
-
rb_define_method(rb_cWindow, "close!", Window_close, 0);
|
|
391
|
+
rb_define_method(rb_cWindow, "initialize", Window_initialize, -1);
|
|
690
392
|
rb_define_method(rb_cWindow, "clear", Window_clear, -1);
|
|
691
393
|
rb_define_method(rb_cWindow, "display", Window_display, 0);
|
|
692
|
-
rb_define_method(rb_cWindow, "poll_event!", Window_poll_event, 1);
|
|
693
|
-
rb_define_method(rb_cWindow, "wait_event!", Window_wait_event, 1);
|
|
694
394
|
|
|
695
395
|
// setters
|
|
696
396
|
rb_define_method(rb_cWindow, "frame_rate=", Window_set_frame_rate, 1);
|
|
697
397
|
rb_define_method(rb_cWindow, "framerate_limit=", Window_set_frame_rate, 1);
|
|
698
|
-
rb_define_method(rb_cWindow, "size=", Window_set_size, 1);
|
|
699
|
-
rb_define_method(rb_cWindow, "minimum_size=", Window_set_minimum_size, 1);
|
|
700
|
-
rb_define_method(rb_cWindow, "maximum_size=", Window_set_maximum_size, 1);
|
|
701
|
-
rb_define_method(rb_cWindow, "title=", Window_set_title, 1);
|
|
702
|
-
rb_define_method(rb_cWindow, "set_icon", Window_set_icon, 2);
|
|
703
|
-
rb_define_method(rb_cWindow, "visible=", Window_set_visible, 1);
|
|
704
398
|
rb_define_method(rb_cWindow, "active=", Window_set_active, 1);
|
|
705
399
|
rb_define_method(rb_cWindow, "vertical_sync_enabled=", Window_set_vertical_sync_enabled, 1);
|
|
706
|
-
rb_define_method(rb_cWindow, "cursor_visible=", Window_set_mouse_cursor_visible, 1);
|
|
707
|
-
rb_define_method(rb_cWindow, "cursor_grabbed=", Window_set_mouse_cursor_grabbed, 1);
|
|
708
|
-
rb_define_method(rb_cWindow, "mouse_cursor=", Window_set_mouse_cursor, 1);
|
|
709
|
-
rb_define_method(rb_cWindow, "cursor=", Window_set_mouse_cursor, 1);
|
|
710
|
-
rb_define_method(rb_cWindow, "key_repeat_enabled=", Window_set_key_repeat_enabled, 1);
|
|
711
|
-
rb_define_method(rb_cWindow, "joystick_threshold=", Window_set_joystick_threshold, 1);
|
|
712
|
-
rb_define_method(rb_cWindow, "position=", Window_set_position, 1);
|
|
713
400
|
rb_define_method(rb_cWindow, "view=", Window_set_view, 1);
|
|
714
401
|
|
|
715
402
|
// getters
|
|
716
|
-
rb_define_method(rb_cWindow, "request_focus", Window_request_focus, 0);
|
|
717
|
-
rb_define_method(rb_cWindow, "focus?", Window_has_focus, 0);
|
|
718
403
|
rb_define_method(rb_cWindow, "draw", Window_draw, -1);
|
|
719
|
-
rb_define_method(rb_cWindow, "position", Window_get_position, 0);
|
|
720
|
-
rb_define_method(rb_cWindow, "size", Window_get_size, 0);
|
|
721
404
|
rb_define_method(rb_cWindow, "view", Window_get_view, 0);
|
|
722
405
|
rb_define_method(rb_cWindow, "default_view", Window_get_default_view, 0);
|
|
723
406
|
rb_define_method(rb_cWindow, "settings", Window_get_settings, 0);
|
|
724
|
-
rb_define_method(rb_cWindow, "native_handle", Window_get_native_handle, 0);
|
|
725
|
-
rb_define_method(rb_cWindow, "create_vulkan_surface", Window_create_vulkan_surface, -1);
|
|
726
407
|
|
|
727
408
|
Window_define_render_target_methods(rb_cWindow);
|
|
728
409
|
}
|
|
729
410
|
|
|
730
|
-
|
|
731
|
-
Window* ptr;
|
|
732
|
-
TypedData_Get_Struct(self, Window, &Window_data_type, ptr);
|
|
733
|
-
return ptr->window;
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
VALUE Get_Klass_Window() {
|
|
411
|
+
VALUE Get_Klass_Window(void) {
|
|
737
412
|
return rb_cWindow;
|
|
738
|
-
}
|
|
413
|
+
}
|
data/ext/window/window.h
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
#include <ruby.h>
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
#include "window/window_base.h"
|
|
7
7
|
|
|
8
|
-
void
|
|
8
|
+
void Init_Window(VALUE rb_module);
|
|
9
9
|
|
|
10
|
-
VALUE Get_Klass_Window();
|
|
10
|
+
VALUE Get_Klass_Window(void);
|
|
11
11
|
|
|
12
|
-
#endif //SFML_RB_WINDOW_WINDOW_H
|
|
12
|
+
#endif // SFML_RB_WINDOW_WINDOW_H
|