diff options
Diffstat (limited to 'scene/gui/graph_edit.cpp')
-rw-r--r-- | scene/gui/graph_edit.cpp | 104 |
1 files changed, 36 insertions, 68 deletions
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 5703564ce2..5b00aab2ef 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -28,6 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "graph_edit.h" + #include "os/input.h" #include "os/keyboard.h" #include "scene/gui/box_container.h" @@ -593,8 +594,6 @@ 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) { -#if 1 - //cubic bezier code float diff = p_to.x - p_from.x; float cp_offset; @@ -621,84 +620,53 @@ void GraphEdit::_draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const colors.push_back(p_to_color); p_where->draw_polyline_colors(points, colors, 2, true); - -#else - - static const int steps = 20; - - //old cosine code - Rect2 r; - r.pos = p_from; - r.expand_to(p_to); - Vector2 sign = Vector2((p_from.x < p_to.x) ? 1 : -1, (p_from.y < p_to.y) ? 1 : -1); - bool flip = sign.x * sign.y < 0; - - Vector2 prev; - for (int i = 0; i <= steps; i++) { - - float d = i / float(steps); - float c = -Math::cos(d * Math_PI) * 0.5 + 0.5; - if (flip) - c = 1.0 - c; - Vector2 p = r.pos + Vector2(d * r.size.width, c * r.size.height); - - if (i > 0) { - - p_where->draw_line(prev, p, p_color.linear_interpolate(p_to_color, d), 2); - } - - prev = p; - } -#endif } void GraphEdit::_connections_layer_draw() { - { - //draw connections - List<List<Connection>::Element *> to_erase; - for (List<Connection>::Element *E = connections.front(); E; E = E->next()) { - - NodePath fromnp(E->get().from); + //draw connections + List<List<Connection>::Element *> to_erase; + for (List<Connection>::Element *E = connections.front(); E; E = E->next()) { - Node *from = get_node(fromnp); - if (!from) { - to_erase.push_back(E); - continue; - } + NodePath fromnp(E->get().from); - GraphNode *gfrom = Object::cast_to<GraphNode>(from); + Node *from = get_node(fromnp); + if (!from) { + to_erase.push_back(E); + continue; + } - if (!gfrom) { - to_erase.push_back(E); - continue; - } + GraphNode *gfrom = Object::cast_to<GraphNode>(from); - NodePath tonp(E->get().to); - Node *to = get_node(tonp); - if (!to) { - to_erase.push_back(E); - continue; - } + if (!gfrom) { + to_erase.push_back(E); + continue; + } - GraphNode *gto = Object::cast_to<GraphNode>(to); + NodePath tonp(E->get().to); + Node *to = get_node(tonp); + if (!to) { + to_erase.push_back(E); + continue; + } - if (!gto) { - to_erase.push_back(E); - continue; - } + GraphNode *gto = Object::cast_to<GraphNode>(to); - Vector2 frompos = gfrom->get_connection_output_pos(E->get().from_port) + gfrom->get_offset() * zoom; - Color color = gfrom->get_connection_output_color(E->get().from_port); - Vector2 topos = gto->get_connection_input_pos(E->get().to_port) + gto->get_offset() * zoom; - Color tocolor = gto->get_connection_input_color(E->get().to_port); - _draw_cos_line(connections_layer, frompos, topos, color, tocolor); + if (!gto) { + to_erase.push_back(E); + continue; } - while (to_erase.size()) { - connections.erase(to_erase.front()->get()); - to_erase.pop_front(); - } + Vector2 frompos = gfrom->get_connection_output_pos(E->get().from_port) + gfrom->get_offset() * zoom; + Color color = gfrom->get_connection_output_color(E->get().from_port); + Vector2 topos = gto->get_connection_input_pos(E->get().to_port) + gto->get_offset() * zoom; + Color tocolor = gto->get_connection_input_color(E->get().to_port); + _draw_cos_line(connections_layer, frompos, topos, color, tocolor); + } + + while (to_erase.size()) { + connections.erase(to_erase.front()->get()); + to_erase.pop_front(); } } |