Skip to content

Commit

Permalink
Merge pull request #44469 from pycbouh/graph-minimap-improvements
Browse files Browse the repository at this point in the history
Fix visual issues with GraphEdit minimap
  • Loading branch information
akien-mga authored Dec 17, 2020
2 parents 2c0d1c3 + f5bcbd8 commit 170a429
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion doc/classes/GraphEdit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
<member name="minimap_enabled" type="bool" setter="set_minimap_enabled" getter="is_minimap_enabled" default="true">
If [code]true[/code], the minimap is visible.
</member>
<member name="minimap_opacity" type="float" setter="set_minimap_opacity" getter="get_minimap_opacity" default="0.45">
<member name="minimap_opacity" type="float" setter="set_minimap_opacity" getter="get_minimap_opacity" default="0.65">
The opacity of the minimap rectangle.
</member>
<member name="minimap_size" type="Vector2" setter="set_minimap_size" getter="get_minimap_size" default="Vector2(240, 160)">
Expand Down
26 changes: 13 additions & 13 deletions scene/gui/graph_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ void GraphEdit::add_child_notify(Node *p_child) {
gn->connect("offset_changed", callable_mp(this, &GraphEdit::_graph_node_moved), varray(gn));
gn->connect("raise_request", callable_mp(this, &GraphEdit::_graph_node_raised), varray(gn));
gn->connect("item_rect_changed", callable_mp((CanvasItem *)connections_layer, &CanvasItem::update));
gn->connect("item_rect_changed", callable_mp((CanvasItem *)minimap, &GraphEditMinimap::update));
_graph_node_moved(gn);
gn->set_mouse_filter(MOUSE_FILTER_PASS);
}
Expand All @@ -409,6 +410,7 @@ void GraphEdit::remove_child_notify(Node *p_child) {
gn->disconnect("offset_changed", callable_mp(this, &GraphEdit::_graph_node_moved));
gn->disconnect("raise_request", callable_mp(this, &GraphEdit::_graph_node_raised));
gn->disconnect("item_rect_changed", callable_mp((CanvasItem *)connections_layer, &CanvasItem::update));
gn->disconnect("item_rect_changed", callable_mp((CanvasItem *)minimap, &GraphEditMinimap::update));
}
}

Expand Down Expand Up @@ -782,7 +784,7 @@ void GraphEdit::_bake_segment2d(Vector<Vector2> &points, Vector<Color> &colors,
}
}

void GraphEdit::_draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, const Color &p_to_color, float p_bezier_ratio) {
void GraphEdit::_draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, const Color &p_to_color, float p_width = 2.0, float p_bezier_ratio = 1.0) {
//cubic bezier code
float diff = p_to.x - p_from.x;
float cp_offset;
Expand All @@ -809,9 +811,9 @@ void GraphEdit::_draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const
colors.push_back(p_to_color);

#ifdef TOOLS_ENABLED
p_where->draw_polyline_colors(points, colors, Math::floor(2 * EDSCALE), true);
p_where->draw_polyline_colors(points, colors, Math::floor(p_width * EDSCALE), true);
#else
p_where->draw_polyline_colors(points, colors, 2, true);
p_where->draw_polyline_colors(points, colors, p_width, true);
#endif
}

Expand Down Expand Up @@ -858,7 +860,7 @@ void GraphEdit::_connections_layer_draw() {
color = color.lerp(activity_color, E->get().activity);
tocolor = tocolor.lerp(activity_color, E->get().activity);
}
_draw_cos_line(connections_layer, frompos, topos, color, tocolor, 1.0);
_draw_cos_line(connections_layer, frompos, topos, color, tocolor);
}

while (to_erase.size()) {
Expand Down Expand Up @@ -897,7 +899,7 @@ void GraphEdit::_top_layer_draw() {
if (!connecting_out) {
SWAP(pos, topos);
}
_draw_cos_line(top_layer, pos, topos, col, col, 1.0);
_draw_cos_line(top_layer, pos, topos, col, col);
}

if (box_selecting) {
Expand Down Expand Up @@ -990,18 +992,18 @@ void GraphEdit::_minimap_draw() {
continue;
}

Vector2 from_slot_position = gfrom->get_offset() + gfrom->get_connection_output_position(E->get().from_port);
Vector2 from_position = minimap->_convert_from_graph_position(from_slot_position * zoom - graph_offset) + minimap_offset;
Vector2 from_slot_position = gfrom->get_offset() * zoom + gfrom->get_connection_output_position(E->get().from_port);
Vector2 from_position = minimap->_convert_from_graph_position(from_slot_position - graph_offset) + minimap_offset;
Color from_color = gfrom->get_connection_output_color(E->get().from_port);
Vector2 to_slot_position = gto->get_offset() + gto->get_connection_input_position(E->get().to_port);
Vector2 to_position = minimap->_convert_from_graph_position(to_slot_position * zoom - graph_offset) + minimap_offset;
Vector2 to_slot_position = gto->get_offset() * zoom + gto->get_connection_input_position(E->get().to_port);
Vector2 to_position = minimap->_convert_from_graph_position(to_slot_position - graph_offset) + minimap_offset;
Color to_color = gto->get_connection_input_color(E->get().to_port);

if (E->get().activity > 0) {
from_color = from_color.lerp(activity_color, E->get().activity);
to_color = to_color.lerp(activity_color, E->get().activity);
}
_draw_cos_line(minimap, from_position, to_position, from_color, to_color, 0.5);
_draw_cos_line(minimap, from_position, to_position, from_color, to_color, 1.0, 0.5);
}

// Draw the "camera" viewport.
Expand Down Expand Up @@ -1495,8 +1497,6 @@ void GraphEdit::_snap_value_changed(double) {
update();
}

// _minimap_toggled

void GraphEdit::set_minimap_size(Vector2 p_size) {
minimap->set_size(p_size);
Vector2 minimap_size = minimap->get_size(); // The size might've been adjusted by the minimum size.
Expand Down Expand Up @@ -1709,7 +1709,7 @@ GraphEdit::GraphEdit() {
zoom_hb->add_child(minimap_button);

Vector2 minimap_size = Vector2(240, 160);
float minimap_opacity = 0.45;
float minimap_opacity = 0.65;

minimap = memnew(GraphEditMinimap(this));
top_layer->add_child(minimap);
Expand Down
2 changes: 1 addition & 1 deletion scene/gui/graph_edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class GraphEdit : public Control {

void _bake_segment2d(Vector<Vector2> &points, Vector<Color> &colors, float p_begin, float p_end, const Vector2 &p_a, const Vector2 &p_out, const Vector2 &p_b, const Vector2 &p_in, int p_depth, int p_min_depth, int p_max_depth, float p_tol, const Color &p_color, const Color &p_to_color, int &lines) const;

void _draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, const Color &p_to_color, float p_bezier_ratio);
void _draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, const Color &p_to_color, float p_width, float p_bezier_ratio);

void _graph_node_raised(Node *p_gn);
void _graph_node_moved(Node *p_gn);
Expand Down

0 comments on commit 170a429

Please sign in to comment.