aboutsummaryrefslogtreecommitdiff
path: root/src/app.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/app.rs')
-rw-r--r--src/app.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/app.rs b/src/app.rs
index 23458f4..fc7f736 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -57,6 +57,7 @@ pub struct AppState<'ctx> {
57 pub file_name: Option<PathBuf>, 57 pub file_name: Option<PathBuf>,
58 pub guides: HashMap<Guide, bool>, 58 pub guides: HashMap<Guide, bool>,
59 pub grid: Grid, 59 pub grid: Grid,
60 pub minimap: bool,
60 pub lisp_env: EnvList, 61 pub lisp_env: EnvList,
61 pub message: Message, 62 pub message: Message,
62 pub mode: Mode, 63 pub mode: Mode,
@@ -128,6 +129,10 @@ impl<'ctx> AppState<'ctx> {
128 self.grid.enabled = !self.grid.enabled; 129 self.grid.enabled = !self.grid.enabled;
129 } 130 }
130 131
132 pub fn toggle_minimap(&mut self) {
133 self.minimap = !self.minimap;
134 }
135
131 pub fn cycle_symmetry(&mut self) { 136 pub fn cycle_symmetry(&mut self) {
132 let Symmetry { x, y } = self.symmetry; 137 let Symmetry { x, y } = self.symmetry;
133 self.symmetry = match (x, y) { 138 self.symmetry = match (x, y) {
@@ -544,6 +549,33 @@ impl<'ctx> AppState<'ctx> {
544 } 549 }
545 } 550 }
546 551
552 fn draw_minimap(&mut self) {
553 let width = self.width();
554 let container = Container::new(Offset::Right(self.width()), Offset::Top(0), &self.canvas)
555 .width(Size::Absolute(self.width()), &self.canvas)
556 .height(Size::Absolute(self.height()), &self.canvas);
557
558 self.canvas.set_draw_color(BLACK);
559 self.canvas.fill_rect(container.area()).unwrap();
560 self.canvas.set_draw_color(WHITE);
561 for (line_nr, scan) in self.pixmap.data[..].chunks(width as usize).enumerate() {
562 let mut pass = 0usize;
563 for (color, length) in utils::compress(scan) {
564 if color {
565 self.canvas
566 .fill_rect(rect!(
567 pass as i32 + container.start.0,
568 line_nr as i32 + container.start.1,
569 length as u32,
570 1
571 ))
572 .unwrap();
573 }
574 pass += length;
575 }
576 }
577 }
578
547 fn draw(&mut self) { 579 fn draw(&mut self) {
548 let cs = self.zoom as u32; 580 let cs = self.zoom as u32;
549 let (width, height) = (self.width(), self.height()); 581 let (width, height) = (self.width(), self.height());
@@ -579,6 +611,9 @@ impl<'ctx> AppState<'ctx> {
579 self.grid 611 self.grid
580 .draw(&mut self.canvas, self.zoom, &self.start, width, height); 612 .draw(&mut self.canvas, self.zoom, &self.start, width, height);
581 } 613 }
614 if self.minimap {
615 self.draw_minimap();
616 }
582 self.draw_guides(); 617 self.draw_guides();
583 self.draw_symmetry(); 618 self.draw_symmetry();
584 self.draw_statusline(); 619 self.draw_statusline();
@@ -639,6 +674,7 @@ impl<'ctx> AppState<'ctx> {
639 lisp_env: vec![prelude::new_env().map_err(AppError::Lisp)?], 674 lisp_env: vec![prelude::new_env().map_err(AppError::Lisp)?],
640 message: Message::new().text(" "), 675 message: Message::new().text(" "),
641 mode: Mode::Draw, 676 mode: Mode::Draw,
677 minimap: false,
642 mouse: (0, 0), 678 mouse: (0, 0),
643 pixmap, 679 pixmap,
644 start: Point::new(60, 60), 680 start: Point::new(60, 60),