Make GraphEdit connections consistent on zoom

This commit is contained in:
Jummit
2021-08-22 11:08:37 +02:00
parent 51800eebc6
commit 7c1181116f
2 changed files with 10 additions and 8 deletions

View File

@ -819,19 +819,21 @@ PackedVector2Array GraphEdit::get_connection_line(const Vector2 &p_from, const V
return curve.tessellate(); return curve.tessellate();
} }
void GraphEdit::_draw_connection_line(CanvasItem *p_where, const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, const Color &p_to_color, float p_width) { void GraphEdit::_draw_connection_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_zoom) {
Vector<Vector2> points = get_connection_line(p_from, p_to); Vector<Vector2> points = get_connection_line(p_from / p_zoom, p_to / p_zoom);
Vector<Vector2> scaled_points;
Vector<Color> colors; Vector<Color> colors;
float length = p_from.distance_to(p_to); float length = p_from.distance_to(p_to);
for (int i = 0; i < points.size(); i++) { for (int i = 0; i < points.size(); i++) {
float d = p_from.distance_to(points[i]) / length; float d = p_from.distance_to(points[i]) / length;
colors.push_back(p_color.lerp(p_to_color, d)); colors.push_back(p_color.lerp(p_to_color, d));
scaled_points.push_back(points[i] * p_zoom);
} }
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
p_where->draw_polyline_colors(points, colors, Math::floor(p_width * EDSCALE), lines_antialiased); p_where->draw_polyline_colors(scaled_points, colors, Math::floor(p_width * EDSCALE), lines_antialiased);
#else #else
p_where->draw_polyline_colors(points, colors, p_width, lines_antialiased); p_where->draw_polyline_colors(scaled_points, colors, p_width, lines_antialiased);
#endif #endif
} }
@ -878,7 +880,7 @@ void GraphEdit::_connections_layer_draw() {
color = color.lerp(activity_color, E->get().activity); color = color.lerp(activity_color, E->get().activity);
tocolor = tocolor.lerp(activity_color, E->get().activity); tocolor = tocolor.lerp(activity_color, E->get().activity);
} }
_draw_connection_line(connections_layer, frompos, topos, color, tocolor, lines_thickness); _draw_connection_line(connections_layer, frompos, topos, color, tocolor, lines_thickness, zoom);
} }
while (to_erase.size()) { while (to_erase.size()) {
@ -917,7 +919,7 @@ void GraphEdit::_top_layer_draw() {
if (!connecting_out) { if (!connecting_out) {
SWAP(pos, topos); SWAP(pos, topos);
} }
_draw_connection_line(top_layer, pos, topos, col, col, lines_thickness); _draw_connection_line(top_layer, pos, topos, col, col, lines_thickness, zoom);
} }
if (box_selecting) { if (box_selecting) {
@ -1021,7 +1023,7 @@ void GraphEdit::_minimap_draw() {
from_color = from_color.lerp(activity_color, E.activity); from_color = from_color.lerp(activity_color, E.activity);
to_color = to_color.lerp(activity_color, E.activity); to_color = to_color.lerp(activity_color, E.activity);
} }
_draw_connection_line(minimap, from_position, to_position, from_color, to_color, 1.0); _draw_connection_line(minimap, from_position, to_position, from_color, to_color, 0.1, minimap->_convert_from_graph_position(Vector2(zoom, zoom)).length());
} }
// Draw the "camera" viewport. // Draw the "camera" viewport.

View File

@ -170,7 +170,7 @@ private:
bool lines_antialiased = true; bool lines_antialiased = true;
PackedVector2Array get_connection_line(const Vector2 &p_from, const Vector2 &p_to); PackedVector2Array get_connection_line(const Vector2 &p_from, const Vector2 &p_to);
void _draw_connection_line(CanvasItem *p_where, const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, const Color &p_to_color, float p_width); void _draw_connection_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_zoom);
void _graph_node_raised(Node *p_gn); void _graph_node_raised(Node *p_gn);
void _graph_node_moved(Node *p_gn); void _graph_node_moved(Node *p_gn);