summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorHaoyu Qiu <timothyqiu32@gmail.com>2023-03-17 15:22:47 +0800
committerYuri Sizov <yuris@humnom.net>2023-04-26 14:32:21 +0200
commit7f1b1e1c1b52ef854062d02b3c481507ba910b1d (patch)
treede250148e3d790f3c70fb7b7a7d93f5e2aae124b /scene
parent9336866de008540986cc6b26c3c5f2cd72cfcf8f (diff)
Fix TouchScreenButton not redrawn when texture changes
(cherry picked from commit a15126915d028a4487e6e9fb4b901b73f5cec3f1)
Diffstat (limited to 'scene')
-rw-r--r--scene/2d/touch_screen_button.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/scene/2d/touch_screen_button.cpp b/scene/2d/touch_screen_button.cpp
index 1c2903fe22..4c8c4f1e16 100644
--- a/scene/2d/touch_screen_button.cpp
+++ b/scene/2d/touch_screen_button.cpp
@@ -31,9 +31,19 @@
#include "touch_screen_button.h"
#include "scene/main/window.h"
+#include "scene/scene_string_names.h"
void TouchScreenButton::set_texture_normal(const Ref<Texture2D> &p_texture) {
+ if (texture_normal == p_texture) {
+ return;
+ }
+ if (texture_normal.is_valid()) {
+ texture_normal->disconnect(SceneStringNames::get_singleton()->changed, callable_mp((CanvasItem *)this, &CanvasItem::queue_redraw));
+ }
texture_normal = p_texture;
+ if (texture_normal.is_valid()) {
+ texture_normal->connect(SceneStringNames::get_singleton()->changed, callable_mp((CanvasItem *)this, &CanvasItem::queue_redraw));
+ }
queue_redraw();
}
@@ -42,7 +52,16 @@ Ref<Texture2D> TouchScreenButton::get_texture_normal() const {
}
void TouchScreenButton::set_texture_pressed(const Ref<Texture2D> &p_texture_pressed) {
+ if (texture_pressed == p_texture_pressed) {
+ return;
+ }
+ if (texture_pressed.is_valid()) {
+ texture_pressed->disconnect(SceneStringNames::get_singleton()->changed, callable_mp((CanvasItem *)this, &CanvasItem::queue_redraw));
+ }
texture_pressed = p_texture_pressed;
+ if (texture_pressed.is_valid()) {
+ texture_pressed->connect(SceneStringNames::get_singleton()->changed, callable_mp((CanvasItem *)this, &CanvasItem::queue_redraw));
+ }
queue_redraw();
}
@@ -59,16 +78,16 @@ Ref<BitMap> TouchScreenButton::get_bitmask() const {
}
void TouchScreenButton::set_shape(const Ref<Shape2D> &p_shape) {
+ if (shape == p_shape) {
+ return;
+ }
if (shape.is_valid()) {
shape->disconnect("changed", callable_mp((CanvasItem *)this, &CanvasItem::queue_redraw));
}
-
shape = p_shape;
-
if (shape.is_valid()) {
shape->connect("changed", callable_mp((CanvasItem *)this, &CanvasItem::queue_redraw));
}
-
queue_redraw();
}