|
@@ -36,8 +36,9 @@ void TextureRect::_notification(int p_what) {
|
|
|
|
|
|
if (p_what == NOTIFICATION_DRAW) {
|
|
if (p_what == NOTIFICATION_DRAW) {
|
|
|
|
|
|
- if (texture.is_null())
|
|
|
|
|
|
+ if (texture.is_null()) {
|
|
return;
|
|
return;
|
|
|
|
+ }
|
|
|
|
|
|
Size2 size;
|
|
Size2 size;
|
|
Point2 offset;
|
|
Point2 offset;
|
|
@@ -85,11 +86,11 @@ void TextureRect::_notification(int p_what) {
|
|
size = get_size();
|
|
size = get_size();
|
|
|
|
|
|
Size2 tex_size = texture->get_size();
|
|
Size2 tex_size = texture->get_size();
|
|
- Size2 scaleSize(size.width / tex_size.width, size.height / tex_size.height);
|
|
|
|
- float scale = scaleSize.width > scaleSize.height ? scaleSize.width : scaleSize.height;
|
|
|
|
- Size2 scaledTexSize = tex_size * scale;
|
|
|
|
|
|
+ Size2 scale_size(size.width / tex_size.width, size.height / tex_size.height);
|
|
|
|
+ float scale = scale_size.width > scale_size.height ? scale_size.width : scale_size.height;
|
|
|
|
+ Size2 scaled_tex_size = tex_size * scale;
|
|
|
|
|
|
- region.position = ((scaledTexSize - size) / scale).abs() / 2.0f;
|
|
|
|
|
|
+ region.position = ((scaled_tex_size - size) / scale).abs() / 2.0f;
|
|
region.size = size / scale;
|
|
region.size = size / scale;
|
|
} break;
|
|
} break;
|
|
}
|
|
}
|
|
@@ -107,11 +108,13 @@ void TextureRect::_notification(int p_what) {
|
|
|
|
|
|
Size2 TextureRect::get_minimum_size() const {
|
|
Size2 TextureRect::get_minimum_size() const {
|
|
|
|
|
|
- if (!expand && !texture.is_null())
|
|
|
|
|
|
+ if (!expand && !texture.is_null()) {
|
|
return texture->get_size();
|
|
return texture->get_size();
|
|
- else
|
|
|
|
|
|
+ } else {
|
|
return Size2();
|
|
return Size2();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
void TextureRect::_bind_methods() {
|
|
void TextureRect::_bind_methods() {
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_texture", "texture"), &TextureRect::set_texture);
|
|
ClassDB::bind_method(D_METHOD("set_texture", "texture"), &TextureRect::set_texture);
|
|
@@ -152,22 +155,21 @@ void TextureRect::_texture_changed() {
|
|
|
|
|
|
void TextureRect::set_texture(const Ref<Texture> &p_tex) {
|
|
void TextureRect::set_texture(const Ref<Texture> &p_tex) {
|
|
|
|
|
|
- if (p_tex == texture)
|
|
|
|
|
|
+ if (p_tex == texture) {
|
|
return;
|
|
return;
|
|
|
|
+ }
|
|
|
|
|
|
- if (texture.is_valid())
|
|
|
|
|
|
+ if (texture.is_valid()) {
|
|
texture->disconnect(CoreStringNames::get_singleton()->changed, this, "_texture_changed");
|
|
texture->disconnect(CoreStringNames::get_singleton()->changed, this, "_texture_changed");
|
|
|
|
+ }
|
|
|
|
|
|
texture = p_tex;
|
|
texture = p_tex;
|
|
|
|
|
|
- if (texture.is_valid())
|
|
|
|
|
|
+ if (texture.is_valid()) {
|
|
texture->connect(CoreStringNames::get_singleton()->changed, this, "_texture_changed");
|
|
texture->connect(CoreStringNames::get_singleton()->changed, this, "_texture_changed");
|
|
|
|
+ }
|
|
|
|
|
|
update();
|
|
update();
|
|
- /*
|
|
|
|
- if (texture.is_valid())
|
|
|
|
- texture->set_flags(texture->get_flags()&(~Texture::FLAG_REPEAT)); //remove repeat from texture, it looks bad in sprites
|
|
|
|
- */
|
|
|
|
minimum_size_changed();
|
|
minimum_size_changed();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -182,6 +184,7 @@ void TextureRect::set_expand(bool p_expand) {
|
|
update();
|
|
update();
|
|
minimum_size_changed();
|
|
minimum_size_changed();
|
|
}
|
|
}
|
|
|
|
+
|
|
bool TextureRect::has_expand() const {
|
|
bool TextureRect::has_expand() const {
|
|
|
|
|
|
return expand;
|
|
return expand;
|
|
@@ -203,6 +206,7 @@ void TextureRect::set_flip_h(bool p_flip) {
|
|
hflip = p_flip;
|
|
hflip = p_flip;
|
|
update();
|
|
update();
|
|
}
|
|
}
|
|
|
|
+
|
|
bool TextureRect::is_flipped_h() const {
|
|
bool TextureRect::is_flipped_h() const {
|
|
|
|
|
|
return hflip;
|
|
return hflip;
|
|
@@ -213,6 +217,7 @@ void TextureRect::set_flip_v(bool p_flip) {
|
|
vflip = p_flip;
|
|
vflip = p_flip;
|
|
update();
|
|
update();
|
|
}
|
|
}
|
|
|
|
+
|
|
bool TextureRect::is_flipped_v() const {
|
|
bool TextureRect::is_flipped_v() const {
|
|
|
|
|
|
return vflip;
|
|
return vflip;
|