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

Improved packed scene previews.

This commit is contained in:
Daniel J. Ramirez
2017-11-17 21:42:14 -06:00
parent 62eda56e67
commit 59c2e8906a
3 changed files with 37 additions and 21 deletions

View File

@@ -906,23 +906,29 @@ void EditorNode::_save_scene_with_preview(String p_file, int p_idx) {
int preview_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size");
preview_size *= EDSCALE;
int width, height;
if (img->get_width() > preview_size && img->get_width() >= img->get_height()) {
width = preview_size;
height = img->get_height() * preview_size / img->get_width();
} else if (img->get_height() > preview_size && img->get_height() >= img->get_width()) {
height = preview_size;
width = img->get_width() * preview_size / img->get_height();
} else {
width = img->get_width();
height = img->get_height();
}
// consider a square region
int vp_size = MIN(img->get_width(), img->get_height());
int x = (img->get_width() - vp_size) / 2;
int y = (img->get_height() - vp_size) / 2;
img->convert(Image::FORMAT_RGB8);
img->resize(width, height);
if (vp_size < preview_size) {
// just square it.
img->crop_from_point(x, y, vp_size, vp_size);
} else {
int ratio = vp_size / preview_size;
int size = preview_size * (ratio / 2);
x = (img->get_width() - size) / 2;
y = (img->get_height() - size) / 2;
img->crop_from_point(x, y, size, size);
// We could get better pictures with better filters
img->resize(preview_size, preview_size, Image::INTERPOLATE_CUBIC);
}
img->flip_y();
//save thumbnail directly, as thumbnailer may not update due to actual scene not changing md5