aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-04-03 10:05:01 +0100
committerAkshay <[email protected]>2021-04-03 10:05:01 +0100
commit316d20f84bd2736b1a663fe763aa82b8cdb8e5c9 (patch)
treec571eab46672552de2be114778e6d33228966659
parent39d6bc989feed29572a44fc3ecefcbe73481fa29 (diff)
fix symmetry calculations and uneven grid drawing
-rw-r--r--src/app.rs54
1 files changed, 35 insertions, 19 deletions
diff --git a/src/app.rs b/src/app.rs
index 725a45a..119fc38 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -132,15 +132,15 @@ impl<'ctx> AppState<'ctx> {
132 let Symmetry { x, y } = self.symmetry; 132 let Symmetry { x, y } = self.symmetry;
133 self.symmetry = match (x, y) { 133 self.symmetry = match (x, y) {
134 (None, None) => Symmetry { 134 (None, None) => Symmetry {
135 x: Some(self.width() / 2), 135 x: Some(self.height() / 2),
136 y: None, 136 y: None,
137 }, 137 },
138 (_, None) => Symmetry { 138 (_, None) => Symmetry {
139 x: None, 139 x: None,
140 y: Some(self.height() / 2), 140 y: Some(self.width() / 2),
141 }, 141 },
142 (None, y) => Symmetry { 142 (None, y) => Symmetry {
143 x: Some(self.width() / 2), 143 x: Some(self.height() / 2),
144 y, 144 y,
145 }, 145 },
146 (Some(_), Some(_)) => Symmetry { x: None, y: None }, 146 (Some(_), Some(_)) => Symmetry { x: None, y: None },
@@ -383,8 +383,14 @@ impl<'ctx> AppState<'ctx> {
383 format!("---, ---") 383 format!("---, ---")
384 }; 384 };
385 let status_text = format!( 385 let status_text = format!(
386 "[DITHER {}][PT {}][KIND {}]", 386 "{} [PT {}][KIND {}]",
387 self.dither_level, mouse_coords, self.brush 387 if self.file_name.is_some() {
388 format!("{}", self.file_name.as_ref().unwrap().display())
389 } else {
390 "No Name".into()
391 },
392 mouse_coords,
393 self.brush
388 ); 394 );
389 draw_text( 395 draw_text(
390 &mut self.canvas, 396 &mut self.canvas,
@@ -513,21 +519,27 @@ impl<'ctx> AppState<'ctx> {
513 let (width, height) = (self.width(), self.height()); 519 let (width, height) = (self.width(), self.height());
514 let start = self.start; 520 let start = self.start;
515 let grid_enabled = self.grid.enabled; 521 let grid_enabled = self.grid.enabled;
516 for (idx, val) in self.pixmap.data.iter().enumerate() { 522 self.canvas.set_draw_color(WHITE);
517 if *val { 523 for x in 0..width {
518 let idx = idx as i32; 524 for y in 0..height {
519 let (x, y) = (idx % width as i32, idx / height as i32); 525 if self.pixmap.get(MapPoint { x, y }) {
520 self.canvas.set_draw_color(WHITE); 526 self.canvas
521 self.canvas 527 .fill_rect(Rect::new(
522 .fill_rect(Rect::new( 528 (x * cs) as i32 + start.x(),
523 x * cs as i32 + start.x(), 529 (y * cs) as i32 + start.y(),
524 y * cs as i32 + start.y(), 530 cs,
525 cs, 531 cs,
526 cs, 532 ))
527 )) 533 .unwrap();
528 .unwrap(); 534 }
529 } 535 }
530 } 536 }
537 // for (idx, val) in self.pixmap.data.iter().enumerate() {
538 // if *val {
539 // let idx = idx as i32;
540 // let (x, y) = (idx % width as i32, idx / height as i32);
541 // }
542 // }
531 if grid_enabled { 543 if grid_enabled {
532 self.draw_grid(); 544 self.draw_grid();
533 } 545 }
@@ -612,7 +624,7 @@ impl<'ctx> AppState<'ctx> {
612 pub fn save_as<P: AsRef<Path>>(&self, file_name: P) -> Result<(), AppError> { 624 pub fn save_as<P: AsRef<Path>>(&self, file_name: P) -> Result<(), AppError> {
613 let image = self.export().encode().unwrap(); 625 let image = self.export().encode().unwrap();
614 let mut file = File::create(file_name).map_err(AppError::File)?; 626 let mut file = File::create(file_name).map_err(AppError::File)?;
615 file.write_all(&image[..]).unwrap(); 627 file.write_all(&image[..]).map_err(AppError::File)?;
616 return Ok(()); 628 return Ok(());
617 } 629 }
618 630
@@ -742,11 +754,15 @@ impl<'ctx> AppState<'ctx> {
742 } 754 }
743 Brush::Fill => { 755 Brush::Fill => {
744 if let Some(c) = contact { 756 if let Some(c) = contact {
757 // this `get` is unchecked because contact is checked
758 // to be within pixmap
745 let target = self.pixmap.get(c); 759 let target = self.pixmap.get(c);
746 let replacement = self.active_color; 760 let replacement = self.active_color;
747 let operation = 761 let operation =
748 self.pixmap.flood_fill(c, target, replacement); 762 self.pixmap.flood_fill(c, target, replacement);
749 for o in operation.iter() { 763 for o in operation.iter() {
764 // this `set` is unchecked because the returned
765 // value of flood_fill is checked to be within pixmap
750 self.pixmap.set(o.clone(), replacement); 766 self.pixmap.set(o.clone(), replacement);
751 } 767 }
752 self.current_operation.extend( 768 self.current_operation.extend(