Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Fix TouchScreenButton not redrawn when texture changes #81100

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions scene/2d/touch_screen_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,19 @@
#include "core/input_map.h"
#include "core/os/input.h"
#include "core/os/os.h"
#include "scene/scene_string_names.h"

void TouchScreenButton::set_texture(const Ref<Texture> &p_texture) {
if (texture == p_texture) {
return;
}
if (texture.is_valid()) {
texture->disconnect(SceneStringNames::get_singleton()->changed, this, "update");
}
texture = p_texture;
if (texture.is_valid()) {
texture->connect(SceneStringNames::get_singleton()->changed, this, "update", varray(), CONNECT_REFERENCE_COUNTED);
}
update();
}

Expand All @@ -44,7 +54,16 @@ Ref<Texture> TouchScreenButton::get_texture() const {
}

void TouchScreenButton::set_texture_pressed(const Ref<Texture> &p_texture_pressed) {
if (texture_pressed == p_texture_pressed) {
return;
}
if (texture_pressed.is_valid()) {
texture_pressed->disconnect(SceneStringNames::get_singleton()->changed, this, "update");
}
texture_pressed = p_texture_pressed;
if (texture_pressed.is_valid()) {
texture_pressed->connect(SceneStringNames::get_singleton()->changed, this, "update", varray(), CONNECT_REFERENCE_COUNTED);
}
update();
}

Expand All @@ -61,16 +80,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", this, "update");
shape->disconnect(SceneStringNames::get_singleton()->changed, this, "update");
}

shape = p_shape;

if (shape.is_valid()) {
shape->connect("changed", this, "update");
shape->connect(SceneStringNames::get_singleton()->changed, this, "update");
}

update();
}

Expand Down