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
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
#include "window/window_base.h"
|
|
2
|
+
|
|
3
|
+
#include <ruby.h>
|
|
4
|
+
|
|
5
|
+
#include "window/video_mode.h"
|
|
6
|
+
#include "window/input_enums.h"
|
|
7
|
+
#include "core/exceptions.h"
|
|
8
|
+
#include "core/macros.h"
|
|
9
|
+
#include "core/unicode.h"
|
|
10
|
+
|
|
11
|
+
static VALUE rb_cWindowBase;
|
|
12
|
+
|
|
13
|
+
static void Window_mark(void* ptr) {
|
|
14
|
+
Window* window = ptr;
|
|
15
|
+
|
|
16
|
+
rb_gc_mark(window->rb_cursor);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static void Window_free(void* ptr) {
|
|
20
|
+
Window* window = ptr;
|
|
21
|
+
|
|
22
|
+
if (window->handle != NULL) {
|
|
23
|
+
if (window->kind == SFML_WINDOW_KIND_WINDOW) {
|
|
24
|
+
sfRenderWindow_destroy(window->handle);
|
|
25
|
+
} else {
|
|
26
|
+
sfWindowBase_destroy(window->handle);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
free(window);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static const rb_data_type_t Window_data_type = {
|
|
34
|
+
.wrap_struct_name = "SFML::Window",
|
|
35
|
+
.function = {.dmark = Window_mark, .dfree = Window_free, .dsize = NULL},
|
|
36
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY};
|
|
37
|
+
|
|
38
|
+
VALUE Window_alloc(VALUE klass) {
|
|
39
|
+
Window* window = malloc(sizeof(Window));
|
|
40
|
+
|
|
41
|
+
if (window == NULL) {
|
|
42
|
+
rb_raise(rb_eNoMemError, "failed to allocate window");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
window->handle = NULL;
|
|
46
|
+
window->kind = SFML_WINDOW_KIND_BASE;
|
|
47
|
+
window->rb_cursor = Qnil;
|
|
48
|
+
|
|
49
|
+
return TypedData_Wrap_Struct(klass, &Window_data_type, window);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
VALUE Window_wrap_handle(VALUE klass, void* handle, WindowKind kind) {
|
|
53
|
+
Window* window = malloc(sizeof(Window));
|
|
54
|
+
|
|
55
|
+
if (window == NULL) {
|
|
56
|
+
rb_raise(rb_eNoMemError, "failed to allocate window");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
window->handle = handle;
|
|
60
|
+
window->kind = kind;
|
|
61
|
+
window->rb_cursor = Qnil;
|
|
62
|
+
|
|
63
|
+
return TypedData_Wrap_Struct(klass, &Window_data_type, window);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static VALUE Window_initialize_copy(VALUE self, VALUE other) {
|
|
67
|
+
(void)other;
|
|
68
|
+
rb_raise(rb_eTypeError, "can't copy a %s", rb_obj_classname(self));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/* call-seq:
|
|
72
|
+
* WindowBase.new(video_mode, title, style = :default, state = :windowed) -> WindowBase
|
|
73
|
+
*
|
|
74
|
+
* Creates an OS window with no OpenGL context of its own.
|
|
75
|
+
*
|
|
76
|
+
* @return [WindowBase]
|
|
77
|
+
* @raise [RuntimeError] if window creation fails
|
|
78
|
+
*/
|
|
79
|
+
static VALUE WindowBase_initialize(int argc, VALUE* argv, VALUE self) {
|
|
80
|
+
VALUE rb_video_mode, rb_title, rb_style, rb_state, title_buffer;
|
|
81
|
+
sfWindowState state = sfWindowed;
|
|
82
|
+
uint32_t style = sfDefaultStyle;
|
|
83
|
+
sfWindowBase* window;
|
|
84
|
+
|
|
85
|
+
rb_scan_args(argc, argv, "22", &rb_video_mode, &rb_title, &rb_style, &rb_state);
|
|
86
|
+
|
|
87
|
+
if (!rb_obj_is_kind_of(rb_video_mode, Get_Klass_Mode())) {
|
|
88
|
+
raise_invalid_argument_class(Get_Klass_Mode());
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (!NIL_P(rb_style)) {
|
|
92
|
+
style = window_style_from_rb(rb_style);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (!NIL_P(rb_state)) {
|
|
96
|
+
state = window_state_from_rb(rb_state);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
title_buffer = utf32_from_rb(rb_title);
|
|
100
|
+
window = sfWindowBase_createUnicode(*Get_Mode_Struct(rb_video_mode), UTF32_PTR(title_buffer),
|
|
101
|
+
style, state);
|
|
102
|
+
RB_GC_GUARD(title_buffer);
|
|
103
|
+
|
|
104
|
+
if (window == NULL) {
|
|
105
|
+
rb_raise(rb_eRuntimeError, "failed to create window");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
Get_Window_Data(self)->handle = window;
|
|
109
|
+
Get_Window_Data(self)->kind = SFML_WINDOW_KIND_BASE;
|
|
110
|
+
|
|
111
|
+
return self;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/* Adopts an existing OS window by its native handle -- the Integer that
|
|
115
|
+
WindowBase#native_handle returns, or one obtained from a GUI toolkit. The
|
|
116
|
+
window is not owned by the toolkit afterwards: destroying it stays the
|
|
117
|
+
toolkit's job, and closing the Ruby object only tears down this wrapper. */
|
|
118
|
+
/* call-seq:
|
|
119
|
+
* WindowBase.from_handle(handle) -> WindowBase
|
|
120
|
+
*
|
|
121
|
+
* @return [WindowBase]
|
|
122
|
+
* @raise [RuntimeError] if window creation fails
|
|
123
|
+
*/
|
|
124
|
+
static VALUE WindowBase_s_from_handle(int argc, VALUE* argv, VALUE klass) {
|
|
125
|
+
VALUE rb_handle;
|
|
126
|
+
sfWindowBase* window;
|
|
127
|
+
|
|
128
|
+
rb_scan_args(argc, argv, "1", &rb_handle);
|
|
129
|
+
|
|
130
|
+
window = sfWindowBase_createFromHandle((sfWindowHandle)(uintptr_t)NUM2ULL(rb_handle));
|
|
131
|
+
|
|
132
|
+
if (window == NULL) {
|
|
133
|
+
rb_raise(rb_eRuntimeError, "failed to create window from handle");
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return Window_wrap_handle(klass, window, SFML_WINDOW_KIND_BASE);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
#define WB_FN(name) sfWindowBase_##name
|
|
140
|
+
#define WB_METHOD(name) WindowBase_##name
|
|
141
|
+
#define WB_HANDLE(self) Get_WindowBase_Struct(self)
|
|
142
|
+
#include "window/window_base.inc"
|
|
143
|
+
#undef WB_FN
|
|
144
|
+
#undef WB_METHOD
|
|
145
|
+
#undef WB_HANDLE
|
|
146
|
+
|
|
147
|
+
/* Document-class: SFML::WindowBase
|
|
148
|
+
* An OS window and its event queue, without an OpenGL context. It is the base
|
|
149
|
+
* of SFML::Window and SFML::RenderWindow, and every method below is also
|
|
150
|
+
* available -- backed by the matching sfRenderWindow entry point -- on both.
|
|
151
|
+
*
|
|
152
|
+
* @!method is_open?
|
|
153
|
+
* Returns +true+ while the window is open.
|
|
154
|
+
* @return [Boolean]
|
|
155
|
+
* @!method close!
|
|
156
|
+
* Closes the window.
|
|
157
|
+
* @return [self]
|
|
158
|
+
* @!method poll_event!(event)
|
|
159
|
+
* Pops the next pending event into +event+, if any, without blocking.
|
|
160
|
+
* @return [Boolean] whether an event was popped
|
|
161
|
+
* @!method wait_event!(event)
|
|
162
|
+
* Blocks until an event is available and pops it into +event+.
|
|
163
|
+
* @return [Boolean] whether an event was popped
|
|
164
|
+
* @!method position
|
|
165
|
+
* Returns the window's position in desktop coordinates.
|
|
166
|
+
* @return [Vector2]
|
|
167
|
+
* @!method position=(value)
|
|
168
|
+
* Moves the window to +value+.
|
|
169
|
+
* @return [Vector2] +value+
|
|
170
|
+
* @!method size
|
|
171
|
+
* Returns the client area size in pixels.
|
|
172
|
+
* @return [Vector2]
|
|
173
|
+
* @!method size=(value)
|
|
174
|
+
* Resizes the window's client area.
|
|
175
|
+
* @return [self]
|
|
176
|
+
* @!method minimum_size=(value)
|
|
177
|
+
* Sets the window's minimum allowed client size.
|
|
178
|
+
* @return [Vector2] +value+
|
|
179
|
+
* @!method maximum_size=(value)
|
|
180
|
+
* Sets the window's maximum allowed client size.
|
|
181
|
+
* @return [Vector2] +value+
|
|
182
|
+
* @!method title=(value)
|
|
183
|
+
* Sets the window title.
|
|
184
|
+
* @return [self]
|
|
185
|
+
* @!method set_icon(size, pixels)
|
|
186
|
+
* Sets the window's icon from RGBA32 pixel data.
|
|
187
|
+
* @return [String] +pixels+
|
|
188
|
+
* @!method visible=(value)
|
|
189
|
+
* Shows or hides the window.
|
|
190
|
+
* @return [self]
|
|
191
|
+
* @!method cursor_visible=(value)
|
|
192
|
+
* Shows or hides the mouse cursor over the window.
|
|
193
|
+
* @return [self]
|
|
194
|
+
* @!method cursor_grabbed=(value)
|
|
195
|
+
* Confines or releases the mouse cursor to the window's client area.
|
|
196
|
+
* @return [self]
|
|
197
|
+
* @!method mouse_cursor=(value)
|
|
198
|
+
* Sets the window's mouse cursor.
|
|
199
|
+
* @return [Cursor] +value+
|
|
200
|
+
* @!method cursor=(value)
|
|
201
|
+
* Sets the window's mouse cursor.
|
|
202
|
+
* @return [Cursor] +value+
|
|
203
|
+
* @!method key_repeat_enabled=(value)
|
|
204
|
+
* Enables or disables key-repeat events.
|
|
205
|
+
* @return [self]
|
|
206
|
+
* @!method joystick_threshold=(value)
|
|
207
|
+
* Sets the minimum joystick axis change that generates a move event.
|
|
208
|
+
* @return [Float] +value+
|
|
209
|
+
* @!method request_focus
|
|
210
|
+
* Requests focus for this window.
|
|
211
|
+
* @return [self]
|
|
212
|
+
* @!method focus?
|
|
213
|
+
* Returns +true+ if the window currently has focus.
|
|
214
|
+
* @return [Boolean]
|
|
215
|
+
* @!method native_handle
|
|
216
|
+
* Returns the OS-specific window handle.
|
|
217
|
+
* @return [Integer]
|
|
218
|
+
* @!method create_vulkan_surface(instance, allocator = nil)
|
|
219
|
+
* Creates a Vulkan surface for this window.
|
|
220
|
+
* @return [Integer, nil] the new +VkSurfaceKHR+, or +nil+ if creation failed
|
|
221
|
+
*/
|
|
222
|
+
void Init_WindowBase(VALUE rb_mSFML) {
|
|
223
|
+
rb_cWindowBase = rb_define_class_under(rb_mSFML, "WindowBase", rb_cObject);
|
|
224
|
+
|
|
225
|
+
rb_define_alloc_func(rb_cWindowBase, Window_alloc);
|
|
226
|
+
|
|
227
|
+
rb_define_singleton_method(rb_cWindowBase, "from_handle", WindowBase_s_from_handle, -1);
|
|
228
|
+
|
|
229
|
+
rb_define_method(rb_cWindowBase, "initialize", WindowBase_initialize, -1);
|
|
230
|
+
rb_define_private_method(rb_cWindowBase, "initialize_copy", Window_initialize_copy, 1);
|
|
231
|
+
|
|
232
|
+
WindowBase_define_methods(rb_cWindowBase);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
VALUE Get_Klass_WindowBase(void) {
|
|
236
|
+
return rb_cWindowBase;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
Window* Get_Window_Data(VALUE self) {
|
|
240
|
+
Window* ptr;
|
|
241
|
+
TypedData_Get_Struct(self, Window, &Window_data_type, ptr);
|
|
242
|
+
return ptr;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
sfWindowBase* Get_WindowBase_Struct(VALUE self) {
|
|
246
|
+
return Get_Window_Data(self)->handle;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
sfRenderWindow* Get_Window_Struct(VALUE self) {
|
|
250
|
+
return Get_Window_Data(self)->handle;
|
|
251
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#ifndef SFML_RB_WINDOW_WINDOW_BASE_H
|
|
2
|
+
#define SFML_RB_WINDOW_WINDOW_BASE_H
|
|
3
|
+
|
|
4
|
+
#include <ruby.h>
|
|
5
|
+
|
|
6
|
+
#include "core/sfml.h"
|
|
7
|
+
|
|
8
|
+
/* Which CSFML handle a wrapper owns. SFML::Window and SFML::RenderWindow wrap
|
|
9
|
+
an sfRenderWindow and share every method with sfWindowBase_, but CSFML keys
|
|
10
|
+
its destroy off the concrete type, so dfree has to know which one to call. */
|
|
11
|
+
typedef enum { SFML_WINDOW_KIND_BASE, SFML_WINDOW_KIND_WINDOW } WindowKind;
|
|
12
|
+
|
|
13
|
+
/* One C struct backs every window class. SFML::WindowBase owns an
|
|
14
|
+
sfWindowBase* and SFML::Window/RenderWindow an sfRenderWindow*; the handle is
|
|
15
|
+
stored as void* and read back through the typed accessors below, one per
|
|
16
|
+
class, so no cast ever crosses the two. */
|
|
17
|
+
typedef struct {
|
|
18
|
+
void* handle;
|
|
19
|
+
WindowKind kind;
|
|
20
|
+
/* sfWindowBase_setMouseCursor requires the Cursor to stay alive for as long
|
|
21
|
+
as it's in use by the window (CSFML/SFML docs), so the wrapper retains it
|
|
22
|
+
-- which is why Window_mark exists, unlike a bare pointer. */
|
|
23
|
+
VALUE rb_cursor;
|
|
24
|
+
} Window;
|
|
25
|
+
|
|
26
|
+
void Init_WindowBase(VALUE rb_module);
|
|
27
|
+
|
|
28
|
+
VALUE Get_Klass_WindowBase(void);
|
|
29
|
+
|
|
30
|
+
Window* Get_Window_Data(VALUE self);
|
|
31
|
+
|
|
32
|
+
sfWindowBase* Get_WindowBase_Struct(VALUE self);
|
|
33
|
+
|
|
34
|
+
sfRenderWindow* Get_Window_Struct(VALUE self);
|
|
35
|
+
|
|
36
|
+
/* Allocates a wrapper with a NULL handle; registered as the allocator of every
|
|
37
|
+
window class so the T_DATA default-allocator warning stays quiet. */
|
|
38
|
+
VALUE Window_alloc(VALUE klass);
|
|
39
|
+
|
|
40
|
+
/* Wraps a freshly created handle, tagging it with the destroy to use. */
|
|
41
|
+
VALUE Window_wrap_handle(VALUE klass, void* handle, WindowKind kind);
|
|
42
|
+
|
|
43
|
+
#endif // SFML_RB_WINDOW_WINDOW_BASE_H
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/* Shared method bodies for every window class (WindowBase, Window,
|
|
2
|
+
RenderWindow). Included from several translation units; each defines WB_FN,
|
|
3
|
+
WB_METHOD and WB_HANDLE before including this file, then undefines them
|
|
4
|
+
after. Generating concrete methods per class keeps the compiler's type
|
|
5
|
+
checks on the handle and on every sf* call, which a runtime dispatch through
|
|
6
|
+
void* would not.
|
|
7
|
+
|
|
8
|
+
CSFML gives sfWindowBase_* and sfRenderWindow_* the same window surface under
|
|
9
|
+
two name prefixes, so WB_FN is the only thing that differs. Anything that is
|
|
10
|
+
not on sfWindowBase (settings, display, setActive, vsync, framerate) lives in
|
|
11
|
+
individual classes, not here. */
|
|
12
|
+
|
|
13
|
+
#include "window/window_base.h"
|
|
14
|
+
#include "window/event.h"
|
|
15
|
+
#include "window/cursor.h"
|
|
16
|
+
#include "system/vec2.h"
|
|
17
|
+
#include "core/exceptions.h"
|
|
18
|
+
#include "core/macros.h"
|
|
19
|
+
#include "core/unicode.h"
|
|
20
|
+
|
|
21
|
+
/* call-seq: is_open? -> true or false */
|
|
22
|
+
static VALUE WB_METHOD(is_open)(VALUE self) {
|
|
23
|
+
return BOOL2RB(WB_FN(isOpen)(WB_HANDLE(self)));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/* call-seq: close! -> self */
|
|
27
|
+
static VALUE WB_METHOD(close)(VALUE self) {
|
|
28
|
+
WB_FN(close)(WB_HANDLE(self));
|
|
29
|
+
return self;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* call-seq: poll_event!(event) -> true or false */
|
|
33
|
+
static VALUE WB_METHOD(poll_event)(VALUE self, VALUE rb_event) {
|
|
34
|
+
if (!rb_obj_is_kind_of(rb_event, Get_Klass_Event())) {
|
|
35
|
+
raise_invalid_argument_class(Get_Klass_Event());
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return BOOL2RB(WB_FN(pollEvent)(WB_HANDLE(self), Get_Event_Struct(rb_event)));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/* call-seq: wait_event!(event) -> true or false */
|
|
42
|
+
static VALUE WB_METHOD(wait_event)(VALUE self, VALUE rb_event) {
|
|
43
|
+
if (!rb_obj_is_kind_of(rb_event, Get_Klass_Event())) {
|
|
44
|
+
raise_invalid_argument_class(Get_Klass_Event());
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return BOOL2RB(WB_FN(waitEvent)(WB_HANDLE(self), sfTime_Zero, Get_Event_Struct(rb_event)));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/* call-seq: position -> Vector2 */
|
|
51
|
+
static VALUE WB_METHOD(get_position)(VALUE self) {
|
|
52
|
+
return VEC2_C2RB(WB_FN(getPosition)(WB_HANDLE(self)));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/* call-seq: position=(value) -> value */
|
|
56
|
+
static VALUE WB_METHOD(set_position)(VALUE self, VALUE rb_arr) {
|
|
57
|
+
WB_FN(setPosition)(WB_HANDLE(self), vec2i_new_from_ruby(rb_arr));
|
|
58
|
+
return self;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/* call-seq: size -> Vector2 */
|
|
62
|
+
static VALUE WB_METHOD(get_size)(VALUE self) {
|
|
63
|
+
return VEC2_C2RB(WB_FN(getSize)(WB_HANDLE(self)));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/* call-seq: size=(value) -> self */
|
|
67
|
+
static VALUE WB_METHOD(set_size)(VALUE self, VALUE rb_size) {
|
|
68
|
+
WB_FN(setSize)(WB_HANDLE(self), vec2u_from_rb(rb_size));
|
|
69
|
+
return self;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/* call-seq: minimum_size=(value) -> value */
|
|
73
|
+
static VALUE WB_METHOD(set_minimum_size)(VALUE self, VALUE rb_size) {
|
|
74
|
+
sfVector2u size = vec2u_from_rb(rb_size);
|
|
75
|
+
|
|
76
|
+
WB_FN(setMinimumSize)(WB_HANDLE(self), &size);
|
|
77
|
+
|
|
78
|
+
return rb_size;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/* call-seq: maximum_size=(value) -> value */
|
|
82
|
+
static VALUE WB_METHOD(set_maximum_size)(VALUE self, VALUE rb_size) {
|
|
83
|
+
sfVector2u size = vec2u_from_rb(rb_size);
|
|
84
|
+
|
|
85
|
+
WB_FN(setMaximumSize)(WB_HANDLE(self), &size);
|
|
86
|
+
|
|
87
|
+
return rb_size;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/* Through the UTF-32 entry point: the narrow setTitle decodes the bytes with
|
|
91
|
+
the C locale and mangles anything outside ASCII. */
|
|
92
|
+
/* call-seq: title=(value) -> self */
|
|
93
|
+
static VALUE WB_METHOD(set_title)(VALUE self, VALUE rb_title) {
|
|
94
|
+
VALUE buffer = utf32_from_rb(rb_title);
|
|
95
|
+
|
|
96
|
+
WB_FN(setUnicodeTitle)(WB_HANDLE(self), UTF32_PTR(buffer));
|
|
97
|
+
|
|
98
|
+
RB_GC_GUARD(buffer);
|
|
99
|
+
|
|
100
|
+
return self;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/* call-seq: set_icon(size, pixels) -> pixels */
|
|
104
|
+
static VALUE WB_METHOD(set_icon)(VALUE self, VALUE rb_size, VALUE rb_pixels) {
|
|
105
|
+
sfVector2u size = vec2u_from_rb(rb_size);
|
|
106
|
+
size_t expected = (size_t)size.x * size.y * 4;
|
|
107
|
+
|
|
108
|
+
StringValue(rb_pixels);
|
|
109
|
+
|
|
110
|
+
if ((size_t)RSTRING_LEN(rb_pixels) < expected) {
|
|
111
|
+
rb_raise(rb_eArgError, "pixel data too short: expected %zu bytes", expected);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
WB_FN(setIcon)(WB_HANDLE(self), size, (const uint8_t*)RSTRING_PTR(rb_pixels));
|
|
115
|
+
|
|
116
|
+
return rb_pixels;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/* call-seq: visible=(value) -> self */
|
|
120
|
+
static VALUE WB_METHOD(set_visible)(VALUE self, VALUE rb_visible) {
|
|
121
|
+
WB_FN(setVisible)(WB_HANDLE(self), RTEST(rb_visible));
|
|
122
|
+
return self;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/* call-seq: cursor_visible=(value) -> self */
|
|
126
|
+
static VALUE WB_METHOD(set_mouse_cursor_visible)(VALUE self, VALUE rb_visible) {
|
|
127
|
+
WB_FN(setMouseCursorVisible)(WB_HANDLE(self), RTEST(rb_visible));
|
|
128
|
+
return self;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/* call-seq: cursor_grabbed=(value) -> self */
|
|
132
|
+
static VALUE WB_METHOD(set_mouse_cursor_grabbed)(VALUE self, VALUE rb_grabbed) {
|
|
133
|
+
WB_FN(setMouseCursorGrabbed)(WB_HANDLE(self), RTEST(rb_grabbed));
|
|
134
|
+
return self;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/* CSFML has no way to clear the cursor back to a system default once set (its C
|
|
138
|
+
API unconditionally dereferences the pointer, so NULL crashes rather than
|
|
139
|
+
clearing), so unlike most assignment-style methods here, nil is not
|
|
140
|
+
accepted. */
|
|
141
|
+
/* call-seq: cursor=(value) -> value */
|
|
142
|
+
static VALUE WB_METHOD(set_mouse_cursor)(VALUE self, VALUE rb_cursor) {
|
|
143
|
+
Window* window = Get_Window_Data(self);
|
|
144
|
+
|
|
145
|
+
if (!rb_obj_is_kind_of(rb_cursor, Get_Klass_Cursor())) {
|
|
146
|
+
raise_invalid_argument_class(Get_Klass_Cursor());
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
WB_FN(setMouseCursor)(WB_HANDLE(self), Get_Cursor_Struct(rb_cursor));
|
|
150
|
+
/* Keep the Cursor alive for as long as the window may use it. */
|
|
151
|
+
window->rb_cursor = rb_cursor;
|
|
152
|
+
|
|
153
|
+
return rb_cursor;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/* call-seq: key_repeat_enabled=(value) -> self */
|
|
157
|
+
static VALUE WB_METHOD(set_key_repeat_enabled)(VALUE self, VALUE rb_enabled) {
|
|
158
|
+
WB_FN(setKeyRepeatEnabled)(WB_HANDLE(self), RTEST(rb_enabled));
|
|
159
|
+
return self;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/* call-seq: joystick_threshold=(value) -> value */
|
|
163
|
+
static VALUE WB_METHOD(set_joystick_threshold)(VALUE self, VALUE rb_threshold) {
|
|
164
|
+
WB_FN(setJoystickThreshold)(WB_HANDLE(self), NUM2DBL(rb_threshold));
|
|
165
|
+
return rb_threshold;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/* call-seq: request_focus -> self */
|
|
169
|
+
static VALUE WB_METHOD(request_focus)(VALUE self) {
|
|
170
|
+
WB_FN(requestFocus)(WB_HANDLE(self));
|
|
171
|
+
return self;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/* call-seq: focus? -> true or false */
|
|
175
|
+
static VALUE WB_METHOD(has_focus)(VALUE self) {
|
|
176
|
+
return BOOL2RB(WB_FN(hasFocus)(WB_HANDLE(self)));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/* call-seq: native_handle -> Integer */
|
|
180
|
+
static VALUE WB_METHOD(get_native_handle)(VALUE self) {
|
|
181
|
+
return ULL2NUM((unsigned long long)(uintptr_t)WB_FN(getNativeHandle)(WB_HANDLE(self)));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/* Vulkan handles cross this binding as Integers, the same way
|
|
185
|
+
SFML::Vulkan.function already returns one -- there is no Vulkan object model
|
|
186
|
+
here to wrap them in. Returns the new VkSurfaceKHR, or nil on failure. */
|
|
187
|
+
/* call-seq: create_vulkan_surface(instance, allocator = nil) -> Integer or nil */
|
|
188
|
+
static VALUE WB_METHOD(create_vulkan_surface)(int argc, VALUE* argv, VALUE self) {
|
|
189
|
+
VALUE rb_instance, rb_allocator;
|
|
190
|
+
VkInstance instance;
|
|
191
|
+
VkSurfaceKHR surface;
|
|
192
|
+
const VkAllocationCallbacks* allocator = NULL;
|
|
193
|
+
|
|
194
|
+
rb_scan_args(argc, argv, "11", &rb_instance, &rb_allocator);
|
|
195
|
+
|
|
196
|
+
instance = (VkInstance)(uintptr_t)NUM2ULL(rb_instance);
|
|
197
|
+
|
|
198
|
+
if (!NIL_P(rb_allocator)) {
|
|
199
|
+
allocator = (const VkAllocationCallbacks*)(uintptr_t)NUM2ULL(rb_allocator);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (!WB_FN(createVulkanSurface)(WB_HANDLE(self), &instance, &surface, allocator)) {
|
|
203
|
+
return Qnil;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return ULL2NUM((unsigned long long)(uintptr_t)surface);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
static void WB_METHOD(define_methods)(VALUE klass) {
|
|
210
|
+
rb_define_method(klass, "is_open?", WB_METHOD(is_open), 0);
|
|
211
|
+
rb_define_method(klass, "close!", WB_METHOD(close), 0);
|
|
212
|
+
rb_define_method(klass, "poll_event!", WB_METHOD(poll_event), 1);
|
|
213
|
+
rb_define_method(klass, "wait_event!", WB_METHOD(wait_event), 1);
|
|
214
|
+
|
|
215
|
+
rb_define_method(klass, "position", WB_METHOD(get_position), 0);
|
|
216
|
+
rb_define_method(klass, "size", WB_METHOD(get_size), 0);
|
|
217
|
+
rb_define_method(klass, "focus?", WB_METHOD(has_focus), 0);
|
|
218
|
+
rb_define_method(klass, "native_handle", WB_METHOD(get_native_handle), 0);
|
|
219
|
+
|
|
220
|
+
rb_define_method(klass, "position=", WB_METHOD(set_position), 1);
|
|
221
|
+
rb_define_method(klass, "size=", WB_METHOD(set_size), 1);
|
|
222
|
+
rb_define_method(klass, "minimum_size=", WB_METHOD(set_minimum_size), 1);
|
|
223
|
+
rb_define_method(klass, "maximum_size=", WB_METHOD(set_maximum_size), 1);
|
|
224
|
+
rb_define_method(klass, "title=", WB_METHOD(set_title), 1);
|
|
225
|
+
rb_define_method(klass, "set_icon", WB_METHOD(set_icon), 2);
|
|
226
|
+
rb_define_method(klass, "visible=", WB_METHOD(set_visible), 1);
|
|
227
|
+
rb_define_method(klass, "cursor_visible=", WB_METHOD(set_mouse_cursor_visible), 1);
|
|
228
|
+
rb_define_method(klass, "cursor_grabbed=", WB_METHOD(set_mouse_cursor_grabbed), 1);
|
|
229
|
+
rb_define_method(klass, "mouse_cursor=", WB_METHOD(set_mouse_cursor), 1);
|
|
230
|
+
rb_define_method(klass, "cursor=", WB_METHOD(set_mouse_cursor), 1);
|
|
231
|
+
rb_define_method(klass, "key_repeat_enabled=", WB_METHOD(set_key_repeat_enabled), 1);
|
|
232
|
+
rb_define_method(klass, "joystick_threshold=", WB_METHOD(set_joystick_threshold), 1);
|
|
233
|
+
|
|
234
|
+
rb_define_method(klass, "request_focus", WB_METHOD(request_focus), 0);
|
|
235
|
+
rb_define_method(klass, "create_vulkan_surface", WB_METHOD(create_vulkan_surface), -1);
|
|
236
|
+
}
|
data/lib/sfml/version.rb
CHANGED
data/sig/audio/sound.rbs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module SFML
|
|
2
2
|
class SoundSourceCone
|
|
3
|
-
def
|
|
3
|
+
def initialize: (Float inner_angle, Float outer_angle, Float outer_gain) -> void
|
|
4
4
|
|
|
5
5
|
def inner_angle: () -> Float
|
|
6
6
|
def inner_angle=: (Float value) -> Float
|
data/sig/audio/sound_stream.rbs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module SFML
|
|
2
2
|
class SoundStream
|
|
3
|
-
def
|
|
3
|
+
def initialize: (Integer channel_count, Integer sample_rate, ?Array[Symbol] channel_map) -> void
|
|
4
4
|
|
|
5
5
|
def channel_count: () -> Integer
|
|
6
6
|
def sample_rate: () -> Integer
|
data/sig/graphics/blend_mode.rbs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module SFML
|
|
2
2
|
class BlendMode
|
|
3
|
-
def
|
|
3
|
+
def initialize: () -> void
|
|
4
4
|
| (Symbol | Integer color_src_factor, Symbol | Integer color_dst_factor,
|
|
5
5
|
Symbol | Integer color_equation, Symbol | Integer alpha_src_factor,
|
|
6
6
|
Symbol | Integer alpha_dst_factor, Symbol | Integer alpha_equation) -> BlendMode
|
data/sig/graphics/circle.rbs
CHANGED
data/sig/graphics/color.rbs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
module SFML
|
|
2
2
|
class Color
|
|
3
|
-
def
|
|
4
|
-
| (Integer r, Integer g, Integer b, ?Integer a) ->
|
|
5
|
-
| (Array[Integer] rgb_or_rgba) ->
|
|
6
|
-
| (Integer packed) ->
|
|
7
|
-
| (Color other) ->
|
|
3
|
+
def initialize: () -> void
|
|
4
|
+
| (Integer r, Integer g, Integer b, ?Integer a) -> void
|
|
5
|
+
| (Array[Integer] rgb_or_rgba) -> void
|
|
6
|
+
| (Integer packed) -> void
|
|
7
|
+
| (Color other) -> void
|
|
8
8
|
def self.from_rgb: (Integer rgb) -> Color
|
|
9
9
|
def self.from_rgba: (Integer rgba) -> Color
|
|
10
10
|
def self.from_integer: (Integer rgba) -> Color
|
data/sig/graphics/image.rbs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module SFML
|
|
2
2
|
class Image
|
|
3
|
-
def
|
|
3
|
+
def initialize: (Vector2 | Array[Integer] size) -> void
|
|
4
4
|
def self.from_color: (Vector2 | Array[Integer] size, Color color) -> Image
|
|
5
5
|
def self.from_pixels: (Vector2 | Array[Integer] size, String pixels) -> Image
|
|
6
6
|
def self.from_file: (String path) -> Image
|
data/sig/graphics/polygon.rbs
CHANGED
data/sig/graphics/rect.rbs
CHANGED
|
@@ -2,11 +2,11 @@ module SFML
|
|
|
2
2
|
class Rect
|
|
3
3
|
include Enumerable[Float]
|
|
4
4
|
|
|
5
|
-
def
|
|
6
|
-
| (Float left, Float top) ->
|
|
7
|
-
| (Float left, Float top, Float width, Float height) ->
|
|
8
|
-
| (Array[Float] left_top_width_height) ->
|
|
9
|
-
| (Rect other) ->
|
|
5
|
+
def initialize: () -> void
|
|
6
|
+
| (Float left, Float top) -> void
|
|
7
|
+
| (Float left, Float top, Float width, Float height) -> void
|
|
8
|
+
| (Array[Float] left_top_width_height) -> void
|
|
9
|
+
| (Rect other) -> void
|
|
10
10
|
|
|
11
11
|
def left: () -> Float
|
|
12
12
|
def left=: (Float value) -> Float
|
data/sig/graphics/rectangle.rbs
CHANGED
|
@@ -2,7 +2,7 @@ module SFML
|
|
|
2
2
|
class RectangleShape
|
|
3
3
|
include Drawable
|
|
4
4
|
|
|
5
|
-
def
|
|
5
|
+
def initialize: (?(Vector2 | Array[Float]) size) -> void
|
|
6
6
|
|
|
7
7
|
def copy: () -> RectangleShape
|
|
8
8
|
def move: (Vector2 | Array[Float] offset) -> self
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module SFML
|
|
2
2
|
class RenderState
|
|
3
|
-
def
|
|
4
|
-
| (Array[Array[Float]] | Array[Float] matrix) ->
|
|
3
|
+
def initialize: () -> void
|
|
4
|
+
| (Array[Array[Float]] | Array[Float] matrix) -> void
|
|
5
5
|
|
|
6
6
|
def transform: () -> Array[untyped]
|
|
7
7
|
def transform=: (Array[Array[Float]] | Array[Float] matrix) -> self
|