sfml3-rb 0.2.2 → 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.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +9 -0
  3. data/CHANGELOG.md +67 -16
  4. data/README.md +123 -32
  5. data/TODO.md +18 -11
  6. data/ext/audio/audio_enums.c +58 -20
  7. data/ext/audio/listener.c +89 -6
  8. data/ext/audio/music.c +212 -5
  9. data/ext/audio/sound.c +218 -9
  10. data/ext/audio/sound_buffer.c +197 -47
  11. data/ext/audio/sound_buffer_recorder.c +90 -18
  12. data/ext/audio/sound_recorder.c +188 -58
  13. data/ext/audio/sound_source_cone.c +127 -33
  14. data/ext/audio/sound_stream.c +204 -21
  15. data/ext/core/exceptions.c +10 -8
  16. data/ext/core/unicode.c +12 -2
  17. data/ext/ext.c +8 -0
  18. data/ext/graphics/blend_mode.c +218 -60
  19. data/ext/graphics/circle.c +300 -16
  20. data/ext/graphics/color.c +253 -94
  21. data/ext/graphics/drawable.c +16 -4
  22. data/ext/graphics/font.c +144 -25
  23. data/ext/graphics/glyph.c +38 -8
  24. data/ext/graphics/image.c +205 -41
  25. data/ext/graphics/polygon.c +317 -30
  26. data/ext/graphics/rect.c +225 -60
  27. data/ext/graphics/rectangle.c +307 -35
  28. data/ext/graphics/render_state.c +124 -12
  29. data/ext/graphics/render_texture.c +191 -14
  30. data/ext/graphics/render_window.c +55 -0
  31. data/ext/graphics/render_window.h +10 -0
  32. data/ext/graphics/shader.c +289 -17
  33. data/ext/graphics/shape.c +265 -32
  34. data/ext/graphics/sprite.c +245 -30
  35. data/ext/graphics/stencil_mode.c +163 -46
  36. data/ext/graphics/target.c +121 -43
  37. data/ext/graphics/target.h +31 -17
  38. data/ext/graphics/text.c +339 -19
  39. data/ext/graphics/texture.c +291 -6
  40. data/ext/graphics/transform.c +178 -5
  41. data/ext/graphics/transformable.c +127 -12
  42. data/ext/graphics/vertex.c +98 -6
  43. data/ext/graphics/vertex_array.c +142 -21
  44. data/ext/graphics/vertex_buffer.c +154 -12
  45. data/ext/graphics/view.c +140 -6
  46. data/ext/network/ftp.c +278 -12
  47. data/ext/network/http.c +179 -44
  48. data/ext/network/ip_address.c +127 -35
  49. data/ext/network/network_enums.c +248 -141
  50. data/ext/network/packet.c +280 -41
  51. data/ext/network/socket_selector.c +98 -21
  52. data/ext/network/tcp_listener.c +82 -18
  53. data/ext/network/tcp_socket.c +135 -27
  54. data/ext/network/udp_socket.c +129 -28
  55. data/ext/ports.rb +7 -0
  56. data/ext/system/buffer.c +47 -16
  57. data/ext/system/clock.c +77 -12
  58. data/ext/system/input_stream.c +113 -51
  59. data/ext/system/sleep.c +10 -2
  60. data/ext/system/time.c +182 -40
  61. data/ext/system/vec2.c +166 -39
  62. data/ext/system/vec3.c +177 -39
  63. data/ext/window/clipboard.c +47 -17
  64. data/ext/window/context.c +66 -13
  65. data/ext/window/context_settings.c +132 -42
  66. data/ext/window/cursor.c +45 -9
  67. data/ext/window/event.c +164 -53
  68. data/ext/window/joystick.c +69 -3
  69. data/ext/window/keyboard.c +168 -116
  70. data/ext/window/mouse.c +64 -13
  71. data/ext/window/sensor.c +28 -2
  72. data/ext/window/touch.c +32 -12
  73. data/ext/window/video_mode.c +93 -31
  74. data/ext/window/vulkan.c +34 -6
  75. data/ext/window/window.c +228 -229
  76. data/ext/window/window.h +4 -4
  77. data/ext/window/window_base.c +251 -0
  78. data/ext/window/window_base.h +43 -0
  79. data/ext/window/window_base.inc +236 -0
  80. data/lib/sfml/version.rb +1 -1
  81. data/sig/audio/audio_enums.rbs +30 -0
  82. data/sig/audio/listener.rbs +16 -0
  83. data/sig/audio/music.rbs +56 -0
  84. data/sig/audio/sound.rbs +51 -0
  85. data/sig/audio/sound_buffer.rbs +17 -0
  86. data/sig/audio/sound_buffer_recorder.rbs +14 -0
  87. data/sig/audio/sound_recorder.rbs +17 -0
  88. data/sig/audio/sound_source_cone.rbs +14 -0
  89. data/sig/audio/sound_stream.rbs +51 -0
  90. data/sig/graphics/blend_mode.rbs +29 -0
  91. data/sig/graphics/circle.rbs +44 -0
  92. data/sig/graphics/color.rbs +39 -0
  93. data/sig/graphics/drawable.rbs +5 -0
  94. data/sig/graphics/font.rbs +20 -0
  95. data/sig/graphics/glyph.rbs +7 -0
  96. data/sig/graphics/image.rbs +22 -0
  97. data/sig/graphics/polygon.rbs +42 -0
  98. data/sig/graphics/rect.rbs +33 -0
  99. data/sig/graphics/rectangle.rbs +42 -0
  100. data/sig/graphics/render_state.rbs +21 -0
  101. data/sig/graphics/render_target.rbs +18 -0
  102. data/sig/graphics/render_texture.rbs +39 -0
  103. data/sig/graphics/render_window.rbs +7 -0
  104. data/sig/graphics/shader.rbs +39 -0
  105. data/sig/graphics/shape.rbs +38 -0
  106. data/sig/graphics/sprite.rbs +34 -0
  107. data/sig/graphics/stencil_mode.rbs +18 -0
  108. data/sig/graphics/target.rbs +8 -0
  109. data/sig/graphics/text.rbs +48 -0
  110. data/sig/graphics/texture.rbs +34 -0
  111. data/sig/graphics/transform.rbs +37 -0
  112. data/sig/graphics/transformable.rbs +25 -0
  113. data/sig/graphics/vertex.rbs +17 -0
  114. data/sig/graphics/vertex_array.rbs +17 -0
  115. data/sig/graphics/vertex_buffer.rbs +22 -0
  116. data/sig/graphics/view.rbs +23 -0
  117. data/sig/network/ftp.rbs +46 -0
  118. data/sig/network/http.rbs +27 -0
  119. data/sig/network/ip_address.rbs +22 -0
  120. data/sig/network/network_enums.rbs +95 -0
  121. data/sig/network/packet.rbs +40 -0
  122. data/sig/network/socket_selector.rbs +14 -0
  123. data/sig/network/tcp_listener.rbs +13 -0
  124. data/sig/network/tcp_socket.rbs +18 -0
  125. data/sig/network/udp_socket.rbs +17 -0
  126. data/sig/sfml/version.rbs +3 -0
  127. data/sig/system/buffer.rbs +11 -0
  128. data/sig/system/clock.rbs +13 -0
  129. data/sig/system/input_stream.rbs +7 -0
  130. data/sig/system/sleep.rbs +3 -0
  131. data/sig/system/time.rbs +28 -0
  132. data/sig/system/vec2.rbs +26 -0
  133. data/sig/system/vec3.rbs +27 -0
  134. data/sig/window/clipboard.rbs +8 -0
  135. data/sig/window/context.rbs +11 -0
  136. data/sig/window/context_settings.rbs +20 -0
  137. data/sig/window/cursor.rbs +6 -0
  138. data/sig/window/event.rbs +20 -0
  139. data/sig/window/joystick.rbs +15 -0
  140. data/sig/window/keyboard.rbs +10 -0
  141. data/sig/window/mouse.rbs +9 -0
  142. data/sig/window/sensor.rbs +8 -0
  143. data/sig/window/touch.rbs +6 -0
  144. data/sig/window/video_mode.rbs +16 -0
  145. data/sig/window/vulkan.rbs +7 -0
  146. data/sig/window/window.rbs +34 -0
  147. data/sig/window/window_base.rbs +33 -0
  148. metadata +76 -3
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SFML
4
- VERSION = '0.2.2'
4
+ VERSION = '0.3.1'
5
5
  end
