Renamed gui to simulator as a better structure.
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
package simulator
|
||||
|
||||
import emu "../machine"
|
||||
import rl "vendor:raylib"
|
||||
|
||||
// Initial window size
|
||||
WINDOW_WIDTH :: 1920
|
||||
WINDOW_HEIGHT :: 1080
|
||||
|
||||
// @TODO: If this grows lets move it into its own file
|
||||
SIDEBAR_PERCENT :: 0.20
|
||||
DISPLAY_PERCENT :: 0.30
|
||||
CONTROLBAR_PERCENT :: 0.05
|
||||
|
||||
Layout :: struct {
|
||||
control_bar : rl.Rectangle,
|
||||
left_panel : rl.Rectangle,
|
||||
display : rl.Rectangle,
|
||||
right_panel : rl.Rectangle,
|
||||
status_bar : rl.Rectangle,
|
||||
}
|
||||
|
||||
// Initialize main the gui 'window'
|
||||
run_gui :: proc(sim: ^Simulator) {
|
||||
rl.SetConfigFlags({.WINDOW_RESIZABLE})
|
||||
rl.InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "raylib")
|
||||
rl.InitAudioDevice()
|
||||
rl.SetTargetFPS(60)
|
||||
beep := rl.LoadSound("./beep.wav")
|
||||
|
||||
// Load fonts
|
||||
font := rl.LoadFontEx("./assets/fonts/Inter_18pt-Regular.ttf", 18, nil, 0)
|
||||
rl.SetTextureFilter(font.texture, .BILINEAR)
|
||||
sim.font = font
|
||||
|
||||
// Initialize style system first
|
||||
rl.GuiLoadStyleDefault()
|
||||
// Then load dark theme
|
||||
rl.GuiLoadStyle("./assets/raygui_styles/style_dark.rgs")
|
||||
// Then override font AFTER (style load resets it)
|
||||
rl.GuiSetFont(font)
|
||||
rl.GuiSetStyle(.DEFAULT, cast(i32)rl.GuiDefaultProperty.TEXT_SIZE, 18)
|
||||
|
||||
// Draw each of the components in its own window within the main window
|
||||
for !rl.WindowShouldClose() {
|
||||
// Recalculate layout each frame based on current window size
|
||||
// Pass these down to gui functions so they can setup their sizes?
|
||||
screen_width := f32(rl.GetScreenWidth())
|
||||
screen_height := f32(rl.GetScreenHeight())
|
||||
sidebar_width := screen_width * 0.20
|
||||
|
||||
// set all the layout structs dynamically with the screen size
|
||||
layout := calc_layout(screen_width, screen_height)
|
||||
|
||||
rl.BeginDrawing()
|
||||
rl.ClearBackground(rl.BLACK)
|
||||
|
||||
// Cycle the machine to update memory etc
|
||||
// if (sim.is_running) else don't run machine, here we can start,pause etc
|
||||
if (!sim.paused) {
|
||||
emu.run_machine(sim.machine, 12)
|
||||
|
||||
// Handle delay timer
|
||||
if sim.machine.delay_timer > 0 do sim.machine.delay_timer -= 1
|
||||
|
||||
// Current sound file is around 1s so stop
|
||||
// immediately when timer is 0
|
||||
if sim.machine.sound_timer > 0 {
|
||||
sim.machine.sound_timer -= 1
|
||||
if !rl.IsSoundPlaying(beep) do rl.PlaySound(beep)
|
||||
} else {
|
||||
rl.StopSound(beep)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
gui_control_bar(layout.control_bar, sim)
|
||||
// gui_left_panel(layout.left_panel, s.machine)
|
||||
// gui_right_panel(layout.right_panel, s.machine)
|
||||
|
||||
// Screen is just drawing the display buffer just needs that as arg
|
||||
// Not the whole sim struct
|
||||
gui_screen(layout.display, sim.machine)
|
||||
gui_status_bar(layout.status_bar, sim)
|
||||
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
rl.UnloadFont(sim.font)
|
||||
rl.UnloadFont(font)
|
||||
rl.UnloadSound(beep)
|
||||
rl.CloseAudioDevice()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
||||
// @TODO: If this grows lets move it into its own file
|
||||
calc_layout :: proc(screen_width: f32, screen_height: f32) -> Layout {
|
||||
control_bar_height := screen_height * CONTROLBAR_PERCENT
|
||||
sidebar_width := screen_width * SIDEBAR_PERCENT
|
||||
sidebar_height := screen_height - control_bar_height
|
||||
display_height := screen_height * DISPLAY_PERCENT - control_bar_height
|
||||
|
||||
return Layout {
|
||||
control_bar = rl.Rectangle {
|
||||
x = 0,
|
||||
y = 0,
|
||||
width = screen_width,
|
||||
height = control_bar_height
|
||||
},
|
||||
left_panel = rl.Rectangle {
|
||||
x = 0,
|
||||
y = control_bar_height,
|
||||
width = sidebar_width,
|
||||
height = sidebar_height
|
||||
},
|
||||
display = rl.Rectangle {
|
||||
x = sidebar_width,
|
||||
y = control_bar_height,
|
||||
width = screen_width - (sidebar_width * 2),
|
||||
height = display_height
|
||||
},
|
||||
right_panel = rl.Rectangle {
|
||||
x = screen_width - sidebar_width,
|
||||
y = control_bar_height,
|
||||
width = sidebar_width,
|
||||
height = sidebar_height
|
||||
},
|
||||
status_bar = rl.Rectangle {
|
||||
x = 0,
|
||||
y = screen_height - control_bar_height,
|
||||
width = screen_width,
|
||||
height = control_bar_height
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user