Fix top level CanvasItem visibility

The editor gizmo fix from previously reverted
642591b6a9 is kept here.
This commit is contained in:
Haoyu Qiu 2022-03-08 01:27:58 +08:00
parent d0901d4d55
commit b76147ec16
4 changed files with 20 additions and 20 deletions

View file

@ -3756,7 +3756,7 @@ void CanvasItemEditor::_draw_invisible_nodes_positions(Node *p_node, const Trans
} }
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(p_node); CanvasItem *canvas_item = Object::cast_to<CanvasItem>(p_node);
if (canvas_item && !canvas_item->is_visible()) { if (canvas_item && !canvas_item->is_visible_in_tree()) {
return; return;
} }

View file

@ -363,18 +363,23 @@ bool CanvasItem::is_visible_in_tree() const {
p = p->get_parent_item(); p = p->get_parent_item();
} }
const Node *n = get_parent(); if (canvas_layer) {
while (n) { return canvas_layer->is_visible();
const CanvasLayer *c = Object::cast_to<CanvasLayer>(n);
if (c && !c->is_visible()) {
return false;
}
n = n->get_parent();
} }
return true; return true;
} }
void CanvasItem::_toplevel_visibility_changed(bool p_visible) {
VisualServer::get_singleton()->canvas_item_set_visible(canvas_item, visible && p_visible);
if (visible) {
_propagate_visibility_changed(p_visible);
} else {
notification(NOTIFICATION_VISIBILITY_CHANGED);
}
}
void CanvasItem::_propagate_visibility_changed(bool p_visible) { void CanvasItem::_propagate_visibility_changed(bool p_visible) {
if (p_visible && first_draw) { //avoid propagating it twice if (p_visible && first_draw) { //avoid propagating it twice
first_draw = false; first_draw = false;
@ -391,7 +396,7 @@ void CanvasItem::_propagate_visibility_changed(bool p_visible) {
for (int i = 0; i < get_child_count(); i++) { for (int i = 0; i < get_child_count(); i++) {
CanvasItem *c = Object::cast_to<CanvasItem>(get_child(i)); CanvasItem *c = Object::cast_to<CanvasItem>(get_child(i));
if (c && c->visible) { //should the toplevels stop propagation? i think so but.. if (c && c->visible && !c->toplevel) {
c->_propagate_visibility_changed(p_visible); c->_propagate_visibility_changed(p_visible);
} }
} }
@ -1062,6 +1067,7 @@ void CanvasItem::force_update_transform() {
} }
void CanvasItem::_bind_methods() { void CanvasItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("_toplevel_visibility_changed", "visible"), &CanvasItem::_toplevel_visibility_changed);
ClassDB::bind_method(D_METHOD("_toplevel_raise_self"), &CanvasItem::_toplevel_raise_self); ClassDB::bind_method(D_METHOD("_toplevel_raise_self"), &CanvasItem::_toplevel_raise_self);
ClassDB::bind_method(D_METHOD("_update_callback"), &CanvasItem::_update_callback); ClassDB::bind_method(D_METHOD("_update_callback"), &CanvasItem::_update_callback);

View file

@ -208,6 +208,7 @@ private:
mutable bool global_invalid; mutable bool global_invalid;
void _toplevel_raise_self(); void _toplevel_raise_self();
void _toplevel_visibility_changed(bool p_visible);
void _propagate_visibility_changed(bool p_visible); void _propagate_visibility_changed(bool p_visible);

View file

@ -51,17 +51,10 @@ void CanvasLayer::set_visible(bool p_visible) {
visible = p_visible; visible = p_visible;
emit_signal("visibility_changed"); emit_signal("visibility_changed");
for (int i = 0; i < get_child_count(); i++) { // For CanvasItems that is explicitly top level or has non-CanvasItem parents.
CanvasItem *c = Object::cast_to<CanvasItem>(get_child(i)); if (is_inside_tree()) {
if (c) { const String group = "root_canvas" + itos(canvas.get_id());
VisualServer::get_singleton()->canvas_item_set_visible(c->get_canvas_item(), p_visible && c->is_visible()); get_tree()->call_group_flags(SceneTree::GROUP_CALL_UNIQUE, group, "_toplevel_visibility_changed", p_visible);
if (c->is_visible()) {
c->_propagate_visibility_changed(p_visible);
} else {
c->notification(CanvasItem::NOTIFICATION_VISIBILITY_CHANGED);
}
}
} }
} }