Skip to content

Commit

Permalink
GH-78 Fix knot rendering with adjusted zooms
Browse files Browse the repository at this point in the history
  • Loading branch information
Naros committed May 13, 2024
1 parent 06f6bd3 commit 4fbb279
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
21 changes: 13 additions & 8 deletions src/editor/graph/graph_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,8 +746,9 @@ PackedVector2Array OrchestratorGraphEdit::_get_connection_knot_points(const OScr

void OrchestratorGraphEdit::_create_connection_knot(const Dictionary& p_connection, const Vector2& p_position)
{
// Knots should be stored within any zoom applied.
const Vector2 position = p_position / get_zoom();
const Vector2 transformed_position = position + get_scroll_offset();
const Vector2 transformed_position = position + (get_scroll_offset() / get_zoom());

const OScriptConnection connection = OScriptConnection::from_dict(p_connection);
const PackedVector2Array knot_points = _get_connection_knot_points(connection);
Expand All @@ -757,8 +758,8 @@ void OrchestratorGraphEdit::_create_connection_knot(const Dictionary& p_connecti
if (!source || !target)
return;

const Vector2 from_position = source->get_output_port_position(connection.from_port) + source->get_position_offset();
const Vector2 to_position = target->get_input_port_position(connection.to_port) + target->get_position_offset();
const Vector2 from_position = source->get_output_port_position(connection.from_port) + (source->get_position_offset() / get_zoom());
const Vector2 to_position = target->get_input_port_position(connection.to_port) + (target->get_position_offset() / get_zoom());

PackedVector2Array points;
points.push_back(from_position);
Expand Down Expand Up @@ -852,8 +853,9 @@ PackedVector2Array OrchestratorGraphEdit::_get_connection_line(const Vector2& p_
{
if (OrchestratorGraphNode* node = Object::cast_to<OrchestratorGraphNode>(get_child(i)))
{
from_port = node->get_port_at_position(p_from_position, PD_Output);
from_node = node->get_script_node_id();
from_port = node->get_port_at_position(p_from_position / get_zoom(), PD_Output);
if (from_port != -1)
from_node = node->get_script_node_id();
}
}

Expand All @@ -864,8 +866,9 @@ PackedVector2Array OrchestratorGraphEdit::_get_connection_line(const Vector2& p_
{
if (OrchestratorGraphNode* node = Object::cast_to<OrchestratorGraphNode>(get_child(i)))
{
to_port = node->get_port_at_position(p_to_position, PD_Input);
to_node = node->get_script_node_id();
to_port = node->get_port_at_position(p_to_position / get_zoom(), PD_Input);
if (to_port != -1)
to_node = node->get_script_node_id();
}
}

Expand All @@ -880,7 +883,9 @@ PackedVector2Array OrchestratorGraphEdit::_get_connection_line(const Vector2& p_
c.to_node = to_node;
c.to_port = to_port;

points.append_array(_get_connection_knot_points(c));
const PackedVector2Array knot_points = _get_connection_knot_points(c);
for (const Vector2& knot_point : knot_points)
points.append(knot_point * get_zoom());
}
points.push_back(p_to_position);

Expand Down
10 changes: 6 additions & 4 deletions src/editor/graph/graph_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,19 +535,21 @@ int32_t OrchestratorGraphNode::get_port_at_position(const Vector2& p_position, E
{
if (p_direction == PD_Input)
{
Vector2 adjusted = p_position - get_position_offset();
const Vector2 position = p_position - get_position_offset();
const Rect2 zone = Rect2(position - Vector2(1,1), Vector2(2,2)); // Fake hotsize
for (int i = 0; i < get_input_port_count(); i++)
{
if (get_input_port_position(i) == adjusted)
if (zone.has_point(get_input_port_position(i)))
return i;
}
}
else if (p_direction == PD_Output)
{
Vector2 adjusted = p_position - get_position_offset();
const Vector2 position = p_position - get_position_offset();
const Rect2 zone = Rect2(position - Vector2(1,1), Vector2(2,2)); // Fake hotzone
for (int i = 0; i < get_output_port_count(); i++)
{
if (get_output_port_position(i) == adjusted)
if (zone.has_point(get_output_port_position(i)))
return i;
}
}
Expand Down

0 comments on commit 4fbb279

Please sign in to comment.