summaryrefslogtreecommitdiff
path: root/scene/gui/texture_progress_bar.cpp
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2023-04-11 21:01:58 +0200
committerGitHub <noreply@github.com>2023-04-11 21:01:58 +0200
commit16a6bdd423aa85272837d0bc6b9e709febdb4ec0 (patch)
treea7f70f8ed81aec219e990c0b3f174dbd200ae793 /scene/gui/texture_progress_bar.cpp
parent4762303f182e65c5293db8d22a4ce88521eba445 (diff)
parent177be9bd37e3dfa4d591eea3bb8ab14a17d06007 (diff)
Merge pull request #75786 from YuriSizov/4.0-cherrypicks
Cherry-picks for the 4.0 branch (future 4.0.3) - 1st batch
Diffstat (limited to 'scene/gui/texture_progress_bar.cpp')
-rw-r--r--scene/gui/texture_progress_bar.cpp49
1 files changed, 26 insertions, 23 deletions
diff --git a/scene/gui/texture_progress_bar.cpp b/scene/gui/texture_progress_bar.cpp
index 2526ee8215..2464e005ee 100644
--- a/scene/gui/texture_progress_bar.cpp
+++ b/scene/gui/texture_progress_bar.cpp
@@ -31,15 +31,10 @@
#include "texture_progress_bar.h"
#include "core/config/engine.h"
+#include "core/core_string_names.h"
void TextureProgressBar::set_under_texture(const Ref<Texture2D> &p_texture) {
- if (under == p_texture) {
- return;
- }
-
- under = p_texture;
- queue_redraw();
- update_minimum_size();
+ _set_texture(&under, p_texture);
}
Ref<Texture2D> TextureProgressBar::get_under_texture() const {
@@ -47,15 +42,7 @@ Ref<Texture2D> TextureProgressBar::get_under_texture() const {
}
void TextureProgressBar::set_over_texture(const Ref<Texture2D> &p_texture) {
- if (over == p_texture) {
- return;
- }
-
- over = p_texture;
- queue_redraw();
- if (under.is_null()) {
- update_minimum_size();
- }
+ _set_texture(&over, p_texture);
}
Ref<Texture2D> TextureProgressBar::get_over_texture() const {
@@ -108,13 +95,7 @@ Size2 TextureProgressBar::get_minimum_size() const {
}
void TextureProgressBar::set_progress_texture(const Ref<Texture2D> &p_texture) {
- if (progress == p_texture) {
- return;
- }
-
- progress = p_texture;
- queue_redraw();
- update_minimum_size();
+ _set_texture(&progress, p_texture);
}
Ref<Texture2D> TextureProgressBar::get_progress_texture() const {
@@ -173,6 +154,28 @@ Color TextureProgressBar::get_tint_over() const {
return tint_over;
}
+void TextureProgressBar::_set_texture(Ref<Texture2D> *p_destination, const Ref<Texture2D> &p_texture) {
+ DEV_ASSERT(p_destination);
+ Ref<Texture2D> &destination = *p_destination;
+ if (destination == p_texture) {
+ return;
+ }
+ if (destination.is_valid()) {
+ destination->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &TextureProgressBar::_texture_changed));
+ }
+ destination = p_texture;
+ if (destination.is_valid()) {
+ // Pass `CONNECT_REFERENCE_COUNTED` to avoid early disconnect in case the same texture is assigned to different "slots".
+ destination->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &TextureProgressBar::_texture_changed), CONNECT_REFERENCE_COUNTED);
+ }
+ _texture_changed();
+}
+
+void TextureProgressBar::_texture_changed() {
+ update_minimum_size();
+ queue_redraw();
+}
+
Point2 TextureProgressBar::unit_val_to_uv(float val) {
if (progress.is_null()) {
return Point2();