add play/pause/stop buttons

This commit is contained in:
Crispy 2024-10-07 01:16:52 +02:00
parent 0ca1b4ba54
commit 90bc93fa02
6 changed files with 47 additions and 9 deletions

BIN
assets/pause.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

BIN
assets/play.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 B

BIN
assets/stop.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

View file

@ -3,6 +3,7 @@ use std::{mem::transmute, ops::Rem};
use raylib::prelude::*; use raylib::prelude::*;
use crate::{ use crate::{
draw_scaled_texture,
level::Level, level::Level,
marble_engine::{ marble_engine::{
board::{Board, Pos}, 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 // background
d.draw_rectangle( d.draw_rectangle(
0, 0,
@ -372,6 +373,38 @@ impl Editor {
d.draw_text("save", 95, 10, 20, Color::WHITE); 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 mut input_text = String::from_utf8_lossy(self.machine.input()).to_string();
let width = d.get_screen_width(); let width = d.get_screen_width();
d.draw_text("input:", width - 260, 10, 20, Color::WHITE); d.draw_text("input:", width - 260, 10, 20, Color::WHITE);

View file

@ -1,4 +1,4 @@
use crate::Textures; use crate::{draw_scaled_texture, Textures};
use super::tile::*; use super::tile::*;
use raylib::prelude::*; use raylib::prelude::*;
@ -233,13 +233,7 @@ impl Board {
let texture = textures.get(&texname); let texture = textures.get(&texname);
let px = x * tile_size + offset.x as i32; let px = x * tile_size + offset.x as i32;
let py = y * tile_size + offset.y as i32; let py = y * tile_size + offset.y as i32;
d.draw_texture_ex( draw_scaled_texture(d, texture, px, py, (1 << zoom) as f32);
texture,
Vector2::new(px as f32, py as f32),
0.0,
(1 << zoom) as f32,
Color::WHITE,
);
} }
} }
} }

View file

@ -191,3 +191,14 @@ pub fn texture_option_button<T>(
pub fn userdata_dir() -> PathBuf { pub fn userdata_dir() -> PathBuf {
PathBuf::from("user") 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);
}