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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +342 -0
- data/README.md +51 -14
- data/TODO.md +199 -0
- data/ext/audio/audio_enums.c +131 -0
- data/ext/audio/audio_enums.h +18 -0
- data/ext/audio/effect_processor.c +233 -0
- data/ext/audio/effect_processor.h +25 -0
- data/ext/audio/listener.c +83 -0
- data/ext/audio/listener.h +8 -0
- data/ext/audio/music.c +174 -0
- data/ext/audio/music.h +14 -0
- data/ext/audio/sound.c +139 -0
- data/ext/audio/sound.h +14 -0
- data/ext/audio/sound_buffer.c +274 -0
- data/ext/audio/sound_buffer.h +18 -0
- data/ext/audio/sound_buffer_recorder.c +109 -0
- data/ext/audio/sound_buffer_recorder.h +14 -0
- data/ext/audio/sound_recorder.c +268 -0
- data/ext/audio/sound_recorder.h +14 -0
- data/ext/audio/sound_source.h +13 -0
- data/ext/audio/sound_source.inc +271 -0
- data/ext/audio/sound_source_cone.c +138 -0
- data/ext/audio/sound_source_cone.h +20 -0
- data/ext/audio/sound_stream.c +294 -0
- data/ext/audio/sound_stream.h +14 -0
- data/ext/{exceptions.c → core/exceptions.c} +10 -8
- data/ext/{ext → core}/exceptions.h +3 -3
- data/ext/core/foreign_thread.c +149 -0
- data/ext/core/foreign_thread.h +31 -0
- data/ext/core/macros.h +8 -0
- data/ext/{ext → core}/sfml.h +5 -3
- data/ext/core/unicode.c +46 -0
- data/ext/core/unicode.h +25 -0
- data/ext/ext.c +125 -14
- data/ext/extconf.rb +51 -6
- data/ext/graphics/blend_mode.c +261 -0
- data/ext/graphics/blend_mode.h +18 -0
- data/ext/graphics/circle.c +319 -0
- data/ext/{ext/klass/drawable → graphics}/circle.h +3 -3
- data/ext/graphics/color.c +318 -0
- data/ext/graphics/color.h +37 -0
- data/ext/{drawable.c → graphics/drawable.c} +11 -11
- data/ext/graphics/drawable.h +10 -0
- data/ext/graphics/enums.c +123 -0
- data/ext/graphics/enums.h +20 -0
- data/ext/graphics/font.c +148 -0
- data/ext/graphics/font.h +14 -0
- data/ext/graphics/glyph.c +60 -0
- data/ext/graphics/glyph.h +14 -0
- data/ext/graphics/image.c +205 -0
- data/ext/graphics/image.h +16 -0
- data/ext/graphics/polygon.c +300 -0
- data/ext/graphics/polygon.h +10 -0
- data/ext/graphics/rect.c +287 -0
- data/ext/graphics/rect.h +30 -0
- data/ext/graphics/rectangle.c +302 -0
- data/ext/graphics/rectangle.h +10 -0
- data/ext/graphics/render_state.c +204 -0
- data/ext/graphics/render_state.h +18 -0
- data/ext/graphics/render_target.inc +181 -0
- data/ext/graphics/render_texture.c +182 -0
- data/ext/graphics/render_texture.h +14 -0
- data/ext/graphics/shader.c +540 -0
- data/ext/graphics/shader.h +14 -0
- data/ext/graphics/shape.c +311 -0
- data/ext/graphics/shape.h +10 -0
- data/ext/graphics/sprite.c +249 -0
- data/ext/graphics/sprite.h +10 -0
- data/ext/graphics/stencil_mode.c +211 -0
- data/ext/graphics/stencil_mode.h +18 -0
- data/ext/graphics/target.c +133 -0
- data/ext/graphics/target.h +40 -0
- data/ext/graphics/text.c +344 -0
- data/ext/graphics/text.h +10 -0
- data/ext/graphics/texture.c +379 -0
- data/ext/graphics/texture.h +16 -0
- data/ext/graphics/transform.c +372 -0
- data/ext/graphics/transform.h +35 -0
- data/ext/{transformable.c → graphics/transformable.c} +168 -144
- data/ext/{ext/klass → graphics}/transformable.h +3 -3
- data/ext/graphics/vertex.c +179 -0
- data/ext/graphics/vertex.h +23 -0
- data/ext/graphics/vertex_array.c +127 -0
- data/ext/graphics/vertex_array.h +10 -0
- data/ext/graphics/vertex_buffer.c +211 -0
- data/ext/graphics/vertex_buffer.h +14 -0
- data/ext/{view.c → graphics/view.c} +168 -169
- data/ext/{ext/klass → graphics}/view.h +3 -3
- data/ext/network/ftp.c +405 -0
- data/ext/network/ftp.h +20 -0
- data/ext/network/http.c +243 -0
- data/ext/network/http.h +18 -0
- data/ext/network/ip_address.c +164 -0
- data/ext/network/ip_address.h +20 -0
- data/ext/network/network_enums.c +298 -0
- data/ext/network/network_enums.h +26 -0
- data/ext/network/packet.c +189 -0
- data/ext/network/packet.h +14 -0
- data/ext/network/socket_selector.c +142 -0
- data/ext/network/socket_selector.h +14 -0
- data/ext/network/tcp_listener.c +115 -0
- data/ext/network/tcp_listener.h +14 -0
- data/ext/network/tcp_socket.c +199 -0
- data/ext/network/tcp_socket.h +17 -0
- data/ext/network/udp_socket.c +190 -0
- data/ext/network/udp_socket.h +14 -0
- data/ext/ports.rb +97 -21
- data/ext/system/buffer.c +77 -0
- data/ext/system/buffer.h +14 -0
- data/ext/system/clock.c +100 -0
- data/ext/{ext/klass → system}/clock.h +3 -3
- data/ext/system/input_stream.c +229 -0
- data/ext/system/input_stream.h +23 -0
- data/ext/system/sleep.c +16 -0
- data/ext/system/sleep.h +8 -0
- data/ext/system/time.c +218 -0
- data/ext/system/time.h +18 -0
- data/ext/system/vec2.c +251 -0
- data/ext/system/vec2.h +55 -0
- data/ext/system/vec3.c +219 -0
- data/ext/system/vec3.h +18 -0
- data/ext/window/clipboard.c +89 -0
- data/ext/window/clipboard.h +8 -0
- data/ext/window/context.c +70 -0
- data/ext/window/context.h +8 -0
- data/ext/window/context_settings.c +220 -0
- data/ext/window/context_settings.h +18 -0
- data/ext/window/cursor.c +56 -0
- data/ext/window/cursor.h +14 -0
- data/ext/window/event.c +216 -0
- data/ext/window/event.h +14 -0
- data/ext/{event_name.c → window/event_name.c} +2 -2
- data/ext/window/event_name.h +8 -0
- data/ext/window/input_enums.c +261 -0
- data/ext/window/input_enums.h +36 -0
- data/ext/window/joystick.c +60 -0
- data/ext/window/joystick.h +8 -0
- data/ext/{keyboard.c → window/keyboard.c} +74 -2
- data/ext/window/keyboard.h +12 -0
- data/ext/window/mouse.c +70 -0
- data/ext/window/mouse.h +8 -0
- data/ext/window/sensor.c +30 -0
- data/ext/window/sensor.h +8 -0
- data/ext/window/touch.c +49 -0
- data/ext/window/touch.h +8 -0
- data/ext/window/video_mode.c +133 -0
- data/ext/window/video_mode.h +14 -0
- data/ext/window/vulkan.c +44 -0
- data/ext/window/vulkan.h +8 -0
- data/ext/window/window.c +414 -0
- data/ext/{ext/klass → window}/window.h +3 -3
- data/lib/sfml/version.rb +4 -2
- data/lib/sfml.rb +2 -0
- metadata +163 -56
- data/ext/circle.c +0 -198
- data/ext/clock.c +0 -65
- data/ext/color.c +0 -43
- data/ext/event.c +0 -148
- data/ext/ext/klass/color.h +0 -26
- data/ext/ext/klass/drawable/image.h +0 -4
- data/ext/ext/klass/drawable/polygon.h +0 -4
- data/ext/ext/klass/drawable/rectangle.h +0 -4
- data/ext/ext/klass/drawable/sprite.h +0 -4
- data/ext/ext/klass/drawable/texture.h +0 -4
- data/ext/ext/klass/event/event_name.h +0 -8
- data/ext/ext/klass/event.h +0 -12
- data/ext/ext/klass/keyboard.h +0 -8
- data/ext/ext/klass/render_state.h +0 -16
- data/ext/ext/klass/target.h +0 -18
- data/ext/ext/klass/transform.h +0 -17
- data/ext/ext/klass/video_mode.h +0 -12
- data/ext/ext/module/drawable/drawable.h +0 -10
- data/ext/ext/module/transform.h +0 -18
- data/ext/ext/module.h +0 -10
- data/ext/ext/rect.h +0 -16
- data/ext/ext/style_name.h +0 -11
- data/ext/ext/vec2.h +0 -38
- data/ext/image.c +0 -5
- data/ext/polygon.c +0 -5
- data/ext/rect.c +0 -26
- data/ext/rectangle.c +0 -5
- data/ext/render_state.c +0 -109
- data/ext/sprite.c +0 -5
- data/ext/style_name.c +0 -15
- data/ext/target.c +0 -106
- data/ext/texture.c +0 -5
- data/ext/transform.c +0 -107
- data/ext/vec2.c +0 -42
- data/ext/video_mode.c +0 -78
- data/ext/window.c +0 -274
|
@@ -1,145 +1,169 @@
|
|
|
1
|
-
#include "
|
|
2
|
-
|
|
3
|
-
#include <ruby.h>
|
|
4
|
-
#include <stdio.h>
|
|
5
|
-
|
|
6
|
-
#include "
|
|
7
|
-
#include "
|
|
8
|
-
#include "
|
|
9
|
-
#include "
|
|
10
|
-
#include "
|
|
11
|
-
|
|
12
|
-
static VALUE rb_cTransformable;
|
|
13
|
-
|
|
14
|
-
static sfTransformable
|
|
15
|
-
return sfTransformable_create();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
static void Transformable_free(void
|
|
19
|
-
sfTransformable_destroy((sfTransformable
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
static
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
1
|
+
#include "graphics/transformable.h"
|
|
2
|
+
|
|
3
|
+
#include <ruby.h>
|
|
4
|
+
#include <stdio.h>
|
|
5
|
+
|
|
6
|
+
#include "graphics/transform.h"
|
|
7
|
+
#include "system/vec2.h"
|
|
8
|
+
#include "graphics/rect.h"
|
|
9
|
+
#include "core/macros.h"
|
|
10
|
+
#include "core/sfml.h"
|
|
11
|
+
|
|
12
|
+
static VALUE rb_cTransformable;
|
|
13
|
+
|
|
14
|
+
static sfTransformable* Transformable_create() {
|
|
15
|
+
return sfTransformable_create();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static void Transformable_free(void* ptr) {
|
|
19
|
+
sfTransformable_destroy((sfTransformable*)ptr);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static const rb_data_type_t Transformable_data_type = {
|
|
23
|
+
.wrap_struct_name = "SFML::Transformable",
|
|
24
|
+
.function = {.dmark = NULL, .dfree = Transformable_free, .dsize = NULL},
|
|
25
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY};
|
|
26
|
+
|
|
27
|
+
static VALUE Transformable_new(VALUE klass) {
|
|
28
|
+
VALUE self;
|
|
29
|
+
sfTransformable* transformable;
|
|
30
|
+
|
|
31
|
+
transformable = Transformable_create();
|
|
32
|
+
self = TypedData_Wrap_Struct(klass, &Transformable_data_type, transformable);
|
|
33
|
+
|
|
34
|
+
rb_obj_call_init(self, 0, NULL);
|
|
35
|
+
|
|
36
|
+
return self;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static VALUE Transformable_init(VALUE self) {
|
|
40
|
+
return self;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static VALUE Transformable_set_position(VALUE self, VALUE rb_position) {
|
|
44
|
+
sfVector2f position = VEC2_RB2C(rb_position);
|
|
45
|
+
sfTransformable_setPosition(Get_Transformable_Struct(self), position);
|
|
46
|
+
|
|
47
|
+
return self;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static VALUE Transformable_set_rotation(VALUE self, VALUE rb_angle) {
|
|
51
|
+
sfTransformable_setRotation(Get_Transformable_Struct(self), NUM2DBL(rb_angle));
|
|
52
|
+
|
|
53
|
+
return self;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static VALUE Transformable_set_scale(VALUE self, VALUE rb_scale) {
|
|
57
|
+
sfVector2f scale = VEC2_RB2C(rb_scale);
|
|
58
|
+
sfTransformable_setScale(Get_Transformable_Struct(self), scale);
|
|
59
|
+
|
|
60
|
+
return self;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static VALUE Transformable_set_origin(VALUE self, VALUE rb_origin) {
|
|
64
|
+
sfVector2f origin = VEC2_RB2C(rb_origin);
|
|
65
|
+
sfTransformable_setOrigin(Get_Transformable_Struct(self), origin);
|
|
66
|
+
|
|
67
|
+
return self;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static VALUE Transformable_get_position(VALUE self) {
|
|
71
|
+
sfVector2f position = sfTransformable_getPosition(Get_Transformable_Struct(self));
|
|
72
|
+
|
|
73
|
+
return VEC2_C2RB(position);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
static VALUE Transformable_get_rotation(VALUE self) {
|
|
77
|
+
return DBL2NUM(sfTransformable_getRotation(Get_Transformable_Struct(self)));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
static VALUE Transformable_get_scale(VALUE self) {
|
|
81
|
+
sfVector2f scale = sfTransformable_getScale(Get_Transformable_Struct(self));
|
|
82
|
+
|
|
83
|
+
return VEC2_C2RB(scale);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
static VALUE Transformable_get_origin(VALUE self) {
|
|
87
|
+
sfVector2f origin = sfTransformable_getOrigin(Get_Transformable_Struct(self));
|
|
88
|
+
|
|
89
|
+
return VEC2_C2RB(origin);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
static VALUE Transformable_move(VALUE self, VALUE rb_move) {
|
|
93
|
+
sfVector2f move = VEC2_RB2C(rb_move);
|
|
94
|
+
sfTransformable_move(Get_Transformable_Struct(self), move);
|
|
95
|
+
|
|
96
|
+
return self;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static VALUE Transformable_rotate(VALUE self, VALUE rb_angle) {
|
|
100
|
+
sfTransformable_rotate(Get_Transformable_Struct(self), NUM2DBL(rb_angle));
|
|
101
|
+
|
|
102
|
+
return self;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
static VALUE Transformable_scale(VALUE self, VALUE rb_scale) {
|
|
106
|
+
sfVector2f scale = VEC2_RB2C(rb_scale);
|
|
107
|
+
sfTransformable_scale(Get_Transformable_Struct(self), scale);
|
|
108
|
+
|
|
109
|
+
return self;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
static VALUE Transformable_get_matrix(VALUE self) {
|
|
113
|
+
sfTransformable* transformable = Get_Transformable_Struct(self);
|
|
114
|
+
sfTransform transform = sfTransformable_getTransform(transformable);
|
|
115
|
+
|
|
116
|
+
return Transform_MatrixToArray(transform.matrix);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
static VALUE Transformable_get_inverse_matrix(VALUE self) {
|
|
120
|
+
sfTransform transform = sfTransformable_getInverseTransform(Get_Transformable_Struct(self));
|
|
121
|
+
|
|
122
|
+
return Transform_MatrixToArray(transform.matrix);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
static VALUE Transformable_copy(VALUE self) {
|
|
126
|
+
sfTransformable* copy = sfTransformable_copy(Get_Transformable_Struct(self));
|
|
127
|
+
VALUE other = TypedData_Wrap_Struct(rb_cTransformable, &Transformable_data_type, copy);
|
|
128
|
+
|
|
129
|
+
rb_obj_call_init(other, 0, NULL);
|
|
130
|
+
|
|
131
|
+
return other;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
void Init_Transformable(VALUE rb_module) {
|
|
135
|
+
rb_cTransformable = rb_define_class_under(rb_module, "Transformable", rb_cObject);
|
|
136
|
+
|
|
137
|
+
rb_define_singleton_method(rb_cTransformable, "new", Transformable_new, 0);
|
|
138
|
+
rb_define_method(rb_cTransformable, "initialize", Transformable_init, 0);
|
|
139
|
+
|
|
140
|
+
rb_define_method(rb_cTransformable, "position=", Transformable_set_position, 1);
|
|
141
|
+
rb_define_method(rb_cTransformable, "rotation=", Transformable_set_rotation, 1);
|
|
142
|
+
rb_define_method(rb_cTransformable, "scale=", Transformable_set_scale, 1);
|
|
143
|
+
rb_define_method(rb_cTransformable, "origin=", Transformable_set_origin, 1);
|
|
144
|
+
|
|
145
|
+
rb_define_method(rb_cTransformable, "position", Transformable_get_position, 0);
|
|
146
|
+
rb_define_method(rb_cTransformable, "rotation", Transformable_get_rotation, 0);
|
|
147
|
+
rb_define_method(rb_cTransformable, "scale", Transformable_get_scale, 0);
|
|
148
|
+
rb_define_method(rb_cTransformable, "origin", Transformable_get_origin, 0);
|
|
149
|
+
|
|
150
|
+
rb_define_method(rb_cTransformable, "move", Transformable_move, 1);
|
|
151
|
+
rb_define_method(rb_cTransformable, "rotate", Transformable_rotate, 1);
|
|
152
|
+
rb_define_method(rb_cTransformable, "scale!", Transformable_scale, 1);
|
|
153
|
+
|
|
154
|
+
rb_define_method(rb_cTransformable, "transform", Transformable_get_matrix, 0);
|
|
155
|
+
rb_define_method(rb_cTransformable, "matrix", Transformable_get_matrix, 0);
|
|
156
|
+
rb_define_method(rb_cTransformable, "inverse_transform", Transformable_get_inverse_matrix, 0);
|
|
157
|
+
|
|
158
|
+
rb_define_method(rb_cTransformable, "copy", Transformable_copy, 0);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
void* Get_Transformable_Struct(VALUE self) {
|
|
162
|
+
sfTransformable* transform;
|
|
163
|
+
TypedData_Get_Struct(self, sfTransformable, &Transformable_data_type, transform);
|
|
164
|
+
return transform;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
VALUE Get_Klass_Transformable() {
|
|
168
|
+
return rb_cTransformable;
|
|
145
169
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
#ifndef
|
|
2
|
-
#define
|
|
1
|
+
#ifndef SFML_RB_GRAPHICS_TRANSFORMABLE_H
|
|
2
|
+
#define SFML_RB_GRAPHICS_TRANSFORMABLE_H
|
|
3
3
|
|
|
4
4
|
#include <ruby.h>
|
|
5
5
|
|
|
@@ -10,4 +10,4 @@ void *Get_Transformable_Struct(VALUE self);
|
|
|
10
10
|
|
|
11
11
|
VALUE Get_Klass_Transformable();
|
|
12
12
|
|
|
13
|
-
#endif //
|
|
13
|
+
#endif //SFML_RB_GRAPHICS_TRANSFORMABLE_H
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
#include "graphics/vertex.h"
|
|
2
|
+
|
|
3
|
+
#include <ruby.h>
|
|
4
|
+
#include <stdlib.h>
|
|
5
|
+
|
|
6
|
+
#include "graphics/color.h"
|
|
7
|
+
#include "system/vec2.h"
|
|
8
|
+
#include "core/exceptions.h"
|
|
9
|
+
#include "core/macros.h"
|
|
10
|
+
|
|
11
|
+
typedef struct {
|
|
12
|
+
sfVertex vertex;
|
|
13
|
+
} Vertex;
|
|
14
|
+
|
|
15
|
+
static VALUE rb_cVertex;
|
|
16
|
+
|
|
17
|
+
static void Vertex_free(void* ptr) {
|
|
18
|
+
free(ptr);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static const rb_data_type_t Vertex_data_type = {
|
|
22
|
+
.wrap_struct_name = "SFML::Vertex",
|
|
23
|
+
.function = {.dmark = NULL, .dfree = Vertex_free, .dsize = NULL},
|
|
24
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY};
|
|
25
|
+
|
|
26
|
+
static VALUE Vertex_wrap(sfVertex vertex) {
|
|
27
|
+
Vertex* ptr = malloc(sizeof(Vertex));
|
|
28
|
+
|
|
29
|
+
ptr->vertex = vertex;
|
|
30
|
+
|
|
31
|
+
return TypedData_Wrap_Struct(rb_cVertex, &Vertex_data_type, ptr);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static VALUE Vertex_new(int argc, VALUE* argv, VALUE klass) {
|
|
35
|
+
VALUE rb_position, rb_color, rb_tex_coords;
|
|
36
|
+
sfVertex vertex = {{0, 0}, {255, 255, 255, 255}, {0, 0}};
|
|
37
|
+
|
|
38
|
+
rb_scan_args(argc, argv, "03", &rb_position, &rb_color, &rb_tex_coords);
|
|
39
|
+
|
|
40
|
+
if (!NIL_P(rb_position)) {
|
|
41
|
+
vertex.position = vec2f_from_rb(rb_position);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!NIL_P(rb_color)) {
|
|
45
|
+
vertex.color = color_from_rb(rb_color);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!NIL_P(rb_tex_coords)) {
|
|
49
|
+
vertex.texCoords = vec2f_from_rb(rb_tex_coords);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return Vertex_wrap(vertex);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static VALUE Vertex_get_position(VALUE self) {
|
|
56
|
+
return vec2f_to_rb(((Vertex*)Get_Vertex_Struct(self))->vertex.position);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
static VALUE Vertex_set_position(VALUE self, VALUE rb_position) {
|
|
60
|
+
((Vertex*)Get_Vertex_Struct(self))->vertex.position = vec2f_from_rb(rb_position);
|
|
61
|
+
return rb_position;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
static VALUE Vertex_get_color(VALUE self) {
|
|
65
|
+
return color_to_rb(((Vertex*)Get_Vertex_Struct(self))->vertex.color);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static VALUE Vertex_set_color(VALUE self, VALUE rb_color) {
|
|
69
|
+
((Vertex*)Get_Vertex_Struct(self))->vertex.color = color_from_rb(rb_color);
|
|
70
|
+
return rb_color;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static VALUE Vertex_get_tex_coords(VALUE self) {
|
|
74
|
+
return vec2f_to_rb(((Vertex*)Get_Vertex_Struct(self))->vertex.texCoords);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static VALUE Vertex_set_tex_coords(VALUE self, VALUE rb_tex_coords) {
|
|
78
|
+
((Vertex*)Get_Vertex_Struct(self))->vertex.texCoords = vec2f_from_rb(rb_tex_coords);
|
|
79
|
+
return rb_tex_coords;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static VALUE Vertex_to_a(VALUE self) {
|
|
83
|
+
Vertex* v = Get_Vertex_Struct(self);
|
|
84
|
+
|
|
85
|
+
return rb_ary_new_from_args(2, vec2f_to_rb(v->vertex.position), color_to_rb(v->vertex.color));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
static VALUE Vertex_eql(VALUE self, VALUE rb_other) {
|
|
89
|
+
sfVertex a = ((Vertex*)Get_Vertex_Struct(self))->vertex;
|
|
90
|
+
sfVertex b;
|
|
91
|
+
|
|
92
|
+
if (!rb_obj_is_kind_of(rb_other, rb_cVertex)) {
|
|
93
|
+
return Qfalse;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
b = ((Vertex*)Get_Vertex_Struct(rb_other))->vertex;
|
|
97
|
+
|
|
98
|
+
return BOOL2RB(a.position.x == b.position.x && a.position.y == b.position.y &&
|
|
99
|
+
a.color.r == b.color.r && a.color.g == b.color.g && a.color.b == b.color.b &&
|
|
100
|
+
a.color.a == b.color.a && a.texCoords.x == b.texCoords.x &&
|
|
101
|
+
a.texCoords.y == b.texCoords.y);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
void Init_Vertex(VALUE rb_module) {
|
|
105
|
+
rb_cVertex = rb_define_class_under(rb_module, "Vertex", rb_cObject);
|
|
106
|
+
|
|
107
|
+
rb_define_singleton_method(rb_cVertex, "new", Vertex_new, -1);
|
|
108
|
+
|
|
109
|
+
rb_define_method(rb_cVertex, "position", Vertex_get_position, 0);
|
|
110
|
+
rb_define_method(rb_cVertex, "color", Vertex_get_color, 0);
|
|
111
|
+
rb_define_method(rb_cVertex, "tex_coords", Vertex_get_tex_coords, 0);
|
|
112
|
+
rb_define_method(rb_cVertex, "position=", Vertex_set_position, 1);
|
|
113
|
+
rb_define_method(rb_cVertex, "color=", Vertex_set_color, 1);
|
|
114
|
+
rb_define_method(rb_cVertex, "tex_coords=", Vertex_set_tex_coords, 1);
|
|
115
|
+
rb_define_method(rb_cVertex, "to_a", Vertex_to_a, 0);
|
|
116
|
+
rb_define_method(rb_cVertex, "==", Vertex_eql, 1);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
VALUE Get_Klass_Vertex(void) {
|
|
120
|
+
return rb_cVertex;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
void* Get_Vertex_Struct(VALUE self) {
|
|
124
|
+
Vertex* ptr;
|
|
125
|
+
TypedData_Get_Struct(self, Vertex, &Vertex_data_type, ptr);
|
|
126
|
+
return ptr;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
sfVertex vertex_from_rb(VALUE rb_vertex) {
|
|
130
|
+
if (rb_obj_is_kind_of(rb_vertex, rb_cVertex)) {
|
|
131
|
+
return ((Vertex*)Get_Vertex_Struct(rb_vertex))->vertex;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (RB_TYPE_P(rb_vertex, T_ARRAY)) {
|
|
135
|
+
return vertex_from_rb(rb_funcall(rb_cVertex, rb_intern("new"), 1, rb_vertex));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
raise_invalid_argument_class(rb_cVertex);
|
|
139
|
+
|
|
140
|
+
return (sfVertex){{0, 0}, {0, 0, 0, 0}, {0, 0}};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
VALUE vertex_to_rb(sfVertex c_vertex) {
|
|
144
|
+
return Vertex_wrap(c_vertex);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
sfVertex* vertices_from_rb(VALUE rb_vertices, size_t* count) {
|
|
148
|
+
VALUE normalized;
|
|
149
|
+
sfVertex* vertices;
|
|
150
|
+
long i, len;
|
|
151
|
+
|
|
152
|
+
Check_Type(rb_vertices, T_ARRAY);
|
|
153
|
+
|
|
154
|
+
len = RARRAY_LEN(rb_vertices);
|
|
155
|
+
normalized = rb_ary_new_capa(len);
|
|
156
|
+
|
|
157
|
+
/* Normalize -- and so raise on a bad element -- before allocating anything:
|
|
158
|
+
vertex_from_rb builds a Vertex out of a plain Array and can raise, and a
|
|
159
|
+
raise after ALLOC_N would leak the buffer. */
|
|
160
|
+
for (i = 0; i < len; i++) {
|
|
161
|
+
VALUE entry = rb_ary_entry(rb_vertices, i);
|
|
162
|
+
|
|
163
|
+
if (!rb_obj_is_kind_of(entry, rb_cVertex)) {
|
|
164
|
+
entry = rb_funcall(rb_cVertex, rb_intern("new"), 1, entry);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
rb_ary_push(normalized, entry);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
vertices = ALLOC_N(sfVertex, len);
|
|
171
|
+
|
|
172
|
+
for (i = 0; i < len; i++) {
|
|
173
|
+
vertices[i] = vertex_from_rb(rb_ary_entry(normalized, i));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
*count = (size_t)len;
|
|
177
|
+
|
|
178
|
+
return vertices;
|
|
179
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#ifndef SFML_RB_GRAPHICS_VERTEX_H
|
|
2
|
+
#define SFML_RB_GRAPHICS_VERTEX_H
|
|
3
|
+
|
|
4
|
+
#include <ruby.h>
|
|
5
|
+
|
|
6
|
+
#include "core/sfml.h"
|
|
7
|
+
|
|
8
|
+
void Init_Vertex(VALUE rb_module);
|
|
9
|
+
|
|
10
|
+
VALUE Get_Klass_Vertex(void);
|
|
11
|
+
|
|
12
|
+
void* Get_Vertex_Struct(VALUE self);
|
|
13
|
+
|
|
14
|
+
sfVertex vertex_from_rb(VALUE rb_vertex);
|
|
15
|
+
|
|
16
|
+
VALUE vertex_to_rb(sfVertex c_vertex);
|
|
17
|
+
|
|
18
|
+
/* Converts an Array of Vertex into a freshly allocated C array; the caller
|
|
19
|
+
xfree()s it. Every element is validated before anything is allocated, so a
|
|
20
|
+
bad element raises without leaking. */
|
|
21
|
+
sfVertex* vertices_from_rb(VALUE rb_vertices, size_t* count);
|
|
22
|
+
|
|
23
|
+
#endif // SFML_RB_GRAPHICS_VERTEX_H
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#include "graphics/vertex_array.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 "graphics/rect.h"
|
|
10
|
+
#include "graphics/vertex.h"
|
|
11
|
+
#include "graphics/enums.h"
|
|
12
|
+
#include "core/exceptions.h"
|
|
13
|
+
#include "core/macros.h"
|
|
14
|
+
|
|
15
|
+
static VALUE rb_cVertexArray;
|
|
16
|
+
|
|
17
|
+
static void VertexArray_free(void *ptr) {
|
|
18
|
+
sfVertexArray_destroy(ptr);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static const rb_data_type_t VertexArray_data_type = {
|
|
22
|
+
.wrap_struct_name = "SFML::VertexArray",
|
|
23
|
+
.function = {.dmark = NULL, .dfree = VertexArray_free, .dsize = NULL},
|
|
24
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
static VALUE VertexArray_wrap(VALUE klass, sfVertexArray *array) {
|
|
28
|
+
if (array == NULL) {
|
|
29
|
+
rb_raise(rb_eRuntimeError, "failed to create vertex array");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return TypedData_Wrap_Struct(klass, &VertexArray_data_type, array);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static sfVertexArray *Get_VertexArray_Struct(VALUE self) {
|
|
36
|
+
sfVertexArray *ptr;
|
|
37
|
+
TypedData_Get_Struct(self, sfVertexArray, &VertexArray_data_type, ptr);
|
|
38
|
+
return ptr;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static VALUE VertexArray_new(VALUE klass) {
|
|
42
|
+
return VertexArray_wrap(klass, sfVertexArray_create());
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static VALUE VertexArray_copy(VALUE self) {
|
|
46
|
+
return VertexArray_wrap(Get_Klass_VertexArray(), sfVertexArray_copy(Get_VertexArray_Struct(self)));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static VALUE VertexArray_get_vertex_count(VALUE self) {
|
|
50
|
+
return SIZET2NUM(sfVertexArray_getVertexCount(Get_VertexArray_Struct(self)));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static VALUE VertexArray_get_vertex(VALUE self, VALUE rb_index) {
|
|
54
|
+
return vertex_to_rb(*sfVertexArray_getVertex(Get_VertexArray_Struct(self), (size_t) NUM2SIZET(rb_index)));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static VALUE VertexArray_set_vertex(VALUE self, VALUE rb_index, VALUE rb_vertex) {
|
|
58
|
+
*sfVertexArray_getVertex(Get_VertexArray_Struct(self), (size_t) NUM2SIZET(rb_index)) = vertex_from_rb(rb_vertex);
|
|
59
|
+
return rb_vertex;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static VALUE VertexArray_append(VALUE self, VALUE rb_vertex) {
|
|
63
|
+
sfVertexArray_append(Get_VertexArray_Struct(self), vertex_from_rb(rb_vertex));
|
|
64
|
+
return self;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static VALUE VertexArray_clear(VALUE self) {
|
|
68
|
+
sfVertexArray_clear(Get_VertexArray_Struct(self));
|
|
69
|
+
return self;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static VALUE VertexArray_resize(VALUE self, VALUE rb_count) {
|
|
73
|
+
sfVertexArray_resize(Get_VertexArray_Struct(self), (size_t) NUM2SIZET(rb_count));
|
|
74
|
+
return self;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static VALUE VertexArray_get_primitive_type(VALUE self) {
|
|
78
|
+
return ID2SYM(rb_intern(primitive_type_name(sfVertexArray_getPrimitiveType(Get_VertexArray_Struct(self)))));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
static VALUE VertexArray_set_primitive_type(VALUE self, VALUE rb_type) {
|
|
82
|
+
sfVertexArray_setPrimitiveType(Get_VertexArray_Struct(self), primitive_type_from_rb(rb_type));
|
|
83
|
+
return rb_type;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
static VALUE VertexArray_get_bounds(VALUE self) {
|
|
87
|
+
return rect_to_rb(sfVertexArray_getBounds(Get_VertexArray_Struct(self)));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
static VALUE VertexArray_draw(VALUE self, VALUE rb_target, VALUE rb_state) {
|
|
91
|
+
if (!rb_obj_is_kind_of(rb_target, Get_Klass_Target())) {
|
|
92
|
+
raise_invalid_argument_class(Get_Klass_Target());
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (!rb_obj_is_kind_of(rb_state, Get_Klass_RenderState())) {
|
|
96
|
+
raise_invalid_argument_class(Get_Klass_RenderState());
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
TARGET_DRAW(Get_Target_Struct(rb_target), sfRenderWindow_drawVertexArray, sfRenderTexture_drawVertexArray,
|
|
100
|
+
Get_VertexArray_Struct(self), Get_RenderState_Struct(rb_state));
|
|
101
|
+
|
|
102
|
+
return Qnil;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
void Init_VertexArray(VALUE rb_module) {
|
|
106
|
+
rb_cVertexArray = rb_define_class_under(rb_module, "VertexArray", rb_cObject);
|
|
107
|
+
|
|
108
|
+
rb_include_module(rb_cVertexArray, Get_Module_Drawable());
|
|
109
|
+
|
|
110
|
+
rb_define_singleton_method(rb_cVertexArray, "new", VertexArray_new, 0);
|
|
111
|
+
|
|
112
|
+
rb_define_method(rb_cVertexArray, "copy", VertexArray_copy, 0);
|
|
113
|
+
rb_define_method(rb_cVertexArray, "vertex_count", VertexArray_get_vertex_count, 0);
|
|
114
|
+
rb_define_method(rb_cVertexArray, "vertex", VertexArray_get_vertex, 1);
|
|
115
|
+
rb_define_method(rb_cVertexArray, "set_vertex", VertexArray_set_vertex, 2);
|
|
116
|
+
rb_define_method(rb_cVertexArray, "append", VertexArray_append, 1);
|
|
117
|
+
rb_define_method(rb_cVertexArray, "clear!", VertexArray_clear, 0);
|
|
118
|
+
rb_define_method(rb_cVertexArray, "resize", VertexArray_resize, 1);
|
|
119
|
+
rb_define_method(rb_cVertexArray, "primitive", VertexArray_get_primitive_type, 0);
|
|
120
|
+
rb_define_method(rb_cVertexArray, "primitive=", VertexArray_set_primitive_type, 1);
|
|
121
|
+
rb_define_method(rb_cVertexArray, "bounds", VertexArray_get_bounds, 0);
|
|
122
|
+
rb_define_method(rb_cVertexArray, "draw", VertexArray_draw, 2);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
VALUE Get_Klass_VertexArray(void) {
|
|
126
|
+
return rb_cVertexArray;
|
|
127
|
+
}
|