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,319 @@
1
+ #include "graphics/circle.h"
2
+
3
+ #include <ruby.h>
4
+ #include <stdlib.h>
5
+
6
+ #include "graphics/drawable.h"
7
+ #include "graphics/target.h"
8
+ #include "graphics/render_state.h"
9
+ #include "core/exceptions.h"
10
+ #include "graphics/transform.h"
11
+ #include "graphics/transformable.h"
12
+ #include "graphics/color.h"
13
+ #include "graphics/rect.h"
14
+ #include "graphics/texture.h"
15
+ #include "system/vec2.h"
16
+ #include "core/macros.h"
17
+ #include "core/sfml.h"
18
+
19
+ typedef struct {
20
+ sfCircleShape* shape;
21
+ VALUE rb_texture;
22
+ } Circle;
23
+
24
+ static VALUE rb_cCircle;
25
+
26
+ static void Circle_mark(void* ptr) {
27
+ rb_gc_mark(((Circle*)ptr)->rb_texture);
28
+ }
29
+
30
+ static void Circle_free(void* ptr) {
31
+ sfCircleShape_destroy(((Circle*)ptr)->shape);
32
+ free(ptr);
33
+ }
34
+
35
+ static const rb_data_type_t Circle_data_type = {
36
+ .wrap_struct_name = "SFML::Circle",
37
+ .function = {.dmark = Circle_mark, .dfree = Circle_free, .dsize = NULL},
38
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY};
39
+
40
+ static Circle* Get_Circle(VALUE self) {
41
+ Circle* ptr;
42
+ TypedData_Get_Struct(self, Circle, &Circle_data_type, ptr);
43
+ return ptr;
44
+ }
45
+
46
+ static sfCircleShape* Get_Circle_Shape(VALUE self) {
47
+ return Get_Circle(self)->shape;
48
+ }
49
+
50
+ static VALUE Circle_wrap(VALUE klass, sfCircleShape* shape) {
51
+ Circle* ptr;
52
+
53
+ if (shape == NULL) {
54
+ rb_raise(rb_eRuntimeError, "failed to create circle shape");
55
+ }
56
+
57
+ ptr = malloc(sizeof(Circle));
58
+ ptr->shape = shape;
59
+ ptr->rb_texture = Qnil;
60
+
61
+ return TypedData_Wrap_Struct(klass, &Circle_data_type, ptr);
62
+ }
63
+
64
+ static VALUE Circle_new(int argc, VALUE* argv, VALUE klass) {
65
+ VALUE rb_radius;
66
+ sfCircleShape* shape;
67
+
68
+ rb_scan_args(argc, argv, "01", &rb_radius);
69
+
70
+ shape = sfCircleShape_create();
71
+
72
+ if (!NIL_P(rb_radius)) {
73
+ sfCircleShape_setRadius(shape, NUM2DBL(rb_radius));
74
+ }
75
+
76
+ return Circle_wrap(klass, shape);
77
+ }
78
+
79
+ static VALUE Circle_copy(VALUE self) {
80
+ Circle* ptr = Get_Circle(self);
81
+ VALUE copy = Circle_wrap(Get_Klass_Circle(), sfCircleShape_copy(ptr->shape));
82
+
83
+ if (!NIL_P(ptr->rb_texture)) {
84
+ Circle* copy_ptr = Get_Circle(copy);
85
+
86
+ copy_ptr->rb_texture = ptr->rb_texture;
87
+ sfCircleShape_setTexture(copy_ptr->shape, Get_Texture_Struct(ptr->rb_texture), false);
88
+ }
89
+
90
+ return copy;
91
+ }
92
+
93
+ static VALUE Circle_set_fill_color(VALUE self, VALUE rb_color) {
94
+ sfCircleShape_setFillColor(Get_Circle_Shape(self), color_from_rb(rb_color));
95
+ return rb_color;
96
+ }
97
+
98
+ static VALUE Circle_get_fill_color(VALUE self) {
99
+ return color_to_rb(sfCircleShape_getFillColor(Get_Circle_Shape(self)));
100
+ }
101
+
102
+ static VALUE Circle_set_outline_color(VALUE self, VALUE rb_color) {
103
+ sfCircleShape_setOutlineColor(Get_Circle_Shape(self), color_from_rb(rb_color));
104
+ return rb_color;
105
+ }
106
+
107
+ static VALUE Circle_get_outline_color(VALUE self) {
108
+ return color_to_rb(sfCircleShape_getOutlineColor(Get_Circle_Shape(self)));
109
+ }
110
+
111
+ static VALUE Circle_set_outline_thickness(VALUE self, VALUE rb_thickness) {
112
+ sfCircleShape_setOutlineThickness(Get_Circle_Shape(self), NUM2DBL(rb_thickness));
113
+ return rb_thickness;
114
+ }
115
+
116
+ static VALUE Circle_get_outline_thickness(VALUE self) {
117
+ return DBL2NUM(sfCircleShape_getOutlineThickness(Get_Circle_Shape(self)));
118
+ }
119
+
120
+ static VALUE Circle_set_radius(VALUE self, VALUE rb_radius) {
121
+ sfCircleShape_setRadius(Get_Circle_Shape(self), NUM2DBL(rb_radius));
122
+ return rb_radius;
123
+ }
124
+
125
+ static VALUE Circle_set_position(VALUE self, VALUE rb_position) {
126
+ sfCircleShape_setPosition(Get_Circle_Shape(self), vec2f_from_rb(rb_position));
127
+ return rb_position;
128
+ }
129
+
130
+ static VALUE Circle_set_rotation(VALUE self, VALUE rb_angle) {
131
+ sfCircleShape_setRotation(Get_Circle_Shape(self), NUM2DBL(rb_angle));
132
+ return rb_angle;
133
+ }
134
+
135
+ static VALUE Circle_set_origin(VALUE self, VALUE rb_origin) {
136
+ sfCircleShape_setOrigin(Get_Circle_Shape(self), vec2f_from_rb(rb_origin));
137
+ return rb_origin;
138
+ }
139
+
140
+ static VALUE Circle_set_scale(VALUE self, VALUE rb_scale) {
141
+ sfCircleShape_setScale(Get_Circle_Shape(self), vec2f_from_rb(rb_scale));
142
+ return rb_scale;
143
+ }
144
+
145
+ static VALUE Circle_get_radius(VALUE self) {
146
+ return DBL2NUM(sfCircleShape_getRadius(Get_Circle_Shape(self)));
147
+ }
148
+
149
+ static VALUE Circle_get_position(VALUE self) {
150
+ return vec2f_to_rb(sfCircleShape_getPosition(Get_Circle_Shape(self)));
151
+ }
152
+
153
+ static VALUE Circle_get_rotation(VALUE self) {
154
+ return DBL2NUM(sfCircleShape_getRotation(Get_Circle_Shape(self)));
155
+ }
156
+
157
+ static VALUE Circle_get_scale(VALUE self) {
158
+ return vec2f_to_rb(sfCircleShape_getScale(Get_Circle_Shape(self)));
159
+ }
160
+
161
+ static VALUE Circle_get_origin(VALUE self) {
162
+ return vec2f_to_rb(sfCircleShape_getOrigin(Get_Circle_Shape(self)));
163
+ }
164
+
165
+ static VALUE Circle_move(VALUE self, VALUE rb_move) {
166
+ sfCircleShape_move(Get_Circle_Shape(self), vec2f_from_rb(rb_move));
167
+ return self;
168
+ }
169
+
170
+ static VALUE Circle_rotate(VALUE self, VALUE rb_angle) {
171
+ sfCircleShape_rotate(Get_Circle_Shape(self), NUM2DBL(rb_angle));
172
+ return self;
173
+ }
174
+
175
+ static VALUE Circle_scale(VALUE self, VALUE rb_scale) {
176
+ sfCircleShape_scale(Get_Circle_Shape(self), vec2f_from_rb(rb_scale));
177
+ return self;
178
+ }
179
+
180
+ static VALUE Circle_get_transform(VALUE self) {
181
+ return Transform_MatrixToArray(sfCircleShape_getTransform(Get_Circle_Shape(self)).matrix);
182
+ }
183
+
184
+ static VALUE Circle_get_inverse_transform(VALUE self) {
185
+ return Transform_MatrixToArray(
186
+ sfCircleShape_getInverseTransform(Get_Circle_Shape(self)).matrix);
187
+ }
188
+
189
+ static VALUE Circle_set_texture(VALUE self, VALUE rb_texture) {
190
+ Circle* ptr = Get_Circle(self);
191
+
192
+ if (NIL_P(rb_texture)) {
193
+ ptr->rb_texture = Qnil;
194
+ sfCircleShape_setTexture(ptr->shape, NULL, false);
195
+ return rb_texture;
196
+ }
197
+
198
+ if (!rb_obj_is_kind_of(rb_texture, Get_Klass_Texture())) {
199
+ raise_invalid_argument_class(Get_Klass_Texture());
200
+ }
201
+
202
+ ptr->rb_texture = rb_texture;
203
+ sfCircleShape_setTexture(ptr->shape, Get_Texture_Struct(rb_texture), false);
204
+
205
+ return rb_texture;
206
+ }
207
+
208
+ static VALUE Circle_get_texture(VALUE self) {
209
+ return Get_Circle(self)->rb_texture;
210
+ }
211
+
212
+ static VALUE Circle_get_texture_rect(VALUE self) {
213
+ return int_rect_to_rb(sfCircleShape_getTextureRect(Get_Circle_Shape(self)));
214
+ }
215
+
216
+ static VALUE Circle_set_texture_rect(VALUE self, VALUE rb_rect) {
217
+ sfCircleShape_setTextureRect(Get_Circle_Shape(self), int_rect_from_rb(rb_rect));
218
+ return rb_rect;
219
+ }
220
+
221
+ static VALUE Circle_get_point_count(VALUE self) {
222
+ return SIZET2NUM(sfCircleShape_getPointCount(Get_Circle_Shape(self)));
223
+ }
224
+
225
+ /* The number of segments the circle is approximated with -- more for a smoother
226
+ outline, fewer for a polygon (3 gives a triangle). */
227
+ static VALUE Circle_set_point_count(VALUE self, VALUE rb_count) {
228
+ sfCircleShape_setPointCount(Get_Circle_Shape(self), NUM2SIZET(rb_count));
229
+
230
+ return self;
231
+ }
232
+
233
+ static VALUE Circle_get_point(VALUE self, VALUE rb_index) {
234
+ return vec2f_to_rb(sfCircleShape_getPoint(Get_Circle_Shape(self), (size_t)NUM2SIZET(rb_index)));
235
+ }
236
+
237
+ static VALUE Circle_get_geometric_center(VALUE self) {
238
+ return vec2f_to_rb(sfCircleShape_getGeometricCenter(Get_Circle_Shape(self)));
239
+ }
240
+
241
+ static VALUE Circle_get_local_bounds(VALUE self) {
242
+ return rect_to_rb(sfCircleShape_getLocalBounds(Get_Circle_Shape(self)));
243
+ }
244
+
245
+ static VALUE Circle_get_global_bounds(VALUE self) {
246
+ return rect_to_rb(sfCircleShape_getGlobalBounds(Get_Circle_Shape(self)));
247
+ }
248
+
249
+ static VALUE Circle_draw(VALUE self, VALUE rb_target, VALUE rb_state) {
250
+ if (!rb_obj_is_kind_of(rb_target, Get_Klass_Target())) {
251
+ raise_invalid_argument_class(Get_Klass_Target());
252
+ }
253
+
254
+ if (!rb_obj_is_kind_of(rb_state, Get_Klass_RenderState())) {
255
+ raise_invalid_argument_class(Get_Klass_RenderState());
256
+ }
257
+
258
+ TARGET_DRAW(Get_Target_Struct(rb_target), sfRenderWindow_drawCircleShape,
259
+ sfRenderTexture_drawCircleShape, Get_Circle_Shape(self),
260
+ Get_RenderState_Struct(rb_state));
261
+
262
+ return Qnil;
263
+ }
264
+
265
+ void Init_Circle(VALUE rb_module) {
266
+ rb_cCircle = rb_define_class_under(rb_module, "Circle", rb_cObject);
267
+
268
+ rb_include_module(rb_cCircle, Get_Module_Drawable());
269
+
270
+ rb_define_singleton_method(rb_cCircle, "new", Circle_new, -1);
271
+
272
+ // methods
273
+ rb_define_method(rb_cCircle, "copy", Circle_copy, 0);
274
+ rb_define_method(rb_cCircle, "move", Circle_move, 1);
275
+ rb_define_method(rb_cCircle, "rotate", Circle_rotate, 1);
276
+ rb_define_method(rb_cCircle, "scale!", Circle_scale, 1);
277
+ rb_define_method(rb_cCircle, "draw", Circle_draw, 2);
278
+
279
+ // setters
280
+ rb_define_method(rb_cCircle, "radius=", Circle_set_radius, 1);
281
+ rb_define_method(rb_cCircle, "position=", Circle_set_position, 1);
282
+ rb_define_method(rb_cCircle, "rotation=", Circle_set_rotation, 1);
283
+ rb_define_method(rb_cCircle, "scale=", Circle_set_scale, 1);
284
+ rb_define_method(rb_cCircle, "origin=", Circle_set_origin, 1);
285
+ rb_define_method(rb_cCircle, "fill_color=", Circle_set_fill_color, 1);
286
+ rb_define_method(rb_cCircle, "outline_color=", Circle_set_outline_color, 1);
287
+ rb_define_method(rb_cCircle, "outline_thickness=", Circle_set_outline_thickness, 1);
288
+ rb_define_method(rb_cCircle, "texture=", Circle_set_texture, 1);
289
+ rb_define_method(rb_cCircle, "texture_rect=", Circle_set_texture_rect, 1);
290
+
291
+ // getters
292
+ rb_define_method(rb_cCircle, "radius", Circle_get_radius, 0);
293
+ rb_define_method(rb_cCircle, "position", Circle_get_position, 0);
294
+ rb_define_method(rb_cCircle, "rotation", Circle_get_rotation, 0);
295
+ rb_define_method(rb_cCircle, "scale", Circle_get_scale, 0);
296
+ rb_define_method(rb_cCircle, "origin", Circle_get_origin, 0);
297
+ rb_define_method(rb_cCircle, "fill_color", Circle_get_fill_color, 0);
298
+ rb_define_method(rb_cCircle, "outline_color", Circle_get_outline_color, 0);
299
+ rb_define_method(rb_cCircle, "outline_thickness", Circle_get_outline_thickness, 0);
300
+ rb_define_method(rb_cCircle, "texture", Circle_get_texture, 0);
301
+ rb_define_method(rb_cCircle, "texture_rect", Circle_get_texture_rect, 0);
302
+ rb_define_method(rb_cCircle, "point_count", Circle_get_point_count, 0);
303
+ rb_define_method(rb_cCircle, "point_count=", Circle_set_point_count, 1);
304
+ rb_define_method(rb_cCircle, "point", Circle_get_point, 1);
305
+ rb_define_method(rb_cCircle, "geometric_center", Circle_get_geometric_center, 0);
306
+ rb_define_method(rb_cCircle, "local_bounds", Circle_get_local_bounds, 0);
307
+ rb_define_method(rb_cCircle, "global_bounds", Circle_get_global_bounds, 0);
308
+ rb_define_method(rb_cCircle, "transform", Circle_get_transform, 0);
309
+ rb_define_method(rb_cCircle, "inverse_transform", Circle_get_inverse_transform, 0);
310
+ rb_define_method(rb_cCircle, "matrix", Circle_get_transform, 0);
311
+ }
312
+
313
+ void* Get_Circle_Struct(VALUE self) {
314
+ return Get_Circle_Shape(self);
315
+ }
316
+
317
+ VALUE Get_Klass_Circle() {
318
+ return rb_cCircle;
319
+ }
@@ -1,5 +1,5 @@
1
- #ifndef SFML_RB_CIRCLE_H
2
- #define SFML_RB_CIRCLE_H
1
+ #ifndef SFML_RB_GRAPHICS_CIRCLE_H
2
+ #define SFML_RB_GRAPHICS_CIRCLE_H
3
3
 
