From 57ebad28a934361c52c84b7b010b1d983cce3efc Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Thu, 22 Jun 2017 09:32:47 -0300 Subject: Order of 2D nodes in tree affects drawing properly again. --- servers/visual/visual_server_canvas.cpp | 12 ++++++++++++ servers/visual/visual_server_canvas.h | 8 ++++++++ 2 files changed, 20 insertions(+) (limited to 'servers') diff --git a/servers/visual/visual_server_canvas.cpp b/servers/visual/visual_server_canvas.cpp index 616990b311..1227863b72 100644 --- a/servers/visual/visual_server_canvas.cpp +++ b/servers/visual/visual_server_canvas.cpp @@ -58,6 +58,12 @@ void VisualServerCanvas::_render_canvas_item(Item *p_canvas_item, const Transfor if (!ci->visible) return; + if (p_canvas_item->children_order_dirty) { + + p_canvas_item->child_items.sort_custom(); + p_canvas_item->children_order_dirty = false; + } + Rect2 rect = ci->get_rect(); Transform2D xform = p_transform * ci->xform; Rect2 global_rect = xform.xform(rect); @@ -171,6 +177,12 @@ void VisualServerCanvas::render_canvas(Canvas *p_canvas, const Transform2D &p_tr VSG::canvas_render->canvas_begin(); + if (p_canvas->children_order_dirty) { + + p_canvas->child_items.sort(); + p_canvas->children_order_dirty = false; + } + int l = p_canvas->child_items.size(); Canvas::ChildItem *ci = p_canvas->child_items.ptr(); diff --git a/servers/visual/visual_server_canvas.h b/servers/visual/visual_server_canvas.h index f78ef635f4..57c7515367 100644 --- a/servers/visual/visual_server_canvas.h +++ b/servers/visual/visual_server_canvas.h @@ -63,6 +63,14 @@ public: } }; + struct ItemIndexSort { + + _FORCE_INLINE_ bool operator()(const Item *p_left, const Item *p_right) const { + + return p_left->index < p_right->index; + } + }; + struct ItemPtrSort { _FORCE_INLINE_ bool operator()(const Item *p_left, const Item *p_right) const { -- cgit v1.2.3