Files
octal_cookie/src/simulator/gui_status_bar.odin
T
jasonhilder 0b5006f985 Step, reset, tick_timer proc and struct cleanup.
Added a tick_timer proc so the code handles the step neatly.
Added some new struct fields to accomodate this and moved danglings
struct defs into the simulator definition.
2026-06-19 12:33:47 +02:00

62 lines
2.0 KiB
Odin

package simulator
import "core:fmt"
import rl "vendor:raylib"
StatusIconShape :: enum { CIRCLE, SQUARE }
gui_status_bar :: proc(rect: rl.Rectangle, sim: ^Simulator) {
// Left to right text draws
rl.DrawRectangleLinesEx(rect, 1, rl.DARKGRAY)
cursor: f32 = rect.x + PADDING_X
cy := rect.y + rect.height * 0.5
if !sim.paused {
status_icon(&cursor, cy, rl.GREEN, .CIRCLE, "Running", sim.font)
} else {
status_icon(&cursor, cy, rl.RED, .SQUARE, "Paused", sim.font)
}
status_divider(&cursor, cy)
status_text(&cursor, cy, fmt.ctprintf("Rom Loaded: %v", sim.rom_loaded), sim.font)
// FPS set far right
fps_text := fmt.ctprintf("FPS: %d", rl.GetFPS())
fps_width := rl.MeasureTextEx(sim.font, fps_text, f32(sim.font.baseSize), 1).x
fps_x := rect.x + rect.width - PADDING_X - fps_width
rl.DrawTextEx(
sim.font,
fps_text,
{fps_x, cy - f32(sim.font.baseSize) * 0.5},
f32(sim.font.baseSize),
1,
rl.RAYWHITE,
)
}
status_icon :: proc(cursor: ^f32, cy: f32, color: rl.Color, shape: StatusIconShape, label: cstring, font: rl.Font) {
size: f32 = 10
ix := cursor^ + size * 0.5
switch shape {
case .CIRCLE: rl.DrawCircleV({ix, cy}, size * 0.5, color)
case .SQUARE: rl.DrawRectangleV({ix - size*0.5, cy - size*0.5}, {size, size}, color)
}
cursor^ += size + 6
rl.DrawTextEx(font, label, {cursor^, cy - f32(font.baseSize) * 0.5}, f32(font.baseSize), 1, rl.RAYWHITE)
cursor^ += rl.MeasureTextEx(font, label, f32(font.baseSize), 1).x + PADDING_X
}
status_divider :: proc(cursor: ^f32, cy: f32) {
rl.DrawLineV({cursor^, cy - 8}, {cursor^, cy + 8}, rl.DARKGRAY)
cursor^ += PADDING_X
}
status_text :: proc(cursor: ^f32, cy: f32, text: cstring, font: rl.Font) {
rl.DrawTextEx(font, text, {cursor^, cy - f32(font.baseSize) * 0.5}, f32(font.baseSize), 1, rl.RAYWHITE)
cursor^ += rl.MeasureTextEx(font, text, f32(font.baseSize), 1).x + PADDING_X
}