From 225351e7c98e91451e0b02fd2b9c3060ebd153a7 Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 4 May 2021 09:37:07 +0530 Subject: add middle mouse pan --- src/app.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/app.rs b/src/app.rs index fc7f736..70d68b8 100644 --- a/src/app.rs +++ b/src/app.rs @@ -68,6 +68,7 @@ pub struct AppState<'ctx> { pub ttf_context: &'ctx Sdl2TtfContext, pub undo_stack: UndoStack, pub zoom: u8, + pub pan_start: Point, } // private actions on appstate @@ -678,6 +679,7 @@ impl<'ctx> AppState<'ctx> { mouse: (0, 0), pixmap, start: Point::new(60, 60), + pan_start: Point::new(0, 0), symmetry: Default::default(), ttf_context, undo_stack: UndoStack::new(), @@ -821,6 +823,12 @@ impl<'ctx> AppState<'ctx> { .unwrap_or(0), ); } + Event::MouseButtonDown { + x, + y, + mouse_btn: MouseButton::Middle, + .. + } => self.pan_start = Point::from((x, y)), // start of operation Event::MouseButtonDown { x, y, mouse_btn, .. @@ -962,6 +970,11 @@ impl<'ctx> AppState<'ctx> { } _ => (), } + } else if mousestate.is_mouse_button_pressed(MouseButton::Middle) { + let pan_end = Point::from((x, y)); + let shift = pan_end - self.pan_start; + self.start += shift; + self.pan_start = pan_end; } } // end of operation -- cgit v1.2.3