Skip to content

Commit 86b40fe

Browse files
committed
Merge pull request godotengine#96902 from SaracenOne/animation_selection_box
Fix selection box + scrolling in animation editor.
2 parents 391849d + 86fc8ef commit 86b40fe

File tree

2 files changed

+61
-12
lines changed

2 files changed

+61
-12
lines changed

editor/animation_track_editor.cpp

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5705,9 +5705,11 @@ void AnimationTrackEditor::_box_selection_draw() {
57055705
}
57065706

57075707
void AnimationTrackEditor::_scroll_input(const Ref<InputEvent> &p_event) {
5708-
if (panner->gui_input(p_event)) {
5709-
scroll->accept_event();
5710-
return;
5708+
if (!box_selecting) {
5709+
if (panner->gui_input(p_event)) {
5710+
scroll->accept_event();
5711+
return;
5712+
}
57115713
}
57125714

57135715
Ref<InputEventMouseButton> mb = p_event;
@@ -5758,6 +5760,8 @@ void AnimationTrackEditor::_scroll_input(const Ref<InputEvent> &p_event) {
57585760
Vector2 from = box_selecting_from;
57595761
Vector2 to = scroll->get_global_transform().xform(mm->get_position());
57605762

5763+
box_selecting_to = to;
5764+
57615765
if (from.x > to.x) {
57625766
SWAP(from.x, to.x);
57635767
}
@@ -5767,11 +5771,7 @@ void AnimationTrackEditor::_scroll_input(const Ref<InputEvent> &p_event) {
57675771
}
57685772

57695773
Rect2 rect(from, to - from);
5770-
Rect2 scroll_rect = Rect2(scroll->get_global_position(), scroll->get_size());
5771-
rect = scroll_rect.intersection(rect);
5772-
box_selection->set_position(rect.position);
5773-
box_selection->set_size(rect.size);
5774-
5774+
box_selection->set_rect(Rect2(from - scroll->get_global_position(), rect.get_size()));
57755775
box_select_rect = rect;
57765776
}
57775777
}
@@ -5790,6 +5790,39 @@ void AnimationTrackEditor::_toggle_bezier_edit() {
57905790
}
57915791
}
57925792

