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
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,22 +20,28 @@
19
20
 
20
21
  static VALUE rb_cWindow;
21
22
 
22
- static sfRenderWindow* Window_create(sfVideoMode* mode, const sfChar32* title, uint32_t style,
23
- sfWindowState state, const sfContextSettings* settings) {
24
- return sfRenderWindow_createUnicode(*mode, title, style, state, settings);
25
- }
26
-
27
- static void Window_free(void* ptr) {
28
- sfRenderWindow_destroy((sfRenderWindow*)ptr);
29
- }
30
-
31
- static const rb_data_type_t Window_data_type = {
32
- .wrap_struct_name = "SFML::Window",
33
- .function = {.dmark = NULL, .dfree = Window_free, .dsize = NULL},
34
- .flags = RUBY_TYPED_FREE_IMMEDIATELY};
35
-
36
- static VALUE Window_new(int argc, VALUE* argv, VALUE klass) {
37
- VALUE self, rb_video_mode, rb_title, rb_style, rb_state, rb_settings, title_buffer;
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
34
+
35
+ /* call-seq:
36
+ * Window.new(video_mode, title, style = :default, state = :windowed, settings = nil) -> Window
37
+ *
38
+ * Creates a window with an OpenGL context from +video_mode+ and +title+.
39
+ *
40
+ * @return [Window]
41
+ * @raise [RuntimeError] if window creation fails
42
+ */
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;
38
45
  sfWindowState state = sfWindowed;
39
46
  sfContextSettings settings;
40
47
  const sfContextSettings* settings_ptr = NULL;
@@ -61,17 +68,16 @@ static VALUE Window_new(int argc, VALUE* argv, VALUE klass) {
61
68
  }
62
69
 
63
70
  title_buffer = utf32_from_rb(rb_title);
64
- window = Window_create(Get_Mode_Struct(rb_video_mode), UTF32_PTR(title_buffer), style, state,
65
- settings_ptr);
71
+ window = sfRenderWindow_createUnicode(*Get_Mode_Struct(rb_video_mode), UTF32_PTR(title_buffer),
72
+ style, state, settings_ptr);
66
73
  RB_GC_GUARD(title_buffer);
67
74
 
68
75
  if (window == NULL) {
69
76
  rb_raise(rb_eRuntimeError, "failed to create window");
70
77
  }
71
78
 
72
- self = TypedData_Wrap_Struct(klass, &Window_data_type, window);
73
-
74
- rb_obj_call_init(self, argc, argv);
79
+ Get_Window_Data(self)->handle = window;
80
+ Get_Window_Data(self)->kind = SFML_WINDOW_KIND_WINDOW;
75
81
 
76
82
  return self;
77
83
  }
