From 2cc2f19a4541a54220e3468d1da339366633a774 Mon Sep 17 00:00:00 2001 From: Kasper Arnklit Frandsen Date: Tue, 1 Apr 2025 11:30:57 +0100 Subject: [PATCH] Add axis snapping for bezier key move --- editor/animation_bezier_editor.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp index 5337b531547..d941de86581 100644 --- a/editor/animation_bezier_editor.cpp +++ b/editor/animation_bezier_editor.cpp @@ -1758,15 +1758,24 @@ void AnimationBezierTrackEdit::gui_input(const Ref &p_event) { Ref mm = p_event; if (moving_selection_attempt && mm.is_valid()) { + Point2 new_pos = mm->get_position(); + if (mm->is_alt_pressed()) { // Axis snap key move when alt is pressed + if (Math::abs(new_pos.x - moving_selection_mouse_begin.x) > Math::abs(new_pos.y - moving_selection_mouse_begin.y)) { + new_pos.y = moving_selection_mouse_begin.y; + } else { + new_pos.x = moving_selection_mouse_begin.x; + } + } + if (!moving_selection) { moving_selection = true; select_single_attempt = IntPair(-1, -1); } if (!read_only) { - float y = (get_size().height / 2.0 - mm->get_position().y) * timeline_v_zoom + timeline_v_scroll; + float y = (get_size().height / 2.0 - new_pos.y) * timeline_v_zoom + timeline_v_scroll; float moving_selection_begin_time = ((moving_selection_mouse_begin.x - limit) / timeline->get_zoom_scale()) + timeline->get_value(); - float new_time = ((mm->get_position().x - limit) / timeline->get_zoom_scale()) + timeline->get_value(); + float new_time = ((new_pos.x - limit) / timeline->get_zoom_scale()) + timeline->get_value(); float moving_selection_pivot = moving_selection_from_key != -1 ? animation->track_get_key_time(moving_selection_from_track, moving_selection_from_key) : 0; float time_delta = new_time - moving_selection_begin_time;