Skip to content

Commit ef917c2

Browse files
committed
Merge pull request godotengine#109199 from KoBeWi/I
Fix inconsistent thumbnail width
2 parents 975bcaa + 4d9b952 commit ef917c2

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

editor/inspector/editor_resource_preview.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,20 @@ void EditorResourcePreview::_generate_preview(Ref<ImageTexture> &r_texture, Ref<
220220
const real_t aspect = small_image->get_size().aspect();
221221
if (aspect > 1.0) {
222222
new_size.y = MAX(1, new_size.y / aspect);
223-
} else {
223+
} else if (aspect < 1.0) {
224224
new_size.x = MAX(1, new_size.x * aspect);
225225
}
226226
small_image->resize(new_size.x, new_size.y, Image::INTERPOLATE_CUBIC);
227+
228+
// Make sure the image is always square.
229+
if (aspect != 1.0) {
230+
Ref<Image> rect = small_image;
231+
const Vector2i rect_size = rect->get_size();
232+
small_image = Image::create_empty(small_thumbnail_size, small_thumbnail_size, false, rect->get_format());
233+
// Blit the rectangle in the center of the square.
234+
small_image->blit_rect(rect, Rect2i(Vector2i(), rect_size), (Vector2i(1, 1) * small_thumbnail_size - rect_size) / 2);
235+
}
236+
227237
r_small_texture.instantiate();
228238
r_small_texture->set_image(small_image);
229239
}

0 commit comments

Comments
 (0)