1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Add feature to Button to make its icon expand/shrink with the button's size

This commit is contained in:
Michael Alexsander Silva Dias
2019-08-20 13:41:14 -03:00
parent 208dd5b4a6
commit 9b09daa8c5
4 changed files with 208 additions and 156 deletions

View File

@@ -205,24 +205,26 @@ void TextureButton::_notification(int p_what) {
case STRETCH_KEEP_ASPECT_COVERED: {
size = get_size();
Size2 tex_size = texdraw->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;
Point2 ofs2 = ((scaledTexSize - size) / scale).abs() / 2.0f;
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;
Point2 ofs2 = ((scaled_tex_size - size) / scale).abs() / 2.0f;
_texture_region = Rect2(ofs2, size / scale);
} break;
}
}
_position_rect = Rect2(ofs, size);
if (_tile)
if (_tile) {
draw_texture_rect(texdraw, _position_rect, _tile);
else
} else {
draw_texture_rect_region(texdraw, _position_rect, _texture_region);
}
} else {
_position_rect = Rect2();
}
if (has_focus() && focused.is_valid()) {
if (has_focus() && focused.is_valid()) {
draw_texture_rect(focused, _position_rect, false);
};
} break;