aboutsummaryrefslogtreecommitdiff
path: root/render/button.c
diff options
context:
space:
mode:
authorjacopo grandi <jak.sk8@hotmail.it>2021-02-18 14:14:23 +0100
committerjacopo grandi <jak.sk8@hotmail.it>2021-02-18 14:14:23 +0100
commit5f0fce4191309e9526b7109a0d87c092ce6a4193 (patch)
tree105257f876551814aa74a0760ec116bd1bf307a5 /render/button.c
parentead78d51e662057467b79d3a65b20c4ba83cbf07 (diff)
main
Diffstat (limited to 'render/button.c')
-rw-r--r--render/button.c21
1 files changed, 21 insertions, 0 deletions
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 <stdlib.h>
+#include <stdio.h>
+#include <button.h>
+
+#include <intersect.h>
+
+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