From d6b803df2fbd84d5ae75bf860168d0329696847f Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 18 May 2021 11:10:37 +0530 Subject: fix center_mouse to behave well outside drawing area --- src/app.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/app.rs b/src/app.rs index 266c28b..68d687f 100644 --- a/src/app.rs +++ b/src/app.rs @@ -296,13 +296,19 @@ 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; + if !self.within_canvas(self.mouse) { + self.center_grid(); + } else { + 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) { -- cgit v1.2.3