From 90bc93fa0242126860a4c5dc67f880b76b3f35f4 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Mon, 7 Oct 2024 01:16:52 +0200 Subject: [PATCH] add play/pause/stop buttons --- assets/pause.png | Bin 0 -> 142 bytes assets/play.png | Bin 0 -> 173 bytes assets/stop.png | Bin 0 -> 129 bytes src/editor.rs | 35 ++++++++++++++++++++++++++++++++++- src/marble_engine/board.rs | 10 ++-------- src/util.rs | 11 +++++++++++ 6 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 assets/pause.png create mode 100644 assets/play.png create mode 100644 assets/stop.png diff --git a/assets/pause.png b/assets/pause.png new file mode 100644 index 0000000000000000000000000000000000000000..d637d3df9e7705625341ac830a0ff5479a07b8be GIT binary patch literal 142 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`p`I>|Ar`&K2@BMId`$WOU*7-Q ze|6V+g2#UBcl>3~%*=e)f3hkM2*?=q^_<`;JZZe}_Mtj8w)NT1tt9uzxddGf>j#>U3PGeE(;%V%@e} QMWFo*p00i_>zopr0FDh(__sNHoA8xCoA(MG6%b+W*f@9ZrnwK(t5xqXs3n;^WM0h1!_BPW dcZ!*xVebPm(Kk}}?SW=8c)I$ztaD0e0sv3}EY<)3 literal 0 HcmV?d00001 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); +}