diff options
-rw-r--r-- | src/app.rs | 20 |
1 files changed, 13 insertions, 7 deletions
@@ -296,13 +296,19 @@ impl<'ctx> AppState<'ctx> { | |||
296 | 296 | ||
297 | // brings the pixel under the mouse to win center | 297 | // brings the pixel under the mouse to win center |
298 | pub fn center_mouse(&mut self) { | 298 | pub fn center_mouse(&mut self) { |
299 | let win_size = self.canvas.window().size(); | 299 | if !self.within_canvas(self.mouse) { |
300 | let win_center = ((win_size.0 / 2) as i32, (win_size.1 / 2) as i32); | 300 | self.center_grid(); |
301 | self.context | 301 | } else { |
302 | .mouse() | 302 | let win_size = self.canvas.window().size(); |
303 | .warp_mouse_in_window(self.canvas.window(), win_center.0, win_center.1); | 303 | let win_center = ((win_size.0 / 2) as i32, (win_size.1 / 2) as i32); |
304 | let delta = Point::from(self.mouse) - Point::from(win_center); | 304 | self.context.mouse().warp_mouse_in_window( |
305 | self.start -= delta; | 305 | self.canvas.window(), |
306 | win_center.0, | ||
307 | win_center.1, | ||
308 | ); | ||
309 | let delta = Point::from(self.mouse) - Point::from(win_center); | ||
310 | self.start -= delta; | ||
311 | } | ||
306 | } | 312 | } |
307 | 313 | ||
308 | pub fn reduce_intensity(&mut self) { | 314 | pub fn reduce_intensity(&mut self) { |