From ec5a819b44747b8da54bd69c4453373ea56a5247 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 9 May 2021 10:23:47 +0530 Subject: add new pan operation: center_mouse --- src/app.rs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/app.rs b/src/app.rs index e69794f..61b2657 100644 --- a/src/app.rs +++ b/src/app.rs @@ -283,6 +283,7 @@ impl<'ctx> AppState<'ctx> { } } + // recenters the viewport pub fn center_grid(&mut self) { let (winsize_x, winsize_y) = self.canvas.window().size(); let grid_width = self.width() * self.zoom as u32; @@ -293,6 +294,17 @@ impl<'ctx> AppState<'ctx> { ); } + // brings the pixel under the mouse to win center + pub fn center_mouse(&mut self) { + let win_size = self.canvas.window().size(); + let win_center = ((win_size.0 / 2) as i32, (win_size.1 / 2) as i32); + self.context + .mouse() + .warp_mouse_in_window(self.canvas.window(), win_center.0, win_center.1); + let delta = Point::from(self.mouse) - Point::from(win_center); + self.start -= delta; + } + pub fn reduce_intensity(&mut self) { if self.dither_level > 0 { self.dither_level -= 1; @@ -804,16 +816,6 @@ impl<'ctx> AppState<'ctx> { } continue; } - Keycode::LCtrl | Keycode::RCtrl => { - self.brush = Brush::line( - self.cache - .borrow() - .as_ref() - .map(|c| c.last_brush.size().unwrap_or(0)) - .unwrap_or(0), - true, - ); - } _ => (), } } @@ -822,8 +824,9 @@ impl<'ctx> AppState<'ctx> { keymod, .. } if self.keybinds.contains_key(&Keybind::new(k, keymod)) => { - let body = self.keybinds.get(&Keybind::new(k, keymod)).unwrap(); - self.eval_expr(&body.clone()); + let body = + self.keybinds.get(&Keybind::new(k, keymod)).unwrap().clone(); + self.eval_expr(&body); } Event::KeyDown { keycode: Some(k), .. @@ -1071,7 +1074,6 @@ impl<'ctx> AppState<'ctx> { } } } - self.cache(); self.redraw(); } } -- cgit v1.2.3