aboutsummaryrefslogtreecommitdiff
path: root/src/brush.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/brush.rs')
-rw-r--r--src/brush.rs61
1 files changed, 35 insertions, 26 deletions
diff --git a/src/brush.rs b/src/brush.rs
index 1a365b1..8ff0cda 100644
--- a/src/brush.rs
+++ b/src/brush.rs
@@ -4,29 +4,36 @@ use crate::bitmap::MapPoint;
4 4
5#[derive(Debug, Copy, Clone)] 5#[derive(Debug, Copy, Clone)]
6pub enum Brush { 6pub enum Brush {
7 Line { 7 Line(LineBrush),
8 size: u8, 8 Circle(CircleBrush),
9 start: Option<MapPoint>, 9 RectSelect(RectSelectBrush),
10 extend: bool,
11 },
12 Circle {
13 size: u8,
14 },
15 RectSelect {
16 start: MapPoint,
17 end: MapPoint,
18 },
19 Fill, 10 Fill,
20 Custom { 11 Custom { size: u8 },
21 size: u8, 12}
22 }, 13
14#[derive(Debug, Copy, Clone)]
15pub struct LineBrush {
16 pub size: u8,
17 pub start: Option<MapPoint>,
18 pub extend: bool,
19}
20
21#[derive(Debug, Copy, Clone)]
22pub struct CircleBrush {
23 pub size: u8,
24}
25
26#[derive(Debug, Copy, Clone)]
27pub struct RectSelectBrush {
28 pub start: MapPoint,
29 pub end: MapPoint,
23} 30}
24 31
25impl Brush { 32impl Brush {
26 pub fn grow(&mut self) { 33 pub fn grow(&mut self) {
27 match self { 34 match self {
28 Brush::Line { ref mut size, .. } => *size += 1, 35 Brush::Line(LineBrush { ref mut size, .. }) => *size += 1,
29 Brush::Circle { ref mut size, .. } => *size += 1, 36 Brush::Circle(CircleBrush { ref mut size, .. }) => *size += 1,
30 Brush::Custom { ref mut size, .. } => *size += 1, 37 Brush::Custom { ref mut size, .. } => *size += 1,
31 _ => (), 38 _ => (),
32 } 39 }
@@ -34,23 +41,23 @@ impl Brush {
34 41
35 pub fn shrink(&mut self) { 42 pub fn shrink(&mut self) {
36 match self { 43 match self {
37 Brush::Line { ref mut size, .. } => *size = size.saturating_sub(1), 44 Brush::Line(LineBrush { ref mut size, .. }) => *size = size.saturating_sub(1),
38 Brush::Circle { ref mut size, .. } => *size = size.saturating_sub(1), 45 Brush::Circle(CircleBrush { ref mut size, .. }) => *size = size.saturating_sub(1),
39 Brush::Custom { ref mut size, .. } => *size = size.saturating_sub(1), 46 Brush::Custom { ref mut size, .. } => *size = size.saturating_sub(1),
40 _ => (), 47 _ => (),
41 } 48 }
42 } 49 }
43 50
44 pub fn new(size: u8) -> Self { 51 pub fn new(size: u8) -> Self {
45 Brush::Circle { size } 52 Brush::Circle(CircleBrush { size })
46 } 53 }
47 54
48 pub fn line(size: u8, extend: bool) -> Self { 55 pub fn line(size: u8, extend: bool) -> Self {
49 Brush::Line { 56 Brush::Line(LineBrush {
50 size, 57 size,
51 start: None, 58 start: None,
52 extend, 59 extend,
53 } 60 })
54 } 61 }
55 62
56 pub fn is_line(&self) -> bool { 63 pub fn is_line(&self) -> bool {
@@ -59,8 +66,8 @@ impl Brush {
59 66
60 pub fn size(&self) -> Option<u8> { 67 pub fn size(&self) -> Option<u8> {
61 match self { 68 match self {
62 Brush::Line { size, .. } => Some(size.clone()), 69 Brush::Line(LineBrush { size, .. }) => Some(size.clone()),
63 Brush::Circle { size } => Some(size.clone()), 70 Brush::Circle(CircleBrush { size }) => Some(size.clone()),
64 _ => None, 71 _ => None,
65 } 72 }
66 } 73 }
@@ -69,8 +76,10 @@ impl Brush {
69impl fmt::Display for Brush { 76impl fmt::Display for Brush {
70 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 77 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
71 match self { 78 match self {
72 Brush::Line { extend, .. } => write!(f, "LINE{}", if *extend { "+" } else { "" }), 79 Brush::Line(LineBrush { extend, .. }) => {
73 Brush::Circle { .. } => write!(f, "CIRCLE"), 80 write!(f, "LINE{}", if *extend { "+" } else { "" })
81 }
82 Brush::Circle(..) => write!(f, "CIRCLE"),
74 Brush::RectSelect { .. } => write!(f, "SELECT"), 83 Brush::RectSelect { .. } => write!(f, "SELECT"),
75 Brush::Fill => write!(f, "FILL"), 84 Brush::Fill => write!(f, "FILL"),
76 Brush::Custom { .. } => write!(f, "CUSTOM"), 85 Brush::Custom { .. } => write!(f, "CUSTOM"),