diff options
Diffstat (limited to 'scene/2d')
-rw-r--r-- | scene/2d/canvas_item.cpp | 39 | ||||
-rw-r--r-- | scene/2d/canvas_item.h | 3 |
2 files changed, 40 insertions, 2 deletions
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 4751551371..2d2da005d0 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -348,6 +348,9 @@ bool CanvasItem::is_visible_in_tree() const { while (p) { if (!p->visible) return false; + if (p->window && !p->window->is_visible()) { + return false; + } p = p->get_parent_item(); } @@ -549,10 +552,30 @@ void CanvasItem::_notification(int p_what) { _update_texture_repeat_changed(false); first_draw = true; - if (get_parent()) { - CanvasItem *ci = Object::cast_to<CanvasItem>(get_parent()); + Node *parent = get_parent(); + if (parent) { + CanvasItem *ci = Object::cast_to<CanvasItem>(parent); if (ci) C = ci->children_items.push_back(this); + if (!ci) { + //look for a window + Viewport *viewport = nullptr; + + while (parent) { + viewport = Object::cast_to<Viewport>(parent); + if (viewport) { + break; + } + parent = parent->get_parent(); + } + + ERR_FAIL_COND(!viewport); + + window = Object::cast_to<Window>(viewport); + if (window) { + window->connect(SceneStringNames::get_singleton()->visibility_changed, callable_mp(this, &CanvasItem::_window_visibility_changed)); + } + } } _enter_canvas(); if (!block_transform_notify && !xform_change.in_list()) { @@ -581,6 +604,9 @@ void CanvasItem::_notification(int p_what) { Object::cast_to<CanvasItem>(get_parent())->children_items.erase(C); C = NULL; } + if (window) { + window->disconnect(SceneStringNames::get_singleton()->visibility_changed, callable_mp(this, &CanvasItem::_window_visibility_changed)); + } global_invalid = true; } break; case NOTIFICATION_DRAW: @@ -601,6 +627,14 @@ void CanvasItem::set_visible(bool p_visible) { else hide(); } + +void CanvasItem::_window_visibility_changed() { + + if (visible) { + _propagate_visibility_changed(window->is_visible()); + } +} + bool CanvasItem::is_visible() const { return visible; @@ -1409,6 +1443,7 @@ CanvasItem::TextureRepeat CanvasItem::get_texture_repeat() const { CanvasItem::CanvasItem() : xform_change(this) { + window = nullptr; canvas_item = VisualServer::get_singleton()->canvas_item_create(); visible = true; pending_update = false; diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h index c7f9500ea1..6bfe3cf0c7 100644 --- a/scene/2d/canvas_item.h +++ b/scene/2d/canvas_item.h @@ -201,6 +201,7 @@ private: int light_mask; + Window *window; bool first_draw; bool visible; bool pending_update; @@ -232,6 +233,8 @@ private: void _enter_canvas(); void _exit_canvas(); + void _window_visibility_changed(); + void _notify_transform(CanvasItem *p_node); void _set_on_top(bool p_on_top) { set_draw_behind_parent(!p_on_top); } |