make erasing continuous

This commit is contained in:
Crispy 2024-10-07 16:51:56 +02:00
parent 49917d18a9
commit e661483cd5
3 changed files with 35 additions and 36 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 191 B

After

Width:  |  Height:  |  Size: 198 B

View file

@ -54,6 +54,7 @@ enum Popup {
#[derive(Debug, Clone)]
enum Tool {
None,
Erase,
SetTile(Tile),
Digits(Option<Pos>),
Math,
@ -200,7 +201,11 @@ impl Editor {
WireType::Cross => WireType::Vertical,
}
}
Tool::None | Tool::SetTile(_) | Tool::Digits(_) | Tool::SelectArea(_, _) => (),
Tool::None
| Tool::Erase
| Tool::SetTile(_)
| Tool::Digits(_)
| Tool::SelectArea(_, _) => (),
}
}
@ -470,7 +475,7 @@ impl Editor {
border,
);
};
tool_button((0, -2), "eraser", Tool::SetTile(Tile::from_char(' ')));
tool_button((0, -2), "eraser", Tool::Erase);
tool_button((1, -2), "selection", Tool::SelectArea(None, false));
tool_button((0, -1), "digit_tool", Tool::Digits(None));
tool_button((1, -1), "transparent", Tool::None);
@ -612,13 +617,8 @@ impl Editor {
if self.active_tool != Tool::None {
let tex = match self.active_tool {
Tool::None => unreachable!(),
Tool::SetTile(t) => {
if t == Tile::Blank {
"selection".into()
} else {
t.texture()
}
}
Tool::Erase => "selection".into(),
Tool::SetTile(t) => t.texture(),
Tool::Math => format!("{}_off", self.tool_menu_math.texture_name()),
Tool::Gate => format!("{}_off", self.tool_menu_gate.texture_name()),
Tool::Wire => format!("{}_off", self.tool_menu_wire.texture_name()),
@ -639,6 +639,7 @@ impl Editor {
if d.is_mouse_button_pressed(MouseButton::MOUSE_BUTTON_LEFT) {
match self.active_tool {
Tool::None => (),
Tool::Erase => (),
Tool::SetTile(tile) => self.set_tile(tile_pos.into(), tile),
Tool::Math => self.set_tile(
tile_pos.into(),
@ -670,6 +671,11 @@ impl Editor {
Tool::SelectArea(_, _) => (),
}
}
if d.is_mouse_button_down(MouseButton::MOUSE_BUTTON_LEFT) {
if self.active_tool == Tool::Erase {
self.set_tile(tile_pos.into(), Tile::Blank)
}
}
if let Tool::SelectArea(selection, is_selecting) = &mut self.active_tool {
if d.is_mouse_button_down(MouseButton::MOUSE_BUTTON_LEFT) {
if *is_selecting {

View file

@ -219,41 +219,38 @@ impl Board {
}
pub fn trim_size(&mut self) {
// top
{
let mut top_blanks = 0;
while top_blanks < self.height && self.rows[top_blanks].iter().all(Tile::is_blank) {
top_blanks += 1;
let mut n = 0;
while n < self.height && self.rows[n].iter().all(Tile::is_blank) {
n += 1;
}
let trim_top = top_blanks.saturating_sub(2);
let trim_top = n.saturating_sub(2);
for _ in 0..trim_top {
self.rows.remove(0);
}
self.offset_y -= trim_top as isize;
self.height -= trim_top;
}
// bottom
{
let mut bottom_blanks = 0;
while bottom_blanks < self.height
&& self.rows[self.height - bottom_blanks - 1]
.iter()
.all(Tile::is_blank)
{
bottom_blanks += 1;
let mut n = 0;
while n < self.height && self.rows[self.height - n - 1].iter().all(Tile::is_blank) {
n += 1;
}
let trim_bottom = bottom_blanks.saturating_sub(2);
let trim_bottom = n.saturating_sub(2);
for _ in 0..trim_bottom {
self.rows.pop();
}
self.height -= trim_bottom;
}
// left
{
let mut left_blanks = 0;
while left_blanks < self.width
&& self.rows.iter().all(|row| row[left_blanks].is_blank())
{
left_blanks += 1;
let mut n = 0;
while n < self.width && self.rows.iter().all(|row| row[n].is_blank()) {
n += 1;
}
let trim_left = left_blanks.saturating_sub(2);
let trim_left = n.saturating_sub(2);
for row in &mut self.rows {
for _ in 0..trim_left {
row.remove(0);
@ -262,17 +259,13 @@ impl Board {
self.offset_x -= trim_left as isize;
self.width -= trim_left;
}
// right
{
let mut right_blanks = 0;
while right_blanks < self.height
&& self
.rows
.iter()
.all(|row| row[self.width - right_blanks - 1].is_blank())
{
right_blanks += 1;
let mut n = 0;
while n < self.width && self.rows.iter().all(|r| r[self.width - n - 1].is_blank()) {
n += 1;
}
let trim_right = right_blanks.saturating_sub(2);
let trim_right = n.saturating_sub(2);
for row in &mut self.rows {
for _ in 0..trim_right {
row.pop();