diff --git a/include/arc/graphics/rectangle.h b/include/arc/graphics/rectangle.h new file mode 100644 index 0000000..6a4fc8b --- /dev/null +++ b/include/arc/graphics/rectangle.h @@ -0,0 +1,19 @@ +#ifndef ARC_GRAPHICS_RECT_H_ +#define ARC_GRAPHICS_RECT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "arc/graphics/color.h" +#include "arc/graphics/renderer.h" +#include "arc/math/rectangle.h" +#include + +void ARC_Rect_Render(ARC_Rect *rect, ARC_Renderer *renderer, ARC_Color *color); + +#ifdef __cplusplus +} +#endif + +#endif // !ARC_GRAPHICS_RECT_H_ diff --git a/src/graphics/sdl/rectangle.c b/src/graphics/sdl/rectangle.c new file mode 100644 index 0000000..074d3d3 --- /dev/null +++ b/src/graphics/sdl/rectangle.c @@ -0,0 +1,11 @@ +#include "arc/graphics/rectangle.h" +#ifdef ARC_SDL +#include "arc/graphics/sdl/renderer.h" +#include + +void ARC_Rect_Render(ARC_Rect *rect, ARC_Renderer *renderer, ARC_Color *color){ + SDL_SetRenderDrawColor(renderer->renderer, color->r, color->g, color->b, color->a); + SDL_RenderDrawRect(renderer->renderer, (SDL_Rect *) rect); +} + +#endif // ARC_SDL \ No newline at end of file diff --git a/src/math/rectangle.c b/src/math/rectangle.c new file mode 100644 index 0000000..897f969 --- /dev/null +++ b/src/math/rectangle.c @@ -0,0 +1,18 @@ +#include "arc/math/rectangle.h" + +//VERY TEMP +#include + +int32_t ARC_Rect_Intersects(ARC_Rect *rect1, ARC_Rect *rect2){ + if(rect1->x <= rect2->x + rect2->w && rect1->x + rect1->w >= rect2->x && + rect1->y <= rect2->y + rect2->h && rect1->y + rect1->h >= rect2->y){ + return 1; + } + return 0; +} + +int32_t ARC_Rect_LineIntersects(ARC_Rect *rect, int32_t *x1, int32_t *y1, int32_t *x2, int32_t *y2){ + //TODO: Replace soon + return SDL_IntersectRectAndLine((SDL_Rect *) rect, x1, y1, x2, y2); +} +