浏览代码

Fix TextureButton focus texture logic

(cherry picked from commit 11111d997ec248ff03cb1250c9dea9f9039e4f71)
kobewi 3 年之前
父节点
当前提交
99195cc163
共有 1 个文件被更改,包括 10 次插入2 次删除
  1. 10 2
      scene/gui/texture_button.cpp

+ 10 - 2
scene/gui/texture_button.cpp

@@ -168,6 +168,12 @@ void TextureButton::_notification(int p_what) {
 
 
 			Point2 ofs;
 			Point2 ofs;
 			Size2 size;
 			Size2 size;
+			bool draw_focus = (has_focus() && focused.is_valid());
+
+			// If no other texture is valid, try using focused texture.
+			if (!texdraw.is_valid() && draw_focus) {
+				texdraw = focused;
+			}
 
 
 			if (texdraw.is_valid()) {
 			if (texdraw.is_valid()) {
 				size = texdraw->get_size();
 				size = texdraw->get_size();
@@ -224,7 +230,9 @@ void TextureButton::_notification(int p_what) {
 				size.width *= hflip ? -1.0f : 1.0f;
 				size.width *= hflip ? -1.0f : 1.0f;
 				size.height *= vflip ? -1.0f : 1.0f;
 				size.height *= vflip ? -1.0f : 1.0f;
 
 
-				if (_tile) {
+				if (texdraw == focused) {
+					// Do nothing, we only needed to calculate the rectangle.
+				} else if (_tile) {
 					draw_texture_rect(texdraw, Rect2(ofs, size), _tile);
 					draw_texture_rect(texdraw, Rect2(ofs, size), _tile);
 				} else {
 				} else {
 					draw_texture_rect_region(texdraw, Rect2(ofs, size), _texture_region);
 					draw_texture_rect_region(texdraw, Rect2(ofs, size), _texture_region);
@@ -233,7 +241,7 @@ void TextureButton::_notification(int p_what) {
 				_position_rect = Rect2();
 				_position_rect = Rect2();
 			}
 			}
 
 
-			if (has_focus() && focused.is_valid()) {
+			if (draw_focus) {
 				draw_texture_rect(focused, Rect2(ofs, size), false);
 				draw_texture_rect(focused, Rect2(ofs, size), false);
 			};
 			};
 		} break;
 		} break;