diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-01-13 00:01:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-13 00:01:34 +0100 |
commit | 2f4d76f068b29783bde653406b51909b29a082a3 (patch) | |
tree | ea21baeedba3bb8144b064316534959c11a0b066 | |
parent | 586a973b6b7daa072eef36eb6a42b60e6d539f94 (diff) | |
parent | fb1cd9e44658209f3f9aae68933c4417d9537baf (diff) |
Merge pull request #56734 from hinlopen/showhide
Minor code improvement in CanvasItem (show/hide/set_visible)
-rw-r--r-- | scene/main/canvas_item.cpp | 41 |
1 files changed, 13 insertions, 28 deletions
diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp index c80665cf2e..59d933fa1d 100644 --- a/scene/main/canvas_item.cpp +++ b/scene/main/canvas_item.cpp @@ -99,34 +99,31 @@ void CanvasItem::_propagate_visibility_changed(bool p_visible) { _unblock(); } -void CanvasItem::show() { - if (visible) { +void CanvasItem::set_visible(bool p_visible) { + if (visible == p_visible) { return; } - visible = true; - RenderingServer::get_singleton()->canvas_item_set_visible(canvas_item, true); + visible = p_visible; + RenderingServer::get_singleton()->canvas_item_set_visible(canvas_item, p_visible); if (!is_inside_tree()) { return; } - _propagate_visibility_changed(true); + _propagate_visibility_changed(p_visible); } -void CanvasItem::hide() { - if (!visible) { - return; - } - - visible = false; - RenderingServer::get_singleton()->canvas_item_set_visible(canvas_item, false); +void CanvasItem::show() { + set_visible(true); +} - if (!is_inside_tree()) { - return; - } +void CanvasItem::hide() { + set_visible(false); +} - _propagate_visibility_changed(false); +bool CanvasItem::is_visible() const { + return visible; } CanvasItem *CanvasItem::current_item_drawn = nullptr; @@ -348,24 +345,12 @@ void CanvasItem::_notification(int p_what) { } } -void CanvasItem::set_visible(bool p_visible) { - if (p_visible) { - show(); - } else { - hide(); - } -} - void CanvasItem::_window_visibility_changed() { if (visible) { _propagate_visibility_changed(window->is_visible()); } } -bool CanvasItem::is_visible() const { - return visible; -} - void CanvasItem::update() { if (!is_inside_tree()) { return; |