diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/rectangle.cpp | 80 | ||||
-rw-r--r-- | src/vector_4d.cpp | 216 |
2 files changed, 290 insertions, 6 deletions
diff --git a/src/rectangle.cpp b/src/rectangle.cpp index 18c86a4..f678cc3 100644 --- a/src/rectangle.cpp +++ b/src/rectangle.cpp @@ -16,6 +16,8 @@ #include "rectangle.hpp" +#include <mruby/array.h> + #include "vector_3d.hpp" #include "view_2d.hpp" #include "view_3d.hpp" @@ -136,6 +138,58 @@ cg_cRectangle_set_height(mrb_state *mrb, mrb_value self) } static mrb_value +cg_cRectangle_get_xy(mrb_state *mrb, mrb_value self) +{ + auto ptr = (std::shared_ptr<VK::Rectangle>*)DATA_PTR(self); + + mrb_value array = mrb_ary_new_capa(mrb, 2); + mrb_ary_push(mrb, array, mrb_float_value(mrb, (*ptr)->x)); + mrb_ary_push(mrb, array, mrb_float_value(mrb, (*ptr)->y)); + + return array; +} + +static mrb_value +cg_cRectangle_get_width_height(mrb_state *mrb, mrb_value self) +{ + auto ptr = (std::shared_ptr<VK::Rectangle>*)DATA_PTR(self); + + mrb_value array = mrb_ary_new_capa(mrb, 2); + mrb_ary_push(mrb, array, mrb_float_value(mrb, (*ptr)->width)); + mrb_ary_push(mrb, array, mrb_float_value(mrb, (*ptr)->height)); + + return array; +} + +static mrb_value +cg_cRectangle_set_xy(mrb_state *mrb, mrb_value self) +{ + mrb_float x, y; + auto ptr = (std::shared_ptr<VK::Rectangle>*)DATA_PTR(self); + + mrb_get_args(mrb, "ff", &x, &y); + + (*ptr)->x = x; + (*ptr)->y = y; + + return self; +} + +static mrb_value +cg_cRectangle_set_width_height(mrb_state *mrb, mrb_value self) +{ + mrb_float width, height; + auto ptr = (std::shared_ptr<VK::Rectangle>*)DATA_PTR(self); + + mrb_get_args(mrb, "ff", &width, &height); + + (*ptr)->width = width; + (*ptr)->height = height; + + return self; +} + +static mrb_value cg_cRectangle_align_vertically(mrb_state *mrb, mrb_value self) { std::shared_ptr<VK::Rectangle> *ptr, *that; @@ -206,19 +260,33 @@ cg_rectangle_init(mrb_state *mrb) mrb_define_method( mrb, cg_cRectangle, "x", cg_cRectangle_get_x, MRB_ARGS_NONE()); mrb_define_method( - mrb, cg_cRectangle, "x=", cg_cRectangle_set_x, MRB_ARGS_REQ(1)); - mrb_define_method( mrb, cg_cRectangle, "y", cg_cRectangle_get_y, MRB_ARGS_NONE()); mrb_define_method( - mrb, cg_cRectangle, "y=", cg_cRectangle_set_y, MRB_ARGS_REQ(1)); - mrb_define_method( mrb, cg_cRectangle, "width", cg_cRectangle_get_width, MRB_ARGS_NONE()); mrb_define_method( - mrb, cg_cRectangle, "width=", cg_cRectangle_set_width, MRB_ARGS_REQ(1)); - mrb_define_method( mrb, cg_cRectangle, "height", cg_cRectangle_get_height, MRB_ARGS_NONE()); + + mrb_define_method( + mrb, cg_cRectangle, "x=", cg_cRectangle_set_x, MRB_ARGS_REQ(1)); + mrb_define_method( + mrb, cg_cRectangle, "y=", cg_cRectangle_set_y, MRB_ARGS_REQ(1)); + mrb_define_method( + mrb, cg_cRectangle, "width=", cg_cRectangle_set_width, MRB_ARGS_REQ(1)); mrb_define_method( mrb, cg_cRectangle, "height=", cg_cRectangle_set_height, MRB_ARGS_REQ(1)); + + mrb_define_method( + mrb, cg_cRectangle, "xy", cg_cRectangle_get_xy, MRB_ARGS_NONE()); + mrb_define_method( + mrb, cg_cRectangle, "width_height", cg_cRectangle_get_width_height, + MRB_ARGS_NONE()); + + mrb_define_method( + mrb, cg_cRectangle, "set_xy", cg_cRectangle_set_xy, MRB_ARGS_REQ(2)); + mrb_define_method( + mrb, cg_cRectangle, "set_width_height", cg_cRectangle_set_width_height, + MRB_ARGS_REQ(2)); + mrb_define_method( mrb, cg_cRectangle, "align_vertically?", cg_cRectangle_align_vertically, MRB_ARGS_REQ(1)); diff --git a/src/vector_4d.cpp b/src/vector_4d.cpp index 5271823..85a265e 100644 --- a/src/vector_4d.cpp +++ b/src/vector_4d.cpp @@ -20,6 +20,8 @@ #include <glm/vec4.hpp> +#include <mruby/array.h> + void cg_free_vector_4d(mrb_state *mrb, void* obj) { @@ -89,6 +91,84 @@ cg_cVector4D_get_h(mrb_state *mrb, mrb_value self) return mrb_float_value(mrb, (*ptr)->w); } +mrb_value +cg_cVector4D_get_xy(mrb_state *mrb, mrb_value self) +{ + std::shared_ptr<glm::vec4> *ptr = + (std::shared_ptr<glm::vec4>*)DATA_PTR(self); + + mrb_value array = mrb_ary_new_capa(mrb, 2); + mrb_ary_push(mrb, array, mrb_float_value(mrb, (*ptr)->x)); + mrb_ary_push(mrb, array, mrb_float_value(mrb, (*ptr)->y)); + + return array; +} + +mrb_value +cg_cVector4D_get_xw(mrb_state *mrb, mrb_value self) +{ + std::shared_ptr<glm::vec4> *ptr = + (std::shared_ptr<glm::vec4>*)DATA_PTR(self); + + mrb_value array = mrb_ary_new_capa(mrb, 2); + mrb_ary_push(mrb, array, mrb_float_value(mrb, (*ptr)->x)); + mrb_ary_push(mrb, array, mrb_float_value(mrb, (*ptr)->z)); + + return array; +} + +mrb_value +cg_cVector4D_get_xh(mrb_state *mrb, mrb_value self) +{ + std::shared_ptr<glm::vec4> *ptr = + (std::shared_ptr<glm::vec4>*)DATA_PTR(self); + + mrb_value array = mrb_ary_new_capa(mrb, 2); + mrb_ary_push(mrb, array, mrb_float_value(mrb, (*ptr)->x)); + mrb_ary_push(mrb, array, mrb_float_value(mrb, (*ptr)->w)); + + return array; +} + +mrb_value +cg_cVector4D_get_yw(mrb_state *mrb, mrb_value self) +{ + std::shared_ptr<glm::vec4> *ptr = + (std::shared_ptr<glm::vec4>*)DATA_PTR(self); + + mrb_value array = mrb_ary_new_capa(mrb, 2); + mrb_ary_push(mrb, array, mrb_float_value(mrb, (*ptr)->y)); + mrb_ary_push(mrb, array, mrb_float_value(mrb, (*ptr)->z)); + + return array; +} + +mrb_value +cg_cVector4D_get_yh(mrb_state *mrb, mrb_value self) +{ + std::shared_ptr<glm::vec4> *ptr = + (std::shared_ptr<glm::vec4>*)DATA_PTR(self); + + mrb_value array = mrb_ary_new_capa(mrb, 2); + mrb_ary_push(mrb, array, mrb_float_value(mrb, (*ptr)->y)); + mrb_ary_push(mrb, array, mrb_float_value(mrb, (*ptr)->w)); + + return array; +} + +mrb_value +cg_cVector4D_get_wh(mrb_state *mrb, mrb_value self) +{ + std::shared_ptr<glm::vec4> *ptr = + (std::shared_ptr<glm::vec4>*)DATA_PTR(self); + + mrb_value array = mrb_ary_new_capa(mrb, 2); + mrb_ary_push(mrb, array, mrb_float_value(mrb, (*ptr)->z)); + mrb_ary_push(mrb, array, mrb_float_value(mrb, (*ptr)->w)); + + return array; +} + static mrb_value cg_cVector4D_set_x(mrb_state *mrb, mrb_value self) { @@ -141,6 +221,90 @@ cg_cVector4D_set_h(mrb_state *mrb, mrb_value self) return self; } +static mrb_value +cg_cVector4D_set_xy(mrb_state *mrb, mrb_value self) +{ + mrb_float x, y; + std::shared_ptr<glm::vec4> *ptr = + (std::shared_ptr<glm::vec4>*)DATA_PTR(self); + + mrb_get_args(mrb, "ff", &x, &y); + (*ptr)->x = x; + (*ptr)->y = y; + + return self; +} + +static mrb_value +cg_cVector4D_set_xw(mrb_state *mrb, mrb_value self) +{ + mrb_float x, w; + std::shared_ptr<glm::vec4> *ptr = + (std::shared_ptr<glm::vec4>*)DATA_PTR(self); + + mrb_get_args(mrb, "ff", &x, &w); + (*ptr)->x = x; + (*ptr)->z = w; + + return self; +} + +static mrb_value +cg_cVector4D_set_xh(mrb_state *mrb, mrb_value self) +{ + mrb_float x, h; + std::shared_ptr<glm::vec4> *ptr = + (std::shared_ptr<glm::vec4>*)DATA_PTR(self); + + mrb_get_args(mrb, "ff", &x, &h); + (*ptr)->x = x; + (*ptr)->w = h; + + return self; +} + +static mrb_value +cg_cVector4D_set_yw(mrb_state *mrb, mrb_value self) +{ + mrb_float y, w; + std::shared_ptr<glm::vec4> *ptr = + (std::shared_ptr<glm::vec4>*)DATA_PTR(self); + + mrb_get_args(mrb, "ff", &y, &w); + (*ptr)->y = y; + (*ptr)->z = w; + + return self; +} + +static mrb_value +cg_cVector4D_set_yh(mrb_state *mrb, mrb_value self) +{ + mrb_float y, h; + std::shared_ptr<glm::vec4> *ptr = + (std::shared_ptr<glm::vec4>*)DATA_PTR(self); + + mrb_get_args(mrb, "ff", &y, &h); + (*ptr)->x = y; + (*ptr)->w = h; + + return self; +} + +static mrb_value +cg_cVector4D_set_wh(mrb_state *mrb, mrb_value self) +{ + mrb_float w, h; + std::shared_ptr<glm::vec4> *ptr = + (std::shared_ptr<glm::vec4>*)DATA_PTR(self); + + mrb_get_args(mrb, "ff", &w, &h); + (*ptr)->z = w; + (*ptr)->w = h; + + return self; +} + void cg_vector_4d_init(mrb_state *mrb) { @@ -172,6 +336,32 @@ cg_vector_4d_init(mrb_state *mrb) mrb, cg_cVector4D, "a", cg_cVector4D_get_h, MRB_ARGS_NONE()); mrb_define_method( + mrb, cg_cVector4D, "xy", cg_cVector4D_get_xy, MRB_ARGS_NONE()); + mrb_define_method( + mrb, cg_cVector4D, "xw", cg_cVector4D_get_xw, MRB_ARGS_NONE()); + mrb_define_method( + mrb, cg_cVector4D, "xh", cg_cVector4D_get_xh, MRB_ARGS_NONE()); + mrb_define_method( + mrb, cg_cVector4D, "yw", cg_cVector4D_get_yw, MRB_ARGS_NONE()); + mrb_define_method( + mrb, cg_cVector4D, "yh", cg_cVector4D_get_yh, MRB_ARGS_NONE()); + mrb_define_method( + mrb, cg_cVector4D, "wh", cg_cVector4D_get_wh, MRB_ARGS_NONE()); + + mrb_define_method( + mrb, cg_cVector4D, "rg", cg_cVector4D_get_xy, MRB_ARGS_NONE()); + mrb_define_method( + mrb, cg_cVector4D, "rb", cg_cVector4D_get_xw, MRB_ARGS_NONE()); + mrb_define_method( + mrb, cg_cVector4D, "ra", cg_cVector4D_get_xh, MRB_ARGS_NONE()); + mrb_define_method( + mrb, cg_cVector4D, "gb", cg_cVector4D_get_yw, MRB_ARGS_NONE()); + mrb_define_method( + mrb, cg_cVector4D, "ga", cg_cVector4D_get_yh, MRB_ARGS_NONE()); + mrb_define_method( + mrb, cg_cVector4D, "ba", cg_cVector4D_get_wh, MRB_ARGS_NONE()); + + mrb_define_method( mrb, cg_cVector4D, "x=", cg_cVector4D_set_x, MRB_ARGS_REQ(1)); mrb_define_method( mrb, cg_cVector4D, "y=", cg_cVector4D_set_y, MRB_ARGS_REQ(1)); @@ -187,4 +377,30 @@ cg_vector_4d_init(mrb_state *mrb) mrb, cg_cVector4D, "b=", cg_cVector4D_set_w, MRB_ARGS_REQ(1)); mrb_define_method( mrb, cg_cVector4D, "a=", cg_cVector4D_set_h, MRB_ARGS_REQ(1)); + + mrb_define_method( + mrb, cg_cVector4D, "set_xy", cg_cVector4D_set_xy, MRB_ARGS_REQ(2)); + mrb_define_method( + mrb, cg_cVector4D, "set_xw", cg_cVector4D_set_xw, MRB_ARGS_REQ(2)); + mrb_define_method( + mrb, cg_cVector4D, "set_xh", cg_cVector4D_set_xh, MRB_ARGS_REQ(2)); + mrb_define_method( + mrb, cg_cVector4D, "set_yw", cg_cVector4D_set_yw, MRB_ARGS_REQ(2)); + mrb_define_method( + mrb, cg_cVector4D, "set_yh", cg_cVector4D_set_yh, MRB_ARGS_REQ(2)); + mrb_define_method( + mrb, cg_cVector4D, "set_wh", cg_cVector4D_set_wh, MRB_ARGS_REQ(2)); + + mrb_define_method( + mrb, cg_cVector4D, "set_rg", cg_cVector4D_set_xy, MRB_ARGS_REQ(2)); + mrb_define_method( + mrb, cg_cVector4D, "set_rb", cg_cVector4D_set_xw, MRB_ARGS_REQ(2)); + mrb_define_method( + mrb, cg_cVector4D, "set_ra", cg_cVector4D_set_xh, MRB_ARGS_REQ(2)); + mrb_define_method( + mrb, cg_cVector4D, "set_gb", cg_cVector4D_set_yw, MRB_ARGS_REQ(2)); + mrb_define_method( + mrb, cg_cVector4D, "set_ga", cg_cVector4D_set_yh, MRB_ARGS_REQ(2)); + mrb_define_method( + mrb, cg_cVector4D, "set_ba", cg_cVector4D_set_wh, MRB_ARGS_REQ(2)); } |