aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui.c
diff options
context:
space:
mode:
authornathansmith117 <thenathansmithsmith@gmail.com>2024-02-21 02:57:18 +0000
committernathansmith117 <thenathansmithsmith@gmail.com>2024-02-21 02:57:18 +0000
commit6c63c3d327cf3b494309db82bdd4489b59d3d247 (patch)
treea5222a6e960e74f884299a558d8b103efcd6804d /src/ui.c
parent801df9c821db87cf2e50f486c63ff083b375eb7e (diff)
downloadPenguinYippies-6c63c3d327cf3b494309db82bdd4489b59d3d247.tar.gz
PenguinYippies-6c63c3d327cf3b494309db82bdd4489b59d3d247.tar.bz2
PenguinYippies-6c63c3d327cf3b494309db82bdd4489b59d3d247.zip
Button thingy working
Diffstat (limited to 'src/ui.c')
-rw-r--r--src/ui.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/ui.c b/src/ui.c
index d0e9aa3..7166add 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -7,9 +7,13 @@ TexturedButton createTexturedButton(Texture* texture, Rectangle rect, const char
TexturedButton button;
button.texture = texture;
button.rect = rect;
+
strncpy((char*)button.message, message, UI_BUTTON_NAME_MAX);
+ button.messageLength = strnlen(button.message, UI_BUTTON_NAME_MAX);
+
button.backgroundColor = backgroundColor;
button.foregroundColor = foregroundColor;
+ button.fontSize = UI_BUTTON_DEFAULT_FONT_SIZE;
button.isPressed = false;
return button;
@@ -27,5 +31,32 @@ bool updateTexturedButton(TexturedButton* button)
button->backgroundColor
);
+
+ // Draw outline thingy.
+ if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
+ {
+ DrawRectangleLinesEx(button->rect, 2, button->foregroundColor);
+ }
+
+ // Draw text centered in button.
+ DrawText(
+ button->message,
+ button->rect.x + (button->rect.width / 2.0 - (button->messageLength * button->fontSize / 4.0)),
+ button->rect.y + (button->rect.height / 2.0 - button->fontSize / 2.0),
+ button->fontSize,
+ button->foregroundColor
+ );
+
+ button->isPressed = false;
+
+ // Check if the button is clicked.
+ if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
+ {
+ if (CheckCollisionPointRec(GetMousePosition(), button->rect))
+ {
+ button->isPressed = true;
+ }
+ }
+
return button->isPressed;
}