aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kdx.42@42l.fr>2023-03-28 07:25:59 +0000
committerkdx <kdx.42@42l.fr>2023-03-28 07:27:10 +0000
commite46475cdd2e0a9cff9330ec88d08640f19164b42 (patch)
tree1e8817249778130e4810cfa34dd9dd27e66df8dc
parent8a95b244a32ac58aafda89ba088d715714ef866a (diff)
downloadtzr-e46475cdd2e0a9cff9330ec88d08640f19164b42.tar.gz
fancy rectangle drawing
-rw-r--r--headers/TZR_render.h5
-rw-r--r--headers/TZR_types.h11
-rw-r--r--sources/TZR_DrawRectangle.c11
3 files changed, 23 insertions, 4 deletions
diff --git a/headers/TZR_render.h b/headers/TZR_render.h
index 592440c..99132a2 100644
--- a/headers/TZR_render.h
+++ b/headers/TZR_render.h
@@ -41,10 +41,13 @@ int TZR_DrawLine(int x0, int y0, int x1, int y1);
/* Return -1 on error. Draw rectangle at `x`;`y` position of size `w`x`h` in the
* framebuffer. */
+#define TZR_DrawRectangle(...) _TZR_DrawRectangle( \
+ &(const TZR_DrawRectangleArgs){ \
+ .x=0, .y=0, .w=0, .h=0, .fill=false, .center=false, ._=0, __VA_ARGS__ })
#ifdef TZR_PARANOID
[[nodiscard]]
#endif
-int TZR_DrawRectangle(bool fill, int x, int y, int w, int h);
+int _TZR_DrawRectangle(const TZR_DrawRectangleArgs *args);
/* Return -1 on error. Draw texture ressource `id` at `x`;`y` position of
* the framebuffer. */
diff --git a/headers/TZR_types.h b/headers/TZR_types.h
index 32f734a..183fe5d 100644
--- a/headers/TZR_types.h
+++ b/headers/TZR_types.h
@@ -33,6 +33,7 @@ typedef struct TZR_Resource TZR_Resource;
typedef enum TZR_EventType TZR_EventType;
typedef struct TZR_Event TZR_Event;
typedef struct TZR_DrawImageArgs TZR_DrawImageArgs;
+typedef struct TZR_DrawRectangleArgs TZR_DrawRectangleArgs;
typedef enum TZR_KeyState TZR_KeyState;
struct TZR_Config {
@@ -103,3 +104,13 @@ struct TZR_DrawImageArgs {
float sy;
bool center;
};
+
+struct TZR_DrawRectangleArgs {
+ int _;
+ int x;
+ int y;
+ int w;
+ int h;
+ bool fill;
+ bool center;
+};
diff --git a/sources/TZR_DrawRectangle.c b/sources/TZR_DrawRectangle.c
index 879eaba..0ea81fa 100644
--- a/sources/TZR_DrawRectangle.c
+++ b/sources/TZR_DrawRectangle.c
@@ -4,10 +4,15 @@
#include <SDL2/SDL_render.h>
int
-TZR_DrawRectangle(bool fill, int x, int y, int w, int h)
+_TZR_DrawRectangle(const TZR_DrawRectangleArgs *args)
{
- const SDL_Rect rect = { x, y, w, h };
- if (fill) {
+ const SDL_Rect rect = {
+ args->x - args->center * (args->w / 2),
+ args->y - args->center * (args->h / 2),
+ args->w,
+ args->h
+ };
+ if (args->fill) {
if (SDL_RenderFillRect(___tzr_renderer, &rect) < 0)
return sdl_error(-1);
} else {