Skip to content

Commit

Permalink
Revert "Fix CanvasItem visibility propagation"
Browse files Browse the repository at this point in the history
This reverts commit 642591b.
  • Loading branch information
timothyqiu committed Mar 7, 2022
1 parent 56bb439 commit ba0a17a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 19 deletions.
2 changes: 1 addition & 1 deletion editor/plugins/canvas_item_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3756,7 +3756,7 @@ void CanvasItemEditor::_draw_invisible_nodes_positions(Node *p_node, const Trans
}

CanvasItem *canvas_item = Object::cast_to<CanvasItem>(p_node);
if (canvas_item && !canvas_item->is_visible_in_tree()) {
if (canvas_item && !canvas_item->is_visible()) {
return;
}

Expand Down
23 changes: 7 additions & 16 deletions scene/2d/canvas_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,31 +353,25 @@ bool CanvasItem::is_visible_in_tree() const {
return visible && parent_visible_in_tree;
}

void CanvasItem::_propagate_visibility_changed(bool p_visible, bool p_is_source) {
void CanvasItem::_propagate_visibility_changed(bool p_visible, bool p_was_visible) {
if (p_visible && first_draw) { //avoid propagating it twice
first_draw = false;
}
if (!p_is_source) {
parent_visible_in_tree = p_visible;
}
parent_visible_in_tree = p_visible;
notification(NOTIFICATION_VISIBILITY_CHANGED);

if (visible && p_visible) {
update();
} else if (!p_visible && (visible || p_is_source)) {
} else if (!p_visible && (visible || p_was_visible)) {
emit_signal(SceneStringNames::get_singleton()->hide);
}
_block();

for (int i = 0; i < get_child_count(); i++) {
CanvasItem *c = Object::cast_to<CanvasItem>(get_child(i));

if (c) { // Should the top_levels stop propagation? I think so, but...
if (c->visible) {
c->_propagate_visibility_changed(p_visible);
} else {
c->parent_visible_in_tree = p_visible;
}
if (c && c->visible) { //should the toplevels stop propagation? i think so but..
c->_propagate_visibility_changed(p_visible);
}
}

Expand All @@ -392,14 +386,11 @@ void CanvasItem::set_visible(bool p_visible) {
visible = p_visible;
VisualServer::get_singleton()->canvas_item_set_visible(canvas_item, p_visible);

if (!parent_visible_in_tree) {
if (is_inside_tree()) {
notification(NOTIFICATION_VISIBILITY_CHANGED);
}
if (!is_inside_tree()) {
return;
}

_propagate_visibility_changed(p_visible, true);
_propagate_visibility_changed(p_visible, !p_visible);
_change_notify("visible");
}

Expand Down
2 changes: 1 addition & 1 deletion scene/2d/canvas_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class CanvasItem : public Node {

void _toplevel_raise_self();

void _propagate_visibility_changed(bool p_visible, bool p_is_source = false);
void _propagate_visibility_changed(bool p_visible, bool p_was_visible = false);

void _update_callback();

Expand Down
2 changes: 1 addition & 1 deletion scene/main/canvas_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void CanvasLayer::set_visible(bool p_visible) {
if (c->is_visible()) {
c->_propagate_visibility_changed(p_visible);
} else {
c->parent_visible_in_tree = p_visible;
c->notification(CanvasItem::NOTIFICATION_VISIBILITY_CHANGED);
}
}
}
Expand Down

0 comments on commit ba0a17a

Please sign in to comment.