summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-10-07 08:57:17 +0200
committerGitHub <noreply@github.com>2019-10-07 08:57:17 +0200
commitf84bf7e8a8b8ea3804b91ec6dfffcd005b9b36c5 (patch)
treea4f5ebcc8243fd36741dfedc9628a8851013cf48 /scene/gui
parentdcf46d311a3249950d3dd08e38827da8257906d7 (diff)
parentc7834ee5663c1169ba49445a5f9b9c4baf6b7489 (diff)
Merge pull request #32351 from nekomatata/texture-rect-size-update
Update TextureRect when its Texture is modified directly
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/texture_rect.cpp20
-rw-r--r--scene/gui/texture_rect.h2
2 files changed, 22 insertions, 0 deletions
diff --git a/scene/gui/texture_rect.cpp b/scene/gui/texture_rect.cpp
index 423794d8ba..473cee5ca1 100644
--- a/scene/gui/texture_rect.cpp
+++ b/scene/gui/texture_rect.cpp
@@ -29,6 +29,7 @@
/*************************************************************************/
#include "texture_rect.h"
+#include "core/core_string_names.h"
#include "servers/visual_server.h"
void TextureRect::_notification(int p_what) {
@@ -123,6 +124,7 @@ void TextureRect::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_flipped_v"), &TextureRect::is_flipped_v);
ClassDB::bind_method(D_METHOD("set_stretch_mode", "stretch_mode"), &TextureRect::set_stretch_mode);
ClassDB::bind_method(D_METHOD("get_stretch_mode"), &TextureRect::get_stretch_mode);
+ ClassDB::bind_method(D_METHOD("_texture_changed"), &TextureRect::_texture_changed);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "expand"), "set_expand", "has_expand");
@@ -140,9 +142,27 @@ void TextureRect::_bind_methods() {
BIND_ENUM_CONSTANT(STRETCH_KEEP_ASPECT_COVERED);
}
+void TextureRect::_texture_changed() {
+
+ if (texture.is_valid()) {
+ update();
+ minimum_size_changed();
+ }
+}
+
void TextureRect::set_texture(const Ref<Texture> &p_tex) {
+ if (p_tex == texture)
+ return;
+
+ if (texture.is_valid())
+ texture->disconnect(CoreStringNames::get_singleton()->changed, this, "_texture_changed");
+
texture = p_tex;
+
+ if (texture.is_valid())
+ texture->connect(CoreStringNames::get_singleton()->changed, this, "_texture_changed");
+
update();
/*
if (texture.is_valid())
diff --git a/scene/gui/texture_rect.h b/scene/gui/texture_rect.h
index 1c5bd9d99c..d144020562 100644
--- a/scene/gui/texture_rect.h
+++ b/scene/gui/texture_rect.h
@@ -56,6 +56,8 @@ private:
Ref<Texture> texture;
StretchMode stretch_mode;
+ void _texture_changed();
+
protected:
void _notification(int p_what);
virtual Size2 get_minimum_size() const;