diff options
Diffstat (limited to 'scene/gui/texture_rect.cpp')
-rw-r--r-- | scene/gui/texture_rect.cpp | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/scene/gui/texture_rect.cpp b/scene/gui/texture_rect.cpp index 473cee5ca1..514eff358e 100644 --- a/scene/gui/texture_rect.cpp +++ b/scene/gui/texture_rect.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -36,8 +36,9 @@ void TextureRect::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { - if (texture.is_null()) + if (texture.is_null()) { return; + } Size2 size; Point2 offset; @@ -85,11 +86,11 @@ void TextureRect::_notification(int p_what) { size = 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; } break; } @@ -107,11 +108,13 @@ void TextureRect::_notification(int p_what) { Size2 TextureRect::get_minimum_size() const { - if (!expand && !texture.is_null()) + if (!expand && !texture.is_null()) { return texture->get_size(); - else + } else { return Size2(); + } } + void TextureRect::_bind_methods() { 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) { - if (p_tex == texture) + if (p_tex == texture) { return; + } - if (texture.is_valid()) + if (texture.is_valid()) { texture->disconnect(CoreStringNames::get_singleton()->changed, this, "_texture_changed"); + } texture = p_tex; - if (texture.is_valid()) + if (texture.is_valid()) { texture->connect(CoreStringNames::get_singleton()->changed, this, "_texture_changed"); + } 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(); } @@ -182,6 +184,7 @@ void TextureRect::set_expand(bool p_expand) { update(); minimum_size_changed(); } + bool TextureRect::has_expand() const { return expand; @@ -203,6 +206,7 @@ void TextureRect::set_flip_h(bool p_flip) { hflip = p_flip; update(); } + bool TextureRect::is_flipped_h() const { return hflip; @@ -213,6 +217,7 @@ void TextureRect::set_flip_v(bool p_flip) { vflip = p_flip; update(); } + bool TextureRect::is_flipped_v() const { return vflip; |