@@ -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 ()) {
@@ -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));
0 commit comments