@@ -5705,9 +5705,11 @@ void AnimationTrackEditor::_box_selection_draw() {
57055705}
57065706
57075707void 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+
57935826void 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 ()) {
@@ -7290,16 +7323,25 @@ AnimationTrackEditor::AnimationTrackEditor() {
72907323 panner->set_scroll_zoom_factor (AnimationTimelineEdit::SCROLL_ZOOM_FACTOR_IN);
72917324 panner->set_callbacks (callable_mp (this , &AnimationTrackEditor::_pan_callback), callable_mp (this , &AnimationTrackEditor::_zoom_callback));
72927325
7326+ box_selection_container = memnew (Control);
7327+ box_selection_container->set_v_size_flags (SIZE_EXPAND_FILL);
7328+ box_selection_container->set_clip_contents (true );
7329+ timeline_vbox->add_child (box_selection_container);
7330+
72937331 scroll = memnew (ScrollContainer);
7294- timeline_vbox->add_child (scroll);
7295- scroll->set_v_size_flags (SIZE_EXPAND_FILL);
7332+ box_selection_container->add_child (scroll);
7333+ scroll->set_anchors_and_offsets_preset (PRESET_FULL_RECT);
7334+
72967335 VScrollBar *sb = scroll->get_v_scroll_bar ();
72977336 scroll->remove_child (sb);
72987337 timeline_scroll->add_child (sb); // Move here so timeline and tracks are always aligned.
72997338 scroll->set_focus_mode (FOCUS_CLICK);
73007339 scroll->connect (SceneStringName (gui_input), callable_mp (this , &AnimationTrackEditor::_scroll_input));
73017340 scroll->connect (SceneStringName (focus_exited), callable_mp (panner.ptr (), &ViewPanner::release_pan_key));
73027341
7342+ scroll->get_v_scroll_bar ()->connect (SceneStringName (value_changed), callable_mp (this , &AnimationTrackEditor::_v_scroll_changed));
7343+ scroll->get_h_scroll_bar ()->connect (SceneStringName (value_changed), callable_mp (this , &AnimationTrackEditor::_h_scroll_changed));
7344+
73037345 bezier_edit = memnew (AnimationBezierTrackEdit);
73047346 timeline_vbox->add_child (bezier_edit);
73057347 bezier_edit->set_editor (this );
@@ -7513,8 +7555,7 @@ AnimationTrackEditor::AnimationTrackEditor() {
75137555 ichb->add_child (insert_confirm_reset);
75147556
75157557 box_selection = memnew (Control);
7516- add_child (box_selection);
7517- box_selection->set_as_top_level (true );
7558+ box_selection_container->add_child (box_selection);
75187559 box_selection->set_mouse_filter (MOUSE_FILTER_IGNORE);
75197560 box_selection->hide ();
75207561 box_selection->connect (SceneStringName (draw), callable_mp (this , &AnimationTrackEditor::_box_selection_draw));
0 commit comments