package simulator import rl "vendor:raylib" gui_screen :: proc(rect: rl.Rectangle, sim: ^Simulator) { 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, nil) s := sim.machine // 2 : 1 // 2 so, for every 1 unit of height I have 2 units of width // twice as wide as it is tall, or half as tall as it is wide aspect_ratio : f32 = 64.0 / 32.0 // create viewport for the ratio view := rect avail_space := bounds.width / bounds.height if avail_space > aspect_ratio { view.width = bounds.height * aspect_ratio view.x = bounds.x + (bounds.width - view.width) * 0.5 } else { view.height = bounds.width / aspect_ratio view.y = bounds.y + (bounds.height - view.height) * 0.5 } // get scale pixel := min(int(view.width / 64), int(view.height / 32)) pixel = max(pixel, 1) draw_w := pixel * 64 draw_h := pixel * 32 // center frame x := i32(view.x + (view.width - f32(draw_w)) * 0.5) y := i32(view.y + (view.height - f32(draw_h)) * 0.5) rl.DrawRectangleLinesEx(rect, 1, rl.DARKGRAY) if !sim.rom_loaded { // centered drop-zone text text: cstring = "PLEASE SELECT AND LOAD A CHIP 8 ROM" text_width := rl.MeasureText(text, BIG_FONT_SIZE) text_x := view.x + (view.width - f32(text_width)) * 0.6 text_y := view.y + (view.height - f32(BIG_FONT_SIZE)) * 0.5 rl.DrawTextEx(sim.font, text, {text_x,text_y}, BIG_FONT_SIZE, 1, rl.WHITE) } else { render_display(&s.display, x, y, i32(pixel)) } } @(private = "file") render_display :: proc(display_buffer: ^[32][64]u8, offset_x, offset_y, scale: i32) { rl.DrawRectangle(offset_x, offset_y, 64 * scale, 32 * scale, rl.BLACK) for y in 0..