From 200e7435687c1b08d122b5ed617198aaedd00315 Mon Sep 17 00:00:00 2001 From: MuffinTastic Date: Wed, 5 Nov 2025 01:34:26 -0800 Subject: [PATCH] Use TEXTURE_FILTER_NEAREST_WITH_MIPMAPS in FileSystemDock --- editor/docks/filesystem_dock.cpp | 41 ++++++++++++++++++++++++++++---- editor/docks/filesystem_dock.h | 1 + 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/editor/docks/filesystem_dock.cpp b/editor/docks/filesystem_dock.cpp index a2342842d3..be16f88036 100644 --- a/editor/docks/filesystem_dock.cpp +++ b/editor/docks/filesystem_dock.cpp @@ -837,12 +837,16 @@ void FileSystemDock::navigate_to_path(const String &p_path) { void FileSystemDock::_file_list_thumbnail_done(const String &p_path, const Ref &p_preview, const Ref &p_small_preview, int p_index, const String &p_filename) { if (p_preview.is_valid()) { if (p_index < files->get_item_count() && files->get_item_text(p_index) == p_filename && files->get_item_metadata(p_index) == p_path) { + Ref thumbnail; + if (file_list_display_mode == FILE_LIST_DISPLAY_LIST) { - if (p_small_preview.is_valid()) { - files->set_item_icon(p_index, p_small_preview); - } + thumbnail = p_small_preview; } else { - files->set_item_icon(p_index, p_preview); + thumbnail = p_preview; + } + + if (thumbnail.is_valid()) { + files->set_item_icon(p_index, _apply_thumbnail_filter(thumbnail, p_path)); } } } @@ -851,10 +855,37 @@ void FileSystemDock::_file_list_thumbnail_done(const String &p_path, const Ref &p_preview, const Ref &p_small_preview, int p_update_id, ObjectID p_item) { TreeItem *item = ObjectDB::get_instance(p_item); if (item && tree_update_id == p_update_id && p_small_preview.is_valid()) { - item->set_icon(0, p_small_preview); + item->set_icon(0, _apply_thumbnail_filter(p_small_preview, p_path)); } } +Ref FileSystemDock::_apply_thumbnail_filter(const Ref &p_thumbnail, const String &p_file_path) const { + if (!p_file_path.is_empty()) { + int index; + EditorFileSystemDirectory *dir = EditorFileSystem::get_singleton()->find_file(p_file_path, &index); + + if (dir) { + if (dir->get_file_import_is_valid(index)) { + const StringName &file_type = dir->get_file_type(index); + + if (file_type == SNAME("CompressedTexture2D") || file_type == SNAME("Image")) { + const String extension = p_file_path.get_extension(); + + if (extension != "svg" && extension != "svgz") { + Ref thumbnail_wrapped; + thumbnail_wrapped.instantiate(); + thumbnail_wrapped->set_diffuse_texture(p_thumbnail); + thumbnail_wrapped->set_texture_filter(CanvasItem::TextureFilter::TEXTURE_FILTER_NEAREST_WITH_MIPMAPS); + return thumbnail_wrapped; + } + } + } + } + } + + return p_thumbnail; +} + void FileSystemDock::_toggle_file_display() { _set_file_display(file_list_display_mode != FILE_LIST_DISPLAY_LIST); emit_signal(SNAME("display_mode_changed")); diff --git a/editor/docks/filesystem_dock.h b/editor/docks/filesystem_dock.h index 527f7c0b59..ebfe4141e3 100644 --- a/editor/docks/filesystem_dock.h +++ b/editor/docks/filesystem_dock.h @@ -357,6 +357,7 @@ private: void _preview_invalidated(const String &p_path); void _file_list_thumbnail_done(const String &p_path, const Ref &p_preview, const Ref &p_small_preview, int p_index, const String &p_filename); void _tree_thumbnail_done(const String &p_path, const Ref &p_preview, const Ref &p_small_preview, int p_update_id, ObjectID p_item); + Ref _apply_thumbnail_filter(const Ref &p_thumbnail, const String &p_file_path) const; void _update_display_mode(bool p_force = false);