diff --git a/assets/pause.png b/assets/pause.png new file mode 100644 index 0000000..d637d3d Binary files /dev/null and b/assets/pause.png differ diff --git a/assets/play.png b/assets/play.png new file mode 100644 index 0000000..be003db Binary files /dev/null and b/assets/play.png differ diff --git a/assets/stop.png b/assets/stop.png new file mode 100644 index 0000000..ac0f9a1 Binary files /dev/null and b/assets/stop.png differ diff --git a/src/editor.rs b/src/editor.rs index 8d3e515..bb17851 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -3,6 +3,7 @@ use std::{mem::transmute, ops::Rem}; use raylib::prelude::*; use crate::{ + draw_scaled_texture, level::Level, marble_engine::{ board::{Board, Pos}, @@ -338,7 +339,7 @@ impl Editor { } } - fn draw_top_bar(&mut self, d: &mut RaylibDrawHandle, _textures: &Textures) { + fn draw_top_bar(&mut self, d: &mut RaylibDrawHandle, textures: &Textures) { // background d.draw_rectangle( 0, @@ -372,6 +373,38 @@ impl Editor { d.draw_text("save", 95, 10, 20, Color::WHITE); } + match self.sim_state { + SimState::Editing => { + if simple_button(d, 260, 4, 32, 32) { + self.start_sim(); + self.sim_state = SimState::Running; + } + draw_scaled_texture(d, textures.get("play"), 260, 4, 2.); + } + SimState::Running => { + if simple_button(d, 260, 4, 32, 32) { + self.sim_state = SimState::Stepping; + } + draw_scaled_texture(d, textures.get("pause"), 260, 4, 2.); + if simple_button(d, 260 + 36, 4, 32, 32) { + self.sim_state = SimState::Editing; + self.complete_popup = Popup::Start; + } + draw_scaled_texture(d, textures.get("stop"), 260 + 36, 4, 2.); + } + SimState::Stepping => { + if simple_button(d, 260, 4, 32, 32) { + self.sim_state = SimState::Running; + } + draw_scaled_texture(d, textures.get("play"), 260, 4, 2.); + if simple_button(d, 260 + 36, 4, 32, 32) { + self.sim_state = SimState::Editing; + self.complete_popup = Popup::Start; + } + draw_scaled_texture(d, textures.get("stop"), 260 + 36, 4, 2.); + } + } + let mut input_text = String::from_utf8_lossy(self.machine.input()).to_string(); let width = d.get_screen_width(); d.draw_text("input:", width - 260, 10, 20, Color::WHITE); diff --git a/src/marble_engine/board.rs b/src/marble_engine/board.rs index d3ee3f3..57f4769 100644 --- a/src/marble_engine/board.rs +++ b/src/marble_engine/board.rs @@ -1,4 +1,4 @@ -use crate::Textures; +use crate::{draw_scaled_texture, Textures}; use super::tile::*; use raylib::prelude::*; @@ -233,13 +233,7 @@ impl Board { let texture = textures.get(&texname); let px = x * tile_size + offset.x as i32; let py = y * tile_size + offset.y as i32; - d.draw_texture_ex( - texture, - Vector2::new(px as f32, py as f32), - 0.0, - (1 << zoom) as f32, - Color::WHITE, - ); + draw_scaled_texture(d, texture, px, py, (1 << zoom) as f32); } } } diff --git a/src/util.rs b/src/util.rs index f5a2d8f..f686024 100644 --- a/src/util.rs +++ b/src/util.rs @@ -191,3 +191,14 @@ pub fn texture_option_button( pub fn userdata_dir() -> PathBuf { PathBuf::from("user") } + +pub fn draw_scaled_texture( + d: &mut RaylibDrawHandle, + texture: &Texture2D, + x: i32, + y: i32, + scale: f32, +) { + let pos = Vector2::new(x as f32, y as f32); + d.draw_texture_ex(texture, pos, 0., scale, Color::WHITE); +}