diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/app.rs | 36 | ||||
-rw-r--r-- | src/lisp/prelude.rs | 9 |
2 files changed, 45 insertions, 0 deletions
@@ -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), |
diff --git a/src/lisp/prelude.rs b/src/lisp/prelude.rs index 8088510..9330372 100644 --- a/src/lisp/prelude.rs +++ b/src/lisp/prelude.rs | |||
@@ -281,6 +281,15 @@ pub fn new_env() -> Result<Environment, LispError> { | |||
281 | Ok(LispExpr::Unit) | 281 | Ok(LispExpr::Unit) |
282 | }); | 282 | }); |
283 | 283 | ||
284 | primitive!(env, Arity::Exact(0), "minimap-enabled?", |_, app| { | ||
285 | Ok(LispExpr::BoolLit(app.minimap)) | ||
286 | }); | ||
287 | |||
288 | primitive!(env, Arity::Exact(1), "set-minimap!", |args, app| { | ||
289 | app.minimap = args[0].cast_bool(); | ||
290 | Ok(LispExpr::Unit) | ||
291 | }); | ||
292 | |||
284 | primitive!(env, Arity::Exact(0), "grid-rectangle", |_, app| { | 293 | primitive!(env, Arity::Exact(0), "grid-rectangle", |_, app| { |
285 | app.grid.kind = GridKind::Rectangle; | 294 | app.grid.kind = GridKind::Rectangle; |
286 | Ok(LispExpr::Unit) | 295 | Ok(LispExpr::Unit) |