diff options
author | UgisBrekis <ugis.brekis@hotmail.lv> | 2016-06-15 18:10:19 +0100 |
---|---|---|
committer | UgisBrekis <ugis.brekis@hotmail.lv> | 2016-06-15 18:10:19 +0100 |
commit | d97e46ffb6e2e449f958296480d52ab5bd779d0d (patch) | |
tree | 364fdedbd000eb21e988de69e307cb1e56ac0ba4 /scene/gui | |
parent | 367aabf03080da8e4e72c9db56b0b2097c86d6b4 (diff) |
Adds the ability to draw parent-children relationship lines in scene tree editor
Can be turned on/off in editor settings + line color change available as
well
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/tree.cpp | 17 | ||||
-rw-r--r-- | scene/gui/tree.h | 3 |
2 files changed, 17 insertions, 3 deletions
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 08fe847a33..f8516f8f5d 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -811,6 +811,8 @@ void Tree::update_cache() { cache.item_margin=get_constant("item_margin"); cache.button_margin=get_constant("button_margin"); cache.guide_width=get_constant("guide_width"); + cache.draw_relationship_lines=get_constant("draw_relationship_lines"); + cache.relationship_line_color=get_color("relationship_line_color"); cache.title_button = get_stylebox("title_button_normal"); cache.title_button_pressed = get_stylebox("title_button_pressed"); @@ -1295,9 +1297,21 @@ int Tree::draw_item(const Point2i& p_pos,const Point2& p_draw_ofs, const Size2& while (c) { + if (cache.draw_relationship_lines == 1){ + int root_ofs = children_pos.x + (hide_folding?cache.hseparation:cache.item_margin); + int parent_ofs = p_pos.x + (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() > 0) + root_pos -= Point2i(cache.arrow->get_width(),0); + + 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; + VisualServer::get_singleton()->canvas_item_add_line(ci, root_pos, Point2i(parent_pos.x, root_pos.y), cache.relationship_line_color); + VisualServer::get_singleton()->canvas_item_add_line(ci, Point2i(parent_pos.x, root_pos.y), parent_pos, cache.relationship_line_color); + } + int child_h=draw_item(children_pos, p_draw_ofs, p_draw_size, c ); - if (child_h<0) + if (child_h<0 && cache.draw_relationship_lines == 0) return -1; // break, stop drawing, no need to anymore htotal+=child_h; @@ -3674,4 +3688,3 @@ Tree::~Tree() { } } - diff --git a/scene/gui/tree.h b/scene/gui/tree.h index 1dad26dffe..0172546c1d 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -377,6 +377,7 @@ friend class TreeItem; Color font_color_selected; Color guide_color; Color drop_position_color; + Color relationship_line_color; int hseparation; int vseparation; @@ -384,6 +385,7 @@ friend class TreeItem; int guide_width; int button_margin; Point2 offset; + int draw_relationship_lines; enum ClickType { CLICK_NONE, @@ -532,4 +534,3 @@ public: VARIANT_ENUM_CAST( Tree::SelectMode ); #endif - |