4
4
  #include <ruby.h>
5
5
 
@@ -9,4 +9,4 @@ void *Get_Circle_Struct(VALUE self);
9
9
 
10
10
  VALUE Get_Klass_Circle();
11
11
 
12
- #endif //SFML_RB_CIRCLE_H
12
+ #endif //SFML_RB_GRAPHICS_CIRCLE_H
@@ -0,0 +1,318 @@
1
+ #include "graphics/color.h"
2
+
3
+ #include <ruby.h>
4
+ #include <stdio.h>
5
+ #include <stdlib.h>
6
+
7
+ #include "core/exceptions.h"
8
+ #include "core/macros.h"
9
+
10
+ typedef struct {
11
+ sfColor color;
12
+ } Color;
13
+
14
+ static VALUE rb_cColor;
15
+
16
+ static void Color_free(void *ptr) {
17
+ free(ptr);
18
+ }
19
+
20
+ static const rb_data_type_t Color_data_type = {
21
+ .wrap_struct_name = "SFML::Color",
22
+ .function = {.dmark = NULL, .dfree = Color_free, .dsize = NULL},
23
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
24
+ };
25
+
26
+ static unsigned char clamp_channel(int value) {
27
+ if (value < 0) {
28
+ return 0;
29
+ }
30
+
31
+ if (value > 255) {
32
+ return 255;
33
+ }
34
+
35
+ return (unsigned char) value;
36
+ }
37
+
38
+ static VALUE Color_wrap(sfColor color) {
39
+ Color *ptr = malloc(sizeof(Color));
40
+
41
+ ptr->color = color;
42
+
43
+ return TypedData_Wrap_Struct(rb_cColor, &Color_data_type, ptr);
44
+ }
45
+
46
+ static sfColor Color_from_integer(VALUE rb_integer) {
47
+ unsigned int value = (unsigned int) NUM2UINT(rb_integer);
48
+
49
+ if (value <= 0xFFFFFF) {
50
+ return (sfColor) {
51
+ (unsigned char) ((value >> 16) & 0xFF),
52
+ (unsigned char) ((value >> 8) & 0xFF),
53
+ (unsigned char) (value & 0xFF),
54
+ 255
55
+ };
56
+ }
57
+
58
+ return (sfColor) {
59
+ (unsigned char) ((value >> 24) & 0xFF),
60
+ (unsigned char) ((value >> 16) & 0xFF),
61
+ (unsigned char) ((value >> 8) & 0xFF),
62
+ (unsigned char) (value & 0xFF)
63
+ };
64
+ }
65
+
66
+ static VALUE Color_new(int argc, VALUE *argv, VALUE klass) {
67
+ VALUE self;
68
+ Color *ptr;
69
+ sfColor color = {0, 0, 0, 255};
70
+
71
+ if (argc == 1 && rb_obj_is_kind_of(argv[0], rb_cColor)) {
72
+ color = ((Color *) Get_Color_Struct(argv[0]))->color;
73
+ } else if (argc == 1 && RB_TYPE_P(argv[0], T_ARRAY)) {
74
+ color = color_from_rb(argv[0]);
75
+ } else if (argc == 1 && RB_INTEGER_TYPE_P(argv[0])) {
76
+ color = Color_from_integer(argv[0]);
77
+ } else if (argc == 3 || argc == 4) {
78
+ color.r = clamp_channel(NUM2INT(argv[0]));
79
+ color.g = clamp_channel(NUM2INT(argv[1]));
80
+ color.b = clamp_channel(NUM2INT(argv[2]));
81
+ color.a = (argc == 4) ? clamp_channel(NUM2INT(argv[3])) : 255;
82
+ } else if (argc != 0) {
83
+ raise_invalid_arguments_excepted(4, argc);
84
+ }
85
+
86
+ ptr = malloc(sizeof(Color));
87
+ ptr->color = color;
88
+
89
+ self = TypedData_Wrap_Struct(klass, &Color_data_type, ptr);
90
+
91
+ return self;
92
+ }
93
+
94
+ static VALUE Color_from_rgb(VALUE klass, VALUE rb_integer) {
95
+ return Color_wrap((sfColor) {
96
+ (unsigned char) ((NUM2UINT(rb_integer) >> 16) & 0xFF),
97
+ (unsigned char) ((NUM2UINT(rb_integer) >> 8) & 0xFF),
98
+ (unsigned char) (NUM2UINT(rb_integer) & 0xFF),
99
+ 255
100
+ });
101
+ }
102
+
103
+ static VALUE Color_from_rgba(VALUE klass, VALUE rb_integer) {
104
+ return Color_wrap(Color_from_integer(rb_integer));
105
+ }
106
+
107
+ static VALUE Color_get_r(VALUE self) {
108
+ return INT2NUM(((Color *) Get_Color_Struct(self))->color.r);
109
+ }
110
+
111
+ static VALUE Color_get_g(VALUE self) {
112
+ return INT2NUM(((Color *) Get_Color_Struct(self))->color.g);
113
+ }
114
+
115
+ static VALUE Color_get_b(VALUE self) {
116
+ return INT2NUM(((Color *) Get_Color_Struct(self))->color.b);
117
+ }
118
+
119
+ static VALUE Color_get_a(VALUE self) {
120
+ return INT2NUM(((Color *) Get_Color_Struct(self))->color.a);
121
+ }
122
+
123
+ static VALUE Color_set_r(VALUE self, VALUE rb_value) {
124
+ ((Color *) Get_Color_Struct(self))->color.r = clamp_channel(NUM2INT(rb_value));
125
+ return rb_value;
126
+ }
127
+
128
+ static VALUE Color_set_g(VALUE self, VALUE rb_value) {
129
+ ((Color *) Get_Color_Struct(self))->color.g = clamp_channel(NUM2INT(rb_value));
130
+ return rb_value;
131
+ }
132
+
133
+ static VALUE Color_set_b(VALUE self, VALUE rb_value) {
134
+ ((Color *) Get_Color_Struct(self))->color.b = clamp_channel(NUM2INT(rb_value));
135
+ return rb_value;
136
+ }
137
+
138
+ static VALUE Color_set_a(VALUE self, VALUE rb_value) {
139
+ ((Color *) Get_Color_Struct(self))->color.a = clamp_channel(NUM2INT(rb_value));
140
+ return rb_value;
141
+ }
142
+
143
+ static VALUE Color_to_i(VALUE self) {
144
+ sfColor color = ((Color *) Get_Color_Struct(self))->color;
145
+
146
+ return UINT2NUM(((unsigned int) color.r << 24) | ((unsigned int) color.g << 16) |
147
+ ((unsigned int) color.b << 8) | (unsigned int) color.a);
148
+ }
149
+
150
+ static VALUE Color_to_a(VALUE self) {
151
+ sfColor color = ((Color *) Get_Color_Struct(self))->color;
152
+
153
+ return rb_ary_new_from_args(4, INT2NUM(color.r), INT2NUM(color.g), INT2NUM(color.b), INT2NUM(color.a));
154
+ }
155
+
156
+ static VALUE Color_eql(VALUE self, VALUE rb_other) {
157
+ sfColor a = ((Color *) Get_Color_Struct(self))->color;
158
+ sfColor b;
159
+
160
+ if (!rb_obj_is_kind_of(rb_other, rb_cColor)) {
161
+ return Qfalse;
162
+ }
163
+
164
+ b = ((Color *) Get_Color_Struct(rb_other))->color;
165
+
166
+ return BOOL2RB(a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a);
167
+ }
168
+
169
+ static VALUE Color_add(VALUE self, VALUE rb_other) {
170
+ sfColor a = ((Color *) Get_Color_Struct(self))->color;
171
+ sfColor b = color_from_rb(rb_other);
172
+
173
+ return Color_wrap((sfColor) {
174
+ clamp_channel(a.r + b.r), clamp_channel(a.g + b.g),
175
+ clamp_channel(a.b + b.b), clamp_channel(a.a + b.a)
176
+ });
177
+ }
178
+
179
+ static VALUE Color_sub(VALUE self, VALUE rb_other) {
180
+ sfColor a = ((Color *) Get_Color_Struct(self))->color;
181
+ sfColor b = color_from_rb(rb_other);
182
+
183
+ return Color_wrap((sfColor) {
184
+ clamp_channel(a.r - b.r), clamp_channel(a.g - b.g),
185
+ clamp_channel(a.b - b.b), clamp_channel(a.a - b.a)
186
+ });
187
+ }
188
+
189
+ static VALUE Color_mul(VALUE self, VALUE rb_other) {
190
+ sfColor a = ((Color *) Get_Color_Struct(self))->color;
191
+ sfColor b = color_from_rb(rb_other);
192
+
193
+ return Color_wrap((sfColor) {
194
+ (unsigned char) ((a.r * b.r) / 255), (unsigned char) ((a.g * b.g) / 255),
195
+ (unsigned char) ((a.b * b.b) / 255), (unsigned char) ((a.a * b.a) / 255)
196
+ });
197
+ }
198
+
199
+ static VALUE Color_to_s(VALUE self) {
200
+ sfColor c = ((Color *) Get_Color_Struct(self))->color;
201
+ char buffer[64];
202
+
203
+ snprintf(buffer, sizeof(buffer), "(%u, %u, %u, %u)", c.r, c.g, c.b, c.a);
204
+
205
+ return rb_str_new2(buffer);
206
+ }
207
+
208
+ static void Color_define_predefined(VALUE klass, const char *name, sfColor color) {
209
+ rb_define_const(klass, name, Color_wrap(color));
210
+ }
211
+
212
+ void Init_Color(VALUE rb_module) {
213
+ rb_cColor = rb_define_class_under(rb_module, "Color", rb_cObject);
214
+
215
+ rb_define_singleton_method(rb_cColor, "new", Color_new, -1);
216
+ rb_define_singleton_method(rb_cColor, "from_rgb", Color_from_rgb, 1);
217
+ rb_define_singleton_method(rb_cColor, "from_rgba", Color_from_rgba, 1);
218
+ rb_define_singleton_method(rb_cColor, "from_integer", Color_from_rgba, 1);
219
+
220
+ rb_define_method(rb_cColor, "r", Color_get_r, 0);
221
+ rb_define_method(rb_cColor, "g", Color_get_g, 0);
222
+ rb_define_method(rb_cColor, "b", Color_get_b, 0);
223
+ rb_define_method(rb_cColor, "a", Color_get_a, 0);
224
+ rb_define_method(rb_cColor, "r=", Color_set_r, 1);
225
+ rb_define_method(rb_cColor, "g=", Color_set_g, 1);
226
+ rb_define_method(rb_cColor, "b=", Color_set_b, 1);
227
+ rb_define_method(rb_cColor, "a=", Color_set_a, 1);
228
+
229
+ rb_define_method(rb_cColor, "to_i", Color_to_i, 0);
230
+ rb_define_method(rb_cColor, "to_a", Color_to_a, 0);
231
+ rb_define_method(rb_cColor, "to_ary", Color_to_a, 0);
232
+ rb_define_method(rb_cColor, "==", Color_eql, 1);
233
+ rb_define_method(rb_cColor, "+", Color_add, 1);
234
+ rb_define_method(rb_cColor, "-", Color_sub, 1);
235
+ rb_define_method(rb_cColor, "*", Color_mul, 1);
236
+ rb_define_method(rb_cColor, "to_s", Color_to_s, 0);
237
+
238
+ Color_define_predefined(rb_cColor, "BLACK", sfBlack);
239
+ Color_define_predefined(rb_cColor, "WHITE", sfWhite);
240
+ Color_define_predefined(rb_cColor, "RED", sfRed);
241
+ Color_define_predefined(rb_cColor, "GREEN", sfGreen);
242
+ Color_define_predefined(rb_cColor, "BLUE", sfBlue);
243
+ Color_define_predefined(rb_cColor, "YELLOW", sfYellow);
244
+ Color_define_predefined(rb_cColor, "MAGENTA", sfMagenta);
245
+ Color_define_predefined(rb_cColor, "CYAN", sfCyan);
246
+ Color_define_predefined(rb_cColor, "TRANSPARENT", sfTransparent);
247
+ }
248
+
249
+ VALUE Get_Klass_Color(void) {
250
+ return rb_cColor;
251
+ }
252
+
253
+ void *Get_Color_Struct(VALUE self) {
254
+ Color *ptr;
255
+ TypedData_Get_Struct(self, Color, &Color_data_type, ptr);
256
+ return ptr;
257
+ }
258
+
259
+ sfColor color_from_rb(VALUE rb_color) {
260
+ if (rb_obj_is_kind_of(rb_color, rb_cColor)) {
261
+ return ((Color *) Get_Color_Struct(rb_color))->color;
262
+ }
263
+
264
+ if (RB_TYPE_P(rb_color, T_ARRAY)) {
265
+ long length = RARRAY_LEN(rb_color);
266
+
267
+ if (length != 3 && length != 4) {
268
+ raise_invalid_array_length(VALID_LENGTH_COLOR);
269
+ }
270
+
271
+ return (sfColor) {
272
+ clamp_channel(NUM2INT(rb_ary_entry(rb_color, 0))),
273
+ clamp_channel(NUM2INT(rb_ary_entry(rb_color, 1))),
274
+ clamp_channel(NUM2INT(rb_ary_entry(rb_color, 2))),
275
+ (length == 4) ? clamp_channel(NUM2INT(rb_ary_entry(rb_color, 3))) : 255
276
+ };
277
+ }
278
+
279
+ if (RB_INTEGER_TYPE_P(rb_color)) {
280
+ return Color_from_integer(rb_color);
281
+ }
282
+
283
+ raise_invalid_argument_class(rb_cColor);
284
+
285
+ return (sfColor) {0, 0, 0, 255};
286
+ }
287
+
288
+ VALUE color_to_rb(sfColor color) {
289
+ return Color_wrap(color);
290
+ }
291
+
292
+ VALUE color_new(int r, int g, int b, int a) {
293
+ return Color_wrap((sfColor) {clamp_channel(r), clamp_channel(g), clamp_channel(b), clamp_channel(a)});
294
+ }
295
+
296
+ void color_check(VALUE rb_color) {
297
+ if (rb_obj_is_kind_of(rb_color, rb_cColor) || RB_TYPE_P(rb_color, T_ARRAY) || RB_INTEGER_TYPE_P(rb_color)) {
298
+ return;
299
+ }
300
+
301
+ raise_invalid_argument_class(rb_cColor);
302
+ }
303
+
304
+ void color_swap(sfColor *color_a, sfColor *color_b) {
305
+ sfColor c;
306
+
307
+ c = *color_b;
308
+ *color_b = *color_a;
309
+ *color_a = c;
310
+ }
311
+
312
+ sfColor color_new_from_rb(VALUE rb_color) {
313
+ return color_from_rb(rb_color);
314
+ }
315
+
316
+ VALUE color_new_from_c(sfColor color) {
317
+ return Color_wrap(color);
318
+ }
@@ -0,0 +1,37 @@
1
+ #ifndef SFML_RB_GRAPHICS_COLOR_H
2
+ #define SFML_RB_GRAPHICS_COLOR_H
3
+
4
+ #include <ruby.h>
5
+
6
+ #include "core/sfml.h"
7
+
8
+ #define VALID_LENGTH_COLOR 4
9
+
10
+ #define UNPACK_COLOR(c_color) \
11
+ (unsigned char) c_color.r, (unsigned char) c_color.g, (unsigned char) c_color.b, (unsigned char) c_color.a
12
+
13
+ #define COLOR_C2RB(c_color) color_to_rb(c_color)
14
+
15
+ #define COLOR_RB2C(rb_color) color_from_rb(rb_color)
16
+
17
+ void Init_Color(VALUE rb_module);
18
+
19
+ VALUE Get_Klass_Color(void);
20
+
21
+ void *Get_Color_Struct(VALUE self);
22
+
23
+ sfColor color_from_rb(VALUE rb_color);
24
+
25
+ VALUE color_to_rb(sfColor color);
26
+
27
+ VALUE color_new(int r, int g, int b, int a);
28
+
29
+ void color_check(VALUE rb_color);
30
+
31
+ void color_swap(sfColor *color_a, sfColor *color_b);
32
+
33
+ sfColor color_new_from_rb(VALUE rb_color);
34
+
35
+ VALUE color_new_from_c(sfColor color);
36
+
37
+ #endif //SFML_RB_GRAPHICS_COLOR_H