diff options
Diffstat (limited to 'src/app.rs')
-rw-r--r-- | src/app.rs | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -257,6 +257,40 @@ impl<'ctx> AppState<'ctx> { | |||
257 | } | 257 | } |
258 | } | 258 | } |
259 | 259 | ||
260 | pub fn repeat_last_paint(&mut self, target: MapPoint) { | ||
261 | self.commit_operation(); | ||
262 | if let Some(ModifyRecord::Paint(records)) = self | ||
263 | .undo_stack | ||
264 | .operations | ||
265 | .iter() | ||
266 | .rev() | ||
267 | .find(|&o| matches!(o, ModifyRecord::Paint(_))) | ||
268 | { | ||
269 | dbg!(target); | ||
270 | // find center of paint cluster | ||
271 | let centroid: MapPoint = records | ||
272 | .iter() | ||
273 | .fold(MapPoint { x: 0, y: 0 }, |acc, x| acc + x.point) | ||
274 | .reduce(records.len() as u32); | ||
275 | dbg!(centroid); | ||
276 | // re-center cluster around target | ||
277 | let centered_op = records | ||
278 | .iter() | ||
279 | .map(|x| PaintRecord { | ||
280 | point: x.point + target - centroid, | ||
281 | ..*x | ||
282 | }) | ||
283 | .collect::<Vec<_>>(); | ||
284 | let mut ud = Vec::new(); | ||
285 | for r in ¢ered_op { | ||
286 | let p = r.point; | ||
287 | let v = r.new; | ||
288 | ud.push(PaintRecord::new(p, self.pixmap.set(p, v), v)); | ||
289 | } | ||
290 | self.undo_stack.push(ModifyRecord::Paint(ud)); | ||
291 | } | ||
292 | } | ||
293 | |||
260 | pub fn zoom_in(&mut self, p: (i32, i32)) { | 294 | pub fn zoom_in(&mut self, p: (i32, i32)) { |
261 | // attempt to center around cursor | 295 | // attempt to center around cursor |
262 | if let Some(p) = self.idx_at_coord(p) { | 296 | if let Some(p) = self.idx_at_coord(p) { |
@@ -774,6 +808,11 @@ impl<'ctx> AppState<'ctx> { | |||
774 | let cursor = (mouse.x(), mouse.y()); | 808 | let cursor = (mouse.x(), mouse.y()); |
775 | self.zoom_out(cursor); | 809 | self.zoom_out(cursor); |
776 | } | 810 | } |
811 | Keycode::Period => { | ||
812 | if let Some(contact) = self.idx_at_coord(self.mouse) { | ||
813 | self.repeat_last_paint(contact.into()); | ||
814 | } | ||
815 | } | ||
777 | // brush ops | 816 | // brush ops |
778 | Keycode::Q => self.brush.shrink(), | 817 | Keycode::Q => self.brush.shrink(), |
779 | Keycode::E => self.brush.grow(), | 818 | Keycode::E => self.brush.grow(), |