From 6b45694836707cedb2dbdf342f27015c4e9df215 Mon Sep 17 00:00:00 2001 From: Aitor Guevara <428243+aitorciki@users.noreply.github.com> Date: Fri, 25 Aug 2023 13:58:32 +0200 Subject: [PATCH] Trigger zoom from pan gestures when pressing ctrl Enables zooming using pan + ctrl on macOS trackpads / Magic Mouse. Windows and Linux don't emit pan gesture events, so shouldn't be affected. Not tested on Android. --- scene/gui/view_panner.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scene/gui/view_panner.cpp b/scene/gui/view_panner.cpp index fc03f2d887c..c61fa1d9b80 100644 --- a/scene/gui/view_panner.cpp +++ b/scene/gui/view_panner.cpp @@ -125,6 +125,17 @@ bool ViewPanner::gui_input(const Ref &p_event, Rect2 p_canvas_rect) Ref pan_gesture = p_event; if (pan_gesture.is_valid()) { + if (pan_gesture->is_ctrl_pressed()) { + // Zoom gesture. + float pan_zoom_factor = 1.02f; + float zoom_direction = pan_gesture->get_delta().x - pan_gesture->get_delta().y; + if (zoom_direction == 0.f) { + return true; + } + float zoom = zoom_direction < 0 ? 1.0 / pan_zoom_factor : pan_zoom_factor; + zoom_callback.call(zoom, pan_gesture->get_position(), p_event); + return true; + } pan_callback.call(-pan_gesture->get_delta() * scroll_speed, p_event); }