gui experiments, add zooming

This commit is contained in:
Crispy 2024-10-04 21:20:53 +02:00
parent de09b785d0
commit af31531869
4 changed files with 161 additions and 13 deletions

View file

@ -1,6 +1,6 @@
use std::collections::HashMap;
use raylib::{drawing::RaylibDrawHandle, math::Vector2, texture::Texture2D};
use raylib::prelude::*;
mod board;
mod tile;
@ -30,6 +30,22 @@ impl Machine {
}
}
pub fn output(&self) -> &[u8] {
&self.output
}
pub fn input(&self) -> &[u8] {
&self.input
}
pub fn input_mut(&mut self) -> &mut Vec<u8> {
&mut self.input
}
pub fn set_input(&mut self, bytes: Vec<u8>) {
self.input = bytes;
}
pub fn new(grid: Board, input: Vec<u8>) -> Self {
// let (grid, marbles) = parse(source);
let mut marbles = Vec::new();
@ -55,14 +71,15 @@ impl Machine {
d: &mut RaylibDrawHandle,
textures: &HashMap<String, Texture2D>,
offset: Vector2,
zoom: i32,
) {
let tile_size = 32;
let tile_size = 16 << zoom;
for x in 0..self.board.width() {
for y in 0..self.board.height() {
if let Some(tile) = self.board.get((x, y).into()) {
let px = x as i32 * tile_size + offset.x as i32 + tile_size / 2;
let py = y as i32 * tile_size + offset.y as i32 + tile_size / 2;
tile.draw(d, textures, px, py, tile_size);
tile.draw(d, textures, px, py, tile_size, zoom);
}
}
}