summaryrefslogtreecommitdiff
path: root/src/rect.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rect.c')
-rw-r--r--src/rect.c249
1 files changed, 0 insertions, 249 deletions
diff --git a/src/rect.c b/src/rect.c
deleted file mode 100644
index fa02ceb..0000000
--- a/src/rect.c
+++ /dev/null
@@ -1,249 +0,0 @@
-/*
- * Copyright 2022 Frederico de Oliveira Linhares
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "rect.h"
-
-void
-cg_free_rect(mrb_state *mrb, void* obj)
-{
- struct cg_rect *ptr = obj;
-
- mrb_free(mrb, ptr);
-}
-
-const struct mrb_data_type cg_rect_type = {
- "CG_Rect", cg_free_rect };
-
-static inline SDL_bool
-align_vertically(int a_x, int a_width, int b_x, int b_width)
-{
- return a_x <= b_x + b_width && a_x + a_width >= b_x;
-}
-
-static inline SDL_bool
-align_horizontally(int a_y, int a_height, int b_y, int b_height)
-{
- return a_y <= b_y + b_height && a_y + a_height >= b_y;
-}
-
-static mrb_value
-cg_cRect_initialize(mrb_state *mrb, mrb_value self)
-{
- mrb_int x, y, width, height;
- struct cg_rect *ptr;
-
- mrb_get_args(mrb, "iiii", &x, &y, &width, &height);
- ptr = (struct cg_rect *)DATA_PTR(self);
- if(ptr) mrb_free(mrb, ptr);
- ptr = (struct cg_rect *)mrb_malloc(mrb, sizeof(struct cg_rect));
-
- ptr->rect.x = x;
- ptr->rect.y = y;
- ptr->rect.w = width;
- ptr->rect.h = height;
-
- mrb_data_init(self, ptr, &cg_rect_type);
- return self;
-}
-
-static mrb_value
-cg_cRect_get_x(mrb_state *mrb, mrb_value self)
-{
- struct cg_rect *ptr;
-
- ptr = (struct cg_rect *)DATA_PTR(self);
-
- return mrb_int_value(mrb, ptr->rect.x);
-}
-
-static mrb_value
-cg_cRect_set_x(mrb_state *mrb, mrb_value self)
-{
- mrb_int x;
- struct cg_rect *ptr;
-
- mrb_get_args(mrb, "i", &x);
- ptr = (struct cg_rect *)DATA_PTR(self);
-
- ptr->rect.x = x;
-
- return mrb_int_value(mrb, ptr->rect.x);
-}
-
-static mrb_value
-cg_cRect_get_y(mrb_state *mrb, mrb_value self)
-{
- struct cg_rect *ptr;
-
- ptr = (struct cg_rect *)DATA_PTR(self);
-
- return mrb_int_value(mrb, ptr->rect.y);
-}
-
-static mrb_value
-cg_cRect_set_y(mrb_state *mrb, mrb_value self)
-{
- mrb_int y;
- struct cg_rect *ptr;
-
- mrb_get_args(mrb, "i", &y);
- ptr = (struct cg_rect *)DATA_PTR(self);
-
- ptr->rect.y = y;
-
- return mrb_int_value(mrb, ptr->rect.y);
-}
-
-static mrb_value
-cg_cRect_get_width(mrb_state *mrb, mrb_value self)
-{
- struct cg_rect *ptr;
-
- ptr = (struct cg_rect *)DATA_PTR(self);
-
- return mrb_int_value(mrb, ptr->rect.w);
-}
-
-static mrb_value
-cg_cRect_set_width(mrb_state *mrb, mrb_value self)
-{
- mrb_int width;
- struct cg_rect *ptr;
-
- mrb_get_args(mrb, "i", &width);
- ptr = (struct cg_rect *)DATA_PTR(self);
-
- ptr->rect.w = width;
-
- return mrb_int_value(mrb, ptr->rect.w);
-}
-
-static mrb_value
-cg_cRect_get_height(mrb_state *mrb, mrb_value self)
-{
- struct cg_rect *ptr;
-
- ptr = (struct cg_rect *)DATA_PTR(self);
-
- return mrb_int_value(mrb, ptr->rect.h);
-}
-
-static mrb_value
-cg_cRect_set_height(mrb_state *mrb, mrb_value self)
-{
- mrb_int height;
- struct cg_rect *ptr;
-
- mrb_get_args(mrb, "i", &height);
- ptr = (struct cg_rect *)DATA_PTR(self);
-
- ptr->rect.h = height;
-
- return mrb_int_value(mrb, ptr->rect.h);
-}
-
-static mrb_value
-cg_cRect_draw_lines(mrb_state *mrb, mrb_value self)
-{
- struct cg_rect *ptr;
- ptr = (struct cg_rect *)DATA_PTR(self);
- SDL_RenderDrawRect(cg_core.renderer, &ptr->rect);
-
- return self;
-}
-
-static mrb_value
-cg_cRect_draw_fill(mrb_state *mrb, mrb_value self)
-{
- struct cg_rect *ptr;
- ptr = (struct cg_rect *)DATA_PTR(self);
- SDL_RenderFillRect(cg_core.renderer, &ptr->rect);
-
- return self;
-}
-
-static mrb_value
-cg_cRect_align_vertically(mrb_state *mrb, mrb_value self)
-{
- struct cg_rect *ptr, *that;
-
- mrb_get_args(mrb, "d", &that, &cg_rect_type);
- ptr = (struct cg_rect *)DATA_PTR(self);
-
- return mrb_bool_value(
- align_vertically(ptr->rect.x, ptr->rect.w, that->rect.x, that->rect.w));
-}
-
-static mrb_value
-cg_cRect_align_horizontally(mrb_state *mrb, mrb_value self)
-{
- struct cg_rect *ptr, *that;
-
- mrb_get_args(mrb, "d", &that, &cg_rect_type);
- ptr = (struct cg_rect *)DATA_PTR(self);
-
- return mrb_bool_value(
- align_horizontally(ptr->rect.y, ptr->rect.h, that->rect.y, that->rect.h));
-}
-
-static mrb_value
-cg_cRect_collide(mrb_state *mrb, mrb_value self)
-{
- struct cg_rect *ptr, *that;
-
- mrb_get_args(mrb, "d", &that, &cg_rect_type);
- ptr = (struct cg_rect *)DATA_PTR(self);
-
- return mrb_bool_value(
- align_vertically(ptr->rect.x, ptr->rect.w, that->rect.x, that->rect.w) &&
- align_horizontally(ptr->rect.y, ptr->rect.h, that->rect.y, that->rect.h));
-}
-
-void
-cg_rect_init(mrb_state *mrb)
-{
- struct RClass *cg_m, *cg_cRect;
-
- cg_m = mrb_module_get(mrb, "CandyGear");
- cg_cRect = mrb_define_class_under(mrb, cg_m, "Rect", mrb->object_class);
- MRB_SET_INSTANCE_TT(cg_cRect, MRB_TT_DATA);
- mrb_define_method(
- mrb, cg_cRect, "initialize", cg_cRect_initialize, MRB_ARGS_REQ(4));
- mrb_define_method(mrb, cg_cRect, "x", cg_cRect_get_x, MRB_ARGS_NONE());
- mrb_define_method(mrb, cg_cRect, "x=", cg_cRect_set_x, MRB_ARGS_REQ(1));
- mrb_define_method(mrb, cg_cRect, "y", cg_cRect_get_y, MRB_ARGS_NONE());
- mrb_define_method(mrb, cg_cRect, "y=", cg_cRect_set_y, MRB_ARGS_REQ(1));
- mrb_define_method(
- mrb, cg_cRect, "width", cg_cRect_get_width, MRB_ARGS_NONE());
- mrb_define_method(
- mrb, cg_cRect, "width=", cg_cRect_set_width, MRB_ARGS_REQ(1));
- mrb_define_method(
- mrb, cg_cRect, "height", cg_cRect_get_height, MRB_ARGS_NONE());
- mrb_define_method(
- mrb, cg_cRect, "height=", cg_cRect_set_height, MRB_ARGS_REQ(1));
- mrb_define_method(
- mrb, cg_cRect, "draw_lines", cg_cRect_draw_lines, MRB_ARGS_NONE());
- mrb_define_method(
- mrb, cg_cRect, "draw_fill", cg_cRect_draw_fill, MRB_ARGS_NONE());
- mrb_define_method(
- mrb, cg_cRect, "align_vertically?", cg_cRect_align_vertically,
- MRB_ARGS_REQ(1));
- mrb_define_method(
- mrb, cg_cRect, "align_horizontally?", cg_cRect_align_horizontally,
- MRB_ARGS_REQ(1));
- mrb_define_method(
- mrb, cg_cRect, "collide?", cg_cRect_collide, MRB_ARGS_REQ(1));
-}