From 8ff25c1e8951304ff5c125e05a8fa044a198ef72 Mon Sep 17 00:00:00 2001 From: nathansmith117 Date: Tue, 20 Feb 2024 20:18:32 -0700 Subject: More buttons --- src/ui.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'src/ui.c') diff --git a/src/ui.c b/src/ui.c index 7166add..f07dc96 100644 --- a/src/ui.c +++ b/src/ui.c @@ -31,28 +31,31 @@ bool updateTexturedButton(TexturedButton* button) button->backgroundColor ); - - // Draw outline thingy. - if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) + // Draw text centered in button if we have a message. + if (button->message[0] != '\0') { - DrawRectangleLinesEx(button->rect, 2, button->foregroundColor); + 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 + ); } - // 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)) + // Outline and detect click stuff. + if (CheckCollisionPointRec(GetMousePosition(), button->rect)) { - if (CheckCollisionPointRec(GetMousePosition(), button->rect)) + // Draw outline thingy. + if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) + { + DrawRectangleLinesEx(button->rect, 2, button->foregroundColor); + } + + // Is clicked. + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { button->isPressed = true; } -- cgit v1.2.3