clean up button creation + center text

This commit is contained in:
2026-06-19 02:21:49 -07:00
parent 433ac4152b
commit 1a18c42b9e
2 changed files with 50 additions and 22 deletions
+23 -22
View File
@@ -36,34 +36,35 @@ poll_controls_command :: proc(world: ^World) -> Command {
return Command{kind = .None}
}
render_controls :: proc(world: ^World) {
if world.phase != .Build do return
bar_y := bottom_bar_y()
rl.DrawRectangle(0, bar_y, SCREEN_W, CONTROL_BAR_H, CONTROL_BAR_BG)
draw_archer_button :: proc(world: ^World, archer: rl.Rectangle) {
arch := get_archetype(.Archer)
archer, start_wave_btn := build_controls_layout()
mouse := rl.GetMousePosition()
arch_bg := CONTROLS_SHOP_IDLE
if world.selected_tower == .Archer do arch_bg = CONTROL_SHOP_SELECTED
if rl.CheckCollisionPointRec(mouse, archer) do arch_bg = CONTROL_BUTTON_HOVER
rl.DrawRectangleRec(archer, arch_bg)
label := fmt.ctprintf("Archer - %dg", arch.cost)
rl.DrawText(label, i32(archer.x) + 6, i32(archer.y) + 4, 14, OVERLAY_TEXT_COLOR)
wave_bg := CONTROL_BUTTON_COLOR
if rl.CheckCollisionPointRec(mouse, start_wave_btn) do wave_bg = CONTROLS_SHOP_HOVER
rl.DrawRectangleRec(start_wave_btn, wave_bg)
rl.DrawText(
"Start Wave",
i32(start_wave_btn.x) + 8,
i32(start_wave_btn.y) + 3,
16,
OVERLAY_TEXT_COLOR,
)
draw_button(archer, label, arch_bg, 14, OVERLAY_TEXT_COLOR)
}
draw_start_wave_button :: proc(start_wave_rect: rl.Rectangle, mouse: rl.Vector2) {
bg := CONTROL_BUTTON_COLOR
if rl.CheckCollisionPointRec(mouse, start_wave_rect) do bg = CONTROL_BUTTON_HOVER
draw_button(start_wave_rect, "Start Wave", bg, 16, OVERLAY_TEXT_COLOR)
}
render_controls :: proc(world: ^World) {
if world.phase != .Build do return
mouse := rl.GetMousePosition()
bar_y := bottom_bar_y()
rl.DrawRectangle(0, bar_y, SCREEN_W, CONTROL_BAR_H, CONTROL_BAR_BG)
archer, start_wave_rect := build_controls_layout()
draw_archer_button(world, archer)
draw_start_wave_button(start_wave_rect, mouse)
}
+27
View File
@@ -0,0 +1,27 @@
package game
import rl "vendor:raylib"
draw_text_centered_in_rect :: proc(
text: cstring,
rect: rl.Rectangle,
font_size: i32,
color: rl.Color,
) {
text_w := rl.MeasureText(text, font_size)
x := i32(rect.x) + (i32(rect.width) - text_w) / 2
y := i32(rect.y) + (i32(rect.height) - font_size) / 2
rl.DrawText(text, x, y, font_size, color)
}
draw_button :: proc(
rect: rl.Rectangle,
label: cstring,
bg: rl.Color,
font_size: i32,
text_color: rl.Color,
) {
rl.DrawRectangleRec(rect, bg)
draw_text_centered_in_rect(label, rect, font_size, text_color)
}