Fix jankiness when drawing GradientTexture2D
This commit is contained in:
parent
6882890a34
commit
3de53c8312
|
@ -121,13 +121,12 @@ void GradientTexture2DEditorRect::_notification(int p_what) {
|
||||||
Size2 rect_size = get_size();
|
Size2 rect_size = get_size();
|
||||||
|
|
||||||
// Get the size and position to draw the texture and handles at.
|
// Get the size and position to draw the texture and handles at.
|
||||||
size = Size2(texture->get_width() * rect_size.height / texture->get_height(), rect_size.height);
|
// Subtract handle sizes so they stay inside the preview, but keep the texture's aspect ratio.
|
||||||
if (size.width > rect_size.width) {
|
Size2 available_size = rect_size - handle_size;
|
||||||
size.width = rect_size.width;
|
Size2 ratio = available_size / texture->get_size();
|
||||||
size.height = texture->get_height() * size.width / texture->get_width();
|
size = MIN(ratio.x, ratio.y) * texture->get_size();
|
||||||
}
|
offset = ((rect_size - size) / 2).round();
|
||||||
offset = ((rect_size - size + handle_size) / 2).round();
|
|
||||||
size -= handle_size;
|
|
||||||
checkerboard->set_rect(Rect2(offset, size));
|
checkerboard->set_rect(Rect2(offset, size));
|
||||||
|
|
||||||
draw_set_transform(offset);
|
draw_set_transform(offset);
|
||||||
|
@ -180,8 +179,9 @@ GradientTexture2DEditorRect::GradientTexture2DEditorRect() {
|
||||||
|
|
||||||
checkerboard = memnew(TextureRect);
|
checkerboard = memnew(TextureRect);
|
||||||
checkerboard->set_stretch_mode(TextureRect::STRETCH_TILE);
|
checkerboard->set_stretch_mode(TextureRect::STRETCH_TILE);
|
||||||
|
checkerboard->set_ignore_texture_size(true);
|
||||||
checkerboard->set_draw_behind_parent(true);
|
checkerboard->set_draw_behind_parent(true);
|
||||||
add_child(checkerboard);
|
add_child(checkerboard, false, INTERNAL_MODE_FRONT);
|
||||||
|
|
||||||
set_custom_minimum_size(Size2(0, 250 * EDSCALE));
|
set_custom_minimum_size(Size2(0, 250 * EDSCALE));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue