summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-09-02 22:12:41 +0200
committerGitHub <noreply@github.com>2019-09-02 22:12:41 +0200
commit037237f5183c4b8752f8a08d610bb9395ad294ea (patch)
treebabb9ac778d48543f1d52f93ea4202a2fb79b156 /editor
parente2060503801945299036de578746c77c6e91acf1 (diff)
parent55b9c6804c17de3bb05562b861bfff6aa0999a8a (diff)
Merge pull request #31898 from Calinou/animation-editor-add-precise-snapping
Implement precise snapping in the animation editor
Diffstat (limited to 'editor')
-rw-r--r--editor/plugins/animation_player_editor_plugin.cpp17
-rw-r--r--editor/plugins/animation_player_editor_plugin.h1
2 files changed, 16 insertions, 2 deletions
diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp
index f42716c827..173079b6de 100644
--- a/editor/plugins/animation_player_editor_plugin.cpp
+++ b/editor/plugins/animation_player_editor_plugin.cpp
@@ -477,6 +477,19 @@ void AnimationPlayerEditor::_select_anim_by_name(const String &p_anim) {
_animation_selected(idx);
}
+double AnimationPlayerEditor::_get_editor_step() const {
+
+ // Returns the effective snapping value depending on snapping modifiers, or 0 if snapping is disabled.
+ if (track_editor->is_snap_enabled()) {
+ const String current = player->get_assigned_animation();
+ const Ref<Animation> anim = player->get_animation(current);
+ // Use more precise snapping when holding Shift
+ return Input::get_singleton()->is_key_pressed(KEY_SHIFT) ? anim->get_step() * 0.25 : anim->get_step();
+ }
+
+ return 0.0;
+}
+
void AnimationPlayerEditor::_animation_name_edited() {
player->stop();
@@ -1017,7 +1030,7 @@ void AnimationPlayerEditor::_seek_value_changed(float p_value, bool p_set) {
float pos = CLAMP(anim->get_length() * (p_value / frame->get_max()), 0, anim->get_length());
if (track_editor->is_snap_enabled()) {
- pos = Math::stepify(pos, anim->get_step());
+ pos = Math::stepify(pos, _get_editor_step());
}
if (player->is_valid() && !p_set) {
@@ -1068,7 +1081,7 @@ void AnimationPlayerEditor::_animation_key_editor_seek(float p_pos, bool p_drag)
Ref<Animation> anim = player->get_animation(player->get_assigned_animation());
updating = true;
- frame->set_value(Math::stepify(p_pos, track_editor->is_snap_enabled() ? anim->get_step() : 0));
+ frame->set_value(Math::stepify(p_pos, _get_editor_step()));
updating = false;
_seek_value_changed(p_pos, !p_drag);
diff --git a/editor/plugins/animation_player_editor_plugin.h b/editor/plugins/animation_player_editor_plugin.h
index 2ab2df68e6..4ad30675ec 100644
--- a/editor/plugins/animation_player_editor_plugin.h
+++ b/editor/plugins/animation_player_editor_plugin.h
@@ -161,6 +161,7 @@ class AnimationPlayerEditor : public VBoxContainer {
} onion;
void _select_anim_by_name(const String &p_anim);
+ double _get_editor_step() const;
void _play_pressed();
void _play_from_pressed();
void _play_bw_pressed();