From 5f0fce4191309e9526b7109a0d87c092ce6a4193 Mon Sep 17 00:00:00 2001 From: jacopo grandi Date: Thu, 18 Feb 2021 14:14:23 +0100 Subject: main --- render/button.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 render/button.c (limited to 'render/button.c') diff --git a/render/button.c b/render/button.c new file mode 100644 index 0000000..eb96f59 --- /dev/null +++ b/render/button.c @@ -0,0 +1,21 @@ +#include +#include +#include + +#include + +bool mouse_in_button (float pt[], txtd *t, button *b) { + int width = get_text_width(b->txt, t); + float size[2] = { width+b->pad*2, 10+b->pad*2 }; + if (pt_rect(pt, b->pos, size)) return true; + return false; +} + +void render_button (SDL_Renderer* rend, txtd *t, button *b) { + int width = get_text_width(b->txt, t); + SDL_Rect rect = { b->pos[0], b->pos[1], width+b->pad*2, 10+b->pad*2 }; + SDL_SetRenderDrawColor(rend, 0, 0, 0, 255); + SDL_RenderDrawRect(rend, &rect); + float offpad[2] = { b->pos[0]+b->pad, b->pos[1]+b->pad }; + render_text(rend, b->txt, offpad, t); +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf