diff --git a/src/simulator/left_panel.odin b/src/simulator/left_panel.odin index 9c8dedd..e4662de 100644 --- a/src/simulator/left_panel.odin +++ b/src/simulator/left_panel.odin @@ -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) + } }