From b91e3237c69b9673e2103b09a62a372aa1124e0d Mon Sep 17 00:00:00 2001 From: Yuri Sizov Date: Mon, 21 Jun 2021 16:54:59 +0300 Subject: [PATCH] Make relationship lines draw on top of TreeItems --- scene/gui/tree.cpp | 53 +++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index cc95c0aac4..31ee061e01 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -1411,36 +1411,35 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 int prev_ofs = children_pos.y - cache.offset.y + p_draw_ofs.y; while (c) { - if (cache.draw_relationship_lines > 0 && (!hide_root || c->parent != root)) { - int root_ofs = children_pos.x + ((p_item->disable_folding || hide_folding) ? cache.hseparation : cache.item_margin); - int parent_ofs = p_pos.x + ((p_item->disable_folding || hide_folding) ? cache.hseparation : cache.item_margin); - Point2i root_pos = Point2i(root_ofs, children_pos.y + label_h / 2) - cache.offset + p_draw_ofs; - - if (c->get_children() != nullptr) { - root_pos -= Point2i(cache.arrow->get_width(), 0); - } - - float line_width = 1.0; -#ifdef TOOLS_ENABLED - line_width *= EDSCALE; -#endif - - Point2i parent_pos = Point2i(parent_ofs - cache.arrow->get_width() / 2, p_pos.y + label_h / 2 + cache.arrow->get_height() / 2) - cache.offset + p_draw_ofs; - - if (root_pos.y + line_width >= 0) { - VisualServer::get_singleton()->canvas_item_add_line(ci, root_pos, Point2i(parent_pos.x - Math::floor(line_width / 2), root_pos.y), cache.relationship_line_color, line_width); - VisualServer::get_singleton()->canvas_item_add_line(ci, Point2i(parent_pos.x, root_pos.y), Point2i(parent_pos.x, prev_ofs), cache.relationship_line_color, line_width); - } - - if (htotal < 0) { - return -1; - } - prev_ofs = root_pos.y; - } - if (htotal >= 0) { int child_h = draw_item(children_pos, p_draw_ofs, p_draw_size, c); + // Draw relationship lines. + if (cache.draw_relationship_lines > 0 && (!hide_root || c->parent != root)) { + int root_ofs = children_pos.x + ((p_item->disable_folding || hide_folding) ? cache.hseparation : cache.item_margin); + int parent_ofs = p_pos.x + ((p_item->disable_folding || hide_folding) ? cache.hseparation : cache.item_margin); + Point2i root_pos = Point2i(root_ofs, children_pos.y + label_h / 2) - cache.offset + p_draw_ofs; + + if (c->get_children() != nullptr) { + root_pos -= Point2i(cache.arrow->get_width(), 0); + } + + float line_width = 1.0; +#ifdef TOOLS_ENABLED + line_width *= EDSCALE; +#endif + + Point2i parent_pos = Point2i(parent_ofs - cache.arrow->get_width() / 2, p_pos.y + label_h / 2 + cache.arrow->get_height() / 2) - cache.offset + p_draw_ofs; + + if (root_pos.y + line_width >= 0) { + // Order of parts on this bend: the horizontal line first, then the vertical line. + VisualServer::get_singleton()->canvas_item_add_line(ci, root_pos, Point2i(parent_pos.x - Math::floor(line_width / 2), root_pos.y), cache.relationship_line_color, line_width); + VisualServer::get_singleton()->canvas_item_add_line(ci, Point2i(parent_pos.x, root_pos.y), Point2i(parent_pos.x, prev_ofs), cache.relationship_line_color, line_width); + } + + prev_ofs = root_pos.y; + } + if (child_h < 0) { if (cache.draw_relationship_lines == 0) { return -1; // break, stop drawing, no need to anymore