sfml3-rb 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.md +14 -0
  3. data/README.md +110 -0
  4. data/ext/circle.c +198 -0
  5. data/ext/clock.c +65 -0
  6. data/ext/color.c +43 -0
  7. data/ext/drawable.c +39 -0
  8. data/ext/event.c +148 -0
  9. data/ext/event_name.c +45 -0
  10. data/ext/exceptions.c +44 -0
  11. data/ext/ext/exceptions.h +16 -0
  12. data/ext/ext/klass/clock.h +12 -0
  13. data/ext/ext/klass/color.h +26 -0
  14. data/ext/ext/klass/drawable/circle.h +12 -0
  15. data/ext/ext/klass/drawable/image.h +4 -0
  16. data/ext/ext/klass/drawable/polygon.h +4 -0
  17. data/ext/ext/klass/drawable/rectangle.h +4 -0
  18. data/ext/ext/klass/drawable/sprite.h +4 -0
  19. data/ext/ext/klass/drawable/texture.h +4 -0
  20. data/ext/ext/klass/event/event_name.h +8 -0
  21. data/ext/ext/klass/event.h +12 -0
  22. data/ext/ext/klass/keyboard.h +8 -0
  23. data/ext/ext/klass/render_state.h +16 -0
  24. data/ext/ext/klass/target.h +18 -0
  25. data/ext/ext/klass/transform.h +17 -0
  26. data/ext/ext/klass/transformable.h +13 -0
  27. data/ext/ext/klass/video_mode.h +12 -0
  28. data/ext/ext/klass/view.h +14 -0
  29. data/ext/ext/klass/window.h +12 -0
  30. data/ext/ext/module/drawable/drawable.h +10 -0
  31. data/ext/ext/module/transform.h +18 -0
  32. data/ext/ext/module.h +10 -0
  33. data/ext/ext/rect.h +16 -0
  34. data/ext/ext/sfml.h +16 -0
  35. data/ext/ext/style_name.h +11 -0
  36. data/ext/ext/vec2.h +38 -0
  37. data/ext/ext.c +47 -0
  38. data/ext/extconf.rb +84 -0
  39. data/ext/image.c +5 -0
  40. data/ext/keyboard.c +135 -0
  41. data/ext/polygon.c +5 -0
  42. data/ext/ports.rb +368 -0
  43. data/ext/rect.c +26 -0
  44. data/ext/rectangle.c +5 -0
  45. data/ext/render_state.c +109 -0
  46. data/ext/sprite.c +5 -0
  47. data/ext/style_name.c +15 -0
  48. data/ext/target.c +106 -0
  49. data/ext/texture.c +5 -0
  50. data/ext/transform.c +107 -0
  51. data/ext/transformable.c +145 -0
  52. data/ext/vec2.c +42 -0
  53. data/ext/video_mode.c +78 -0
  54. data/ext/view.c +170 -0
  55. data/ext/window.c +274 -0
  56. data/lib/sfml/version.rb +3 -0
  57. data/lib/sfml.rb +9 -0
  58. metadata +104 -0
