sfml3-rb 0.0.1 → 0.2.2

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 (191) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +342 -0
  3. data/README.md +51 -14
  4. data/TODO.md +199 -0
  5. data/ext/audio/audio_enums.c +131 -0
  6. data/ext/audio/audio_enums.h +18 -0
  7. data/ext/audio/effect_processor.c +233 -0
  8. data/ext/audio/effect_processor.h +25 -0
  9. data/ext/audio/listener.c +83 -0
  10. data/ext/audio/listener.h +8 -0
  11. data/ext/audio/music.c +174 -0
  12. data/ext/audio/music.h +14 -0
  13. data/ext/audio/sound.c +139 -0
  14. data/ext/audio/sound.h +14 -0
  15. data/ext/audio/sound_buffer.c +274 -0
  16. data/ext/audio/sound_buffer.h +18 -0
  17. data/ext/audio/sound_buffer_recorder.c +109 -0
  18. data/ext/audio/sound_buffer_recorder.h +14 -0
  19. data/ext/audio/sound_recorder.c +268 -0
  20. data/ext/audio/sound_recorder.h +14 -0
  21. data/ext/audio/sound_source.h +13 -0
  22. data/ext/audio/sound_source.inc +271 -0
  23. data/ext/audio/sound_source_cone.c +138 -0
  24. data/ext/audio/sound_source_cone.h +20 -0
  25. data/ext/audio/sound_stream.c +294 -0
  26. data/ext/audio/sound_stream.h +14 -0
  27. data/ext/{exceptions.c → core/exceptions.c} +10 -8
  28. data/ext/{ext → core}/exceptions.h +3 -3
  29. data/ext/core/foreign_thread.c +149 -0
  30. data/ext/core/foreign_thread.h +31 -0
  31. data/ext/core/macros.h +8 -0
  32. data/ext/{ext → core}/sfml.h +5 -3
  33. data/ext/core/unicode.c +46 -0
  34. data/ext/core/unicode.h +25 -0
  35. data/ext/ext.c +125 -14
  36. data/ext/extconf.rb +51 -6
  37. data/ext/graphics/blend_mode.c +261 -0
  38. data/ext/graphics/blend_mode.h +18 -0
  39. data/ext/graphics/circle.c +319 -0
  40. data/ext/{ext/klass/drawable → graphics}/circle.h +3 -3
  41. data/ext/graphics/color.c +318 -0
  42. data/ext/graphics/color.h +37 -0
  43. data/ext/{drawable.c → graphics/drawable.c} +11 -11
  44. data/ext/graphics/drawable.h +10 -0
  45. data/ext/graphics/enums.c +123 -0
  46. data/ext/graphics/enums.h +20 -0
  47. data/ext/graphics/font.c +148 -0
  48. data/ext/graphics/font.h +14 -0
  49. data/ext/graphics/glyph.c +60 -0
  50. data/ext/graphics/glyph.h +14 -0
  51. data/ext/graphics/image.c +205 -0
  52. data/ext/graphics/image.h +16 -0
  53. data/ext/graphics/polygon.c +300 -0
  54. data/ext/graphics/polygon.h +10 -0
  55. data/ext/graphics/rect.c +287 -0
  56. data/ext/graphics/rect.h +30 -0
  57. data/ext/graphics/rectangle.c +302 -0
  58. data/ext/graphics/rectangle.h +10 -0
  59. data/ext/graphics/render_state.c +204 -0
  60. data/ext/graphics/render_state.h +18 -0
  61. data/ext/graphics/render_target.inc +181 -0
  62. data/ext/graphics/render_texture.c +182 -0
  63. data/ext/graphics/render_texture.h +14 -0
  64. data/ext/graphics/shader.c +540 -0
  65. data/ext/graphics/shader.h +14 -0
  66. data/ext/graphics/shape.c +311 -0
  67. data/ext/graphics/shape.h +10 -0
  68. data/ext/graphics/sprite.c +249 -0
  69. data/ext/graphics/sprite.h +10 -0
  70. data/ext/graphics/stencil_mode.c +211 -0
  71. data/ext/graphics/stencil_mode.h +18 -0
  72. data/ext/graphics/target.c +133 -0
  73. data/ext/graphics/target.h +40 -0
  74. data/ext/graphics/text.c +344 -0
  75. data/ext/graphics/text.h +10 -0
  76. data/ext/graphics/texture.c +379 -0
  77. data/ext/graphics/texture.h +16 -0
  78. data/ext/graphics/transform.c +372 -0
  79. data/ext/graphics/transform.h +35 -0
  80. data/ext/{transformable.c → graphics/transformable.c} +168 -144
  81. data/ext/{ext/klass → graphics}/transformable.h +3 -3
  82. data/ext/graphics/vertex.c +179 -0
  83. data/ext/graphics/vertex.h +23 -0
  84. data/ext/graphics/vertex_array.c +127 -0
  85. data/ext/graphics/vertex_array.h +10 -0
  86. data/ext/graphics/vertex_buffer.c +211 -0
  87. data/ext/graphics/vertex_buffer.h +14 -0
  88. data/ext/{view.c → graphics/view.c} +168 -169
  89. data/ext/{ext/klass → graphics}/view.h +3 -3
  90. data/ext/network/ftp.c +405 -0
  91. data/ext/network/ftp.h +20 -0
  92. data/ext/network/http.c +243 -0
  93. data/ext/network/http.h +18 -0
  94. data/ext/network/ip_address.c +164 -0
  95. data/ext/network/ip_address.h +20 -0
  96. data/ext/network/network_enums.c +298 -0
  97. data/ext/network/network_enums.h +26 -0
  98. data/ext/network/packet.c +189 -0
  99. data/ext/network/packet.h +14 -0
  100. data/ext/network/socket_selector.c +142 -0
  101. data/ext/network/socket_selector.h +14 -0
  102. data/ext/network/tcp_listener.c +115 -0
  103. data/ext/network/tcp_listener.h +14 -0
  104. data/ext/network/tcp_socket.c +199 -0
  105. data/ext/network/tcp_socket.h +17 -0
  106. data/ext/network/udp_socket.c +190 -0
  107. data/ext/network/udp_socket.h +14 -0
  108. data/ext/ports.rb +97 -21
  109. data/ext/system/buffer.c +77 -0
  110. data/ext/system/buffer.h +14 -0
  111. data/ext/system/clock.c +100 -0
  112. data/ext/{ext/klass → system}/clock.h +3 -3
  113. data/ext/system/input_stream.c +229 -0
  114. data/ext/system/input_stream.h +23 -0
  115. data/ext/system/sleep.c +16 -0
  116. data/ext/system/sleep.h +8 -0
  117. data/ext/system/time.c +218 -0
  118. data/ext/system/time.h +18 -0
  119. data/ext/system/vec2.c +251 -0
  120. data/ext/system/vec2.h +55 -0
  121. data/ext/system/vec3.c +219 -0
  122. data/ext/system/vec3.h +18 -0
  123. data/ext/window/clipboard.c +89 -0
  124. data/ext/window/clipboard.h +8 -0
  125. data/ext/window/context.c +70 -0
  126. data/ext/window/context.h +8 -0
  127. data/ext/window/context_settings.c +220 -0
  128. data/ext/window/context_settings.h +18 -0
  129. data/ext/window/cursor.c +56 -0
  130. data/ext/window/cursor.h +14 -0
  131. data/ext/window/event.c +216 -0
  132. data/ext/window/event.h +14 -0
  133. data/ext/{event_name.c → window/event_name.c} +2 -2
  134. data/ext/window/event_name.h +8 -0
  135. data/ext/window/input_enums.c +261 -0
  136. data/ext/window/input_enums.h +36 -0
  137. data/ext/window/joystick.c +60 -0
  138. data/ext/window/joystick.h +8 -0
  139. data/ext/{keyboard.c → window/keyboard.c} +74 -2
  140. data/ext/window/keyboard.h +12 -0
  141. data/ext/window/mouse.c +70 -0
  142. data/ext/window/mouse.h +8 -0
  143. data/ext/window/sensor.c +30 -0
  144. data/ext/window/sensor.h +8 -0
  145. data/ext/window/touch.c +49 -0
  146. data/ext/window/touch.h +8 -0
  147. data/ext/window/video_mode.c +133 -0
  148. data/ext/window/video_mode.h +14 -0
  149. data/ext/window/vulkan.c +44 -0
  150. data/ext/window/vulkan.h +8 -0
  151. data/ext/window/window.c +414 -0
  152. data/ext/{ext/klass → window}/window.h +3 -3
  153. data/lib/sfml/version.rb +4 -2
  154. data/lib/sfml.rb +2 -0
  155. metadata +163 -56
  156. data/ext/circle.c +0 -198
  157. data/ext/clock.c +0 -65
  158. data/ext/color.c +0 -43
  159. data/ext/event.c +0 -148
  160. data/ext/ext/klass/color.h +0 -26
  161. data/ext/ext/klass/drawable/image.h +0 -4
  162. data/ext/ext/klass/drawable/polygon.h +0 -4
  163. data/ext/ext/klass/drawable/rectangle.h +0 -4
  164. data/ext/ext/klass/drawable/sprite.h +0 -4
  165. data/ext/ext/klass/drawable/texture.h +0 -4
  166. data/ext/ext/klass/event/event_name.h +0 -8
  167. data/ext/ext/klass/event.h +0 -12
  168. data/ext/ext/klass/keyboard.h +0 -8
  169. data/ext/ext/klass/render_state.h +0 -16
  170. data/ext/ext/klass/target.h +0 -18
  171. data/ext/ext/klass/transform.h +0 -17
  172. data/ext/ext/klass/video_mode.h +0 -12
  173. data/ext/ext/module/drawable/drawable.h +0 -10
  174. data/ext/ext/module/transform.h +0 -18
  175. data/ext/ext/module.h +0 -10
  176. data/ext/ext/rect.h +0 -16
  177. data/ext/ext/style_name.h +0 -11
  178. data/ext/ext/vec2.h +0 -38
  179. data/ext/image.c +0 -5
  180. data/ext/polygon.c +0 -5
  181. data/ext/rect.c +0 -26
  182. data/ext/rectangle.c +0 -5
  183. data/ext/render_state.c +0 -109
  184. data/ext/sprite.c +0 -5
  185. data/ext/style_name.c +0 -15
  186. data/ext/target.c +0 -106
  187. data/ext/texture.c +0 -5
  188. data/ext/transform.c +0 -107
  189. data/ext/vec2.c +0 -42
  190. data/ext/video_mode.c +0 -78
  191. data/ext/window.c +0 -274