@@ -80,8 +86,14 @@ static VALUE Window_new(int argc, VALUE* argv, VALUE klass) {
80
86
  Window#native_handle returns, or one obtained from a GUI toolkit. The window
81
87
  is not owned by the toolkit afterwards: destroying it stays the toolkit's
82
88
  job, and closing the Ruby object only tears down the render context. */
89
+ /* call-seq:
90
+ * Window.from_handle(handle, settings = nil) -> Window
91
+ *
92
+ * @return [Window]
93
+ * @raise [RuntimeError] if window creation fails
94
+ */
83
95
  static VALUE Window_s_from_handle(int argc, VALUE* argv, VALUE klass) {
84
- VALUE self, rb_handle, rb_settings;
96
+ VALUE rb_handle, rb_settings;
85
97
  sfContextSettings settings;
86
98
  const sfContextSettings* settings_ptr = NULL;
87
99
  sfRenderWindow* window;
@@ -100,26 +112,17 @@ static VALUE Window_s_from_handle(int argc, VALUE* argv, VALUE klass) {
100
112
  rb_raise(rb_eRuntimeError, "failed to create window from handle");
101
113
  }
102
114
 
103
- self = TypedData_Wrap_Struct(klass, &Window_data_type, window);
104
-
105
- rb_obj_call_init(self, 0, NULL);
106
-
107
- return self;
108
- }
109
-
110
- static VALUE Window_init(int argc, VALUE* argv, VALUE self) {
111
- return self;
112
- }
113
-
114
- static VALUE Window_is_open(VALUE self) {
115
- return BOOL2RB(sfRenderWindow_isOpen(Get_Window_Struct(self)));
116
- }
117
-
118
- static VALUE Window_close(VALUE self) {
119
- sfRenderWindow_close(Get_Window_Struct(self));
120
- return self;
115
+ return Window_wrap_handle(klass, window, SFML_WINDOW_KIND_WINDOW);
121
116
  }
122
117
 
118
+ /* call-seq:
119
+ * clear(color = Color::BLACK) -> self
120
+ *
121
+ * Clears the window to +color+ (black by default).
122
+ *
123
+ * @return [self]
124
+ * @raise [ArgumentError] if given more than one argument
125
+ */
123
126
  static VALUE Window_clear(int argc, VALUE* argv, VALUE self) {
124
127
  sfColor color = sfBlack;
125
128
 
@@ -137,181 +140,71 @@ static VALUE Window_clear(int argc, VALUE* argv, VALUE self) {
137
140
  return self;
138
141
  }
139
142
 
143
+ /* call-seq: display -> self
144
+ *
145
+ * Presents everything drawn since the last call to the screen.
146
+ *
147
+ * @return [self]
148
+ */
140
149
  static VALUE Window_display(VALUE self) {
141
150
  sfRenderWindow_display(Get_Window_Struct(self));
142
151
  return self;
143
152
  }
144
153
 
145
- static VALUE Window_poll_event(VALUE self, VALUE rb_event) {
146
- if (!rb_obj_is_kind_of(rb_event, Get_Klass_Event())) {
147
- raise_invalid_argument_class(Get_Klass_Event());
148
- }
149
-
150
- return BOOL2RB(sfRenderWindow_pollEvent(Get_Window_Struct(self), Get_Event_Struct(rb_event)));
151
- }
152
-
153
- static VALUE Window_wait_event(VALUE self, VALUE rb_event) {
154
- if (!rb_obj_is_kind_of(rb_event, Get_Klass_Event())) {
155
- raise_invalid_argument_class(Get_Klass_Event());
156
- }
157
-
158
- return BOOL2RB(
159
- sfRenderWindow_waitEvent(Get_Window_Struct(self), sfTime_Zero, Get_Event_Struct(rb_event)));
160
- }
161
-
162
- static VALUE Window_get_position(VALUE self) {
163
- return VEC2_C2RB(sfRenderWindow_getPosition(Get_Window_Struct(self)));
164
- }
165
-
166
- static VALUE Window_set_position(VALUE self, VALUE rb_arr) {
167
- sfRenderWindow_setPosition(Get_Window_Struct(self), vec2i_new_from_ruby(rb_arr));
168
- return self;
169
- }
170
-
154
+ /* call-seq:
155
+ * frame_rate=(value) -> self
156
+ *
157
+ * Limits the framerate to +value+ frames per second; 0 disables the limit.
158
+ *
159
+ * @return [self]
160
+ */
171
161
  static VALUE Window_set_frame_rate(VALUE self, VALUE rb_limit) {
172
162
  sfRenderWindow_setFramerateLimit(Get_Window_Struct(self), NUM2INT(rb_limit));
173
163
  return self;
174
164
  }
175
165
 
176
- static VALUE Window_set_size(VALUE self, VALUE rb_size) {
177
- sfRenderWindow_setSize(Get_Window_Struct(self), vec2u_from_rb(rb_size));
178
- return self;
179
- }
180
-
181
- static VALUE Window_get_size(VALUE self) {
182
- return VEC2_C2RB(sfRenderWindow_getSize(Get_Window_Struct(self)));
183
- }
184
-
185
- static VALUE Window_set_minimum_size(VALUE self, VALUE rb_size) {
186
- sfVector2u size = vec2u_from_rb(rb_size);
187
-
188
- sfRenderWindow_setMinimumSize(Get_Window_Struct(self), &size);
189
-
190
- return rb_size;
191
- }
192
-
193
- static VALUE Window_set_maximum_size(VALUE self, VALUE rb_size) {
194
- sfVector2u size = vec2u_from_rb(rb_size);
195
-
196
- sfRenderWindow_setMaximumSize(Get_Window_Struct(self), &size);
197
-
198
- return rb_size;
199
- }
200
-
166
+ /* call-seq:
167
+ * active=(value) -> true or false
168
+ *
169
+ * Activates or deactivates this window's OpenGL context as the current one on
170
+ * the calling thread.
171
+ *
172
+ * @return [Boolean] whether activation succeeded
173
+ */
201
174
  static VALUE Window_set_active(VALUE self, VALUE rb_active) {
202
175
  return BOOL2RB(sfRenderWindow_setActive(Get_Window_Struct(self), RTEST(rb_active)));
203
176
  }
204
177
 
205
- static VALUE Window_get_native_handle(VALUE self) {
206
- return ULL2NUM(
207
- (unsigned long long)(uintptr_t)sfRenderWindow_getNativeHandle(Get_Window_Struct(self)));
208
- }
209
-
210
- /* Vulkan handles cross this binding as Integers, the same way
211
- SFML::Vulkan.function already returns one -- there is no Vulkan object model
212
- here to wrap them in. Returns the new VkSurfaceKHR, or nil if creation
213
- failed. */
214
- static VALUE Window_create_vulkan_surface(int argc, VALUE* argv, VALUE self) {
215
- VALUE rb_instance, rb_allocator;
216
- VkInstance instance;
217
- VkSurfaceKHR surface;
218
- const VkAllocationCallbacks* allocator = NULL;
219
-
220
- rb_scan_args(argc, argv, "11", &rb_instance, &rb_allocator);
221
-
222
- instance = (VkInstance)(uintptr_t)NUM2ULL(rb_instance);
223
-
224
- if (!NIL_P(rb_allocator)) {
225
- allocator = (const VkAllocationCallbacks*)(uintptr_t)NUM2ULL(rb_allocator);
226
- }
227
-
228
- if (!sfRenderWindow_createVulkanSurface(Get_Window_Struct(self), &instance, &surface,
229
- allocator)) {
230
- return Qnil;
231
- }
232
-
233
- return ULL2NUM((unsigned long long)(uintptr_t)surface);
234
- }
235
-
236
- static VALUE Window_set_icon(VALUE self, VALUE rb_size, VALUE rb_pixels) {
237
- StringValue(rb_pixels);
238
-
239
- sfRenderWindow_setIcon(Get_Window_Struct(self), vec2u_from_rb(rb_size),
240
- (const uint8_t*)RSTRING_PTR(rb_pixels));
241
-
242
- return rb_pixels;
243
- }
244
-
245
- static VALUE Window_get_settings(VALUE self) {
246
- return context_settings_to_rb(sfRenderWindow_getSettings(Get_Window_Struct(self)));
247
- }
248
-
249
- /* Through the UTF-32 entry point: sfRenderWindow_setTitle decodes the bytes
250
- with the C locale and mangles anything outside ASCII. */
251
- static VALUE Window_set_title(VALUE self, VALUE rb_title) {
252
- VALUE buffer = utf32_from_rb(rb_title);
253
-
254
- sfRenderWindow_setUnicodeTitle(Get_Window_Struct(self), UTF32_PTR(buffer));
255
-
256
- RB_GC_GUARD(buffer);
257
-
258
- return self;
259
- }
260
-
261
- static VALUE Window_set_visible(VALUE self, VALUE rb_visible) {
262
- sfRenderWindow_setVisible(Get_Window_Struct(self), RTEST(rb_visible));
263
- return self;
264
- }
265
-
178
+ /* call-seq:
179
+ * vertical_sync_enabled=(value) -> self
180
+ *
181
+ * Enables or disables vertical synchronization.
182
+ *
183
+ * @return [self]
184
+ */
266
185
  static VALUE Window_set_vertical_sync_enabled(VALUE self, VALUE rb_enable) {
267
186
  sfRenderWindow_setVerticalSyncEnabled(Get_Window_Struct(self), RTEST(rb_enable));
268
187
  return self;
269
188
  }
270
189
 
271
- static VALUE Window_set_mouse_cursor_visible(VALUE self, VALUE rb_visible) {
272
- sfRenderWindow_setMouseCursorVisible(Get_Window_Struct(self), RTEST(rb_visible));
273
- return self;
274
- }
275
-
276
- static VALUE Window_set_mouse_cursor_grabbed(VALUE self, VALUE rb_grabbed) {
277
- sfRenderWindow_setMouseCursorGrabbed(Get_Window_Struct(self), RTEST(rb_grabbed));
278
- return self;
279
- }
280
-
281
- static VALUE Window_set_mouse_cursor(VALUE self, VALUE rb_cursor) {
282
- if (NIL_P(rb_cursor)) {
283
- sfRenderWindow_setMouseCursor(Get_Window_Struct(self), NULL);
284
- return rb_cursor;
285
- }
286
-
287
- if (!rb_obj_is_kind_of(rb_cursor, Get_Klass_Cursor())) {
288
- raise_invalid_argument_class(Get_Klass_Cursor());
289
- }
290
-
291
- sfRenderWindow_setMouseCursor(Get_Window_Struct(self), Get_Cursor_Struct(rb_cursor));
292
-
293
- return rb_cursor;
294
- }
295
-
296
- static VALUE Window_set_key_repeat_enabled(VALUE self, VALUE rb_enabled) {
297
- sfRenderWindow_setKeyRepeatEnabled(Get_Window_Struct(self), RTEST(rb_enabled));
298
- return self;
299
- }
300
-
301
- static VALUE Window_set_joystick_threshold(VALUE self, VALUE rb_threshold) {
302
- sfRenderWindow_setJoystickThreshold(Get_Window_Struct(self), NUM2DBL(rb_threshold));
303
- return rb_threshold;
304
- }
305
-
306
- static VALUE Window_request_focus(VALUE self) {
307
- sfRenderWindow_requestFocus(Get_Window_Struct(self));
308
- return self;
309
- }
310
-
311
- static VALUE Window_has_focus(VALUE self) {
312
- return BOOL2RB(sfRenderWindow_hasFocus(Get_Window_Struct(self)));
190
+ /* call-seq: settings -> ContextSettings
191
+ *
192
+ * Returns the context settings this window was created with.
193
+ *
194
+ * @return [ContextSettings] the settings this window's context was created with
195
+ */
196
+ static VALUE Window_get_settings(VALUE self) {
197
+ return context_settings_to_rb(sfRenderWindow_getSettings(Get_Window_Struct(self)));
313
198
  }
314
199
 
200
+ /* call-seq:
201
+ * draw(drawable, state = nil) -> self
202
+ *
203
+ * Draws +drawable+ into the window.
204
+ *
205
+ * @return [self]
206
+ * @raise [ArgumentError] if given no arguments or more than 2
207
+ */
315
208
  static VALUE Window_draw(int argc, VALUE* argv, VALUE self) {
316
209
  VALUE rb_drawable, rb_state;
317
210
 
@@ -327,6 +220,13 @@ static VALUE Window_draw(int argc, VALUE* argv, VALUE self) {
327
220
  return self;
328
221
  }
329
222
 
223
+ /* call-seq: view=(value) -> self
224
+ *
225
+ * Sets the window's active view to +value+.
226
+ *
227
+ * @return [self]
228
+ * @raise [ArgumentError] if +value+ is not a View
229
+ */
330
230
  static VALUE Window_set_view(VALUE self, VALUE rb_view) {
331
231
  if (!rb_obj_is_kind_of(rb_view, Get_Klass_View())) {
332
232
  rb_raise(rb_eArgError, "invalid object, expected a View object");
@@ -337,10 +237,22 @@ static VALUE Window_set_view(VALUE self, VALUE rb_view) {
337
237
  return self;
338
238
  }
339
239
 
240
+ /* call-seq: view -> View
241
+ *
242
+ * Returns a copy of the window's currently active view.
243
+ *
244
+ * @return [View] a copy of the window's currently active view
245
+ */
340
246
  static VALUE Window_get_view(VALUE self) {
341
247
  return Get_Casting_View(sfView_copy(sfRenderWindow_getView(Get_Window_Struct(self))));
342
248
  }
343
249
 
250
+ /* call-seq: default_view -> View
251
+ *
252
+ * Returns a copy of the window's default view.
253
+ *
254
+ * @return [View] a copy of the window's default view
255
+ */
344
256
  static VALUE Window_get_default_view(VALUE self) {
345
257
  return Get_Casting_View(sfView_copy((sfRenderWindow_getDefaultView(Get_Window_Struct(self)))));
346
258
  }
@@ -353,62 +265,149 @@ static VALUE Window_get_default_view(VALUE self) {
353
265
  #undef RT_METHOD
354
266
  #undef RT_HANDLE
355
267
 
356
- void Init_Window(VALUE rb_module) {
357
- rb_cWindow = rb_define_class_under(rb_module, "Window", rb_cObject);
268
+ /* Document-class: SFML::Window
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.
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
342
+ * @!method srgb?
343
+ * Returns +true+ if the target's framebuffer is sRGB-capable.
344
+ * @return [Boolean]
345
+ * @!method clear_stencil(value)
346
+ * Clears the stencil buffer to +value+.
347
+ * @return [self]
348
+ * @!method clear_color_and_stencil(color, stencil)
349
+ * Clears the color buffer to +color+ and the stencil buffer to +stencil+.
350
+ * @return [self]
351
+ * @!method viewport(view = nil)
352
+ * Returns the current viewport rectangle in pixels.
353
+ * @return [Rect] the current viewport in pixels; +view+ defaults to the target's current view
354
+ * @!method scissor(view = nil)
355
+ * Returns the current scissor rectangle in pixels.
356
+ * @return [Rect] the current scissor rectangle in pixels; +view+ defaults to the target's current
357
+ * view
358
+ * @!method map_pixel_to_coords(point, view = nil)
359
+ * Converts a pixel position to world coordinates, using the inverse of the view transform.
360
+ * @return [Vector2]
361
+ * @!method map_coords_to_pixel(point, view = nil)
362
+ * Converts a world position to pixel coordinates.
363
+ * @return [Vector2]
364
+ * @!method push_gl_states
365
+ * Saves the current OpenGL state.
366
+ * @return [self]
367
+ * @!method pop_gl_states
368
+ * Restores the OpenGL state saved by #push_gl_states.
369
+ * @return [self]
370
+ * @!method reset_gl_states
371
+ * Resets the OpenGL state to SFML's defaults.
372
+ * @return [self]
373
+ * @!method draw_primitives(vertices, primitive, state = nil)
374
+ * Draws raw vertex data as the given primitive type.
375
+ * @return [self]
376
+ * @!method draw_vertex_buffer_range(buffer, first, count, state = nil)
377
+ * Draws a range of vertices from a vertex buffer.
378
+ * @return [self]
379
+ */
380
+ void Init_Window(VALUE rb_mSFML) {
381
+ rb_cWindow = rb_define_class_under(rb_mSFML, "Window", Get_Klass_WindowBase());
382
+
383
+ rb_define_alloc_func(rb_cWindow, Window_alloc);
358
384
 
359
- rb_define_singleton_method(rb_cWindow, "new", Window_new, -1);
360
385
  rb_define_singleton_method(rb_cWindow, "from_handle", Window_s_from_handle, -1);
361
386
 
387
+ // methods generated from window_base.inc, overridden with sfRenderWindow_*
388
+ Window_define_methods(rb_cWindow);
389
+
362
390
  // methods
363
- rb_define_method(rb_cWindow, "initialize", Window_init, -1);
364
- rb_define_method(rb_cWindow, "is_open?", Window_is_open, 0);
365
- rb_define_method(rb_cWindow, "close!", Window_close, 0);
391
+ rb_define_method(rb_cWindow, "initialize", Window_initialize, -1);
366
392
  rb_define_method(rb_cWindow, "clear", Window_clear, -1);
367
393
  rb_define_method(rb_cWindow, "display", Window_display, 0);
368
- rb_define_method(rb_cWindow, "poll_event!", Window_poll_event, 1);
369
- rb_define_method(rb_cWindow, "wait_event!", Window_wait_event, 1);
370
394
 
371
395
  // setters
372
396
  rb_define_method(rb_cWindow, "frame_rate=", Window_set_frame_rate, 1);
373
397
  rb_define_method(rb_cWindow, "framerate_limit=", Window_set_frame_rate, 1);
374
- rb_define_method(rb_cWindow, "size=", Window_set_size, 1);
375
- rb_define_method(rb_cWindow, "minimum_size=", Window_set_minimum_size, 1);
376
- rb_define_method(rb_cWindow, "maximum_size=", Window_set_maximum_size, 1);
377
- rb_define_method(rb_cWindow, "title=", Window_set_title, 1);
378
- rb_define_method(rb_cWindow, "set_icon", Window_set_icon, 2);
379
- rb_define_method(rb_cWindow, "visible=", Window_set_visible, 1);
380
398
  rb_define_method(rb_cWindow, "active=", Window_set_active, 1);
381
399
  rb_define_method(rb_cWindow, "vertical_sync_enabled=", Window_set_vertical_sync_enabled, 1);
382
- rb_define_method(rb_cWindow, "cursor_visible=", Window_set_mouse_cursor_visible, 1);
383
- rb_define_method(rb_cWindow, "cursor_grabbed=", Window_set_mouse_cursor_grabbed, 1);
384
- rb_define_method(rb_cWindow, "mouse_cursor=", Window_set_mouse_cursor, 1);
385
- rb_define_method(rb_cWindow, "cursor=", Window_set_mouse_cursor, 1);
386
- rb_define_method(rb_cWindow, "key_repeat_enabled=", Window_set_key_repeat_enabled, 1);
387
- rb_define_method(rb_cWindow, "joystick_threshold=", Window_set_joystick_threshold, 1);
388
- rb_define_method(rb_cWindow, "position=", Window_set_position, 1);
389
400
  rb_define_method(rb_cWindow, "view=", Window_set_view, 1);
390
401
 
391
402
  // getters
392
- rb_define_method(rb_cWindow, "request_focus", Window_request_focus, 0);
393
- rb_define_method(rb_cWindow, "focus?", Window_has_focus, 0);
394
403
  rb_define_method(rb_cWindow, "draw", Window_draw, -1);
395
- rb_define_method(rb_cWindow, "position", Window_get_position, 0);
396
- rb_define_method(rb_cWindow, "size", Window_get_size, 0);
397
404
  rb_define_method(rb_cWindow, "view", Window_get_view, 0);
398
405
  rb_define_method(rb_cWindow, "default_view", Window_get_default_view, 0);
399
406
  rb_define_method(rb_cWindow, "settings", Window_get_settings, 0);
400
- rb_define_method(rb_cWindow, "native_handle", Window_get_native_handle, 0);
401
- rb_define_method(rb_cWindow, "create_vulkan_surface", Window_create_vulkan_surface, -1);
402
407
 
403
408
  Window_define_render_target_methods(rb_cWindow);
404
409
  }
405
410
 
406
- void* Get_Window_Struct(VALUE self) {
407
- sfRenderWindow* ptr;
408
- TypedData_Get_Struct(self, sfRenderWindow, &Window_data_type, ptr);
409
- return ptr;
410
- }
411
-
412
- VALUE Get_Klass_Window() {
411
+ VALUE Get_Klass_Window(void) {
413
412
  return rb_cWindow;
414
- }
413
+ }
data/ext/window/window.h CHANGED
@@ -3,10 +3,10 @@
3
3
 
4
4
  #include <ruby.h>
5
5
 
6
- void Init_Window(VALUE rb_module);
6
+ #include "window/window_base.h"
7
7
 
8
- void *Get_Window_Struct(VALUE self);
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