diff options
Diffstat (limited to 'src/app.rs')
-rw-r--r-- | src/app.rs | 89 |
1 files changed, 52 insertions, 37 deletions
@@ -1,5 +1,5 @@ | |||
1 | use crate::{ | 1 | use crate::{ |
2 | bitmap::{positive_angle_with_x, abs_difference, Axis, MapPoint, Pixmap}, | 2 | bitmap::{abs_difference, positive_angle_with_x, Axis, MapPoint, Pixmap}, |
3 | brush::{Brush, CircleBrush, LineBrush, RectSelectBrush}, | 3 | brush::{Brush, CircleBrush, LineBrush, RectSelectBrush}, |
4 | cache::Cache, | 4 | cache::Cache, |
5 | command::CommandBox, | 5 | command::CommandBox, |
@@ -458,27 +458,34 @@ impl<'ctx> AppState<'ctx> { | |||
458 | "{:.width$}°", | 458 | "{:.width$}°", |
459 | angle, | 459 | angle, |
460 | width = if (angle - ANGLE).abs() < 1e-3 { 3 } else { 0 } | 460 | width = if (angle - ANGLE).abs() < 1e-3 { 3 } else { 0 } |
461 | ), | 461 | ), |
462 | PINK, | 462 | PINK, |
463 | (self.mouse.0 + size as i32, self.mouse.1 + size as i32), | 463 | (self.mouse.0 + size as i32, self.mouse.1 + size as i32), |
464 | ); | 464 | ); |
465 | for MapPoint { x, y } in line.into_iter() { | 465 | for MapPoint { x, y } in line.into_iter() { |
466 | self.canvas.set_draw_color(PINK); | 466 | self.canvas.set_draw_color(PINK); |
467 | self.canvas | 467 | self.canvas |
468 | .fill_rect(Rect::new( | 468 | .fill_rect(Rect::new( |
469 | x as i32 * cs as i32 + self.start.x(), | 469 | x as i32 * cs as i32 + self.start.x(), |
470 | y as i32 * cs as i32 + self.start.y(), | 470 | y as i32 * cs as i32 + self.start.y(), |
471 | cs, | 471 | cs, |
472 | cs, | 472 | cs, |
473 | )) | 473 | )) |
474 | .unwrap(); | 474 | .unwrap(); |
475 | } | 475 | } |
476 | } | 476 | } |
477 | } | 477 | } |
478 | Brush::RectSelect(RectSelectBrush { start: Some(s), end: Some(e), active_end }) => { | 478 | Brush::RectSelect(RectSelectBrush { |
479 | start: Some(s), | ||
480 | end: Some(e), | ||
481 | .. | ||
482 | }) => { | ||
479 | self.canvas.set_draw_color(PINK); | 483 | self.canvas.set_draw_color(PINK); |
480 | let (width, height) = (abs_difference(s.x, e.x), abs_difference(s.y, e.y)); | 484 | let (width, height) = (abs_difference(s.x, e.x), abs_difference(s.y, e.y)); |
481 | let MapPoint{x: start_x, y: start_y} = utils::rect_coords(s, e).0; | 485 | let MapPoint { |
486 | x: start_x, | ||
487 | y: start_y, | ||
488 | } = utils::rect_coords(s, e).0; | ||
482 | let start_loc_x = self.start.x() + (start_x * cs) as i32; | 489 | let start_loc_x = self.start.x() + (start_x * cs) as i32; |
483 | let start_loc_y = self.start.y() + (start_y * cs) as i32; | 490 | let start_loc_y = self.start.y() + (start_y * cs) as i32; |
484 | draw_text( | 491 | draw_text( |
@@ -488,11 +495,11 @@ impl<'ctx> AppState<'ctx> { | |||
488 | PINK, | 495 | PINK, |
489 | (start_loc_x, start_loc_y - 20), | 496 | (start_loc_x, start_loc_y - 20), |
490 | ); | 497 | ); |
491 | self.canvas.draw_rect( | 498 | self.canvas |
492 | rect!(start_loc_x, start_loc_y, width * cs, height * cs) | 499 | .draw_rect(rect!(start_loc_x, start_loc_y, width * cs, height * cs)) |
493 | ).unwrap(); | 500 | .unwrap(); |
494 | } | 501 | } |
495 | _ => () | 502 | _ => (), |
496 | } | 503 | } |
497 | } | 504 | } |
498 | 505 | ||
@@ -748,7 +755,7 @@ impl<'ctx> AppState<'ctx> { | |||
748 | Keycode::Escape => { | 755 | Keycode::Escape => { |
749 | match self.brush { | 756 | match self.brush { |
750 | Brush::RectSelect(_) => self.brush = Brush::rect(), | 757 | Brush::RectSelect(_) => self.brush = Brush::rect(), |
751 | _ => () | 758 | _ => (), |
752 | } | 759 | } |
753 | continue; | 760 | continue; |
754 | } | 761 | } |
@@ -879,42 +886,50 @@ impl<'ctx> AppState<'ctx> { | |||
879 | } => { | 886 | } => { |
880 | if mousestate.is_mouse_button_pressed(MouseButton::Left) { | 887 | if mousestate.is_mouse_button_pressed(MouseButton::Left) { |
881 | match self.brush { | 888 | match self.brush { |
882 | Brush::RectSelect(RectSelectBrush{start, end, active_end}) => { | 889 | Brush::RectSelect(RectSelectBrush { |
890 | start, | ||
891 | end, | ||
892 | active_end, | ||
893 | }) => { | ||
883 | if active_end { | 894 | if active_end { |
884 | self.brush = Brush::RectSelect(RectSelectBrush{ | 895 | self.brush = Brush::RectSelect(RectSelectBrush { |
885 | start, | 896 | start, |
886 | end: self.idx_at_coord((x, y)).map(MapPoint::from), | 897 | end: self |
887 | active_end | 898 | .idx_at_coord((x, y)) |
899 | .map(MapPoint::from), | ||
900 | active_end, | ||
888 | }); | 901 | }); |
889 | } else { | 902 | } else { |
890 | self.brush = Brush::RectSelect(RectSelectBrush{ | 903 | self.brush = Brush::RectSelect(RectSelectBrush { |
891 | start: self.idx_at_coord((x, y)).map(MapPoint::from), | 904 | start: self |
905 | .idx_at_coord((x, y)) | ||
906 | .map(MapPoint::from), | ||
892 | end, | 907 | end, |
893 | active_end | 908 | active_end, |
894 | }); | 909 | }); |
895 | } | 910 | } |
896 | }, | 911 | } |
897 | Brush::Circle(CircleBrush { size }) | 912 | Brush::Circle(CircleBrush { size }) |
898 | | Brush::Line(LineBrush { size, .. }) => { | 913 | | Brush::Line(LineBrush { size, .. }) => { |
899 | let pt = (x, y); | 914 | let pt = (x, y); |
900 | let val = self.active_color; | 915 | let val = self.active_color; |
901 | if let Ok(o) = self.paint_point(pt, val, size) { | 916 | if let Ok(o) = self.paint_point(pt, val, size) { |
902 | self.current_operation.extend(o); | 917 | self.current_operation.extend(o); |
903 | } | 918 | } |
904 | }, | 919 | } |
905 | _ => () | 920 | _ => (), |
906 | } | 921 | } |
907 | } else if mousestate.is_mouse_button_pressed(MouseButton::Right) { | 922 | } else if mousestate.is_mouse_button_pressed(MouseButton::Right) { |
908 | match self.brush { | 923 | match self.brush { |
909 | Brush::Circle(CircleBrush { size }) | 924 | Brush::Circle(CircleBrush { size }) |
910 | | Brush::Line(LineBrush { size, .. }) => { | 925 | | Brush::Line(LineBrush { size, .. }) => { |
911 | let pt = (x, y); | 926 | let pt = (x, y); |
912 | let val = !self.active_color; | 927 | let val = !self.active_color; |
913 | if let Ok(o) = self.paint_point(pt, val, size) { | 928 | if let Ok(o) = self.paint_point(pt, val, size) { |
914 | self.current_operation.extend(o); | 929 | self.current_operation.extend(o); |
915 | } | 930 | } |
916 | }, | 931 | } |
917 | _ => () | 932 | _ => (), |
918 | } | 933 | } |
919 | } | 934 | } |
920 | } | 935 | } |