Added/updated components to be isolated rectangles.
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
package simulator
|
||||
|
||||
import "core:log"
|
||||
import rl "vendor:raylib"
|
||||
|
||||
import emu "../machine"
|
||||
import tfd "../../external/tinyfiledialogs"
|
||||
|
||||
gui_file_loader :: proc(rect: rl.Rectangle, sim: ^Simulator) {
|
||||
rl.DrawRectangleLinesEx(rect, 1, rl.GRAY)
|
||||
|
||||
bounds := rl.Rectangle {
|
||||
x = rect.x + PADDING_X,
|
||||
y = rect.y + PADDING_Y,
|
||||
width = rect.width - (PADDING_X * 2),
|
||||
height = rect.height - (PADDING_Y * 2),
|
||||
}
|
||||
rl.GuiPanel(bounds, "Rom / File")
|
||||
|
||||
// drop-zone occupies the panel's content area, minus space for the button
|
||||
drop_zone := rl.Rectangle {
|
||||
bounds.x + PADDING_X,
|
||||
bounds.y + PADDING_Y,
|
||||
bounds.width - (PADDING_X * 2),
|
||||
bounds.height - ((PADDING_Y * 2) + (BUTTON_HEIGHT + PADDING_Y))
|
||||
}
|
||||
|
||||
// centered drop-zone text
|
||||
text: cstring = "Drop a CHIP-8 ROM here"
|
||||
text_width := rl.MeasureText(text, BIG_FONT_SIZE)
|
||||
text_x := drop_zone.x + (drop_zone.width - f32(text_width)) / 2
|
||||
text_y := drop_zone.y + (drop_zone.height - f32(BIG_FONT_SIZE)) / 2
|
||||
rl.DrawTextEx(sim.font, text, {text_x, text_y}, BIG_FONT_SIZE, 1, rl.WHITE)
|
||||
|
||||
// open rom button below drop-zone
|
||||
btn_rect := rl.Rectangle {
|
||||
drop_zone.x,
|
||||
drop_zone.y + drop_zone.height + PADDING_Y,
|
||||
drop_zone.width,
|
||||
BUTTON_HEIGHT,
|
||||
}
|
||||
|
||||
if rl.GuiButton(btn_rect, "Open ROM") {
|
||||
ret := tfd.openFileDialog("Open File Dialog", nil, 0, nil, nil, 0,)
|
||||
rom_path := string(ret)
|
||||
if rom_path == "" do return
|
||||
|
||||
// reset machine state
|
||||
emu.reset_machine(sim.machine)
|
||||
|
||||
// load new rom
|
||||
err := emu.load_rom(sim.machine, rom_path)
|
||||
if err != nil {
|
||||
// @TODO: update status bar here
|
||||
panic("failed to load rom!")
|
||||
}
|
||||
|
||||
sim.rom_loaded = true
|
||||
}
|
||||
|
||||
// Handle file drop
|
||||
if rl.IsFileDropped() {
|
||||
dropped_file := rl.LoadDroppedFiles()
|
||||
if dropped_file.count > 0 {
|
||||
mouse := rl.GetMousePosition()
|
||||
|
||||
if rl.CheckCollisionPointRec(mouse, drop_zone) {
|
||||
path_str := string(dropped_file.paths[0])
|
||||
log.info("file dropped: ", path_str)
|
||||
// @TODO: Stop sim, reset mem etc, load new rom
|
||||
} else {
|
||||
log.info("File dropped outside drop zone, ignoring")
|
||||
}
|
||||
}
|
||||
rl.UnloadDroppedFiles(dropped_file)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user