diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-11-18 07:27:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-18 07:27:45 +0100 |
commit | 58ca9f17a2650bb381972210d1babbf34ac6819c (patch) | |
tree | 5d237550ca69bc791e200ca76087b124297141bd | |
parent | 0a96235b44f9a8c19a1d463e057be7b8b1a20df9 (diff) | |
parent | e9802d9b02ffa61388478b53a904e870211319fc (diff) |
Merge pull request #33686 from KoBeWi/relan
Fix animation key snapping at high zooms
-rw-r--r-- | editor/animation_track_editor.cpp | 11 | ||||
-rw-r--r-- | editor/animation_track_editor.h | 2 |
2 files changed, 9 insertions, 4 deletions
diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 33f833afa4..40aa9a28b2 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -2026,7 +2026,7 @@ void AnimationTrackEdit::_notification(int p_what) { float offset = animation->track_get_key_time(track, i) - timeline->get_value(); if (editor->is_key_selected(track, i) && editor->is_moving_selection()) { - offset = editor->snap_time(offset + editor->get_moving_selection_offset()); + offset = editor->snap_time(offset + editor->get_moving_selection_offset(), true); } offset = offset * scale + limit; if (i < animation->track_get_key_count(track) - 1) { @@ -5703,7 +5703,7 @@ void AnimationTrackEditor::_selection_changed() { } } -float AnimationTrackEditor::snap_time(float p_value) { +float AnimationTrackEditor::snap_time(float p_value, bool p_relative) { if (is_snap_enabled()) { @@ -5713,7 +5713,12 @@ float AnimationTrackEditor::snap_time(float p_value) { else snap_increment = step->get_value(); - p_value = Math::stepify(p_value, snap_increment); + if (p_relative) { + double rel = Math::fmod(timeline->get_value(), snap_increment); + p_value = Math::stepify(p_value + rel, snap_increment) - rel; + } else { + p_value = Math::stepify(p_value, snap_increment); + } } return p_value; diff --git a/editor/animation_track_editor.h b/editor/animation_track_editor.h index fd28d8f4d1..ef6a769196 100644 --- a/editor/animation_track_editor.h +++ b/editor/animation_track_editor.h @@ -521,7 +521,7 @@ public: bool is_moving_selection() const; bool is_snap_enabled() const; float get_moving_selection_offset() const; - float snap_time(float p_value); + float snap_time(float p_value, bool p_relative = false); bool is_grouping_tracks(); MenuButton *get_edit_menu(); |