summaryrefslogtreecommitdiffstats
path: root/editor/animation_bezier_editor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/animation_bezier_editor.cpp')
-rw-r--r--editor/animation_bezier_editor.cpp76
1 files changed, 41 insertions, 35 deletions
diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp
index ffd609d925..aa8962b580 100644
--- a/editor/animation_bezier_editor.cpp
+++ b/editor/animation_bezier_editor.cpp
@@ -682,6 +682,7 @@ void AnimationBezierTrackEdit::set_editor(AnimationTrackEditor *p_editor) {
editor = p_editor;
connect("clear_selection", callable_mp(editor, &AnimationTrackEditor::_clear_selection).bind(false));
connect("select_key", callable_mp(editor, &AnimationTrackEditor::_key_selected), CONNECT_DEFERRED);
+ connect("deselect_key", callable_mp(editor, &AnimationTrackEditor::_key_deselected), CONNECT_DEFERRED);
}
void AnimationBezierTrackEdit::_play_position_draw() {
@@ -871,14 +872,14 @@ void AnimationBezierTrackEdit::_change_selected_keys_handle_mode(Animation::Hand
}
void AnimationBezierTrackEdit::_clear_selection_for_anim(const Ref<Animation> &p_anim) {
- if (!(animation == p_anim)) {
+ if (!(animation == p_anim) || !is_visible()) {
return;
}
_clear_selection();
}
-void AnimationBezierTrackEdit::_select_at_anim(const Ref<Animation> &p_anim, int p_track, real_t p_pos) {
- if (!(animation == p_anim)) {
+void AnimationBezierTrackEdit::_select_at_anim(const Ref<Animation> &p_anim, int p_track, real_t p_pos, bool p_single) {
+ if (!(animation == p_anim) || !is_visible()) {
return;
}
@@ -886,7 +887,7 @@ void AnimationBezierTrackEdit::_select_at_anim(const Ref<Animation> &p_anim, int
ERR_FAIL_COND(idx < 0);
selection.insert(IntPair(p_track, idx));
- emit_signal(SNAME("select_key"), idx, true, p_track);
+ emit_signal(SNAME("select_key"), idx, p_single, p_track);
queue_redraw();
}
@@ -1002,7 +1003,7 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
return;
} else if (ED_IS_SHORTCUT("animation_bezier_editor/select_all_keys", p_event)) {
for (int i = 0; i < edit_points.size(); ++i) {
- selection.insert(IntPair(edit_points[i].track, edit_points[i].key));
+ _select_at_anim(animation, edit_points[i].track, animation->track_get_key_time(edit_points[i].track, edit_points[i].key), i == 0);
}
queue_redraw();
@@ -1010,6 +1011,7 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
return;
} else if (ED_IS_SHORTCUT("animation_bezier_editor/deselect_all_keys", p_event)) {
selection.clear();
+ emit_signal(SNAME("clear_selection"));
queue_redraw();
accept_event();
@@ -1218,7 +1220,7 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
//insert new point
if (mb->get_position().x >= limit && mb->get_position().x < get_size().width && mb->is_command_or_control_pressed()) {
float h = (get_size().height / 2.0 - mb->get_position().y) * timeline_v_zoom + timeline_v_scroll;
- Array new_point = make_default_bezier_key(h);
+ Array new_point = animation->make_default_bezier_key(h);
real_t time = ((mb->get_position().x - limit) / timeline->get_zoom_scale()) + timeline->get_value();
while (animation->track_find_key(selected_track, time, Animation::FIND_MODE_APPROX) != -1) {
@@ -1235,7 +1237,7 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
int index = animation->track_find_key(selected_track, time, Animation::FIND_MODE_APPROX);
ERR_FAIL_COND(index == -1);
_clear_selection();
- selection.insert(IntPair(selected_track, index));
+ _select_at_anim(animation, selected_track, animation->track_get_key_time(selected_track, index), true);
moving_selection_attempt = true;
moving_selection = false;
@@ -1277,13 +1279,15 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
Rect2 selection_rect(bs_from, bs_to - bs_from);
bool track_set = false;
+ int j = 0;
for (int i = 0; i < edit_points.size(); i++) {
if (edit_points[i].point_rect.intersects(selection_rect)) {
- selection.insert(IntPair(edit_points[i].track, edit_points[i].key));
+ _select_at_anim(animation, edit_points[i].track, animation->track_get_key_time(edit_points[i].track, edit_points[i].key), j == 0 && !box_selecting_add);
if (!track_set) {
track_set = true;
set_animation_and_track(animation, edit_points[i].track, read_only);
}
+ j++;
}
}
} else {
@@ -1418,21 +1422,22 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation);
// 7-reselect
-
+ int i = 0;
for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) {
real_t oldpos = animation->track_get_key_time(E->get().first, E->get().second);
real_t newpos = oldpos + moving_selection_offset.x;
- undo_redo->add_do_method(this, "_select_at_anim", animation, E->get().first, newpos);
- undo_redo->add_undo_method(this, "_select_at_anim", animation, E->get().first, oldpos);
+ undo_redo->add_do_method(this, "_select_at_anim", animation, E->get().first, newpos, i == 0);
+ undo_redo->add_undo_method(this, "_select_at_anim", animation, E->get().first, oldpos, i == 0);
+ i++;
}
undo_redo->commit_action();
} else if (select_single_attempt != IntPair(-1, -1)) {
selection.clear();
- selection.insert(select_single_attempt);
set_animation_and_track(animation, select_single_attempt.first, read_only);
+ _select_at_anim(animation, select_single_attempt.first, animation->track_get_key_time(select_single_attempt.first, select_single_attempt.second), true);
}
moving_selection = false;
@@ -1567,9 +1572,10 @@ bool AnimationBezierTrackEdit::_try_select_at_ui_pos(const Point2 &p_pos, bool p
if (selection.has(pair)) {
if (p_deselectable) {
selection.erase(pair);
+ emit_signal(SNAME("deselect_key"), edit_points[i].key, edit_points[i].track);
}
} else {
- selection.insert(pair);
+ _select_at_anim(animation, edit_points[i].track, animation->track_get_key_time(edit_points[i].track, edit_points[i].key), false);
}
queue_redraw();
select_single_attempt = IntPair(-1, -1);
@@ -1595,7 +1601,7 @@ bool AnimationBezierTrackEdit::_try_select_at_ui_pos(const Point2 &p_pos, bool p
set_animation_and_track(animation, pair.first, read_only);
if (!selection.has(pair)) {
selection.clear();
- selection.insert(pair);
+ _select_at_anim(animation, edit_points[i].track, animation->track_get_key_time(edit_points[i].track, edit_points[i].key), true);
}
}
return true;
@@ -1637,19 +1643,6 @@ void AnimationBezierTrackEdit::_zoom_callback(float p_zoom_factor, Vector2 p_ori
queue_redraw();
}
-Array AnimationBezierTrackEdit::make_default_bezier_key(float p_value) {
- Array new_point;
- new_point.resize(5);
-
- new_point[0] = p_value;
- new_point[1] = -0.25;
- new_point[2] = 0;
- new_point[3] = 0.25;
- new_point[4] = 0;
-
- return new_point;
-}
-
float AnimationBezierTrackEdit::get_bezier_key_value(Array p_bezier_key_array) {
return p_bezier_key_array[0];
}
@@ -1669,7 +1662,7 @@ void AnimationBezierTrackEdit::_menu_selected(int p_index) {
time += 0.001;
}
float h = (get_size().height / 2.0 - menu_insert_key.y) * timeline_v_zoom + timeline_v_scroll;
- Array new_point = make_default_bezier_key(h);
+ Array new_point = animation->make_default_bezier_key(h);
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
undo_redo->create_action(TTR("Add Bezier Point"));
undo_redo->add_do_method(animation.ptr(), "track_insert_key", selected_track, time, new_point);
@@ -1763,12 +1756,16 @@ void AnimationBezierTrackEdit::duplicate_selected_keys(real_t p_ofs, bool p_ofs_
undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation);
// Reselect duplicated.
+ int i = 0;
for (const Pair<int, real_t> &E : new_selection_values) {
- undo_redo->add_do_method(this, "_select_at_anim", animation, E.first, E.second);
+ undo_redo->add_do_method(this, "_select_at_anim", animation, E.first, E.second, i == 0);
+ i++;
}
+ i = 0;
for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) {
real_t time = animation->track_get_key_time(E->get().first, E->get().second);
- undo_redo->add_undo_method(this, "_select_at_anim", animation, E->get().first, time);
+ undo_redo->add_undo_method(this, "_select_at_anim", animation, E->get().first, time, i == 0);
+ i++;
}
undo_redo->add_do_method(this, "queue_redraw");
@@ -1805,16 +1802,20 @@ void AnimationBezierTrackEdit::copy_selected_keys(bool p_cut) {
undo_redo->create_action(TTR("Animation Cut Keys"), UndoRedo::MERGE_DISABLE, animation.ptr());
undo_redo->add_do_method(this, "_clear_selection_for_anim", animation);
undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation);
+ int i = 0;
for (RBMap<AnimationTrackEditor::SelectedKey, AnimationTrackEditor::KeyInfo>::Element *E = keys.back(); E; E = E->prev()) {
int track_idx = E->key().track;
int key_idx = E->key().key;
float time = E->value().pos;
undo_redo->add_do_method(animation.ptr(), "track_remove_key_at_time", track_idx, time);
undo_redo->add_undo_method(animation.ptr(), "track_insert_key", track_idx, time, animation->track_get_key_value(track_idx, key_idx), animation->track_get_key_transition(track_idx, key_idx));
- undo_redo->add_undo_method(this, "_select_at_anim", animation, track_idx, time);
+ undo_redo->add_undo_method(this, "_select_at_anim", animation, track_idx, time, i == 0);
+ i++;
}
+ i = 0;
for (RBMap<AnimationTrackEditor::SelectedKey, AnimationTrackEditor::KeyInfo>::Element *E = keys.back(); E; E = E->prev()) {
- undo_redo->add_undo_method(this, "_select_at_anim", animation, E->key().track, E->value().pos);
+ undo_redo->add_undo_method(this, "_select_at_anim", animation, E->key().track, E->value().pos, i == 0);
+ i++;
}
undo_redo->commit_action();
}
@@ -1863,7 +1864,7 @@ void AnimationBezierTrackEdit::paste_keys(real_t p_ofs, bool p_ofs_valid) {
Variant value = key.value;
if (key.track_type != Animation::TYPE_BEZIER) {
- value = make_default_bezier_key(key.value);
+ value = animation->make_default_bezier_key(key.value);
}
undo_redo->add_do_method(animation.ptr(), "track_insert_key", selected_track, dst_time, value, key.transition);
@@ -1883,11 +1884,15 @@ void AnimationBezierTrackEdit::paste_keys(real_t p_ofs, bool p_ofs_valid) {
undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation);
// Reselect pasted.
+ int i = 0;
for (const Pair<int, float> &E : new_selection_values) {
- undo_redo->add_do_method(this, "_select_at_anim", animation, E.first, E.second);
+ undo_redo->add_do_method(this, "_select_at_anim", animation, E.first, E.second, i == 0);
+ i++;
}
+ i = 0;
for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) {
- undo_redo->add_undo_method(this, "_select_at_anim", animation, E->get().first, animation->track_get_key_time(E->get().first, E->get().second));
+ undo_redo->add_undo_method(this, "_select_at_anim", animation, E->get().first, animation->track_get_key_time(E->get().first, E->get().second), i == 0);
+ i++;
}
undo_redo->commit_action();
@@ -1928,6 +1933,7 @@ void AnimationBezierTrackEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("_bezier_track_insert_key"), &AnimationBezierTrackEdit::_bezier_track_insert_key);
ADD_SIGNAL(MethodInfo("select_key", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::BOOL, "single"), PropertyInfo(Variant::INT, "track")));
+ ADD_SIGNAL(MethodInfo("deselect_key", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::INT, "track")));
ADD_SIGNAL(MethodInfo("clear_selection"));
}