use std::fmt; use crate::bitmap::MapPoint; #[derive(Debug, Copy, Clone)] pub enum Brush { Line { size: u8, start: Option, extend: bool, }, Circle { size: u8, }, RectSelect { start: MapPoint, end: MapPoint, }, Fill, Custom { size: u8, }, } impl Brush { pub fn grow(&mut self) { match self { Brush::Line { ref mut size, .. } => *size += 1, Brush::Circle { ref mut size, .. } => *size += 1, Brush::Custom { ref mut size, .. } => *size += 1, _ => (), } } pub fn shrink(&mut self) { match self { Brush::Line { ref mut size, .. } => *size = size.saturating_sub(1), Brush::Circle { ref mut size, .. } => *size = size.saturating_sub(1), Brush::Custom { ref mut size, .. } => *size = size.saturating_sub(1), _ => (), } } pub fn new(size: u8) -> Self { Brush::Circle { size } } pub fn line(size: u8, extend: bool) -> Self { Brush::Line { size, start: None, extend, } } pub fn is_line(&self) -> bool { matches!(self, Self::Line { .. }) } pub fn size(&self) -> Option { match self { Brush::Line { size, .. } => Some(size.clone()), Brush::Circle { size } => Some(size.clone()), _ => None, } } } impl fmt::Display for Brush { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Brush::Line { extend, .. } => write!(f, "LINE{}", if *extend { "+" } else { "" }), Brush::Circle { .. } => write!(f, "CIRCLE"), Brush::RectSelect { .. } => write!(f, "SELECT"), Brush::Fill => write!(f, "FILL"), Brush::Custom { .. } => write!(f, "CUSTOM"), } } }