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.

(cherry picked from commit 6b45694836)
This commit is contained in:
Aitor Guevara 2023-08-25 13:58:32 +02:00 committed by Yuri Sizov
parent 9f10aedb17
commit 43d24379a5

View File

@ -125,6 +125,17 @@ bool ViewPanner::gui_input(const Ref<InputEvent> &p_event, Rect2 p_canvas_rect)
Ref<InputEventPanGesture> 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);
}