5793+
void AnimationTrackEditor::_scroll_changed(const Vector2 &p_val) {
5794+
if (box_selecting) {
5795+
const Vector2 scroll_difference = p_val - prev_scroll_position;
5796+
5797+
Vector2 from = box_selecting_from - scroll_difference;
5798+
Vector2 to = box_selecting_to;
5799+
5800+
box_selecting_from = from;
5801+
5802+
if (from.x > to.x) {
5803+
SWAP(from.x, to.x);
5804+
}
5805+
5806+
if (from.y > to.y) {
5807+
SWAP(from.y, to.y);
5808+
}
5809+
5810+
Rect2 rect(from, to - from);
5811+
box_selection->set_rect(Rect2(from - scroll->get_global_position(), rect.get_size()));
5812+
box_select_rect = rect;
5813+
}
5814+
5815+
prev_scroll_position = p_val;
5816+
}
5817+
5818+
void AnimationTrackEditor::_v_scroll_changed(float p_val) {
5819+
_scroll_changed(Vector2(prev_scroll_position.x, p_val));
5820+
}
5821+
5822+
void AnimationTrackEditor::_h_scroll_changed(float p_val) {
5823+
_scroll_changed(Vector2(p_val, prev_scroll_position.y));
5824+
}
5825+
57935826
void AnimationTrackEditor::_pan_callback(Vector2 p_scroll_vec, Ref<InputEvent> p_event) {
57945827
Ref<InputEventWithModifiers> iewm = p_event;
57955828
if (iewm.is_valid() && iewm->is_alt_pressed()) {
@@ -7272,16 +7305,25 @@ AnimationTrackEditor::AnimationTrackEditor() {
72727305
panner->set_scroll_zoom_factor(AnimationTimelineEdit::SCROLL_ZOOM_FACTOR_IN);
72737306
panner->set_callbacks(callable_mp(this, &AnimationTrackEditor::_pan_callback), callable_mp(this, &AnimationTrackEditor::_zoom_callback));
72747307

7308+
box_selection_container = memnew(Control);
7309+
box_selection_container->set_v_size_flags(SIZE_EXPAND_FILL);
7310+
box_selection_container->set_clip_contents(true);
7311+
timeline_vbox->add_child(box_selection_container);
7312+
72757313
scroll = memnew(ScrollContainer);
7276-
timeline_vbox->add_child(scroll);
7277-
scroll->set_v_size_flags(SIZE_EXPAND_FILL);
7314+
box_selection_container->add_child(scroll);
7315+
scroll->set_anchors_and_offsets_preset(PRESET_FULL_RECT);
7316+
72787317
VScrollBar *sb = scroll->get_v_scroll_bar();
72797318
scroll->remove_child(sb);
72807319
timeline_scroll->add_child(sb); // Move here so timeline and tracks are always aligned.
72817320
scroll->set_focus_mode(FOCUS_CLICK);
72827321
scroll->connect(SceneStringName(gui_input), callable_mp(this, &AnimationTrackEditor::_scroll_input));
72837322
scroll->connect(SceneStringName(focus_exited), callable_mp(panner.ptr(), &ViewPanner::release_pan_key));
72847323

7324+
scroll->get_v_scroll_bar()->connect(SceneStringName(value_changed), callable_mp(this, &AnimationTrackEditor::_v_scroll_changed));
7325+
scroll->get_h_scroll_bar()->connect(SceneStringName(value_changed), callable_mp(this, &AnimationTrackEditor::_h_scroll_changed));
7326+
72857327
bezier_edit = memnew(AnimationBezierTrackEdit);
72867328
timeline_vbox->add_child(bezier_edit);
72877329
bezier_edit->set_editor(this);
@@ -7493,8 +7535,7 @@ AnimationTrackEditor::AnimationTrackEditor() {
74937535
ichb->add_child(insert_confirm_reset);
74947536

74957537
box_selection = memnew(Control);
7496-
add_child(box_selection);
7497-
box_selection->set_as_top_level(true);
7538+
box_selection_container->add_child(box_selection);
74987539
box_selection->set_mouse_filter(MOUSE_FILTER_IGNORE);
74997540
box_selection->hide();
75007541
box_selection->connect(SceneStringName(draw), callable_mp(this, &AnimationTrackEditor::_box_selection_draw));

editor/animation_track_editor.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,10 @@ class AnimationTrackEditor : public VBoxContainer {
498498

499499
PropertyInfo _find_hint_for_track(int p_idx, NodePath &r_base_path, Variant *r_current_val = nullptr);
500500

501+
void _scroll_changed(const Vector2 &p_val);
502+
void _v_scroll_changed(float p_val);
503+
void _h_scroll_changed(float p_val);
504+
501505
Ref<ViewPanner> panner;
502506
void _pan_callback(Vector2 p_scroll_vec, Ref<InputEvent> p_event);
503507
void _zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref<InputEvent> p_event);
@@ -540,11 +544,15 @@ class AnimationTrackEditor : public VBoxContainer {
540544
void _update_key_edit();
541545
void _clear_key_edit();
542546

547+
Control *box_selection_container = nullptr;
548+
543549
Control *box_selection = nullptr;
544550
void _box_selection_draw();
545551
bool box_selecting = false;
546552
Vector2 box_selecting_from;
553+
Vector2 box_selecting_to;
547554
Rect2 box_select_rect;
555+
Vector2 prev_scroll_position;
548556
void _scroll_input(const Ref<InputEvent> &p_event);
549557

550558
Vector<Ref<AnimationTrackEditPlugin>> track_edit_plugins;

0 commit comments

Comments
 (0)