sfml3-rb 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -0
- data/README.md +36 -13
- data/TODO.md +18 -11
- data/ext/audio/music.c +6 -0
- data/ext/audio/sound.c +43 -4
- data/ext/audio/sound_buffer.c +8 -0
- data/ext/audio/sound_buffer_recorder.c +8 -3
- data/ext/audio/sound_recorder.c +21 -11
- data/ext/audio/sound_source_cone.c +18 -3
- data/ext/audio/sound_stream.c +25 -15
- data/ext/ext.c +4 -0
- data/ext/graphics/blend_mode.c +16 -8
- data/ext/graphics/circle.c +30 -13
- data/ext/graphics/color.c +17 -8
- data/ext/graphics/drawable.c +3 -2
- data/ext/graphics/font.c +6 -0
- data/ext/graphics/glyph.c +7 -0
- data/ext/graphics/image.c +25 -4
- data/ext/graphics/polygon.c +31 -11
- data/ext/graphics/rect.c +16 -8
- data/ext/graphics/rectangle.c +30 -11
- data/ext/graphics/render_state.c +8 -10
- data/ext/graphics/render_texture.c +27 -11
- data/ext/graphics/render_window.c +55 -0
- data/ext/graphics/render_window.h +10 -0
- data/ext/graphics/shader.c +6 -0
- data/ext/graphics/shape.c +23 -16
- data/ext/graphics/sprite.c +34 -10
- data/ext/graphics/stencil_mode.c +16 -8
- data/ext/graphics/target.c +60 -27
- data/ext/graphics/target.h +22 -8
- data/ext/graphics/text.c +33 -13
- data/ext/graphics/texture.c +34 -3
- data/ext/graphics/transformable.c +11 -20
- data/ext/graphics/vertex.c +18 -3
- data/ext/graphics/vertex_array.c +18 -9
- data/ext/graphics/vertex_buffer.c +30 -10
- data/ext/graphics/view.c +16 -10
- data/ext/network/ftp.c +30 -3
- data/ext/network/http.c +23 -6
- data/ext/network/ip_address.c +25 -14
- data/ext/network/packet.c +8 -3
- data/ext/network/socket_selector.c +8 -3
- data/ext/network/tcp_listener.c +8 -3
- data/ext/network/tcp_socket.c +8 -3
- data/ext/network/udp_socket.c +8 -3
- data/ext/system/buffer.c +13 -11
- data/ext/system/clock.c +11 -5
- data/ext/system/input_stream.c +21 -11
- data/ext/system/time.c +17 -13
- data/ext/system/vec2.c +17 -11
- data/ext/system/vec3.c +18 -11
- data/ext/window/context.c +14 -11
- data/ext/window/context_settings.c +16 -4
- data/ext/window/cursor.c +6 -0
- data/ext/window/event.c +15 -25
- data/ext/window/mouse.c +28 -11
- data/ext/window/touch.c +12 -10
- data/ext/window/video_mode.c +16 -25
- data/ext/window/window.c +110 -435
- data/ext/window/window.h +4 -4
- data/ext/window/window_base.c +251 -0
- data/ext/window/window_base.h +43 -0
- data/ext/window/window_base.inc +236 -0
- data/lib/sfml/version.rb +1 -1
- data/sig/audio/sound.rbs +1 -1
- data/sig/audio/sound_buffer_recorder.rbs +1 -1
- data/sig/audio/sound_recorder.rbs +1 -1
- data/sig/audio/sound_source_cone.rbs +1 -1
- data/sig/audio/sound_stream.rbs +1 -1
- data/sig/graphics/blend_mode.rbs +1 -1
- data/sig/graphics/circle.rbs +1 -1
- data/sig/graphics/color.rbs +5 -5
- data/sig/graphics/image.rbs +1 -1
- data/sig/graphics/polygon.rbs +1 -1
- data/sig/graphics/rect.rbs +5 -5
- data/sig/graphics/rectangle.rbs +1 -1
- data/sig/graphics/render_state.rbs +2 -2
- data/sig/graphics/render_target.rbs +18 -0
- data/sig/graphics/render_texture.rbs +4 -2
- data/sig/graphics/render_window.rbs +7 -0
- data/sig/graphics/shape.rbs +1 -1
- data/sig/graphics/sprite.rbs +2 -2
- data/sig/graphics/stencil_mode.rbs +2 -2
- data/sig/graphics/target.rbs +1 -3
- data/sig/graphics/text.rbs +4 -4
- data/sig/graphics/texture.rbs +1 -1
- data/sig/graphics/transformable.rbs +1 -1
- data/sig/graphics/vertex.rbs +4 -4
- data/sig/graphics/vertex_array.rbs +1 -1
- data/sig/graphics/vertex_buffer.rbs +4 -4
- data/sig/graphics/view.rbs +0 -1
- data/sig/network/ftp.rbs +1 -1
- data/sig/network/http.rbs +2 -2
- data/sig/network/ip_address.rbs +1 -1
- data/sig/network/packet.rbs +1 -1
- data/sig/network/socket_selector.rbs +1 -1
- data/sig/network/tcp_listener.rbs +1 -1
- data/sig/network/tcp_socket.rbs +1 -1
- data/sig/network/udp_socket.rbs +1 -1
- data/sig/sfml/version.rbs +3 -0
- data/sig/system/buffer.rbs +1 -1
- data/sig/system/clock.rbs +1 -1
- data/sig/system/input_stream.rbs +1 -1
- data/sig/system/time.rbs +4 -4
- data/sig/system/vec2.rbs +4 -4
- data/sig/system/vec3.rbs +4 -4
- data/sig/window/context.rbs +1 -1
- data/sig/window/context_settings.rbs +1 -1
- data/sig/window/event.rbs +1 -1
- data/sig/window/mouse.rbs +2 -2
- data/sig/window/touch.rbs +1 -1
- data/sig/window/video_mode.rbs +1 -1
- data/sig/window/window.rbs +2 -25
- data/sig/window/window_base.rbs +33 -0
- metadata +11 -2
data/ext/graphics/circle.c
CHANGED
|
@@ -61,6 +61,27 @@ static VALUE Circle_wrap(VALUE klass, sfCircleShape* shape) {
|
|
|
61
61
|
return TypedData_Wrap_Struct(klass, &Circle_data_type, ptr);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
static VALUE Circle_alloc(VALUE klass) {
|
|
65
|
+
Circle* ptr = malloc(sizeof(Circle));
|
|
66
|
+
sfCircleShape* shape;
|
|
67
|
+
|
|
68
|
+
if (ptr == NULL) {
|
|
69
|
+
rb_raise(rb_eNoMemError, "failed to allocate circle shape");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
shape = sfCircleShape_create();
|
|
73
|
+
|
|
74
|
+
if (shape == NULL) {
|
|
75
|
+
free(ptr);
|
|
76
|
+
rb_raise(rb_eRuntimeError, "failed to create circle shape");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
ptr->shape = shape;
|
|
80
|
+
ptr->rb_texture = Qnil;
|
|
81
|
+
|
|
82
|
+
return TypedData_Wrap_Struct(klass, &Circle_data_type, ptr);
|
|
83
|
+
}
|
|
84
|
+
|
|
64
85
|
/* call-seq:
|
|
65
86
|
* Circle.new(radius = 0) -> Circle
|
|
66
87
|
*
|
|
@@ -68,19 +89,16 @@ static VALUE Circle_wrap(VALUE klass, sfCircleShape* shape) {
|
|
|
68
89
|
*
|
|
69
90
|
* @return [Circle]
|
|
70
91
|
*/
|
|
71
|
-
static VALUE
|
|
92
|
+
static VALUE Circle_initialize(int argc, VALUE* argv, VALUE self) {
|
|
72
93
|
VALUE rb_radius;
|
|
73
|
-
sfCircleShape* shape;
|
|
74
94
|
|
|
75
95
|
rb_scan_args(argc, argv, "01", &rb_radius);
|
|
76
96
|
|
|
77
|
-
shape = sfCircleShape_create();
|
|
78
|
-
|
|
79
97
|
if (!NIL_P(rb_radius)) {
|
|
80
|
-
sfCircleShape_setRadius(
|
|
98
|
+
sfCircleShape_setRadius(Get_Circle_Shape(self), NUM2DBL(rb_radius));
|
|
81
99
|
}
|
|
82
100
|
|
|
83
|
-
return
|
|
101
|
+
return self;
|
|
84
102
|
}
|
|
85
103
|
|
|
86
104
|
/* call-seq: copy -> Circle
|
|
@@ -465,17 +483,14 @@ static VALUE Circle_get_global_bounds(VALUE self) {
|
|
|
465
483
|
* @return [nil]
|
|
466
484
|
*/
|
|
467
485
|
static VALUE Circle_draw(VALUE self, VALUE rb_target, VALUE rb_state) {
|
|
468
|
-
|
|
469
|
-
raise_invalid_argument_class(Get_Klass_Target());
|
|
470
|
-
}
|
|
486
|
+
TargetView view = Get_RenderTarget_View(rb_target);
|
|
471
487
|
|
|
472
488
|
if (!rb_obj_is_kind_of(rb_state, Get_Klass_RenderState())) {
|
|
473
489
|
raise_invalid_argument_class(Get_Klass_RenderState());
|
|
474
490
|
}
|
|
475
491
|
|
|
476
|
-
TARGET_DRAW(
|
|
477
|
-
|
|
478
|
-
Get_RenderState_Struct(rb_state));
|
|
492
|
+
TARGET_DRAW(view, sfRenderWindow_drawCircleShape, sfRenderTexture_drawCircleShape,
|
|
493
|
+
Get_Circle_Shape(self), Get_RenderState_Struct(rb_state));
|
|
479
494
|
|
|
480
495
|
return Qnil;
|
|
481
496
|
}
|
|
@@ -532,9 +547,11 @@ static VALUE Circle_draw(VALUE self, VALUE rb_target, VALUE rb_state) {
|
|
|
532
547
|
void Init_Circle(VALUE rb_mSFML) {
|
|
533
548
|
rb_cCircle = rb_define_class_under(rb_mSFML, "Circle", rb_cObject);
|
|
534
549
|
|
|
550
|
+
rb_define_alloc_func(rb_cCircle, Circle_alloc);
|
|
551
|
+
|
|
535
552
|
rb_include_module(rb_cCircle, Get_Module_Drawable());
|
|
536
553
|
|
|
537
|
-
|
|
554
|
+
rb_define_method(rb_cCircle, "initialize", Circle_initialize, -1);
|
|
538
555
|
|
|
539
556
|
// methods
|
|
540
557
|
rb_define_method(rb_cCircle, "copy", Circle_copy, 0);
|
data/ext/graphics/color.c
CHANGED
|
@@ -54,6 +54,18 @@ static sfColor Color_from_integer(VALUE rb_integer) {
|
|
|
54
54
|
(unsigned char)((value >> 8) & 0xFF), (unsigned char)(value & 0xFF)};
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
static VALUE Color_alloc(VALUE klass) {
|
|
58
|
+
Color* ptr = malloc(sizeof(Color));
|
|
59
|
+
|
|
60
|
+
if (ptr == NULL) {
|
|
61
|
+
rb_raise(rb_eNoMemError, "failed to allocate color");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
ptr->color = (sfColor){0, 0, 0, 255};
|
|
65
|
+
|
|
66
|
+
return TypedData_Wrap_Struct(klass, &Color_data_type, ptr);
|
|
67
|
+
}
|
|
68
|
+
|
|
57
69
|
/* call-seq:
|
|
58
70
|
* Color.new -> Color(0, 0, 0, 255)
|
|
59
71
|
* Color.new(r, g, b, a=255) -> Color(r, g, b, a)
|
|
@@ -70,9 +82,7 @@ static sfColor Color_from_integer(VALUE rb_integer) {
|
|
|
70
82
|
* @raise [ArgumentError] if given an Array shorter than 3 elements, or an
|
|
71
83
|
* argument count other than 0, 1, 3 or 4
|
|
72
84
|
*/
|
|
73
|
-
static VALUE
|
|
74
|
-
VALUE self;
|
|
75
|
-
Color* ptr;
|
|
85
|
+
static VALUE Color_initialize(int argc, VALUE* argv, VALUE self) {
|
|
76
86
|
sfColor color = {0, 0, 0, 255};
|
|
77
87
|
|
|
78
88
|
if (argc == 1 && rb_obj_is_kind_of(argv[0], rb_cColor)) {
|
|
@@ -90,10 +100,7 @@ static VALUE Color_new(int argc, VALUE* argv, VALUE klass) {
|
|
|
90
100
|
raise_invalid_arguments_excepted(4, argc);
|
|
91
101
|
}
|
|
92
102
|
|
|
93
|
-
|
|
94
|
-
ptr->color = color;
|
|
95
|
-
|
|
96
|
-
self = TypedData_Wrap_Struct(klass, &Color_data_type, ptr);
|
|
103
|
+
((Color*)Get_Color_Struct(self))->color = color;
|
|
97
104
|
|
|
98
105
|
return self;
|
|
99
106
|
}
|
|
@@ -344,7 +351,9 @@ static VALUE Color_to_s(VALUE self) {
|
|
|
344
351
|
void Init_Color(VALUE rb_mSFML) {
|
|
345
352
|
rb_cColor = rb_define_class_under(rb_mSFML, "Color", rb_cObject);
|
|
346
353
|
|
|
347
|
-
|
|
354
|
+
rb_define_alloc_func(rb_cColor, Color_alloc);
|
|
355
|
+
rb_define_method(rb_cColor, "initialize", Color_initialize, -1);
|
|
356
|
+
|
|
348
357
|
rb_define_singleton_method(rb_cColor, "from_rgb", Color_from_rgb, 1);
|
|
349
358
|
rb_define_singleton_method(rb_cColor, "from_rgba", Color_from_rgba, 1);
|
|
350
359
|
|
data/ext/graphics/drawable.c
CHANGED
|
@@ -36,8 +36,9 @@ static VALUE Drawable_draw(VALUE self, VALUE rb_target, VALUE rb_state) {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/* Document-module: SFML::Drawable
|
|
39
|
-
* A mixin for anything that can be drawn to a render target (
|
|
40
|
-
* RenderTexture
|
|
39
|
+
* A mixin for anything that can be drawn to a render target (RenderWindow,
|
|
40
|
+
* RenderTexture -- both include RenderTarget -- or a legacy Target) via
|
|
41
|
+
* #draw(target, state).
|
|
41
42
|
*/
|
|
42
43
|
void Init_Drawable(VALUE rb_mSFML) {
|
|
43
44
|
rb_mDrawable = rb_define_module_under(rb_mSFML, "Drawable");
|
data/ext/graphics/font.c
CHANGED
|
@@ -225,12 +225,18 @@ static VALUE Font_get_info(VALUE self) {
|
|
|
225
225
|
return rb_str_new_cstr(info.family != NULL ? info.family : "");
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
+
static VALUE Font_alloc(VALUE klass) {
|
|
229
|
+
(void)klass;
|
|
230
|
+
rb_raise(rb_eNotImpError, "use Font.from_file, Font.from_memory or Font.from_stream");
|
|
231
|
+
}
|
|
232
|
+
|
|
228
233
|
/* Document-class: SFML::Font
|
|
229
234
|
* A font face used to render text, loaded from a file, memory buffer or
|
|
230
235
|
* stream. Glyphs are rasterized and cached lazily per character size.
|
|
231
236
|
*/
|
|
232
237
|
void Init_Font(VALUE rb_mSFML) {
|
|
233
238
|
rb_cFont = rb_define_class_under(rb_mSFML, "Font", rb_cObject);
|
|
239
|
+
rb_define_alloc_func(rb_cFont, Font_alloc);
|
|
234
240
|
|
|
235
241
|
rb_define_singleton_method(rb_cFont, "from_file", Font_from_file, 1);
|
|
236
242
|
rb_define_singleton_method(rb_cFont, "from_memory", Font_from_memory, 1);
|
data/ext/graphics/glyph.c
CHANGED
|
@@ -66,12 +66,19 @@ static VALUE Glyph_get_texture_rect(VALUE self) {
|
|
|
66
66
|
return int_rect_to_rb(Get_Glyph(self)->glyph.textureRect);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
static VALUE Glyph_alloc(VALUE klass) {
|
|
70
|
+
(void)klass;
|
|
71
|
+
rb_raise(rb_eNotImpError,
|
|
72
|
+
"glyph objects are returned by Font#glyph and cannot be constructed directly");
|
|
73
|
+
}
|
|
74
|
+
|
|
69
75
|
/* Document-class: SFML::Glyph
|
|
70
76
|
* A single character's rendering metrics and texture location, as returned
|
|
71
77
|
* by Font#glyph. Read-only.
|
|
72
78
|
*/
|
|
73
79
|
void Init_Glyph(VALUE rb_mSFML) {
|
|
74
80
|
rb_cGlyph = rb_define_class_under(rb_mSFML, "Glyph", rb_cObject);
|
|
81
|
+
rb_define_alloc_func(rb_cGlyph, Glyph_alloc);
|
|
75
82
|
|
|
76
83
|
rb_define_method(rb_cGlyph, "advance", Glyph_get_advance, 0);
|
|
77
84
|
rb_define_method(rb_cGlyph, "bounds", Glyph_get_bounds, 0);
|
data/ext/graphics/image.c
CHANGED
|
@@ -15,7 +15,9 @@
|
|
|
15
15
|
static VALUE rb_cImage;
|
|
16
16
|
|
|
17
17
|
static void Image_free(void* ptr) {
|
|
18
|
-
|
|
18
|
+
if (ptr != NULL) {
|
|
19
|
+
sfImage_destroy(ptr);
|
|
20
|
+
}
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
static const rb_data_type_t Image_data_type = {
|
|
@@ -31,6 +33,15 @@ static VALUE Image_wrap(VALUE klass, sfImage* image) {
|
|
|
31
33
|
return TypedData_Wrap_Struct(klass, &Image_data_type, image);
|
|
32
34
|
}
|
|
33
35
|
|
|
36
|
+
static VALUE Image_initialize_copy(VALUE self, VALUE other) {
|
|
37
|
+
(void)other;
|
|
38
|
+
rb_raise(rb_eTypeError, "can't copy a %s", rb_obj_classname(self));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static VALUE Image_alloc(VALUE klass) {
|
|
42
|
+
return TypedData_Wrap_Struct(klass, &Image_data_type, NULL);
|
|
43
|
+
}
|
|
44
|
+
|
|
34
45
|
/* call-seq:
|
|
35
46
|
* Image.new(size) -> Image
|
|
36
47
|
*
|
|
@@ -40,8 +51,16 @@ static VALUE Image_wrap(VALUE klass, sfImage* image) {
|
|
|
40
51
|
* @return [Image]
|
|
41
52
|
* @raise [RuntimeError] if the image cannot be created
|
|
42
53
|
*/
|
|
43
|
-
static VALUE
|
|
44
|
-
|
|
54
|
+
static VALUE Image_initialize(VALUE self, VALUE rb_size) {
|
|
55
|
+
sfImage* image = sfImage_create(vec2u_from_rb(rb_size));
|
|
56
|
+
|
|
57
|
+
if (image == NULL) {
|
|
58
|
+
rb_raise(rb_eRuntimeError, "failed to create image");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
DATA_PTR(self) = image;
|
|
62
|
+
|
|
63
|
+
return self;
|
|
45
64
|
}
|
|
46
65
|
|
|
47
66
|
/* call-seq:
|
|
@@ -313,7 +332,9 @@ static VALUE Image_flip_vertically(VALUE self) {
|
|
|
313
332
|
void Init_Image(VALUE rb_mSFML) {
|
|
314
333
|
rb_cImage = rb_define_class_under(rb_mSFML, "Image", rb_cObject);
|
|
315
334
|
|
|
316
|
-
|
|
335
|
+
rb_define_alloc_func(rb_cImage, Image_alloc);
|
|
336
|
+
rb_define_method(rb_cImage, "initialize", Image_initialize, 1);
|
|
337
|
+
rb_define_private_method(rb_cImage, "initialize_copy", Image_initialize_copy, 1);
|
|
317
338
|
rb_define_singleton_method(rb_cImage, "from_color", Image_from_color, 2);
|
|
318
339
|
rb_define_singleton_method(rb_cImage, "from_pixels", Image_from_pixels, 2);
|
|
319
340
|
rb_define_singleton_method(rb_cImage, "from_file", Image_from_file, 1);
|
data/ext/graphics/polygon.c
CHANGED
|
@@ -59,6 +59,27 @@ static VALUE ConvexShape_wrap(VALUE klass, sfConvexShape* shape) {
|
|
|
59
59
|
return TypedData_Wrap_Struct(klass, &ConvexShape_data_type, ptr);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
static VALUE ConvexShape_alloc(VALUE klass) {
|
|
63
|
+
ConvexShape* ptr = malloc(sizeof(ConvexShape));
|
|
64
|
+
sfConvexShape* shape;
|
|
65
|
+
|
|
66
|
+
if (ptr == NULL) {
|
|
67
|
+
rb_raise(rb_eNoMemError, "failed to allocate convex shape");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
shape = sfConvexShape_create();
|
|
71
|
+
|
|
72
|
+
if (shape == NULL) {
|
|
73
|
+
free(ptr);
|
|
74
|
+
rb_raise(rb_eRuntimeError, "failed to create convex shape");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
ptr->shape = shape;
|
|
78
|
+
ptr->rb_texture = Qnil;
|
|
79
|
+
|
|
80
|
+
return TypedData_Wrap_Struct(klass, &ConvexShape_data_type, ptr);
|
|
81
|
+
}
|
|
82
|
+
|
|
62
83
|
/* call-seq:
|
|
63
84
|
* ConvexShape.new(point_count = 0) -> ConvexShape
|
|
64
85
|
*
|
|
@@ -66,17 +87,17 @@ static VALUE ConvexShape_wrap(VALUE klass, sfConvexShape* shape) {
|
|
|
66
87
|
*
|
|
67
88
|
* @return [ConvexShape]
|
|
68
89
|
*/
|
|
69
|
-
static VALUE
|
|
70
|
-
sfConvexShape* shape = sfConvexShape_create();
|
|
90
|
+
static VALUE ConvexShape_initialize(int argc, VALUE* argv, VALUE self) {
|
|
71
91
|
VALUE rb_point_count;
|
|
72
92
|
|
|
73
93
|
rb_scan_args(argc, argv, "01", &rb_point_count);
|
|
74
94
|
|
|
75
95
|
if (!NIL_P(rb_point_count)) {
|
|
76
|
-
sfConvexShape_setPointCount(
|
|
96
|
+
sfConvexShape_setPointCount(Get_ConvexShape_Struct(self),
|
|
97
|
+
(size_t)NUM2SIZET(rb_point_count));
|
|
77
98
|
}
|
|
78
99
|
|
|
79
|
-
return
|
|
100
|
+
return self;
|
|
80
101
|
}
|
|
81
102
|
|
|
82
103
|
/* call-seq: copy -> ConvexShape
|
|
@@ -463,17 +484,14 @@ static VALUE ConvexShape_get_global_bounds(VALUE self) {
|
|
|
463
484
|
* @return [nil]
|
|
464
485
|
*/
|
|
465
486
|
static VALUE ConvexShape_draw(VALUE self, VALUE rb_target, VALUE rb_state) {
|
|
466
|
-
|
|
467
|
-
raise_invalid_argument_class(Get_Klass_Target());
|
|
468
|
-
}
|
|
487
|
+
TargetView view = Get_RenderTarget_View(rb_target);
|
|
469
488
|
|
|
470
489
|
if (!rb_obj_is_kind_of(rb_state, Get_Klass_RenderState())) {
|
|
471
490
|
raise_invalid_argument_class(Get_Klass_RenderState());
|
|
472
491
|
}
|
|
473
492
|
|
|
474
|
-
TARGET_DRAW(
|
|
475
|
-
|
|
476
|
-
Get_RenderState_Struct(rb_state));
|
|
493
|
+
TARGET_DRAW(view, sfRenderWindow_drawConvexShape, sfRenderTexture_drawConvexShape,
|
|
494
|
+
Get_ConvexShape_Struct(self), Get_RenderState_Struct(rb_state));
|
|
477
495
|
|
|
478
496
|
return Qnil;
|
|
479
497
|
}
|
|
@@ -520,9 +538,11 @@ static VALUE ConvexShape_draw(VALUE self, VALUE rb_target, VALUE rb_state) {
|
|
|
520
538
|
void Init_ConvexShape(VALUE rb_mSFML) {
|
|
521
539
|
rb_cConvexShape = rb_define_class_under(rb_mSFML, "ConvexShape", rb_cObject);
|
|
522
540
|
|
|
541
|
+
rb_define_alloc_func(rb_cConvexShape, ConvexShape_alloc);
|
|
542
|
+
|
|
523
543
|
rb_include_module(rb_cConvexShape, Get_Module_Drawable());
|
|
524
544
|
|
|
525
|
-
|
|
545
|
+
rb_define_method(rb_cConvexShape, "initialize", ConvexShape_initialize, -1);
|
|
526
546
|
|
|
527
547
|
rb_define_method(rb_cConvexShape, "copy", ConvexShape_copy, 0);
|
|
528
548
|
|
data/ext/graphics/rect.c
CHANGED
|
@@ -30,6 +30,18 @@ static VALUE Rect_wrap(sfFloatRect rect) {
|
|
|
30
30
|
return TypedData_Wrap_Struct(rb_cRect, &Rect_data_type, ptr);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
static VALUE Rect_alloc(VALUE klass) {
|
|
34
|
+
Rect* ptr = malloc(sizeof(Rect));
|
|
35
|
+
|
|
36
|
+
if (ptr == NULL) {
|
|
37
|
+
rb_raise(rb_eNoMemError, "failed to allocate rect");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
ptr->rect = (sfFloatRect){{0, 0}, {0, 0}};
|
|
41
|
+
|
|
42
|
+
return TypedData_Wrap_Struct(klass, &Rect_data_type, ptr);
|
|
43
|
+
}
|
|
44
|
+
|
|
33
45
|
/* call-seq:
|
|
34
46
|
* Rect.new -> Rect(0, 0, 0, 0)
|
|
35
47
|
* Rect.new(left, top) -> Rect(left, top, 0, 0)
|
|
@@ -44,9 +56,7 @@ static VALUE Rect_wrap(sfFloatRect rect) {
|
|
|
44
56
|
* @raise [ArgumentError] if given an Array shorter than 4 elements, or an
|
|
45
57
|
* argument count other than 0, 1, 2 or 4
|
|
46
58
|
*/
|
|
47
|
-
static VALUE
|
|
48
|
-
VALUE self;
|
|
49
|
-
Rect* ptr;
|
|
59
|
+
static VALUE Rect_initialize(int argc, VALUE* argv, VALUE self) {
|
|
50
60
|
sfFloatRect rect = {{0, 0}, {0, 0}};
|
|
51
61
|
|
|
52
62
|
if (argc == 1 && rb_obj_is_kind_of(argv[0], rb_cRect)) {
|
|
@@ -62,10 +72,7 @@ static VALUE Rect_new(int argc, VALUE* argv, VALUE klass) {
|
|
|
62
72
|
raise_invalid_arguments_excepted(4, argc);
|
|
63
73
|
}
|
|
64
74
|
|
|
65
|
-
|
|
66
|
-
ptr->rect = rect;
|
|
67
|
-
|
|
68
|
-
self = TypedData_Wrap_Struct(klass, &Rect_data_type, ptr);
|
|
75
|
+
((Rect*)Get_Rect_Struct(self))->rect = rect;
|
|
69
76
|
|
|
70
77
|
return self;
|
|
71
78
|
}
|
|
@@ -362,7 +369,8 @@ void Init_Rect(VALUE rb_mSFML) {
|
|
|
362
369
|
|
|
363
370
|
rb_include_module(rb_cRect, rb_mEnumerable);
|
|
364
371
|
|
|
365
|
-
|
|
372
|
+
rb_define_alloc_func(rb_cRect, Rect_alloc);
|
|
373
|
+
rb_define_method(rb_cRect, "initialize", Rect_initialize, -1);
|
|
366
374
|
|
|
367
375
|
rb_define_method(rb_cRect, "left", Rect_get_left, 0);
|
|
368
376
|
rb_define_method(rb_cRect, "top", Rect_get_top, 0);
|
data/ext/graphics/rectangle.c
CHANGED
|
@@ -60,6 +60,27 @@ static VALUE RectangleShape_wrap(VALUE klass, sfRectangleShape* shape) {
|
|
|
60
60
|
return TypedData_Wrap_Struct(klass, &RectangleShape_data_type, ptr);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
static VALUE RectangleShape_alloc(VALUE klass) {
|
|
64
|
+
RectangleShape* ptr = malloc(sizeof(RectangleShape));
|
|
65
|
+
sfRectangleShape* shape;
|
|
66
|
+
|
|
67
|
+
if (ptr == NULL) {
|
|
68
|
+
rb_raise(rb_eNoMemError, "failed to allocate rectangle shape");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
shape = sfRectangleShape_create();
|
|
72
|
+
|
|
73
|
+
if (shape == NULL) {
|
|
74
|
+
free(ptr);
|
|
75
|
+
rb_raise(rb_eRuntimeError, "failed to create rectangle shape");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
ptr->shape = shape;
|
|
79
|
+
ptr->rb_texture = Qnil;
|
|
80
|
+
|
|
81
|
+
return TypedData_Wrap_Struct(klass, &RectangleShape_data_type, ptr);
|
|
82
|
+
}
|
|
83
|
+
|
|
63
84
|
/* call-seq:
|
|
64
85
|
* RectangleShape.new(size = Vector2.new(0, 0)) -> RectangleShape
|
|
65
86
|
*
|
|
@@ -67,17 +88,16 @@ static VALUE RectangleShape_wrap(VALUE klass, sfRectangleShape* shape) {
|
|
|
67
88
|
*
|
|
68
89
|
* @return [RectangleShape]
|
|
69
90
|
*/
|
|
70
|
-
static VALUE
|
|
71
|
-
sfRectangleShape* shape = sfRectangleShape_create();
|
|
91
|
+
static VALUE RectangleShape_initialize(int argc, VALUE* argv, VALUE self) {
|
|
72
92
|
VALUE rb_size;
|
|
73
93
|
|
|
74
94
|
rb_scan_args(argc, argv, "01", &rb_size);
|
|
75
95
|
|
|
76
96
|
if (!NIL_P(rb_size)) {
|
|
77
|
-
sfRectangleShape_setSize(
|
|
97
|
+
sfRectangleShape_setSize(Get_RectangleShape_Struct(self), vec2f_from_rb(rb_size));
|
|
78
98
|
}
|
|
79
99
|
|
|
80
|
-
return
|
|
100
|
+
return self;
|
|
81
101
|
}
|
|
82
102
|
|
|
83
103
|
/* call-seq: copy -> RectangleShape
|
|
@@ -451,17 +471,14 @@ static VALUE RectangleShape_get_global_bounds(VALUE self) {
|
|
|
451
471
|
* @return [nil]
|
|
452
472
|
*/
|
|
453
473
|
static VALUE RectangleShape_draw(VALUE self, VALUE rb_target, VALUE rb_state) {
|
|
454
|
-
|
|
455
|
-
raise_invalid_argument_class(Get_Klass_Target());
|
|
456
|
-
}
|
|
474
|
+
TargetView view = Get_RenderTarget_View(rb_target);
|
|
457
475
|
|
|
458
476
|
if (!rb_obj_is_kind_of(rb_state, Get_Klass_RenderState())) {
|
|
459
477
|
raise_invalid_argument_class(Get_Klass_RenderState());
|
|
460
478
|
}
|
|
461
479
|
|
|
462
|
-
TARGET_DRAW(
|
|
463
|
-
|
|
464
|
-
Get_RenderState_Struct(rb_state));
|
|
480
|
+
TARGET_DRAW(view, sfRenderWindow_drawRectangleShape, sfRenderTexture_drawRectangleShape,
|
|
481
|
+
Get_RectangleShape_Struct(self), Get_RenderState_Struct(rb_state));
|
|
465
482
|
|
|
466
483
|
return Qnil;
|
|
467
484
|
}
|
|
@@ -504,9 +521,11 @@ static VALUE RectangleShape_draw(VALUE self, VALUE rb_target, VALUE rb_state) {
|
|
|
504
521
|
void Init_RectangleShape(VALUE rb_mSFML) {
|
|
505
522
|
rb_cRectangleShape = rb_define_class_under(rb_mSFML, "RectangleShape", rb_cObject);
|
|
506
523
|
|
|
524
|
+
rb_define_alloc_func(rb_cRectangleShape, RectangleShape_alloc);
|
|
525
|
+
|
|
507
526
|
rb_include_module(rb_cRectangleShape, Get_Module_Drawable());
|
|
508
527
|
|
|
509
|
-
|
|
528
|
+
rb_define_method(rb_cRectangleShape, "initialize", RectangleShape_initialize, -1);
|
|
510
529
|
|
|
511
530
|
rb_define_method(rb_cRectangleShape, "copy", RectangleShape_copy, 0);
|
|
512
531
|
|
data/ext/graphics/render_state.c
CHANGED
|
@@ -56,6 +56,10 @@ static VALUE RenderStates_wrap(VALUE klass, RenderStates* states) {
|
|
|
56
56
|
return TypedData_Wrap_Struct(klass, &RenderStates_data_type, states);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
static VALUE RenderStates_alloc(VALUE klass) {
|
|
60
|
+
return RenderStates_wrap(klass, RenderStates_create());
|
|
61
|
+
}
|
|
62
|
+
|
|
59
63
|
/* call-seq:
|
|
60
64
|
* RenderState.new -> RenderState
|
|
61
65
|
* RenderState.new(matrix) -> RenderState
|
|
@@ -67,22 +71,15 @@ static VALUE RenderStates_wrap(VALUE klass, RenderStates* states) {
|
|
|
67
71
|
* @return [RenderState]
|
|
68
72
|
* @raise [ArgumentError] if given more than one argument
|
|
69
73
|
*/
|
|
70
|
-
static VALUE
|
|
71
|
-
RenderStates* states;
|
|
72
|
-
VALUE self;
|
|
73
|
-
|
|
74
|
+
static VALUE RenderStates_initialize(int argc, VALUE* argv, VALUE self) {
|
|
74
75
|
if (argc > 1) {
|
|
75
76
|
raise_invalid_arguments_excepted(1, argc);
|
|
76
77
|
}
|
|
77
78
|
|
|
78
|
-
states = RenderStates_create();
|
|
79
|
-
|
|
80
79
|
if (argc == 1) {
|
|
81
|
-
|
|
80
|
+
Get_RenderState_Struct(self)->transform = Transform_ArrayToTransform(argv[0]);
|
|
82
81
|
}
|
|
83
82
|
|
|
84
|
-
self = RenderStates_wrap(klass, states);
|
|
85
|
-
|
|
86
83
|
return self;
|
|
87
84
|
}
|
|
88
85
|
|
|
@@ -282,7 +279,8 @@ static VALUE RenderStates_set_shader(VALUE self, VALUE rb_shader) {
|
|
|
282
279
|
void Init_RenderState(VALUE rb_mSFML) {
|
|
283
280
|
rb_cRenderState = rb_define_class_under(rb_mSFML, "RenderState", rb_cObject);
|
|
284
281
|
|
|
285
|
-
|
|
282
|
+
rb_define_alloc_func(rb_cRenderState, RenderStates_alloc);
|
|
283
|
+
rb_define_method(rb_cRenderState, "initialize", RenderStates_initialize, -1);
|
|
286
284
|
|
|
287
285
|
// setters
|
|
288
286
|
rb_define_method(rb_cRenderState, "transform=", RenderStates_set_transform, 1);
|
|
@@ -15,7 +15,9 @@
|
|
|
15
15
|
static VALUE rb_cRenderTexture;
|
|
16
16
|
|
|
17
17
|
static void RenderTexture_free(void* ptr) {
|
|
18
|
-
|
|
18
|
+
if (ptr != NULL) {
|
|
19
|
+
sfRenderTexture_destroy(ptr);
|
|
20
|
+
}
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
static const rb_data_type_t RenderTexture_data_type = {
|
|
@@ -29,12 +31,13 @@ sfRenderTexture* Get_RenderTexture_Struct(VALUE self) {
|
|
|
29
31
|
return ptr;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
static VALUE
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
static VALUE RenderTexture_initialize_copy(VALUE self, VALUE other) {
|
|
35
|
+
(void)other;
|
|
36
|
+
rb_raise(rb_eTypeError, "can't copy a %s", rb_obj_classname(self));
|
|
37
|
+
}
|
|
36
38
|
|
|
37
|
-
|
|
39
|
+
static VALUE RenderTexture_alloc(VALUE klass) {
|
|
40
|
+
return TypedData_Wrap_Struct(klass, &RenderTexture_data_type, NULL);
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
/* call-seq:
|
|
@@ -46,14 +49,23 @@ static VALUE RenderTexture_wrap(VALUE klass, sfRenderTexture* render_texture) {
|
|
|
46
49
|
* @return [RenderTexture]
|
|
47
50
|
* @raise [RuntimeError] if creation fails
|
|
48
51
|
*/
|
|
49
|
-
static VALUE
|
|
52
|
+
static VALUE RenderTexture_initialize(int argc, VALUE* argv, VALUE self) {
|
|
50
53
|
VALUE rb_size, rb_settings;
|
|
54
|
+
sfRenderTexture* render_texture;
|
|
51
55
|
|
|
52
56
|
rb_scan_args(argc, argv, "11", &rb_size, &rb_settings);
|
|
53
57
|
|
|
54
58
|
(void)rb_settings;
|
|
55
59
|
|
|
56
|
-
|
|
60
|
+
render_texture = sfRenderTexture_create(vec2u_from_rb(rb_size), NULL);
|
|
61
|
+
|
|
62
|
+
if (render_texture == NULL) {
|
|
63
|
+
rb_raise(rb_eRuntimeError, "failed to create render texture");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
DATA_PTR(self) = render_texture;
|
|
67
|
+
|
|
68
|
+
return self;
|
|
57
69
|
}
|
|
58
70
|
|
|
59
71
|
/* call-seq: size -> Vector2
|
|
@@ -239,8 +251,7 @@ static VALUE RenderTexture_draw(int argc, VALUE* argv, VALUE self) {
|
|
|
239
251
|
rb_drawable = argv[0];
|
|
240
252
|
rb_state = (argc == 2) ? argv[1] : Get_New_RenderState();
|
|
241
253
|
|
|
242
|
-
rb_funcall(
|
|
243
|
-
rb_state);
|
|
254
|
+
rb_funcall(rb_drawable, rb_intern("draw"), 2, self, rb_state);
|
|
244
255
|
|
|
245
256
|
return self;
|
|
246
257
|
}
|
|
@@ -314,7 +325,12 @@ static VALUE RenderTexture_maximum_antialiasing_level(VALUE klass) {
|
|
|
314
325
|
void Init_RenderTexture(VALUE rb_mSFML) {
|
|
315
326
|
rb_cRenderTexture = rb_define_class_under(rb_mSFML, "RenderTexture", rb_cObject);
|
|
316
327
|
|
|
317
|
-
|
|
328
|
+
rb_include_module(rb_cRenderTexture, Get_Module_RenderTarget());
|
|
329
|
+
|
|
330
|
+
rb_define_alloc_func(rb_cRenderTexture, RenderTexture_alloc);
|
|
331
|
+
rb_define_method(rb_cRenderTexture, "initialize", RenderTexture_initialize, -1);
|
|
332
|
+
rb_define_private_method(rb_cRenderTexture, "initialize_copy", RenderTexture_initialize_copy,
|
|
333
|
+
1);
|
|
318
334
|
rb_define_singleton_method(rb_cRenderTexture, "maximum_antialiasing_level",
|
|
319
335
|
RenderTexture_maximum_antialiasing_level, 0);
|
|
320
336
|
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#include "graphics/render_window.h"
|
|
2
|
+
|
|
3
|
+
#include <ruby.h>
|
|
4
|
+
|
|
5
|
+
#include "graphics/render_state.h"
|
|
6
|
+
#include "graphics/target.h"
|
|
7
|
+
#include "window/window.h"
|
|
8
|
+
#include "window/window_base.h"
|
|
9
|
+
#include "core/exceptions.h"
|
|
10
|
+
#include "core/macros.h"
|
|
11
|
+
|
|
12
|
+
static VALUE rb_cRenderWindow;
|
|
13
|
+
|
|
14
|
+
/* call-seq:
|
|
15
|
+
* draw(drawable, state = nil) -> self
|
|
16
|
+
*
|
|
17
|
+
* Draws +drawable+ into the window. Unlike Window#draw this hands +self+ to the
|
|
18
|
+
* drawable, because a RenderWindow is a RenderTarget.
|
|
19
|
+
*
|
|
20
|
+
* @return [self]
|
|
21
|
+
* @raise [ArgumentError] if given no arguments or more than 2
|
|
22
|
+
*/
|
|
23
|
+
static VALUE RenderWindow_draw(int argc, VALUE* argv, VALUE self) {
|
|
24
|
+
VALUE rb_drawable, rb_state;
|
|
25
|
+
|
|
26
|
+
if (argc == 0 || argc > 2) {
|
|
27
|
+
raise_invalid_arguments_excepted(-1, argc);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
rb_drawable = argv[0];
|
|
31
|
+
rb_state = (argc == 2) ? argv[1] : Get_New_RenderState();
|
|
32
|
+
|
|
33
|
+
rb_funcall(rb_drawable, rb_intern("draw"), 2, self, rb_state);
|
|
34
|
+
|
|
35
|
+
return self;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/* Document-class: SFML::RenderWindow
|
|
39
|
+
* A SFML::Window that is also a SFML::RenderTarget, so it can be handed
|
|
40
|
+
* directly to a drawable's #draw as well as drawn into with #draw. Creation,
|
|
41
|
+
* events and every window method come from Window (and WindowBase); the
|
|
42
|
+
* render-target surface is listed on SFML::RenderTarget.
|
|
43
|
+
*/
|
|
44
|
+
void Init_RenderWindow(VALUE rb_mSFML) {
|
|
45
|
+
rb_cRenderWindow = rb_define_class_under(rb_mSFML, "RenderWindow", Get_Klass_Window());
|
|
46
|
+
|
|
47
|
+
rb_define_alloc_func(rb_cRenderWindow, Window_alloc);
|
|
48
|
+
rb_define_method(rb_cRenderWindow, "draw", RenderWindow_draw, -1);
|
|
49
|
+
|
|
50
|
+
rb_include_module(rb_cRenderWindow, Get_Module_RenderTarget());
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
VALUE Get_Klass_RenderWindow(void) {
|
|
54
|
+
return rb_cRenderWindow;
|
|
55
|
+
}
|
data/ext/graphics/shader.c
CHANGED
|
@@ -728,6 +728,11 @@ static VALUE Shader_set_uniform(VALUE self, VALUE rb_name, VALUE rb_value) {
|
|
|
728
728
|
return self;
|
|
729
729
|
}
|
|
730
730
|
|
|
731
|
+
static VALUE Shader_alloc(VALUE klass) {
|
|
732
|
+
(void)klass;
|
|
733
|
+
rb_raise(rb_eNotImpError, "use Shader.from_file, Shader.from_memory or Shader.from_stream");
|
|
734
|
+
}
|
|
735
|
+
|
|
731
736
|
/* Document-class: SFML::Shader
|
|
732
737
|
* A GLSL vertex/geometry/fragment shader program, uploaded to the GPU and
|
|
733
738
|
* carried on RenderState#shader.
|
|
@@ -757,6 +762,7 @@ static VALUE Shader_set_uniform(VALUE self, VALUE rb_name, VALUE rb_value) {
|
|
|
757
762
|
*/
|
|
758
763
|
void Init_Shader(VALUE rb_mSFML) {
|
|
759
764
|
rb_cShader = rb_define_class_under(rb_mSFML, "Shader", rb_cObject);
|
|
765
|
+
rb_define_alloc_func(rb_cShader, Shader_alloc);
|
|
760
766
|
|
|
761
767
|
rb_define_singleton_method(rb_cShader, "from_file", Shader_from_file, -1);
|
|
762
768
|
rb_define_singleton_method(rb_cShader, "from_memory", Shader_from_memory, -1);
|