summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2022-01-13 00:01:34 +0100
committerGitHub <noreply@github.com>2022-01-13 00:01:34 +0100
commit2f4d76f068b29783bde653406b51909b29a082a3 (patch)
treeea21baeedba3bb8144b064316534959c11a0b066 /scene
parent586a973b6b7daa072eef36eb6a42b60e6d539f94 (diff)
parentfb1cd9e44658209f3f9aae68933c4417d9537baf (diff)
Merge pull request #56734 from hinlopen/showhide
Minor code improvement in CanvasItem (show/hide/set_visible)
Diffstat (limited to 'scene')
-rw-r--r--scene/main/canvas_item.cpp41
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;