|
1 | 1 | #include "button.h" |
2 | 2 |
|
3 | | -Button InitButton(Texture2D text, Vector2 offset, Sound soundFx, GameState state) |
| 3 | +Button InitButton(Texture2D texture, const char *text, Vector2 offset, Sound soundFx, GameState state) |
4 | 4 | { |
5 | 5 | // Define frame rectangle for drawing |
6 | | - float height = (float)text.height / BUTTON_FRAMES; |
7 | | - Rectangle sourceRec = {0, 0, (float)text.width, height}; |
| 6 | + float height = (float)texture.height / BUTTON_FRAMES; |
| 7 | + Rectangle sourceRec = {0, 0, (float)texture.width, height}; |
8 | 8 |
|
9 | 9 | // Define button position on screen |
10 | 10 | Rectangle btnPosition = { |
11 | | - screenWidth / 2.0f - text.width / 2.0f + offset.x, |
12 | | - screenHeight / 2.0f - text.height / BUTTON_FRAMES / 2.0f + offset.y, |
13 | | - (float)text.width, |
| 11 | + screenWidth / 2.0f - texture.width / 2.0f + offset.x, |
| 12 | + screenHeight / 2.0f - texture.height / BUTTON_FRAMES / 2.0f + offset.y, |
| 13 | + (float)texture.width, |
14 | 14 | height}; |
15 | 15 |
|
16 | 16 | return (Button){ |
17 | | - .texture = text, |
| 17 | + .texture = texture, |
| 18 | + .text = text, |
18 | 19 | .rect = sourceRec, |
19 | 20 | .position = btnPosition, |
20 | 21 | .frameHeight = height, |
@@ -63,5 +64,7 @@ void UpdateButton(Button *button) |
63 | 64 |
|
64 | 65 | void DrawButton(Button *button) |
65 | 66 | { |
66 | | - DrawTextureRec(button->texture, button->rect, (Vector2){button->position.x, button->position.y}, WHITE); |
| 67 | + // DrawTextureRec(button->texture, button->rect, (Vector2){button->position.x, button->position.y}, WHITE); |
| 68 | + DrawRectangle(button->position.x, button->position.y, button->rect.x, button->rect.y, LIGHTGRAY); |
| 69 | + DrawText(button->text, button->position.x + 40, button->position.y + 10, 40, BLACK); |
67 | 70 | } |
0 commit comments