void CanvasItem::_enter_canvas() { if ((!get_parent() || !get_parent()->cast_to<CanvasItem>()) || toplevel) { Node *n = this; Viewport *viewport=NULL; canvas_layer=NULL; while(n) { if (n->cast_to<Viewport>()) { viewport = n->cast_to<Viewport>(); break; } if (!canvas_layer && n->cast_to<CanvasLayer>()) { canvas_layer = n->cast_to<CanvasLayer>(); } n=n->get_parent(); } RID canvas; if (canvas_layer) canvas=canvas_layer->get_world_2d()->get_canvas(); else canvas=viewport->find_world_2d()->get_canvas(); VisualServer::get_singleton()->canvas_item_set_parent(canvas_item,canvas); group = "root_canvas"+itos(canvas.get_id()); add_to_group(group); get_tree()->call_group(SceneTree::GROUP_CALL_UNIQUE,group,"_raise_self"); } else { CanvasItem *parent = get_parent_item(); VisualServer::get_singleton()->canvas_item_set_parent(canvas_item,parent->get_canvas_item()); parent->_queue_sort_children(); } pending_update=false; update(); notification(NOTIFICATION_ENTER_CANVAS); }
void CanvasItem::_enter_canvas() { if ((!Object::cast_to<CanvasItem>(get_parent())) || toplevel) { Node *n = this; canvas_layer = NULL; while (n) { canvas_layer = Object::cast_to<CanvasLayer>(n); if (canvas_layer) { break; } n = n->get_parent(); } RID canvas; if (canvas_layer) canvas = canvas_layer->get_world_2d()->get_canvas(); else canvas = get_viewport()->find_world_2d()->get_canvas(); VisualServer::get_singleton()->canvas_item_set_parent(canvas_item, canvas); group = "root_canvas" + itos(canvas.get_id()); add_to_group(group); if (canvas_layer) canvas_layer->reset_sort_index(); else get_viewport()->gui_reset_canvas_sort_index(); get_tree()->call_group_flags(SceneTree::GROUP_CALL_UNIQUE, group, "_toplevel_raise_self"); } else { CanvasItem *parent = get_parent_item(); canvas_layer = parent->canvas_layer; VisualServer::get_singleton()->canvas_item_set_parent(canvas_item, parent->get_canvas_item()); VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item, get_index()); } pending_update = false; update(); notification(NOTIFICATION_ENTER_CANVAS); }