Compare commits

...

2 Commits

3 changed files with 95 additions and 51 deletions
+40 -44
View File
@@ -10,7 +10,8 @@ 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
CONTROL_BAR_H :: f32(50)
STATUS_BAR_H :: f32(30)
Layout :: struct {
control_bar : rl.Rectangle,
@@ -33,11 +34,9 @@ run_gui :: proc(sim: ^Simulator) {
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)
@@ -56,7 +55,6 @@ run_gui :: proc(sim: ^Simulator) {
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)
@@ -75,7 +73,7 @@ run_gui :: proc(sim: ^Simulator) {
}
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)
// 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(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
},
}
calc_layout :: proc(screen_width: f32, screen_height: f32) -> Layout {
sidebar_width := screen_width * SIDEBAR_PERCENT
content_height := screen_height - CONTROL_BAR_H - STATUS_BAR_H
display_height := screen_height * DISPLAY_PERCENT - CONTROL_BAR_H - STATUS_BAR_H
return Layout {
control_bar = rl.Rectangle {
x = 0,
y = 0,
width = screen_width,
height = CONTROL_BAR_H,
},
left_panel = rl.Rectangle {
x = 0,
y = CONTROL_BAR_H,
width = sidebar_width,
height = content_height,
},
display = rl.Rectangle {
x = sidebar_width,
y = CONTROL_BAR_H,
width = screen_width - (sidebar_width * 2),
height = display_height,
},
right_panel = rl.Rectangle {
x = screen_width - sidebar_width,
y = CONTROL_BAR_H,
width = sidebar_width,
height = content_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
import m "../machine"
import "core:strings"
import "core:log"
import rl "vendor:raylib"
gui_left_panel :: proc(rect: rl.Rectangle, s: ^m.System) {
rl.DrawRectangleLinesEx(rect, 1, rl.DARKGRAY)
gui_left_panel :: proc(rect: rl.Rectangle, sim: ^Simulator) {
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"
Simulator :: struct {
font: rl.Font,
machine: ^emu.System,
running: bool,
paused: bool,
cycles_per_second: int
cycles_per_second: int,
font: rl.Font,
}
// Requires an initilized emulatore System Struct