Skip to content

Commit

Permalink
GH-542 Fix tween animation for focusing graph nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Naros committed Jul 17, 2024
1 parent 5f6de0e commit dbced0d
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/editor/graph/graph_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,26 +835,24 @@ void OrchestratorGraphEdit::_focus_node(int p_node_id, bool p_animated)
node->set_selected(true);

// Calculate position
Vector2 position = (node->get_position_offset() * get_zoom()) - (get_viewport_rect().get_center() / 2);
Vector2 position = (node->get_position_offset()) - (get_viewport_rect().get_center() / 2);
if (!p_animated)
{
set_scroll_offset(position);
return;
}

const float duration = 0.2f;
{
Ref<Tween> tween = get_tree()->create_tween();
tween->tween_method(Callable(this, "set_scroll_offset"), get_scroll_offset(), position, duration);
tween->set_ease(Tween::EASE_OUT_IN);
tween->play();
}
{
Ref<Tween> tween = get_tree()->create_tween();
Ref<Tween> tween = get_tree()->create_tween();
if (!UtilityFunctions::is_equal_approx(1.f, get_zoom()))
tween->tween_method(Callable(this, "set_zoom"), get_zoom(), 1.f, duration);
tween->set_ease(Tween::EASE_OUT_IN);
tween->play();
}

Ref<MethodTweener> scroll_tween = tween->tween_method(Callable(this, "set_scroll_offset"), get_scroll_offset(), position, duration);
if (!UtilityFunctions::is_equal_approx(1.f, get_zoom()))
scroll_tween->set_delay(duration);

tween->set_ease(Tween::EASE_IN_OUT);
tween->play();
}
}
}
Expand Down

0 comments on commit dbced0d

Please sign in to comment.