Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2df6a14610 | |||
| 141aea0fc4 |
@@ -1,11 +1,30 @@
|
|||||||
package gui
|
package gui
|
||||||
|
|
||||||
|
import "core:log"
|
||||||
import m "../machine"
|
import m "../machine"
|
||||||
import rl "vendor:raylib"
|
import rl "vendor:raylib"
|
||||||
|
|
||||||
CB_PADDING :: 20
|
PADDING :: 10
|
||||||
|
|
||||||
gui_control_bar :: proc(rect: rl.Rectangle, s: ^m.System) {
|
gui_control_bar :: proc(rect: rl.Rectangle, s: ^m.System) {
|
||||||
rl.DrawRectangleLinesEx(rect, 1, rl.DARKGRAY)
|
rl.DrawRectangleLinesEx(rect, 1, rl.DARKGRAY)
|
||||||
rl.GuiButton(rl.Rectangle{rect.x, rect.y, 100, rect.height}, "test")
|
|
||||||
|
// Small text area
|
||||||
|
|
||||||
|
// Control bar buttons
|
||||||
|
btn_w : f32 = 80
|
||||||
|
btn_h : f32 = rect.height - (PADDING * 2)
|
||||||
|
gap : f32 = 6
|
||||||
|
cursor : f32 = rect.x + PADDING
|
||||||
|
|
||||||
|
if btn(&cursor, rect, btn_h, btn_w, gap, "RUN") { log.info("RUN clicked") }
|
||||||
|
if btn(&cursor, rect, btn_h, btn_w, gap, "PAUSE") { log.info("PAUSE clicked") }
|
||||||
|
if btn(&cursor, rect, btn_h, btn_w, gap, "STEP") { log.info("STEP clicked") }
|
||||||
|
if btn(&cursor, rect, btn_h, btn_w, gap, "STOP") { log.info("STOP clicked") }
|
||||||
|
}
|
||||||
|
|
||||||
|
btn :: proc(cursor: ^f32, rect: rl.Rectangle, h, w, gap: f32, label: cstring) -> bool {
|
||||||
|
r := rl.Rectangle{cursor^, rect.y + PADDING, w, h}
|
||||||
|
cursor^ += w + gap
|
||||||
|
return rl.GuiButton(r, label)
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-31
@@ -7,16 +7,16 @@ import rl "vendor:raylib"
|
|||||||
WINDOW_WIDTH :: 1920
|
WINDOW_WIDTH :: 1920
|
||||||
WINDOW_HEIGHT :: 1080
|
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
|
CONTROLBAR_PERCENT :: 0.05
|
||||||
|
|
||||||
Layout :: struct {
|
Layout :: struct {
|
||||||
left_panel : rl.Rectangle,
|
|
||||||
right_panel : rl.Rectangle,
|
|
||||||
display : rl.Rectangle,
|
|
||||||
control_bar : rl.Rectangle,
|
control_bar : rl.Rectangle,
|
||||||
|
left_panel : rl.Rectangle,
|
||||||
|
display : rl.Rectangle,
|
||||||
|
right_panel : rl.Rectangle,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize main the gui 'window'
|
// Initialize main the gui 'window'
|
||||||
@@ -34,20 +34,16 @@ init_gui :: proc(s: ^m.System) {
|
|||||||
screen_height := f32(rl.GetScreenHeight())
|
screen_height := f32(rl.GetScreenHeight())
|
||||||
sidebar_width := screen_width * 0.20
|
sidebar_width := screen_width * 0.20
|
||||||
|
|
||||||
|
// set all the layout structs dynamically with the screen size
|
||||||
layout := calc_layout(screen_width, screen_height)
|
layout := calc_layout(screen_width, screen_height)
|
||||||
|
|
||||||
rl.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
rl.ClearBackground(rl.BLACK)
|
rl.ClearBackground(rl.BLACK)
|
||||||
|
|
||||||
// TODO: move this out / make better
|
// Cycle the machine to update memory etc
|
||||||
// --------------------------------------
|
m.run_machine(s)
|
||||||
// CPU cycles
|
|
||||||
for _ in 0..<12 {
|
|
||||||
m.handle_input(s)
|
|
||||||
m.cycle(s)
|
|
||||||
}
|
|
||||||
// --------------------------------------
|
|
||||||
|
|
||||||
|
// Now draw the update data
|
||||||
gui_left_panel(layout.left_panel, s)
|
gui_left_panel(layout.left_panel, s)
|
||||||
gui_right_panel(layout.right_panel, s)
|
gui_right_panel(layout.right_panel, s)
|
||||||
gui_screen(layout.display, s)
|
gui_screen(layout.display, s)
|
||||||
@@ -60,38 +56,37 @@ init_gui :: proc(s: ^m.System) {
|
|||||||
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 {
|
calc_layout :: proc(screen_width: f32, screen_height: f32) -> Layout {
|
||||||
|
control_bar_height := screen_height * CONTROLBAR_PERCENT
|
||||||
sidebar_width := screen_width * SIDEBAR_PERCENT
|
sidebar_width := screen_width * SIDEBAR_PERCENT
|
||||||
display_height := screen_height * DISPLAY_PERCENT
|
sidebar_height := screen_height - control_bar_height
|
||||||
|
display_height := screen_height * DISPLAY_PERCENT - control_bar_height
|
||||||
|
|
||||||
return Layout {
|
return Layout {
|
||||||
left_panel = rl.Rectangle {
|
control_bar = rl.Rectangle {
|
||||||
x = 0,
|
x = 0,
|
||||||
y = 0,
|
y = 0,
|
||||||
width = sidebar_width,
|
width = screen_width,
|
||||||
height = screen_height
|
height = control_bar_height
|
||||||
},
|
},
|
||||||
|
left_panel = rl.Rectangle {
|
||||||
right_panel = rl.Rectangle {
|
x = 0,
|
||||||
x = screen_width - sidebar_width,
|
y = control_bar_height,
|
||||||
y = 0,
|
|
||||||
width = sidebar_width,
|
width = sidebar_width,
|
||||||
height = screen_height
|
height = sidebar_height
|
||||||
},
|
},
|
||||||
|
|
||||||
display = rl.Rectangle {
|
display = rl.Rectangle {
|
||||||
x = sidebar_width,
|
x = sidebar_width,
|
||||||
y = 0,
|
y = control_bar_height,
|
||||||
width = screen_width - (sidebar_width * 2),
|
width = screen_width - (sidebar_width * 2),
|
||||||
height = display_height
|
height = display_height
|
||||||
},
|
},
|
||||||
|
right_panel = rl.Rectangle {
|
||||||
control_bar = rl.Rectangle {
|
x = screen_width - sidebar_width,
|
||||||
x = sidebar_width,
|
y = control_bar_height,
|
||||||
y = display_height,
|
width = sidebar_width,
|
||||||
width = screen_width - (sidebar_width * 2),
|
height = sidebar_height
|
||||||
height = (screen_height * 0.05)
|
},
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -334,4 +334,3 @@ op_mem_get :: proc(s: ^System, vx_idx: u16) {
|
|||||||
s.v[loop_idx] = s.memory[s.i + loop_idx]
|
s.v[loop_idx] = s.memory[s.i + loop_idx]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,3 +60,11 @@ init :: proc() -> System {
|
|||||||
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
run_machine :: proc(s: ^System) {
|
||||||
|
// CPU cycles
|
||||||
|
for _ in 0..<12 {
|
||||||
|
handle_input(s)
|
||||||
|
cycle(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user