Compare commits

..

2 Commits

3 changed files with 95 additions and 51 deletions
+41 -45
View File
@@ -10,7 +10,8 @@ WINDOW_HEIGHT :: 1080
// @TODO: If this grows lets move it into its own file // @TODO: If this grows lets move it into its own file
SIDEBAR_PERCENT :: 0.20 SIDEBAR_PERCENT :: 0.20
DISPLAY_PERCENT :: 0.30 DISPLAY_PERCENT :: 0.30
CONTROLBAR_PERCENT :: 0.05 CONTROL_BAR_H :: f32(50)
STATUS_BAR_H :: f32(30)
Layout :: struct { Layout :: struct {
control_bar : rl.Rectangle, control_bar : rl.Rectangle,
@@ -33,11 +34,9 @@ run_gui :: proc(sim: ^Simulator) {
rl.SetTextureFilter(font.texture, .BILINEAR) rl.SetTextureFilter(font.texture, .BILINEAR)
sim.font = font sim.font = font
// Initialize style system first
rl.GuiLoadStyleDefault() rl.GuiLoadStyleDefault()
// Then load dark theme
rl.GuiLoadStyle("./assets/raygui_styles/style_dark.rgs") rl.GuiLoadStyle("./assets/raygui_styles/style_dark.rgs")
// Then override font AFTER (style load resets it)
rl.GuiSetFont(font) rl.GuiSetFont(font)
rl.GuiSetStyle(.DEFAULT, cast(i32)rl.GuiDefaultProperty.TEXT_SIZE, 18) rl.GuiSetStyle(.DEFAULT, cast(i32)rl.GuiDefaultProperty.TEXT_SIZE, 18)
@@ -56,7 +55,6 @@ run_gui :: proc(sim: ^Simulator) {
rl.ClearBackground(rl.BLACK) rl.ClearBackground(rl.BLACK)
// Cycle the machine to update memory etc // 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) { if (!sim.paused) {
emu.run_machine(sim.machine, 12) emu.run_machine(sim.machine, 12)
@@ -75,7 +73,7 @@ run_gui :: proc(sim: ^Simulator) {
} }
gui_control_bar(layout.control_bar, sim) gui_control_bar(layout.control_bar, sim)
// gui_left_panel(layout.left_panel, s.machine) gui_left_panel(layout.left_panel, sim)
// gui_right_panel(layout.right_panel, s.machine) // gui_right_panel(layout.right_panel, s.machine)
// Screen is just drawing the display buffer just needs that as arg // Screen is just drawing the display buffer just needs that as arg
@@ -87,49 +85,47 @@ run_gui :: proc(sim: ^Simulator) {
} }
rl.UnloadFont(sim.font) rl.UnloadFont(sim.font)
rl.UnloadFont(font)
rl.UnloadSound(beep) rl.UnloadSound(beep)
rl.CloseAudioDevice() rl.CloseAudioDevice()
rl.CloseWindow() rl.CloseWindow()
} }
// @TODO: If this grows lets move it into its own file // @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 { calc_layout :: proc(screen_width: f32, screen_height: f32) -> Layout {
control_bar = rl.Rectangle { sidebar_width := screen_width * SIDEBAR_PERCENT
x = 0, content_height := screen_height - CONTROL_BAR_H - STATUS_BAR_H
y = 0, display_height := screen_height * DISPLAY_PERCENT - CONTROL_BAR_H - STATUS_BAR_H
width = screen_width,
height = control_bar_height return Layout {
}, control_bar = rl.Rectangle {
left_panel = rl.Rectangle { x = 0,
x = 0, y = 0,
y = control_bar_height, width = screen_width,
width = sidebar_width, height = CONTROL_BAR_H,
height = sidebar_height },
}, left_panel = rl.Rectangle {
display = rl.Rectangle { x = 0,
x = sidebar_width, y = CONTROL_BAR_H,
y = control_bar_height, width = sidebar_width,
width = screen_width - (sidebar_width * 2), height = content_height,
height = display_height },
}, display = rl.Rectangle {
right_panel = rl.Rectangle { x = sidebar_width,
x = screen_width - sidebar_width, y = CONTROL_BAR_H,
y = control_bar_height, width = screen_width - (sidebar_width * 2),
width = sidebar_width, height = display_height,
height = sidebar_height },
}, right_panel = rl.Rectangle {
status_bar = rl.Rectangle { x = screen_width - sidebar_width,
x = 0, y = CONTROL_BAR_H,
y = screen_height - control_bar_height, width = sidebar_width,
width = screen_width, height = content_height,
height = control_bar_height },
}, status_bar = rl.Rectangle {
} x = 0,
} y = screen_height - STATUS_BAR_H,
width = screen_width, height = STATUS_BAR_H,
},
}
}
+52 -3
View File
@@ -1,8 +1,57 @@
package simulator package simulator
import m "../machine" import "core:strings"
import "core:log"
import rl "vendor:raylib" import rl "vendor:raylib"
gui_left_panel :: proc(rect: rl.Rectangle, s: ^m.System) { gui_left_panel :: proc(rect: rl.Rectangle, sim: ^Simulator) {
rl.DrawRectangleLinesEx(rect, 1, rl.DARKGRAY) top_panel := rl.Rectangle {
rect.x,
rect.y,
rect.width,
rect.height / 2,
}
rl.DrawRectangleLinesEx(top_panel, 1, rl.DARKGRAY)
bottom_panel := rl.Rectangle {
rect.x,
rect.y + top_panel.height,
rect.width,
rect.height / 2,
}
rl.DrawRectangleLinesEx(bottom_panel, 1, rl.GREEN)
gui_key_pad(bottom_panel, sim.machine.keypad, sim.font)
}
gui_key_pad :: proc(rect: rl.Rectangle, display: [16]bool, font: rl.Font) {
Key :: struct { label: string, index: int}
keys := [16]Key {
{"1", 1}, {"2", 2}, {"3", 3}, {"C", 12},
{"4", 4}, {"5", 5}, {"6", 6}, {"D", 13},
{"7", 7}, {"8", 8}, {"9", 9}, {"D", 14},
{"A", 10}, {"0", 0}, {"B", 11}, {"F", 15}
}
btn_width := f32(rect.width / 4)
btn_height := f32(rect.height / 4)
for val, idx in keys {
str := strings.clone_to_cstring(val.label)
ri := int(idx / 4)
ci := idx % 4
irect := rl.Rectangle{
x = btn_width * f32(ci),
y = (btn_height * f32(ri)) + rect.y,
width = btn_width,
height = btn_height,
}
if(display[val.index]) { rl.DrawRectangleRec(irect, rl.DARKGRAY) }
rl.DrawRectangleLinesEx(irect, 1, rl.GRAY)
rl.DrawTextEx(font, str, rl.Vector2{irect.x + btn_width / 2, irect.y + btn_height / 2}, 18, 1, rl.WHITE)
// Free the allocations!
delete(str)
}
} }
+2 -3
View File
@@ -4,12 +4,11 @@ import emu "../machine"
import rl "vendor:raylib" import rl "vendor:raylib"
Simulator :: struct { Simulator :: struct {
font: rl.Font,
machine: ^emu.System, machine: ^emu.System,
running: bool, running: bool,
paused: bool, paused: bool,
cycles_per_second: int cycles_per_second: int,
font: rl.Font,
} }
// Requires an initilized emulatore System Struct // Requires an initilized emulatore System Struct