Fix TextureButton's click mask texture size ignored if missing normal texture
This commit is contained in:
parent
5708a3a02e
commit
63554c7765
1 changed files with 16 additions and 15 deletions
|
@ -178,13 +178,14 @@ void TextureButton::_notification(int p_what) {
|
||||||
texdraw = focused;
|
texdraw = focused;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (texdraw.is_valid()) {
|
if (texdraw.is_valid() || click_mask.is_valid()) {
|
||||||
size = texdraw->get_size();
|
const Size2 texdraw_size = texdraw.is_valid() ? texdraw->get_size() : Size2(click_mask->get_size());
|
||||||
_texture_region = Rect2(Point2(), texdraw->get_size());
|
|
||||||
|
size = texdraw_size;
|
||||||
|
_texture_region = Rect2(Point2(), texdraw_size);
|
||||||
_tile = false;
|
_tile = false;
|
||||||
switch (stretch_mode) {
|
switch (stretch_mode) {
|
||||||
case STRETCH_KEEP:
|
case STRETCH_KEEP:
|
||||||
size = texdraw->get_size();
|
|
||||||
break;
|
break;
|
||||||
case STRETCH_SCALE:
|
case STRETCH_SCALE:
|
||||||
size = get_size();
|
size = get_size();
|
||||||
|
@ -194,18 +195,17 @@ void TextureButton::_notification(int p_what) {
|
||||||
_tile = true;
|
_tile = true;
|
||||||
break;
|
break;
|
||||||
case STRETCH_KEEP_CENTERED:
|
case STRETCH_KEEP_CENTERED:
|
||||||
ofs = (get_size() - texdraw->get_size()) / 2;
|
ofs = (get_size() - texdraw_size) / 2;
|
||||||
size = texdraw->get_size();
|
|
||||||
break;
|
break;
|
||||||
case STRETCH_KEEP_ASPECT_CENTERED:
|
case STRETCH_KEEP_ASPECT_CENTERED:
|
||||||
case STRETCH_KEEP_ASPECT: {
|
case STRETCH_KEEP_ASPECT: {
|
||||||
Size2 _size = get_size();
|
Size2 _size = get_size();
|
||||||
float tex_width = texdraw->get_width() * _size.height / texdraw->get_height();
|
float tex_width = texdraw_size.width * _size.height / texdraw_size.height;
|
||||||
float tex_height = _size.height;
|
float tex_height = _size.height;
|
||||||
|
|
||||||
if (tex_width > _size.width) {
|
if (tex_width > _size.width) {
|
||||||
tex_width = _size.width;
|
tex_width = _size.width;
|
||||||
tex_height = texdraw->get_height() * tex_width / texdraw->get_width();
|
tex_height = texdraw_size.height * tex_width / texdraw_size.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stretch_mode == STRETCH_KEEP_ASPECT_CENTERED) {
|
if (stretch_mode == STRETCH_KEEP_ASPECT_CENTERED) {
|
||||||
|
@ -217,10 +217,9 @@ void TextureButton::_notification(int p_what) {
|
||||||
} break;
|
} break;
|
||||||
case STRETCH_KEEP_ASPECT_COVERED: {
|
case STRETCH_KEEP_ASPECT_COVERED: {
|
||||||
size = get_size();
|
size = get_size();
|
||||||
Size2 tex_size = texdraw->get_size();
|
Size2 scale_size = size / texdraw_size;
|
||||||
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;
|
float scale = scale_size.width > scale_size.height ? scale_size.width : scale_size.height;
|
||||||
Size2 scaled_tex_size = tex_size * scale;
|
Size2 scaled_tex_size = texdraw_size * scale;
|
||||||
Point2 ofs2 = ((scaled_tex_size - size) / scale).abs() / 2.0f;
|
Point2 ofs2 = ((scaled_tex_size - size) / scale).abs() / 2.0f;
|
||||||
_texture_region = Rect2(ofs2, size / scale);
|
_texture_region = Rect2(ofs2, size / scale);
|
||||||
} break;
|
} break;
|
||||||
|
@ -233,10 +232,12 @@ void TextureButton::_notification(int p_what) {
|
||||||
|
|
||||||
if (draw_focus_only) {
|
if (draw_focus_only) {
|
||||||
// Do nothing, we only needed to calculate the rectangle.
|
// Do nothing, we only needed to calculate the rectangle.
|
||||||
} else if (_tile) {
|
} else if (texdraw.is_valid()) {
|
||||||
draw_texture_rect(texdraw, Rect2(ofs, size), _tile);
|
if (_tile) {
|
||||||
} else {
|
draw_texture_rect(texdraw, Rect2(ofs, size), _tile);
|
||||||
draw_texture_rect_region(texdraw, Rect2(ofs, size), _texture_region);
|
} else {
|
||||||
|
draw_texture_rect_region(texdraw, Rect2(ofs, size), _texture_region);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_position_rect = Rect2();
|
_position_rect = Rect2();
|
||||||
|
|
Loading…
Reference in a new issue