data/ext/target.c ADDED
@@ -0,0 +1,106 @@
1
+ #include "ext/klass/target.h"
2
+
3
+ #include <stdio.h>
4
+ #include <stdlib.h>
5
+ #include <ext/klass/drawable/circle.h>
6
+ #include <ext/klass/render_state.h>
7
+
8
+ #include "ext/module/transform.h"
9
+ #include "ext/klass/transformable.h"
10
+ #include "ext/klass/view.h"
11
+ #include "ext/klass/window.h"
12
+ #include "ext/vec2.h"
13
+ #include "ext/rect.h"
14
+ #include "ext/module.h"
15
+ #include "ext/sfml.h"
16
+
17
+ static VALUE rb_cTarget;
18
+
19
+ static Target *RenderTarget_create(sfRenderWindow *c_window) {
20
+ Target *target = malloc(sizeof(Target));
21
+
22
+ target->window = c_window;
23
+
24
+ return target;
25
+ }
26
+
27
+ static void RenderTarget_free(void *ptr) {
28
+ free(ptr);
29
+ }
30
+
31
+ static VALUE RenderTarget_new(VALUE klass, VALUE rb_window) {
32
+ VALUE self;
33
+ Target *target;
34
+
35
+ if (!rb_obj_is_kind_of(rb_window, Get_Klass_Window())) {
36
+ rb_raise(rb_eArgError, "Expected a Window object");
37
+ }
38
+
39
+ target = RenderTarget_create(Get_Window_Struct(rb_window));
40
+ self = Data_Wrap_Struct(klass, 0, RenderTarget_free, target);
41
+
42
+ VALUE argv[1] = {rb_window};
43
+ rb_obj_call_init(self, 1, argv);
44
+
45
+ return self;
46
+ }
47
+
48
+ static VALUE RenderTarget_init(VALUE self, VALUE rb_window) {
49
+ return self;
50
+ }
51
+
52
+ static VALUE RenderTarget_draw(VALUE self, VALUE rb_drawable, VALUE rb_state) {
53
+ Target *target = Get_Target_Struct(self);
54
+
55
+ if (rb_obj_is_kind_of(rb_drawable, Get_Klass_Circle())) {
56
+ sfRenderWindow_drawCircleShape(target->window, Get_Circle_Struct(rb_drawable), Get_RenderState_Struct(rb_state));
57
+ } else {
58
+ rb_funcall(rb_drawable, rb_intern("draw"), 2, self, rb_state);
59
+ }
60
+
61
+ return self;
62
+ }
63
+
64
+ static VALUE RenderTarget_set_view(VALUE self, VALUE rb_view) {
65
+ if (!rb_obj_is_kind_of(rb_view, Get_Klass_View())) {
66
+ rb_raise(rb_eArgError, "Expected a View object");
67
+ }
68
+
69
+ sfRenderWindow_setView(((Target *) Get_Target_Struct(self))->window, Get_View_Struct(rb_view));
70
+
71
+ return Qnil;
72
+ }
73
+
74
+ static VALUE RenderTarget_get_view(VALUE self) {
75
+ return Get_Casting_View(sfView_copy(sfRenderWindow_getView(((Target *) Get_Target_Struct(self))->window)));
76
+ }
77
+
78
+ void Init_Target(VALUE rb_module) {
79
+ rb_cTarget = rb_define_class_under(rb_module, "Target", rb_cObject);
80
+
81
+ rb_define_singleton_method(rb_cTarget, "new", RenderTarget_new, 1);
82
+
83
+ // methods
84
+ rb_define_method(rb_cTarget, "initialize", RenderTarget_init, 1);
85
+ rb_define_method(rb_cTarget, "draw", RenderTarget_draw, 2);
86
+
87
+ // setters
88
+ rb_define_method(rb_cTarget, "view=", RenderTarget_set_view, 1);
89
+
90
+ // getters
91
+ rb_define_method(rb_cTarget, "view", RenderTarget_get_view, 0);
92
+ }
93
+
94
+ VALUE Get_Klass_Target(void) {
95
+ return rb_cTarget;
96
+ }
97
+
98
+ void *Get_Target_Struct(VALUE self) {
99
+ Target *ptr;
100
+ Data_Get_Struct(self, Target, ptr);
101
+ return ptr;
102
+ }
103
+
104
+ VALUE Get_New_Target(VALUE rb_window) {
105
+ return RenderTarget_new(Get_Klass_Target(), rb_window);
106
+ }
data/ext/texture.c ADDED
@@ -0,0 +1,5 @@
1
+ //
2
+ // Created by Sealtiel on 03/06/2022.
3
+ //
4
+
5
+ #include "ext/klass/drawable/texture.h"
data/ext/transform.c ADDED
@@ -0,0 +1,107 @@
1
+ #include "ext/module/transform.h"
2
+
3
+ #include <ruby.h>
4
+ #include <stdio.h>
5
+
6
+ #include "ext/vec2.h"
7
+ #include "ext/rect.h"
8
+ #include "ext/module.h"
9
+ #include "ext/sfml.h"
10
+
11
+
12
+ static VALUE rb_mTransform;
13
+
14
+ VALUE Transform_combine(VALUE self, VALUE rb_arr_a, VALUE rb_arr_b) {
15
+ sfTransform transform_a, transform_b;
16
+ float matrix_a[MATRIX_LENGTH], matrix_b[MATRIX_LENGTH];
17
+
18
+ Transform_ArrayToMatrix(rb_arr_a, matrix_a);
19
+ Transform_ArrayToMatrix(rb_arr_b, matrix_b);
20
+
21
+ Transform_SwapMatrix(matrix_a, transform_a.matrix);
22
+ Transform_SwapMatrix(matrix_b, transform_b.matrix);
23
+
24
+ sfTransform_combine(&transform_a, &transform_b);
25
+
26
+ return Transform_MatrixToArray(transform_a.matrix);
27
+ }
28
+
29
+ VALUE Transform_inverse(VALUE self, VALUE rb_matrix) {
30
+ sfTransform transform;
31
+ float matrix[MATRIX_LENGTH];
32
+
33
+ Transform_ArrayToMatrix(rb_matrix, matrix);
34
+ Transform_SwapMatrix(matrix, transform.matrix);
35
+
36
+ return Transform_MatrixToArray(sfTransform_getInverse(&transform).matrix);
37
+ }
38
+
39
+ void Init_Transform(VALUE rb_module) {
40
+ rb_mTransform = rb_define_module_under(rb_module, "Transform");
41
+
42
+ rb_define_module_function(rb_mTransform, "combine", Transform_combine, 2);
43
+ rb_define_module_function(rb_mTransform, "inverse", Transform_inverse, 1);
44
+ }
45
+
46
+ VALUE Transform_MatrixToArray(float *c_matrix) {
47
+ VALUE rb_arr;
48
+ size_t i;
49
+
50
+ if (c_matrix == NULL) {
51
+ return Qnil;
52
+ }
53
+
54
+ rb_arr = rb_ary_new();
55
+
56
+ for (i = 0; i < MATRIX_LENGTH; i++) {
57
+ rb_ary_push(rb_arr, DBL2NUM(c_matrix[i]));
58
+ }
59
+
60
+ return rb_arr;
61
+ }
62
+
63
+ void Transform_ArrayToMatrix(VALUE rb_matrix, float *c_matrix) {
64
+ size_t i;
65
+
66
+ if (c_matrix == NULL) {
67
+ return;
68
+ }
69
+
70
+ if (rb_array_len(rb_matrix) != MATRIX_LENGTH) {
71
+ return;
72
+ }
73
+
74
+ for (i = 0; i < MATRIX_LENGTH; i++) {
75
+ c_matrix[i] = NUM2DBL(rb_ary_entry(rb_matrix, (long) i));
76
+ }
77
+ }
78
+
79
+ void Transform_SwapMatrix(const float *c_matrix_a, float *c_matrix_b) {
80
+ size_t i;
81
+
82
+ if (c_matrix_a == NULL || c_matrix_b == NULL) {
83
+ return;
84
+ }
85
+
86
+ for (i = 0; i < MATRIX_LENGTH; i++) {
87
+ c_matrix_b[i] = c_matrix_a[i];
88
+ }
89
+ }
90
+
91
+ sfTransform Transform_ArrayToTransform(VALUE rb_matrix) {
92
+ float c_matrix[MATRIX_LENGTH];
93
+ sfTransform transform;
94
+
95
+ Transform_ArrayToMatrix(rb_matrix, c_matrix);
96
+ Transform_SwapMatrix(c_matrix, transform.matrix);
97
+
98
+ return transform;
99
+ }
100
+
101
+ VALUE Transform_TransformToArray(sfTransform c_transform) {
102
+ float c_matrix[MATRIX_LENGTH];
103
+
104
+ Transform_SwapMatrix(c_transform.matrix, c_matrix);
105
+
106
+ return Transform_MatrixToArray(c_matrix);
107
+ }
@@ -0,0 +1,145 @@
1
+ #include "ext/klass/transformable.h"
2
+
3
+ #include <ruby.h>
4
+ #include <stdio.h>
5
+
6
+ #include "ext/module/transform.h"
7
+ #include "ext/vec2.h"
8
+ #include "ext/rect.h"
9
+ #include "ext/module.h"
10
+ #include "ext/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 VALUE Transformable_new(VALUE klass) {
23
+ VALUE self;
24
+ sfTransformable *transformable;
25
+
26
+ transformable = Transformable_create();
27
+ self = Data_Wrap_Struct(klass, 0, Transformable_free, transformable);
28
+
29
+ rb_obj_call_init(self, 0, NULL);
30
+
31
+ return self;
32
+ }
33
+
34
+ static VALUE Transformable_init(VALUE self) {
35
+ return self;
36
+ }
37
+
38
+ static VALUE Transformable_set_position(VALUE self, VALUE rb_position) {
39
+ sfVector2f position = VEC2_RB2C(rb_position);
40
+ sfTransformable_setPosition(Get_Transformable_Struct(self), position);
41
+
42
+ return self;
43
+ }
44
+
45
+ static VALUE Transformable_set_rotation(VALUE self, VALUE rb_angle) {
46
+ sfTransformable_setRotation(Get_Transformable_Struct(self), NUM2DBL(rb_angle));
47
+
48
+ return self;
49
+ }
50
+
51
+ static VALUE Transformable_set_scale(VALUE self, VALUE rb_scale) {
52
+ sfVector2f scale = VEC2_RB2C(rb_scale);
53
+ sfTransformable_setScale(Get_Transformable_Struct(self), scale);
54
+
55
+ return self;
56
+ }
57
+
58
+ static VALUE Transformable_set_origin(VALUE self, VALUE rb_origin) {
59
+ sfVector2f origin = VEC2_RB2C(rb_origin);
60
+ sfTransformable_setOrigin(Get_Transformable_Struct(self), origin);
61
+
62
+ return self;
63
+ }
64
+
65
+ static VALUE Transformable_get_position(VALUE self) {
66
+ sfVector2f position = sfTransformable_getPosition(Get_Transformable_Struct(self));
67
+
68
+ return VEC2_C2RB(position);
69
+ }
70
+
71
+ static VALUE Transformable_get_rotation(VALUE self) {
72
+ return DBL2NUM(sfTransformable_getRotation(Get_Transformable_Struct(self)));
73
+ }
74
+
75
+ static VALUE Transformable_get_scale(VALUE self) {
76
+ sfVector2f scale = sfTransformable_getScale(Get_Transformable_Struct(self));
77
+
78
+ return VEC2_C2RB(scale);
79
+ }
80
+
81
+ static VALUE Transformable_get_origin(VALUE self) {
82
+ sfVector2f origin = sfTransformable_getOrigin(Get_Transformable_Struct(self));
83
+
84
+ return VEC2_C2RB(origin);
85
+ }
86
+
87
+ static VALUE Transformable_move(VALUE self, VALUE rb_move) {
88
+ sfVector2f move = VEC2_RB2C(rb_move);
89
+ sfTransformable_move(Get_Transformable_Struct(self), move);
90
+
91
+ return self;
92
+ }
93
+
94
+ static VALUE Transformable_rotate(VALUE self, VALUE rb_angle) {
95
+ sfTransformable_rotate(Get_Transformable_Struct(self), NUM2DBL(rb_angle));
96
+
97
+ return self;
98
+ }
99
+
100
+ static VALUE Transformable_scale(VALUE self, VALUE rb_scale) {
101
+ sfVector2f scale = VEC2_RB2C(rb_scale);
102
+ sfTransformable_scale(Get_Transformable_Struct(self), scale);
103
+
104
+ return self;
105
+ }
106
+
107
+ static VALUE Transformable_get_matrix(VALUE self) {
108
+ sfTransformable *transformable = Get_Transformable_Struct(self);
109
+ sfTransform transform = sfTransformable_getTransform(transformable);
110
+
111
+ return Transform_MatrixToArray(transform.matrix);
112
+ }
113
+
114
+ void Init_Transformable(VALUE rb_module) {
115
+ rb_cTransformable = rb_define_class_under(rb_module, "Transformable", rb_cObject);
116
+
117
+ rb_define_singleton_method(rb_cTransformable, "new", Transformable_new, 0);
118
+ rb_define_method(rb_cTransformable, "initialize", Transformable_init, 0);
119
+
120
+ rb_define_method(rb_cTransformable, "position=", Transformable_set_position, 1);
121
+ rb_define_method(rb_cTransformable, "angle=", Transformable_set_rotation, 1);
122
+ rb_define_method(rb_cTransformable, "scale=", Transformable_set_scale, 1);
123
+ rb_define_method(rb_cTransformable, "origin=", Transformable_set_origin, 1);
124
+
125
+ rb_define_method(rb_cTransformable, "position", Transformable_get_position, 0);
126
+ rb_define_method(rb_cTransformable, "angle", Transformable_get_rotation, 0);
127
+ rb_define_method(rb_cTransformable, "scale", Transformable_get_scale, 0);
128
+ rb_define_method(rb_cTransformable, "origin", Transformable_get_origin, 0);
129
+
130
+ rb_define_method(rb_cTransformable, "move", Transformable_move, 1);
131
+ rb_define_method(rb_cTransformable, "rotate", Transformable_rotate, 1);
132
+ rb_define_method(rb_cTransformable, "escalate", Transformable_scale, 1);
133
+
134
+ rb_define_method(rb_cTransformable, "matrix", Transformable_get_matrix, 0);
135
+ }
136
+
137
+ void *Get_Transformable_Struct(VALUE self) {
138
+ sfTransformable *transform;
139
+ Data_Get_Struct(self, sfTransformable, transform);
140
+ return transform;
141
+ }
142
+
143
+ VALUE Get_Klass_Transformable() {
144
+ return rb_cTransformable;
145
+ }
data/ext/vec2.c ADDED
@@ -0,0 +1,42 @@
1
+ #include "ext/vec2.h"
2
+
3
+ #include <stdio.h>
4
+ #include <stdlib.h>
5
+
6
+ #include "ext/exceptions.h"
7
+
8
+ VALUE vec2_new(float x, float y) {
9
+ VALUE rb_vec;
10
+
11
+ rb_vec = rb_ary_new();
12
+
13
+ rb_ary_store(rb_vec, 0, DBL2NUM(x));
14
+ rb_ary_store(rb_vec, 1, DBL2NUM(y));
15
+
16
+ return rb_vec;
17
+ }
18
+
19
+ void vec2_check(VALUE rb_arr) {
20
+ if (rb_array_len(rb_arr) != 2) {
21
+ raise_invalid_argument_class(rb_cArray);
22
+ }
23
+ }
24
+
25
+ VALUE vec2f_new_from_c(sfVector2f c_vec) {
26
+ return VEC2_C2RB(c_vec);
27
+ }
28
+
29
+ sfVector2i vec2i_new_from_ruby(VALUE rb_arr) {
30
+ sfVector2i vec = VEC2_RB2C_T(int, rb_arr);
31
+ return vec;
32
+ }
33
+
34
+ sfVector2u vec2u_new_from_ruby(VALUE rb_arr) {
35
+ sfVector2u vec = VEC2_RB2C_T(unsigned, rb_arr);
36
+ return vec;
37
+ }
38
+
39
+ sfVector2f vec2f_new_from_ruby(VALUE rb_arr) {
40
+ sfVector2f vec = VEC2_RB2C_T(float, rb_arr);
41
+ return vec;
42
+ }
data/ext/video_mode.c ADDED
@@ -0,0 +1,78 @@
1
+ #include "ext/klass/video_mode.h"
2
+
3
+ #include <ruby.h>
4
+ #include <stdio.h>
5
+
6
+ #include "ext/sfml.h"
7
+ #include "ext/module.h"
8
+
9
+ static VALUE rb_cMode;
10
+
11
+ static sfVideoMode *VideoMode_create(unsigned width, unsigned heigth, unsigned bitsPerPixel) {
12
+ sfVideoMode *mode = malloc(sizeof(sfVideoMode));
13
+
14
+ mode->size.x = width;
15
+ mode->size.y = heigth;
16
+ mode->bitsPerPixel = bitsPerPixel;
17
+
18
+ return mode;
19
+ }
20
+
21
+ static void VideoMode_free(void *ptr) {
22
+ free(ptr);
23
+ }
24
+
25
+ static VALUE VideoMode_new(VALUE klass, VALUE rb_width, VALUE rb_height, VALUE rb_bits) {
26
+ VALUE self;
27
+ sfVideoMode *ptr;
28
+
29
+ VALUE argv[] = {rb_width, rb_height, rb_bits};
30
+
31
+ ptr = VideoMode_create(NUM2INT(rb_width), NUM2INT(rb_height), NUM2INT(rb_bits));
32
+ self = Data_Wrap_Struct(klass, 0, VideoMode_free, ptr);
33
+
34
+ rb_obj_call_init(self, 3, argv);
35
+
36
+ return self;
37
+ }
38
+
39
+ static VALUE VideoMode_init(VALUE self, VALUE rb_width, VALUE rb_height, VALUE rb_bits) {
40
+ rb_iv_set(self, "@width", rb_width);
41
+ rb_iv_set(self, "@height", rb_height);
42
+ rb_iv_set(self, "@bits", rb_bits);
43
+
44
+ return self;
45
+ }
46
+
47
+ static VALUE VideoMode_is_available(VALUE self) {
48
+ sfVideoMode *ptr = Get_Mode_Struct(self);
49
+
50
+ if (sfVideoMode_isValid(*ptr)) {
51
+ return Qtrue;
52
+ }
53
+
54
+ return Qfalse;
55
+ }
56
+
57
+ void Init_VideoMode(VALUE rb_module) {
58
+ rb_cMode = rb_define_class_under(rb_module, "VideoMode", rb_cObject);
59
+
60
+ rb_define_singleton_method(rb_cMode, "new", VideoMode_new, 3);
61
+
62
+ // methods
63
+ rb_define_method(rb_cMode, "initialize", VideoMode_init, 3);
64
+ rb_define_method(rb_cMode, "available?", VideoMode_is_available, 0);
65
+ rb_define_attr(rb_cMode, "width", 1, 0);
66
+ rb_define_attr(rb_cMode, "height", 1, 0);
67
+ rb_define_attr(rb_cMode, "bits", 1, 0);
68
+ }
69
+
70
+ void *Get_Mode_Struct(VALUE self) {
71
+ sfVideoMode *ptr;
72
+ Data_Get_Struct(self, sfVideoMode, ptr);
73
+ return ptr;
74
+ }
75
+
76
+ VALUE Get_Klass_Mode() {
77
+ return rb_cMode;
78
+ }
data/ext/view.c ADDED
@@ -0,0 +1,170 @@
1
+ #include "ext/klass/view.h"
2
+
3
+ #include <stdio.h>
4
+
5
+ #include "ext/module/transform.h"
6
+ #include "ext/klass/transformable.h"
7
+ #include "ext/klass/color.h"
8
+ #include "ext/vec2.h"
9
+ #include "ext/rect.h"
10
+ #include "ext/module.h"
11
+ #include "ext/sfml.h"
12
+
13
+ static VALUE rb_cView;
14
+
15
+ static sfView *View_create() {
16
+ return sfView_create();
17
+ }
18
+
19
+ static void View_free(void *ptr) {
20
+ sfView_destroy(ptr);
21
+ }
22
+
23
+ static VALUE View_new_from(VALUE klass, sfView *c_view) {
24
+ VALUE self;
25
+ sfView *view;
26
+
27
+ if (c_view != NULL) {
28
+ view = c_view;
29
+ } else {
30
+ view = View_create();
31
+ }
32
+
33
+ self = Data_Wrap_Struct(klass, 0, View_free, view);
34
+
35
+ rb_obj_call_init(self, 0, NULL);
36
+
37
+ return self;
38
+ }
39
+
40
+ static VALUE View_new(VALUE klass) {
41
+ return View_new_from(klass, NULL);
42
+ }
43
+
44
+ static VALUE View_init(VALUE self) {
45
+ return self;
46
+ }
47
+
48
+ static VALUE View_set_position(VALUE self, VALUE rb_position) {
49
+ sfView *view = Get_View_Struct(self);
50
+ sfVector2f position = VEC2_RB2C(rb_position);
51
+ sfVector2f size = sfView_getSize(view);
52
+
53
+ sfFloatRect rect = {{position.x, position.y}, {size.x, size.y}};
54
+
55
+ sfView_setViewport(Get_View_Struct(self), rect);
56
+
57
+ return self;
58
+ }
59
+
60
+
61
+ static VALUE View_set_rotation(VALUE self, VALUE rb_rotation) {
62
+ sfView_setRotation(Get_View_Struct(self), NUM2DBL(rb_rotation));
63
+ return self;
64
+ }
65
+
66
+
67
+ static VALUE View_set_size(VALUE self, VALUE rb_scale) {
68
+ sfView_setSize(Get_View_Struct(self), vec2f_new_from_ruby(rb_scale));
69
+ return self;
70
+ }
71
+
72
+
73
+ static VALUE View_set_center(VALUE self, VALUE rb_origin) {
74
+ sfVector2f origin = VEC2_RB2C(rb_origin);
75
+ sfView_setCenter(Get_View_Struct(self), origin);
76
+ return self;
77
+ }
78
+
79
+ static VALUE View_set_viewport(VALUE self, VALUE rb_viewport) {
80
+ sfFloatRect viewport = RECT_RB2C(rb_viewport);
81
+ sfView_setViewport(Get_View_Struct(self), viewport);
82
+
83
+ return self;
84
+ }
85
+
86
+ static VALUE View_get_position(VALUE self) {
87
+ sfFloatRect viewport = sfView_getViewport(Get_View_Struct(self));
88
+ return vec2_new(viewport.position.x, viewport.position.y);
89
+ }
90
+
91
+
92
+ static VALUE View_get_rotation(VALUE self) {
93
+ return DBL2NUM(sfView_getRotation(Get_View_Struct(self)));
94
+ }
95
+
96
+
97
+ static VALUE View_get_size(VALUE self) {
98
+ return vec2f_new_from_c(sfView_getSize(Get_View_Struct(self)));
99
+ }
100
+
101
+
102
+ static VALUE View_get_center(VALUE self) {
103
+ return vec2f_new_from_c(sfView_getCenter(Get_View_Struct(self)));
104
+ }
105
+
106
+ static VALUE View_get_viewport(VALUE self) {
107
+ return RECT_C2RB(sfView_getViewport(Get_View_Struct(self)));
108
+ }
109
+
110
+ static VALUE View_move(VALUE self, VALUE rb_move) {
111
+ sfView_move(Get_View_Struct(self), vec2f_new_from_ruby(rb_move));
112
+ return self;
113
+ }
114
+
115
+ static VALUE View_rotate(VALUE self, VALUE rb_angle) {
116
+ sfView_rotate(Get_View_Struct(self), NUM2DBL(rb_angle));
117
+
118
+ return self;
119
+ }
120
+
121
+ static VALUE View_zoom(VALUE self, VALUE rb_zoom) {
122
+ sfView_zoom(Get_View_Struct(self), NUM2DBL(rb_zoom));
123
+
124
+ return self;
125
+ }
126
+
127
+ static VALUE View_copy(VALUE self) {
128
+ return Get_Casting_View(sfView_copy(Get_View_Struct(self)));
129
+ }
130
+
131
+ void Init_View(VALUE rb_module) {
132
+ rb_cView = rb_define_class_under(rb_module, "View", rb_cObject);
133
+
134
+ rb_define_singleton_method(rb_cView, "new", View_new, 0);
135
+
136
+ // methods
137
+ rb_define_method(rb_cView, "initialize", View_init, 0);
138
+ rb_define_method(rb_cView, "move", View_move, 1);
139
+ rb_define_method(rb_cView, "rotate", View_rotate, 1);
140
+ rb_define_method(rb_cView, "zoom", View_zoom, 1);
141
+ rb_define_method(rb_cView, "copy", View_copy, 0);
142
+
143
+ // setters
144
+ rb_define_method(rb_cView, "position=", View_set_position, 1);
145
+ rb_define_method(rb_cView, "angle=", View_set_rotation, 1);
146
+ rb_define_method(rb_cView, "size=", View_set_size, 1);
147
+ rb_define_method(rb_cView, "center=", View_set_center, 1);
148
+ rb_define_method(rb_cView, "viewport=", View_set_viewport, 1);
149
+
150
+ // getters
151
+ rb_define_method(rb_cView, "position", View_get_position, 0);
152
+ rb_define_method(rb_cView, "angle", View_get_rotation, 0);
153
+ rb_define_method(rb_cView, "size", View_get_size, 0);
154
+ rb_define_method(rb_cView, "center", View_get_center, 0);
155
+ rb_define_method(rb_cView, "viewport", View_get_viewport, 0);
156
+ }
157
+
158
+ void *Get_View_Struct(VALUE self) {
159
+ sfView *ptr;
160
+ Data_Get_Struct(self, sfView, ptr);
161
+ return ptr;
162
+ }
163
+
164
+ VALUE Get_Klass_View() {
165
+ return rb_cView;
166
+ }
167
+
168
+ VALUE Get_Casting_View(void *ptr) {
169
+ return View_new_from(Get_Klass_View(), ptr);
170
+ }