@@ -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
@@ -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
@@ -0,0 +1,51 @@
1
+ module SFML
2
+ class Sound
3
+ def initialize: (SoundBuffer buffer) -> void
4
+
5
+ def copy: () -> Sound
6
+ def buffer: () -> SoundBuffer
7
+ def buffer=: (SoundBuffer value) -> SoundBuffer
8
+
9
+ def play: () -> self
10
+ def pause: () -> self
11
+ def stop: () -> self
12
+ def status: () -> (:stopped | :paused | :playing)
13
+ def looping?: () -> bool
14
+ def looping=: (bool value) -> bool
15
+ def pitch: () -> Float
16
+ def pitch=: (Float value) -> Float
17
+ def pan: () -> Float
18
+ def pan=: (Float value) -> Float
19
+ def volume: () -> Float
20
+ def volume=: (Float value) -> Float
21
+ def spatialization_enabled?: () -> bool
22
+ def spatialization_enabled=: (bool value) -> bool
23
+ def position: () -> Vector3
24
+ def position=: (Vector3 value) -> Vector3
25
+ def direction: () -> Vector3
26
+ def direction=: (Vector3 value) -> Vector3
27
+ def velocity: () -> Vector3
28
+ def velocity=: (Vector3 value) -> Vector3
29
+ def cone: () -> SoundSourceCone
30
+ def cone=: (SoundSourceCone value) -> SoundSourceCone
31
+ def doppler_factor: () -> Float
32
+ def doppler_factor=: (Float value) -> Float
33
+ def directional_attenuation_factor: () -> Float
34
+ def directional_attenuation_factor=: (Float value) -> Float
35
+ def relative_to_listener?: () -> bool
36
+ def relative_to_listener=: (bool value) -> bool
37
+ def min_distance: () -> Float
38
+ def min_distance=: (Float value) -> Float
39
+ def max_distance: () -> Float
40
+ def max_distance=: (Float value) -> Float
41
+ def min_gain: () -> Float
42
+ def min_gain=: (Float value) -> Float
43
+ def max_gain: () -> Float
44
+ def max_gain=: (Float value) -> Float
45
+ def attenuation: () -> Float
46
+ def attenuation=: (Float value) -> Float
47
+ def playing_offset: () -> Time
48
+ def playing_offset=: (Time value) -> Time
49
+ def effect_processor=: (Proc proc) -> Proc
50
+ end
51
+ end