@@ -0,0 +1,133 @@
1
+ #include "window/video_mode.h"
2
+
3
+ #include <ruby.h>
4
+ #include <stdlib.h>
5
+
6
+ #include "system/vec2.h"
7
+ #include "core/sfml.h"
8
+ #include "core/macros.h"
9
+
10
+ static VALUE rb_cMode;
11
+
12
+ static sfVideoMode *VideoMode_alloc(unsigned width, unsigned height, unsigned bits, int *created) {
13
+ sfVideoMode *mode = malloc(sizeof(sfVideoMode));
14
+
15
+ if (created != NULL) {
16
+ *created = 1;
17
+ }
18
+
19
+ mode->size.x = width;
20
+ mode->size.y = height;
21
+ mode->bitsPerPixel = bits;
22
+
23
+ return mode;
24
+ }
25
+
26
+ static void VideoMode_free(void *ptr) {
27
+ free(ptr);
28
+ }
29
+
30
+ static const rb_data_type_t VideoMode_data_type = {
31
+ .wrap_struct_name = "SFML::VideoMode",
32
+ .function = {.dmark = NULL, .dfree = VideoMode_free, .dsize = NULL},
33
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
34
+ };
35
+
36
+ static VALUE VideoMode_from_c(sfVideoMode mode) {
37
+ sfVideoMode *ptr = VideoMode_alloc(mode.size.x, mode.size.y, mode.bitsPerPixel, NULL);
38
+ VALUE self = TypedData_Wrap_Struct(rb_cMode, &VideoMode_data_type, ptr);
39
+
40
+ rb_iv_set(self, "@width", UINT2NUM(mode.size.x));
41
+ rb_iv_set(self, "@height", UINT2NUM(mode.size.y));
42
+ rb_iv_set(self, "@bits", UINT2NUM(mode.bitsPerPixel));
43
+
44
+ return self;
45
+ }
46
+
47
+ static VALUE VideoMode_new(VALUE klass, VALUE rb_width, VALUE rb_height, VALUE rb_bits) {
48
+ VALUE self;
49
+ VALUE argv[] = {rb_width, rb_height, rb_bits};
50
+
51
+ self = VideoMode_from_c((sfVideoMode) {
52
+ {(unsigned) NUM2UINT(rb_width), (unsigned) NUM2UINT(rb_height)},
53
+ (unsigned) NUM2UINT(rb_bits)
54
+ });
55
+
56
+ rb_obj_call_init(self, 3, argv);
57
+
58
+ return self;
59
+ }
60
+
61
+ static VALUE VideoMode_init(VALUE self, VALUE rb_width, VALUE rb_height, VALUE rb_bits) {
62
+ rb_iv_set(self, "@width", rb_width);
63
+ rb_iv_set(self, "@height", rb_height);
64
+ rb_iv_set(self, "@bits", rb_bits);
65
+
66
+ return self;
67
+ }
68
+
69
+ static VALUE VideoMode_desktop_mode(VALUE klass) {
70
+ return VideoMode_from_c(sfVideoMode_getDesktopMode());
71
+ }
72
+
73
+ static VALUE VideoMode_fullscreen_modes(VALUE klass) {
74
+ size_t count = 0;
75
+ const sfVideoMode *modes = sfVideoMode_getFullscreenModes(&count);
76
+ VALUE array = rb_ary_new_capa((long) count);
77
+
78
+ for (size_t i = 0; i < count; i++) {
79
+ rb_ary_push(array, VideoMode_from_c(modes[i]));
80
+ }
81
+
82
+ return array;
83
+ }
84
+
85
+ static VALUE VideoMode_is_available(VALUE self) {
86
+ return BOOL2RB(sfVideoMode_isValid(*Get_Mode_Struct(self)));
87
+ }
88
+
89
+ static VALUE VideoMode_get_size(VALUE self) {
90
+ sfVideoMode *mode = Get_Mode_Struct(self);
91
+
92
+ return vec2f_to_rb((sfVector2f) {(float) mode->size.x, (float) mode->size.y});
93
+ }
94
+
95
+ static VALUE VideoMode_eql(VALUE self, VALUE rb_other) {
96
+ sfVideoMode a = *Get_Mode_Struct(self);
97
+ sfVideoMode b;
98
+
99
+ if (!rb_obj_is_kind_of(rb_other, rb_cMode)) {
100
+ return Qfalse;
101
+ }
102
+
103
+ b = *Get_Mode_Struct(rb_other);
104
+
105
+ return BOOL2RB(a.size.x == b.size.x && a.size.y == b.size.y && a.bitsPerPixel == b.bitsPerPixel);
106
+ }
107
+
108
+ void Init_VideoMode(VALUE rb_module) {
109
+ rb_cMode = rb_define_class_under(rb_module, "VideoMode", rb_cObject);
110
+
111
+ rb_define_singleton_method(rb_cMode, "new", VideoMode_new, 3);
112
+ rb_define_singleton_method(rb_cMode, "desktop_mode", VideoMode_desktop_mode, 0);
113
+ rb_define_singleton_method(rb_cMode, "fullscreen_modes", VideoMode_fullscreen_modes, 0);
114
+
115
+ rb_define_method(rb_cMode, "initialize", VideoMode_init, 3);
116
+ rb_define_method(rb_cMode, "available?", VideoMode_is_available, 0);
117
+ rb_define_method(rb_cMode, "valid?", VideoMode_is_available, 0);
118
+ rb_define_method(rb_cMode, "size", VideoMode_get_size, 0);
119
+ rb_define_method(rb_cMode, "==", VideoMode_eql, 1);
120
+ rb_define_attr(rb_cMode, "width", 1, 0);
121
+ rb_define_attr(rb_cMode, "height", 1, 0);
122
+ rb_define_attr(rb_cMode, "bits", 1, 0);
123
+ }
124
+
125
+ sfVideoMode *Get_Mode_Struct(VALUE self) {
126
+ sfVideoMode *ptr;
127
+ TypedData_Get_Struct(self, sfVideoMode, &VideoMode_data_type, ptr);
128
+ return ptr;
129
+ }
130
+
131
+ VALUE Get_Klass_Mode() {
132
+ return rb_cMode;
133
+ }
@@ -0,0 +1,14 @@
1
+ #ifndef SFML_RB_WINDOW_VIDEO_MODE_H
2
+ #define SFML_RB_WINDOW_VIDEO_MODE_H
3
+
4
+ #include <ruby.h>
5
+
6
+ #include "core/sfml.h"
7
+
8
+ void Init_VideoMode(VALUE rb_module);
9
+
10
+ sfVideoMode *Get_Mode_Struct(VALUE self);
11
+
12
+ VALUE Get_Klass_Mode();
13
+
14
+ #endif //SFML_RB_WINDOW_VIDEO_MODE_H
@@ -0,0 +1,44 @@
1
+ #include "window/vulkan.h"
2
+
3
+ #include <ruby.h>
4
+
5
+ #include "core/macros.h"
6
+ #include "core/sfml.h"
7
+
8
+ static VALUE Vulkan_is_available(int argc, VALUE *argv, VALUE module) {
9
+ VALUE rb_require_graphics;
10
+ bool require_graphics = false;
11
+
12
+ rb_scan_args(argc, argv, "01", &rb_require_graphics);
13
+
14
+ if (!NIL_P(rb_require_graphics)) {
15
+ require_graphics = RTEST(rb_require_graphics);
16
+ }
17
+
18
+ return BOOL2RB(sfVulkan_isAvailable(require_graphics));
19
+ }
20
+
21
+ static VALUE Vulkan_get_function(VALUE module, VALUE rb_name) {
22
+ return ULL2NUM((unsigned long long) (uintptr_t) sfVulkan_getFunction(StringValueCStr(rb_name)));
23
+ }
24
+
25
+ static VALUE Vulkan_get_graphics_required_instance_extensions(VALUE module) {
26
+ size_t count = 0;
27
+ const char *const *extensions = sfVulkan_getGraphicsRequiredInstanceExtensions(&count);
28
+ VALUE array = rb_ary_new_capa((long) count);
29
+
30
+ for (size_t i = 0; i < count; i++) {
31
+ rb_ary_push(array, rb_str_new_cstr(extensions[i]));
32
+ }
33
+
34
+ return array;
35
+ }
36
+
37
+ void Init_Vulkan(VALUE rb_module) {
38
+ VALUE rb_mVulkan = rb_define_module_under(rb_module, "Vulkan");
39
+
40
+ rb_define_module_function(rb_mVulkan, "available?", Vulkan_is_available, -1);
41
+ rb_define_module_function(rb_mVulkan, "function", Vulkan_get_function, 1);
42
+ rb_define_module_function(rb_mVulkan, "graphics_required_instance_extensions",
43
+ Vulkan_get_graphics_required_instance_extensions, 0);
44
+ }
@@ -0,0 +1,8 @@
1
+ #ifndef SFML_RB_WINDOW_VULKAN_H
2
+ #define SFML_RB_WINDOW_VULKAN_H
3
+
4
+ #include <ruby.h>
5
+
6
+ void Init_Vulkan(VALUE rb_module);
7
+
8
+ #endif //SFML_RB_WINDOW_VULKAN_H
@@ -0,0 +1,414 @@
1
+ #include "window/window.h"
2
+
3
+ #include <stdio.h>
4
+
5
+ #include "graphics/render_state.h"
6
+ #include "graphics/target.h"
7
+ #include "graphics/view.h"
8
+ #include "window/video_mode.h"
9
+ #include "window/event.h"
10
+ #include "window/input_enums.h"
11
+ #include "window/context_settings.h"
12
+ #include "window/cursor.h"
13
+ #include "graphics/color.h"
14
+ #include "core/exceptions.h"
15
+ #include "system/vec2.h"
16
+ #include "core/macros.h"
17
+ #include "core/unicode.h"
18
+ #include "core/sfml.h"
19
+
20
+ static VALUE rb_cWindow;
21
+
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;
38
+ sfWindowState state = sfWindowed;
39
+ sfContextSettings settings;
40
+ const sfContextSettings* settings_ptr = NULL;
41
+ uint32_t style = sfDefaultStyle;
42
+ sfRenderWindow* window;
43
+
44
+ rb_scan_args(argc, argv, "23", &rb_video_mode, &rb_title, &rb_style, &rb_state, &rb_settings);
45
+
46
+ if (!rb_obj_is_kind_of(rb_video_mode, Get_Klass_Mode())) {
47
+ raise_invalid_argument_class(Get_Klass_Mode());
48
+ }
49
+
50
+ if (!NIL_P(rb_style)) {
51
+ style = window_style_from_rb(rb_style);
52
+ }
53
+
54
+ if (!NIL_P(rb_state)) {
55
+ state = window_state_from_rb(rb_state);
56
+ }
57
+
58
+ if (!NIL_P(rb_settings)) {
59
+ settings = context_settings_from_rb(rb_settings);
60
+ settings_ptr = &settings;
61
+ }
62
+
63
+ 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);
66
+ RB_GC_GUARD(title_buffer);
67
+
68
+ if (window == NULL) {
69
+ rb_raise(rb_eRuntimeError, "failed to create window");
70
+ }
71
+
72
+ self = TypedData_Wrap_Struct(klass, &Window_data_type, window);
73
+
74
+ rb_obj_call_init(self, argc, argv);
75
+
76
+ return self;
77
+ }
78
+
79
+ /* Adopts an existing OS window by its native handle -- the Integer that
80
+ Window#native_handle returns, or one obtained from a GUI toolkit. The window
81
+ is not owned by the toolkit afterwards: destroying it stays the toolkit's
82
+ job, and closing the Ruby object only tears down the render context. */
83
+ static VALUE Window_s_from_handle(int argc, VALUE* argv, VALUE klass) {
84
+ VALUE self, rb_handle, rb_settings;
85
+ sfContextSettings settings;
86
+ const sfContextSettings* settings_ptr = NULL;
87
+ sfRenderWindow* window;
88
+
89
+ rb_scan_args(argc, argv, "11", &rb_handle, &rb_settings);
90
+
91
+ if (!NIL_P(rb_settings)) {
92
+ settings = context_settings_from_rb(rb_settings);
93
+ settings_ptr = &settings;
94
+ }
95
+
96
+ window = sfRenderWindow_createFromHandle((sfWindowHandle)(uintptr_t)NUM2ULL(rb_handle),
97
+ settings_ptr);
98
+
99
+ if (window == NULL) {
100
+ rb_raise(rb_eRuntimeError, "failed to create window from handle");
101
+ }
102
+
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;
121
+ }
122
+
123
+ static VALUE Window_clear(int argc, VALUE* argv, VALUE self) {
124
+ sfColor color = sfBlack;
125
+
126
+ if (argc > 1) {
127
+ raise_invalid_arguments_excepted(1, argc);
128
+ }
129
+
130
+ if (argc == 1) {
131
+ color_check(argv[0]);
132
+ color = color_new_from_rb(argv[0]);
133
+ }
134
+
135
+ sfRenderWindow_clear(Get_Window_Struct(self), color);
136
+
137
+ return self;
138
+ }
139
+
140
+ static VALUE Window_display(VALUE self) {
141
+ sfRenderWindow_display(Get_Window_Struct(self));
142
+ return self;
143
+ }
144
+
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
+
171
+ static VALUE Window_set_frame_rate(VALUE self, VALUE rb_limit) {
172
+ sfRenderWindow_setFramerateLimit(Get_Window_Struct(self), NUM2INT(rb_limit));
173
+ return self;
174
+ }
175
+
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
+
201
+ static VALUE Window_set_active(VALUE self, VALUE rb_active) {
202
+ return BOOL2RB(sfRenderWindow_setActive(Get_Window_Struct(self), RTEST(rb_active)));
203
+ }
204
+
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
+
266
+ static VALUE Window_set_vertical_sync_enabled(VALUE self, VALUE rb_enable) {
267
+ sfRenderWindow_setVerticalSyncEnabled(Get_Window_Struct(self), RTEST(rb_enable));
268
+ return self;
269
+ }
270
+
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)));
313
+ }
314
+
315
+ static VALUE Window_draw(int argc, VALUE* argv, VALUE self) {
316
+ VALUE rb_drawable, rb_state;
317
+
318
+ if (argc == 0 || argc > 2) {
319
+ raise_invalid_arguments_excepted(-1, argc);
320
+ }
321
+
322
+ rb_drawable = argv[0];
323
+ rb_state = (argc == 2) ? argv[1] : Get_New_RenderState();
324
+
325
+ rb_funcall(Get_New_Target(self), rb_intern("draw"), 2, rb_drawable, rb_state);
326
+
327
+ return self;
328
+ }
329
+
330
+ static VALUE Window_set_view(VALUE self, VALUE rb_view) {
331
+ if (!rb_obj_is_kind_of(rb_view, Get_Klass_View())) {
332
+ rb_raise(rb_eArgError, "invalid object, expected a View object");
333
+ }
334
+
335
+ sfRenderWindow_setView(Get_Window_Struct(self), Get_View_Struct(rb_view));
336
+
337
+ return self;
338
+ }
339
+
340
+ static VALUE Window_get_view(VALUE self) {
341
+ return Get_Casting_View(sfView_copy(sfRenderWindow_getView(Get_Window_Struct(self))));
342
+ }
343
+
344
+ static VALUE Window_get_default_view(VALUE self) {
345
+ return Get_Casting_View(sfView_copy((sfRenderWindow_getDefaultView(Get_Window_Struct(self)))));
346
+ }
347
+
348
+ #define RT_FN(name) sfRenderWindow_##name
349
+ #define RT_METHOD(name) Window_##name
350
+ #define RT_HANDLE(self) Get_Window_Struct(self)
351
+ #include "graphics/render_target.inc"
352
+ #undef RT_FN
353
+ #undef RT_METHOD
354
+ #undef RT_HANDLE
355
+
356
+ void Init_Window(VALUE rb_module) {
357
+ rb_cWindow = rb_define_class_under(rb_module, "Window", rb_cObject);
358
+
359
+ rb_define_singleton_method(rb_cWindow, "new", Window_new, -1);
360
+ rb_define_singleton_method(rb_cWindow, "from_handle", Window_s_from_handle, -1);
361
+
362
+ // 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);
366
+ rb_define_method(rb_cWindow, "clear", Window_clear, -1);
367
+ 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
+
371
+ // setters
372
+ rb_define_method(rb_cWindow, "frame_rate=", Window_set_frame_rate, 1);
373
+ 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
+ rb_define_method(rb_cWindow, "active=", Window_set_active, 1);
381
+ 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
+ rb_define_method(rb_cWindow, "view=", Window_set_view, 1);
390
+
391
+ // 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
+ 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
+ rb_define_method(rb_cWindow, "view", Window_get_view, 0);
398
+ rb_define_method(rb_cWindow, "default_view", Window_get_default_view, 0);
399
+ 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
+
403
+ Window_define_render_target_methods(rb_cWindow);
404
+ }
405
+
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() {
413
+ return rb_cWindow;
414
+ }
@@ -1,5 +1,5 @@
1
- #ifndef SFML_RB_WINDOW_H
2
- #define SFML_RB_WINDOW_H
1
+ #ifndef SFML_RB_WINDOW_WINDOW_H
2
+ #define SFML_RB_WINDOW_WINDOW_H
3
3
 
4
4
  #include <ruby.h>
5
5
 
@@ -9,4 +9,4 @@ void *Get_Window_Struct(VALUE self);
9
9
 
10
10
  VALUE Get_Klass_Window();
11
11
 
12
- #endif //SFML_RB_WINDOW_H
12
+ #endif //SFML_RB_WINDOW_WINDOW_H
data/lib/sfml/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SFML
2
- VERSION = '0.0.1'.freeze
3
- end
4
+ VERSION = '0.2.2'
5
+ end
data/lib/sfml.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sfml/version'
2
4
 
3
5
  begin