diff --git a/include/arc/engine/engine.h b/include/arc/engine/engine.h index e7f9f85..0c75d81 100644 --- a/include/arc/engine/engine.h +++ b/include/arc/engine/engine.h @@ -26,7 +26,7 @@ typedef struct ARC_EngineData { //NOTE: most work below is temp, and will change once I figure out a better way to write this header -void ARC_EngineData_Create(ARC_EngineData **data, ARC_Handler_CleanDataFn cleanfn); +void ARC_EngineData_Create(ARC_EngineData **data, ARC_Handler_CleanDataFn cleanfn, ARC_Point windowSize); void ARC_EngineData_Destroy(ARC_EngineData *data); diff --git a/include/arc/graphics/color.h b/include/arc/graphics/color.h new file mode 100644 index 0000000..bca34bc --- /dev/null +++ b/include/arc/graphics/color.h @@ -0,0 +1,19 @@ +#ifndef ARC_GRAPHICS_COLOR_H_ +#define ARC_GRAPHICS_COLOR_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +typedef struct ARC_Color { + uint8_t r, g, b, a; +} ARC_Color; + + +#ifdef __cplusplus +} +#endif + +#endif // !ARC_GRAPHICS_COLOR_H_ diff --git a/include/arc/graphics/line.h b/include/arc/graphics/line.h new file mode 100644 index 0000000..55207f6 --- /dev/null +++ b/include/arc/graphics/line.h @@ -0,0 +1,19 @@ +#ifndef ARC_GRAPHICS_LINE_H_ +#define ARC_GRAPHICS_LINE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "arc/graphics/color.h" +#include "arc/graphics/renderer.h" +#include "arc/math/rectangle.h" +#include + +void ARC_Line_Render(int32_t *x1, int32_t *y1, int32_t *x2, int32_t *y2, ARC_Renderer *renderer, ARC_Color *color); + +#ifdef __cplusplus +} +#endif + +#endif // !ARC_GRAPHICS_LINE_H_ diff --git a/include/arc/graphics/rect.h b/include/arc/graphics/rect.h new file mode 100644 index 0000000..ad52bf2 --- /dev/null +++ b/include/arc/graphics/rect.h @@ -0,0 +1,23 @@ +#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); + +int32_t ARC_Rect_Intersects(ARC_Rect *rect1, ARC_Rect *rect2); + +int32_t ARC_Rect_LineIntersects(ARC_Rect *rect, int32_t *x1, int32_t *y1, int32_t *x2, int32_t *y2); + +#ifdef __cplusplus +} +#endif + +#endif // !ARC_GRAPHICS_RECT_H_ diff --git a/include/arc/math/point.h b/include/arc/math/point.h index bfdad69..b5b33b2 100644 --- a/include/arc/math/point.h +++ b/include/arc/math/point.h @@ -11,4 +11,8 @@ typedef struct ARC_UPoint { uint32_t x, y; } ARC_UPoint; +typedef struct ARC_FPoint { + float x, y; +} ARC_FPoint; + #endif // ARC_MATH_POINT_H_ diff --git a/src/engine/engine.c b/src/engine/engine.c index cf5523a..f080c7f 100644 --- a/src/engine/engine.c +++ b/src/engine/engine.c @@ -18,7 +18,7 @@ #include "arc/input/sdl/keyboard.h" #endif // ARC_SDL -void ARC_EngineData_Create(ARC_EngineData **data, ARC_Handler_CleanDataFn cleanfn){ +void ARC_EngineData_Create(ARC_EngineData **data, ARC_Handler_CleanDataFn cleanfn, ARC_Point windowSize){ *data = (ARC_EngineData *)malloc(sizeof(ARC_EngineData)); (*data)->window = NULL; (*data)->renderer = NULL; @@ -31,7 +31,7 @@ void ARC_EngineData_Create(ARC_EngineData **data, ARC_Handler_CleanDataFn cleanf ARC_MouseInfo mouseInfo; ARC_KeyboardInfo keyboardInfo; - (*data)->windowSize = (ARC_Point){ 2560, 1440 }; + (*data)->windowSize = windowSize; #ifdef ARC_SDL windowInfo = (ARC_WindowInfo){ "title", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, (*data)->windowSize.x, (*data)->windowSize.y, 0 }; diff --git a/src/graphics/sdl/line.c b/src/graphics/sdl/line.c new file mode 100644 index 0000000..65c242e --- /dev/null +++ b/src/graphics/sdl/line.c @@ -0,0 +1,11 @@ +#include "arc/graphics/line.h" +#ifdef ARC_SDL +#include "arc/graphics/sdl/renderer.h" +#include + +void ARC_Line_Render(int32_t *x1, int32_t *y1, int32_t *x2, int32_t *y2, ARC_Renderer *renderer, ARC_Color *color){ + SDL_SetRenderDrawColor(renderer->renderer, color->r, color->g, color->b, color->a); + SDL_RenderDrawLine(renderer->renderer, *x1, *y1, *x2, *y2); +} + +#endif // ARC_SDL \ No newline at end of file diff --git a/src/graphics/sdl/rect.c b/src/graphics/sdl/rect.c new file mode 100644 index 0000000..b327467 --- /dev/null +++ b/src/graphics/sdl/rect.c @@ -0,0 +1,23 @@ +#include "arc/graphics/rect.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); +} + +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){ + return SDL_IntersectRectAndLine((SDL_Rect *) rect, x1, y1, x2, y2); +} + +#endif // ARC_SDL \ No newline at end of file