summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgroud <gilles.roudiere@gmail.com>2018-09-12 13:10:49 +0200
committergroud <gilles.roudiere@gmail.com>2018-09-14 10:14:33 +0200
commitb2633a97b9efa7b926d6682342480c5ccb482369 (patch)
tree048121a9e25fe54f41b26a5e913e79af2ac059e7
parent5f3bbbdc8152375f1f7f0770d56e1933a559ea20 (diff)
Add thumnails to the tree view
-rw-r--r--editor/editor_file_dialog.cpp4
-rw-r--r--editor/editor_file_dialog.h4
-rw-r--r--editor/editor_node.cpp2
-rw-r--r--editor/editor_node.h2
-rw-r--r--editor/editor_resource_preview.cpp109
-rw-r--r--editor/editor_resource_preview.h11
-rw-r--r--editor/editor_settings.cpp2
-rw-r--r--editor/filesystem_dock.cpp28
-rw-r--r--editor/filesystem_dock.h4
-rw-r--r--editor/plugins/editor_preview_plugins.cpp151
-rw-r--r--editor/plugins/editor_preview_plugins.h26
11 files changed, 203 insertions, 140 deletions
diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp
index 3659a06bb7..d0007bd5d1 100644
--- a/editor/editor_file_dialog.cpp
+++ b/editor/editor_file_dialog.cpp
@@ -269,7 +269,7 @@ void EditorFileDialog::_post_popup() {
set_process_unhandled_input(true);
}
-void EditorFileDialog::_thumbnail_result(const String &p_path, const Ref<Texture> &p_preview, const Variant &p_udata) {
+void EditorFileDialog::_thumbnail_result(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, const Variant &p_udata) {
if (display_mode == DISPLAY_LIST || p_preview.is_null())
return;
@@ -284,7 +284,7 @@ void EditorFileDialog::_thumbnail_result(const String &p_path, const Ref<Texture
}
}
-void EditorFileDialog::_thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Variant &p_udata) {
+void EditorFileDialog::_thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, const Variant &p_udata) {
set_process(false);
preview_waiting = false;
diff --git a/editor/editor_file_dialog.h b/editor/editor_file_dialog.h
index 61eeff9162..56cefb9a47 100644
--- a/editor/editor_file_dialog.h
+++ b/editor/editor_file_dialog.h
@@ -190,8 +190,8 @@ private:
void _save_to_recent();
//callback function is callback(String p_path,Ref<Texture> preview,Variant udata) preview null if could not load
- void _thumbnail_result(const String &p_path, const Ref<Texture> &p_preview, const Variant &p_udata);
- void _thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Variant &p_udata);
+ void _thumbnail_result(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, const Variant &p_udata);
+ void _thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, const Variant &p_udata);
void _request_single_thumbnail(const String &p_path);
void _unhandled_input(const Ref<InputEvent> &p_event);
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index b652a25b6b..1449be9724 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -3915,7 +3915,7 @@ void EditorNode::_reposition_active_tab(int idx_to) {
_update_scene_tabs();
}
-void EditorNode::_thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Variant &p_udata) {
+void EditorNode::_thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, const Variant &p_udata) {
int p_tab = p_udata.operator signed int();
if (p_preview.is_valid()) {
Rect2 rect = scene_tabs->get_tab_rect(p_tab);
diff --git a/editor/editor_node.h b/editor/editor_node.h
index 5a17ab6ca0..93f5d499b7 100644
--- a/editor/editor_node.h
+++ b/editor/editor_node.h
@@ -535,7 +535,7 @@ private:
void _scene_tab_exit();
void _scene_tab_input(const Ref<InputEvent> &p_input);
void _reposition_active_tab(int idx_to);
- void _thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Variant &p_udata);
+ void _thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, const Variant &p_udata);
void _scene_tab_script_edited(int p_tab);
Dictionary _get_main_scene_state();
diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp
index edfee595ea..ee528401ad 100644
--- a/editor/editor_resource_preview.cpp
+++ b/editor/editor_resource_preview.cpp
@@ -30,11 +30,14 @@
#include "editor_resource_preview.h"
+#include "core/method_bind_ext.gen.inc"
+
#include "core/io/resource_loader.h"
#include "core/io/resource_saver.h"
#include "core/message_queue.h"
#include "core/os/file_access.h"
#include "core/project_settings.h"
+#include "editor_node.h"
#include "editor_scale.h"
#include "editor_settings.h"
@@ -46,32 +49,37 @@ bool EditorResourcePreviewGenerator::handles(const String &p_type) const {
ERR_EXPLAIN("EditorResourcePreviewGenerator::handles needs to be overridden");
ERR_FAIL_V(false);
}
-Ref<Texture> EditorResourcePreviewGenerator::generate(const RES &p_from) const {
+
+Ref<Texture> EditorResourcePreviewGenerator::generate(const RES &p_from, const Size2 p_size) const {
if (get_script_instance() && get_script_instance()->has_method("generate")) {
- return get_script_instance()->call("generate", p_from);
+ return get_script_instance()->call("generate", p_from, p_size);
}
ERR_EXPLAIN("EditorResourcePreviewGenerator::generate needs to be overridden");
ERR_FAIL_V(Ref<Texture>());
}
-Ref<Texture> EditorResourcePreviewGenerator::generate_from_path(const String &p_path) const {
+Ref<Texture> EditorResourcePreviewGenerator::generate_from_path(const String &p_path, const Size2 p_size) const {
if (get_script_instance() && get_script_instance()->has_method("generate_from_path")) {
- return get_script_instance()->call("generate_from_path", p_path);
+ return get_script_instance()->call("generate_from_path", p_path, p_size);
}
RES res = ResourceLoader::load(p_path);
if (!res.is_valid())
return res;
- return generate(res);
+ return generate(res, p_size);
+}
+
+bool EditorResourcePreviewGenerator::should_generate_small_preview() const {
+ return false;
}
void EditorResourcePreviewGenerator::_bind_methods() {
ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "handles", PropertyInfo(Variant::STRING, "type")));
- ClassDB::add_virtual_method(get_class_static(), MethodInfo(CLASS_INFO(Texture), "generate", PropertyInfo(Variant::OBJECT, "from", PROPERTY_HINT_RESOURCE_TYPE, "Resource")));
- ClassDB::add_virtual_method(get_class_static(), MethodInfo(CLASS_INFO(Texture), "generate_from_path", PropertyInfo(Variant::STRING, "path", PROPERTY_HINT_FILE)));
+ ClassDB::add_virtual_method(get_class_static(), MethodInfo(CLASS_INFO(Texture), "generate", PropertyInfo(Variant::OBJECT, "from", PROPERTY_HINT_RESOURCE_TYPE, "Resource"), PropertyInfo(Variant::VECTOR2, "size")));
+ ClassDB::add_virtual_method(get_class_static(), MethodInfo(CLASS_INFO(Texture), "generate_from_path", PropertyInfo(Variant::STRING, "path", PROPERTY_HINT_FILE), PropertyInfo(Variant::VECTOR2, "size")));
}
EditorResourcePreviewGenerator::EditorResourcePreviewGenerator() {
@@ -85,7 +93,7 @@ void EditorResourcePreview::_thread_func(void *ud) {
erp->_thread();
}
-void EditorResourcePreview::_preview_ready(const String &p_str, const Ref<Texture> &p_texture, ObjectID id, const StringName &p_func, const Variant &p_ud) {
+void EditorResourcePreview::_preview_ready(const String &p_str, const Ref<Texture> &p_texture, const Ref<Texture> &p_small_texture, ObjectID id, const StringName &p_func, const Variant &p_ud) {
preview_mutex->lock();
@@ -103,6 +111,7 @@ void EditorResourcePreview::_preview_ready(const String &p_str, const Ref<Textur
Item item;
item.order = order++;
item.preview = p_texture;
+ item.small_preview = p_small_texture;
item.last_hash = hash;
item.modified_time = modified_time;
@@ -110,11 +119,10 @@ void EditorResourcePreview::_preview_ready(const String &p_str, const Ref<Textur
preview_mutex->unlock();
- MessageQueue::get_singleton()->push_call(id, p_func, path, p_texture, p_ud);
+ MessageQueue::get_singleton()->push_call(id, p_func, path, p_texture, p_small_texture, p_ud);
}
-Ref<Texture> EditorResourcePreview::_generate_preview(const QueueItem &p_item, const String &cache_base) {
-
+void EditorResourcePreview::_generate_preview(Ref<ImageTexture> &r_texture, Ref<ImageTexture> &r_small_texture, const QueueItem &p_item, const String &cache_base) {
String type;
if (p_item.resource.is_valid())
@@ -122,40 +130,59 @@ Ref<Texture> EditorResourcePreview::_generate_preview(const QueueItem &p_item, c
else
type = ResourceLoader::get_resource_type(p_item.path);
- if (type == "")
- return Ref<Texture>(); //could not guess type
+ if (type == "") {
+ r_texture = Ref<ImageTexture>();
+ r_small_texture = Ref<ImageTexture>();
+ return; //could not guess type
+ }
- Ref<Texture> generated;
+ int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size");
+ thumbnail_size *= EDSCALE;
- for (int i = 0; i < preview_generators.size(); i++) {
+ r_texture = Ref<ImageTexture>();
+ r_small_texture = Ref<ImageTexture>();
+ for (int i = 0; i < preview_generators.size(); i++) {
if (!preview_generators[i]->handles(type))
continue;
+
+ Ref<Texture> generated;
if (p_item.resource.is_valid()) {
- generated = preview_generators[i]->generate(p_item.resource);
+ generated = preview_generators[i]->generate(p_item.resource, Vector2(thumbnail_size, thumbnail_size));
} else {
- generated = preview_generators[i]->generate_from_path(p_item.path);
+ generated = preview_generators[i]->generate_from_path(p_item.path, Vector2(thumbnail_size, thumbnail_size));
}
+ r_texture = generated;
+ if (preview_generators[i]->should_generate_small_preview()) {
+ int small_thumbnail_size = EditorNode::get_singleton()->get_theme_base()->get_icon("Object", "EditorIcons")->get_width(); // Kind of a workaround to retreive the default icon size
+ small_thumbnail_size *= EDSCALE;
+
+ Ref<Image> small_image = r_texture->get_data();
+ small_image->resize(small_thumbnail_size, small_thumbnail_size, Image::INTERPOLATE_CUBIC);
+ r_small_texture.instance();
+ r_small_texture->create_from_image(small_image);
+ }
break;
}
if (!p_item.resource.is_valid()) {
// cache the preview in case it's a resource on disk
- if (generated.is_valid()) {
- int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size");
- thumbnail_size *= EDSCALE;
+ if (r_texture.is_valid()) {
//wow it generated a preview... save cache
- ResourceSaver::save(cache_base + ".png", generated);
+ bool has_small_texture = r_small_texture.is_valid();
+ ResourceSaver::save(cache_base + ".png", r_texture);
+ if (has_small_texture) {
+ ResourceSaver::save(cache_base + "_small.png", r_small_texture);
+ }
FileAccess *f = FileAccess::open(cache_base + ".txt", FileAccess::WRITE);
f->store_line(itos(thumbnail_size));
+ f->store_line(itos(has_small_texture));
f->store_line(itos(FileAccess::get_modified_time(p_item.path)));
f->store_line(FileAccess::get_md5(p_item.path));
memdelete(f);
}
}
-
- return generated;
}
void EditorResourcePreview::_thread() {
@@ -177,7 +204,7 @@ void EditorResourcePreview::_thread() {
path += ":" + itos(cache[item.path].last_hash); //keep last hash (see description of what this is in condition below)
}
- _preview_ready(path, cache[item.path].preview, item.id, item.function, item.userdata);
+ _preview_ready(path, cache[item.path].preview, cache[item.path].small_preview, item.id, item.function, item.userdata);
preview_mutex->unlock();
} else {
@@ -185,15 +212,17 @@ void EditorResourcePreview::_thread() {
preview_mutex->unlock();
Ref<ImageTexture> texture;
+ Ref<ImageTexture> small_texture;
int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size");
thumbnail_size *= EDSCALE;
if (item.resource.is_valid()) {
- texture = _generate_preview(item, String());
+ _generate_preview(texture, small_texture, item, String());
+
//adding hash to the end of path (should be ID:<objid>:<hash>) because of 5 argument limit to call_deferred
- _preview_ready(item.path + ":" + itos(item.resource->hash_edited_version()), texture, item.id, item.function, item.userdata);
+ _preview_ready(item.path + ":" + itos(item.resource->hash_edited_version()), texture, small_texture, item.id, item.function, item.userdata);
} else {
@@ -207,12 +236,13 @@ void EditorResourcePreview::_thread() {
FileAccess *f = FileAccess::open(file, FileAccess::READ);
if (!f) {
- //generate
- texture = _generate_preview(item, cache_base);
+ // No cache found, generate
+ _generate_preview(texture, small_texture, item, cache_base);
} else {
uint64_t modtime = FileAccess::get_modified_time(item.path);
int tsize = f->get_line().to_int64();
+ bool has_small_texture = f->get_line().to_int();
uint64_t last_modtime = f->get_line().to_int64();
bool cache_valid = true;
@@ -236,6 +266,7 @@ void EditorResourcePreview::_thread() {
f = FileAccess::open(file, FileAccess::WRITE);
f->store_line(itos(modtime));
+ f->store_line(itos(has_small_texture));
f->store_line(md5);
memdelete(f);
}
@@ -243,12 +274,12 @@ void EditorResourcePreview::_thread() {
memdelete(f);
}
- //cache_valid = false;
-
if (cache_valid) {
Ref<Image> img;
img.instance();
+ Ref<Image> small_img;
+ small_img.instance();
if (img->load(cache_base + ".png") != OK) {
cache_valid = false;
@@ -256,16 +287,24 @@ void EditorResourcePreview::_thread() {
texture.instance();
texture->create_from_image(img, Texture::FLAG_FILTER);
+
+ if (has_small_texture) {
+ if (small_img->load(cache_base + "_small.png") != OK) {
+ cache_valid = false;
+ } else {
+ small_texture.instance();
+ small_texture->create_from_image(small_img, Texture::FLAG_FILTER);
+ }
+ }
}
}
if (!cache_valid) {
- texture = _generate_preview(item, cache_base);
+ _generate_preview(texture, small_texture, item, cache_base);
}
}
-
- _preview_ready(item.path, texture, item.id, item.function, item.userdata);
+ _preview_ready(item.path, texture, small_texture, item.id, item.function, item.userdata);
}
}
@@ -287,7 +326,7 @@ void EditorResourcePreview::queue_edited_resource_preview(const Ref<Resource> &p
if (cache.has(path_id) && cache[path_id].last_hash == p_res->hash_edited_version()) {
cache[path_id].order = order++;
- p_receiver->call_deferred(p_receiver_func, path_id, cache[path_id].preview, p_userdata);
+ p_receiver->call_deferred(p_receiver_func, path_id, cache[path_id].preview, cache[path_id].small_preview, p_userdata);
preview_mutex->unlock();
return;
}
@@ -312,7 +351,7 @@ void EditorResourcePreview::queue_resource_preview(const String &p_path, Object
preview_mutex->lock();
if (cache.has(p_path)) {
cache[p_path].order = order++;
- p_receiver->call_deferred(p_receiver_func, p_path, cache[p_path].preview, p_userdata);
+ p_receiver->call_deferred(p_receiver_func, p_path, cache[p_path].preview, cache[p_path].small_preview, p_userdata);
preview_mutex->unlock();
return;
}
diff --git a/editor/editor_resource_preview.h b/editor/editor_resource_preview.h
index 434b26e901..a3417cdf60 100644
--- a/editor/editor_resource_preview.h
+++ b/editor/editor_resource_preview.h
@@ -63,8 +63,10 @@ protected:
public:
virtual bool handles(const String &p_type) const;
- virtual Ref<Texture> generate(const RES &p_from) const;
- virtual Ref<Texture> generate_from_path(const String &p_path) const;
+ virtual Ref<Texture> generate(const RES &p_from, const Size2 p_size) const;
+ virtual Ref<Texture> generate_from_path(const String &p_path, const Size2 p_size) const;
+
+ virtual bool should_generate_small_preview() const;
EditorResourcePreviewGenerator();
};
@@ -92,6 +94,7 @@ class EditorResourcePreview : public Node {
struct Item {
Ref<Texture> preview;
+ Ref<Texture> small_preview;
int order;
uint32_t last_hash;
uint64_t modified_time;
@@ -101,8 +104,8 @@ class EditorResourcePreview : public Node {
Map<String, Item> cache;
- void _preview_ready(const String &p_str, const Ref<Texture> &p_texture, ObjectID id, const StringName &p_func, const Variant &p_ud);
- Ref<Texture> _generate_preview(const QueueItem &p_item, const String &cache_base);
+ void _preview_ready(const String &p_str, const Ref<Texture> &p_texture, const Ref<Texture> &p_small_texture, ObjectID id, const StringName &p_func, const Variant &p_ud);
+ void _generate_preview(Ref<ImageTexture> &r_texture, Ref<ImageTexture> &r_small_texture, const QueueItem &p_item, const String &cache_base);
static void _thread_func(void *ud);
void _thread();
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp
index d649ec2128..696f389b84 100644
--- a/editor/editor_settings.cpp
+++ b/editor/editor_settings.cpp
@@ -510,9 +510,9 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
_initial_set("filesystem/file_dialog/show_hidden_files", false);
_initial_set("filesystem/file_dialog/display_mode", 0);
hints["filesystem/file_dialog/display_mode"] = PropertyInfo(Variant::INT, "filesystem/file_dialog/display_mode", PROPERTY_HINT_ENUM, "Thumbnails,List");
+
_initial_set("filesystem/file_dialog/thumbnail_size", 64);
hints["filesystem/file_dialog/thumbnail_size"] = PropertyInfo(Variant::INT, "filesystem/file_dialog/thumbnail_size", PROPERTY_HINT_RANGE, "32,128,16");
-
_initial_set("docks/filesystem/disable_split", false);
_initial_set("docks/filesystem/split_mode_minimum_height", 600);
_initial_set("docks/filesystem/display_files_in_tree", false);
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp
index 39ded5ca5a..b406242759 100644
--- a/editor/filesystem_dock.cpp
+++ b/editor/filesystem_dock.cpp
@@ -98,6 +98,10 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory
if (path == file_metadata) {
file_item->select(0);
}
+ Array udata;
+ udata.push_back(tree_update_id);
+ udata.push_back(file_item);
+ EditorResourcePreview::get_singleton()->queue_resource_preview(file_metadata, this, "_tree_thumbnail_done", udata);
}
}
@@ -133,6 +137,7 @@ void FileSystemDock::_update_tree(bool keep_collapse_state, bool p_uncollapse_ro
// Recreate the tree
tree->clear();
+ tree_update_id++;
updating_tree = true;
TreeItem *root = tree->create_item();
@@ -496,10 +501,9 @@ void FileSystemDock::navigate_to_path(const String &p_path) {
}
}
-void FileSystemDock::_thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Variant &p_udata) {
+void FileSystemDock::_file_list_thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, const Variant &p_udata) {
if ((file_list_vb->is_visible_in_tree() || path == p_path.get_base_dir()) && p_preview.is_valid()) {
-
Array uarr = p_udata;
int idx = uarr[0];
String file = uarr[1];
@@ -508,6 +512,18 @@ void FileSystemDock::_thumbnail_done(const String &p_path, const Ref<Texture> &p
}
}
+void FileSystemDock::_tree_thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, const Variant &p_udata) {
+ if (p_small_preview.is_valid()) {
+ Array uarr = p_udata;
+ if (tree_update_id == (int)uarr[0]) {
+ TreeItem *file_item = Object::cast_to<TreeItem>(uarr[1]);
+ if (file_item) {
+ file_item->set_icon(0, p_small_preview);
+ }
+ }
+ }
+}
+
void FileSystemDock::_update_file_list_display_mode_button() {
if (button_file_list_display_mode->is_pressed()) {
@@ -707,7 +723,7 @@ void FileSystemDock::_update_files(bool p_keep_selection) {
udata.resize(2);
udata[0] = item_index;
udata[1] = fname;
- EditorResourcePreview::get_singleton()->queue_resource_preview(fpath, this, "_thumbnail_done", udata);
+ EditorResourcePreview::get_singleton()->queue_resource_preview(fpath, this, "_file_list_thumbnail_done", udata);
}
} else {
files->add_item(fname, type_icon, true);
@@ -792,7 +808,7 @@ void FileSystemDock::_preview_invalidated(const String &p_path) {
udata.resize(2);
udata[0] = i;
udata[1] = files->get_item_text(i);
- EditorResourcePreview::get_singleton()->queue_resource_preview(p_path, this, "_thumbnail_done", udata);
+ EditorResourcePreview::get_singleton()->queue_resource_preview(p_path, this, "_file_list_thumbnail_done", udata);
break;
}
}
@@ -2072,7 +2088,8 @@ void FileSystemDock::_bind_methods() {
ClassDB::bind_method(D_METHOD("_file_list_rmb_select"), &FileSystemDock::_file_list_rmb_select);
ClassDB::bind_method(D_METHOD("_file_list_rmb_pressed"), &FileSystemDock::_file_list_rmb_pressed);
- ClassDB::bind_method(D_METHOD("_thumbnail_done"), &FileSystemDock::_thumbnail_done);
+ ClassDB::bind_method(D_METHOD("_file_list_thumbnail_done"), &FileSystemDock::_file_list_thumbnail_done);
+ ClassDB::bind_method(D_METHOD("_tree_thumbnail_done"), &FileSystemDock::_tree_thumbnail_done);
ClassDB::bind_method(D_METHOD("_file_list_activate_file"), &FileSystemDock::_file_list_activate_file);
ClassDB::bind_method(D_METHOD("_tree_activate_file"), &FileSystemDock::_tree_activate_file);
ClassDB::bind_method(D_METHOD("_select_file"), &FileSystemDock::_select_file);
@@ -2316,6 +2333,7 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) {
new_resource_dialog->connect("create", this, "_resource_created");
updating_tree = false;
+ tree_update_id = 0;
initialized = false;
import_dock_needs_update = false;
diff --git a/editor/filesystem_dock.h b/editor/filesystem_dock.h
index 40e3f60136..34a2666ecb 100644
--- a/editor/filesystem_dock.h
+++ b/editor/filesystem_dock.h
@@ -164,6 +164,7 @@ private:
bool initialized;
bool updating_tree;
+ int tree_update_id;
Tree *tree; //directories
ItemList *files;
bool import_dock_needs_update;
@@ -250,7 +251,8 @@ private:
String _get_drag_target_folder(const Point2 &p_point, Control *p_from) const;
void _preview_invalidated(const String &p_path);
- void _thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Variant &p_udata);
+ void _file_list_thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, const Variant &p_udata);
+ void _tree_thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, const Variant &p_udata);
void _update_display_mode();
diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp
index 72a746e95b..7f83865777 100644
--- a/editor/plugins/editor_preview_plugins.cpp
+++ b/editor/plugins/editor_preview_plugins.cpp
@@ -78,7 +78,11 @@ bool EditorTexturePreviewPlugin::handles(const String &p_type) const {
return ClassDB::is_parent_class(p_type, "Texture");
}
-Ref<Texture> EditorTexturePreviewPlugin::generate(const RES &p_from) const {
+bool EditorTexturePreviewPlugin::should_generate_small_preview() const {
+ return true;
+}
+
+Ref<Texture> EditorTexturePreviewPlugin::generate(const RES &p_from, const Size2 p_size) const {
Ref<Image> img;
Ref<AtlasTexture> atex = p_from;
@@ -100,8 +104,6 @@ Ref<Texture> EditorTexturePreviewPlugin::generate(const RES &p_from) const {
img = img->duplicate();
img->clear_mipmaps();
- int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size");
- thumbnail_size *= EDSCALE;
if (img->is_compressed()) {
if (img->decompress() != OK)
return Ref<Texture>();
@@ -109,22 +111,15 @@ Ref<Texture> EditorTexturePreviewPlugin::generate(const RES &p_from) const {
img->convert(Image::FORMAT_RGBA8);
}
- int width, height;
- if (img->get_width() > thumbnail_size && img->get_width() >= img->get_height()) {
-
- width = thumbnail_size;
- height = img->get_height() * thumbnail_size / img->get_width();
- } else if (img->get_height() > thumbnail_size && img->get_height() >= img->get_width()) {
-
- height = thumbnail_size;
- width = img->get_width() * thumbnail_size / img->get_height();
- } else {
-
- width = img->get_width();
- height = img->get_height();
+ Vector2 new_size = img->get_size();
+ if (new_size.x > p_size.x) {
+ new_size = Vector2(p_size.x, new_size.y * p_size.x / new_size.x);
}
+ if (new_size.y > p_size.y) {
+ new_size = Vector2(new_size.x * p_size.y / new_size.y, p_size.y);
+ }
+ img->resize(new_size.x, new_size.y, Image::INTERPOLATE_CUBIC);
- img->resize(width, height);
post_process_preview(img);
Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture));
@@ -143,7 +138,7 @@ bool EditorImagePreviewPlugin::handles(const String &p_type) const {
return p_type == "Image";
}
-Ref<Texture> EditorImagePreviewPlugin::generate(const RES &p_from) const {
+Ref<Texture> EditorImagePreviewPlugin::generate(const RES &p_from, const Size2 p_size) const {
Ref<Image> img = p_from;
@@ -153,8 +148,6 @@ Ref<Texture> EditorImagePreviewPlugin::generate(const RES &p_from) const {
img = img->duplicate();
img->clear_mipmaps();
- int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size");
- thumbnail_size *= EDSCALE;
if (img->is_compressed()) {
if (img->decompress() != OK)
return Ref<Image>();
@@ -162,22 +155,15 @@ Ref<Texture> EditorImagePreviewPlugin::generate(const RES &p_from) const {
img->convert(Image::FORMAT_RGBA8);
}
- int width, height;
- if (img->get_width() > thumbnail_size && img->get_width() >= img->get_height()) {
-
- width = thumbnail_size;
- height = img->get_height() * thumbnail_size / img->get_width();
- } else if (img->get_height() > thumbnail_size && img->get_height() >= img->get_width()) {
-
- height = thumbnail_size;
- width = img->get_width() * thumbnail_size / img->get_height();
- } else {
-
- width = img->get_width();
- height = img->get_height();
+ Vector2 new_size = img->get_size();
+ if (new_size.x > p_size.x) {
+ new_size = Vector2(p_size.x, new_size.y * p_size.x / new_size.x);
+ }
+ if (new_size.y > p_size.y) {
+ new_size = Vector2(new_size.x * p_size.y / new_size.y, p_size.y);
}
+ img->resize(new_size.x, new_size.y, Image::INTERPOLATE_CUBIC);
- img->resize(width, height);
post_process_preview(img);
Ref<ImageTexture> ptex;
@@ -190,6 +176,9 @@ Ref<Texture> EditorImagePreviewPlugin::generate(const RES &p_from) const {
EditorImagePreviewPlugin::EditorImagePreviewPlugin() {
}
+bool EditorImagePreviewPlugin::should_generate_small_preview() const {
+ return true;
+}
////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////
bool EditorBitmapPreviewPlugin::handles(const String &p_type) const {
@@ -197,7 +186,7 @@ bool EditorBitmapPreviewPlugin::handles(const String &p_type) const {
return ClassDB::is_parent_class(p_type, "BitMap");
}
-Ref<Texture> EditorBitmapPreviewPlugin::generate(const RES &p_from) const {
+Ref<Texture> EditorBitmapPreviewPlugin::generate(const RES &p_from, const Size2 p_size) const {
Ref<BitMap> bm = p_from;
@@ -227,8 +216,6 @@ Ref<Texture> EditorBitmapPreviewPlugin::generate(const RES &p_from) const {
img.instance();
img->create(bm->get_size().width, bm->get_size().height, 0, Image::FORMAT_L8, data);
- int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size");
- thumbnail_size *= EDSCALE;
if (img->is_compressed()) {
if (img->decompress() != OK)
return Ref<Texture>();
@@ -236,22 +223,15 @@ Ref<Texture> EditorBitmapPreviewPlugin::generate(const RES &p_from) const {
img->convert(Image::FORMAT_RGBA8);
}
- int width, height;
- if (img->get_width() > thumbnail_size && img->get_width() >= img->get_height()) {
-
- width = thumbnail_size;
- height = img->get_height() * thumbnail_size / img->get_width();
- } else if (img->get_height() > thumbnail_size && img->get_height() >= img->get_width()) {
-
- height = thumbnail_size;
- width = img->get_width() * thumbnail_size / img->get_height();
- } else {
-
- width = img->get_width();
- height = img->get_height();
+ Vector2 new_size = img->get_size();
+ if (new_size.x > p_size.x) {
+ new_size = Vector2(p_size.x, new_size.y * p_size.x / new_size.x);
+ }
+ if (new_size.y > p_size.y) {
+ new_size = Vector2(new_size.x * p_size.y / new_size.y, p_size.y);
}
+ img->resize(new_size.x, new_size.y, Image::INTERPOLATE_CUBIC);
- img->resize(width, height);
post_process_preview(img);
Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture));
@@ -260,6 +240,10 @@ Ref<Texture> EditorBitmapPreviewPlugin::generate(const RES &p_from) const {
return ptex;
}
+bool EditorBitmapPreviewPlugin::should_generate_small_preview() const {
+ return true;
+}
+
EditorBitmapPreviewPlugin::EditorBitmapPreviewPlugin() {
}
@@ -269,12 +253,12 @@ bool EditorPackedScenePreviewPlugin::handles(const String &p_type) const {
return ClassDB::is_parent_class(p_type, "PackedScene");
}
-Ref<Texture> EditorPackedScenePreviewPlugin::generate(const RES &p_from) const {
+Ref<Texture> EditorPackedScenePreviewPlugin::generate(const RES &p_from, const Size2 p_size) const {
- return generate_from_path(p_from->get_path());
+ return generate_from_path(p_from->get_path(), p_size);
}
-Ref<Texture> EditorPackedScenePreviewPlugin::generate_from_path(const String &p_path) const {
+Ref<Texture> EditorPackedScenePreviewPlugin::generate_from_path(const String &p_path, const Size2 p_size) const {
String temp_path = EditorSettings::get_singleton()->get_cache_dir();
String cache_base = ProjectSettings::get_singleton()->globalize_path(p_path).md5_text();
@@ -323,7 +307,11 @@ bool EditorMaterialPreviewPlugin::handles(const String &p_type) const {
return ClassDB::is_parent_class(p_type, "Material"); //any material
}
-Ref<Texture> EditorMaterialPreviewPlugin::generate(const RES &p_from) const {
+bool EditorMaterialPreviewPlugin::should_generate_small_preview() const {
+ return true;
+}
+
+Ref<Texture> EditorMaterialPreviewPlugin::generate(const RES &p_from, const Size2 p_size) const {
Ref<Material> material = p_from;
ERR_FAIL_COND_V(material.is_null(), Ref<Texture>());
@@ -346,10 +334,9 @@ Ref<Texture> EditorMaterialPreviewPlugin::generate(const RES &p_from) const {
ERR_FAIL_COND_V(!img.is_valid(), Ref<ImageTexture>());
- int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size");
- thumbnail_size *= EDSCALE;
img->convert(Image::FORMAT_RGBA8);
- img->resize(thumbnail_size, thumbnail_size);
+ int thumbnail_size = MAX(p_size.x, p_size.y);
+ img->resize(thumbnail_size, thumbnail_size, Image::INTERPOLATE_CUBIC);
post_process_preview(img);
Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture));
ptex->create_from_image(img, 0);
@@ -490,7 +477,7 @@ bool EditorScriptPreviewPlugin::handles(const String &p_type) const {
return ClassDB::is_parent_class(p_type, "Script");
}
-Ref<Texture> EditorScriptPreviewPlugin::generate(const RES &p_from) const {
+Ref<Texture> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size2 p_size) const {
Ref<Script> scr = p_from;
if (scr.is_null())
@@ -512,10 +499,9 @@ Ref<Texture> EditorScriptPreviewPlugin::generate(const RES &p_from) const {
int line = 0;
int col = 0;
- int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size");
- thumbnail_size *= EDSCALE;
Ref<Image> img;
img.instance();
+ int thumbnail_size = MAX(p_size.x, p_size.y);
img->create(thumbnail_size, thumbnail_size, 0, Image::FORMAT_RGBA8);
Color bg_color = EditorSettings::get_singleton()->get("text_editor/highlighting/background_color");
@@ -613,16 +599,15 @@ bool EditorAudioStreamPreviewPlugin::handles(const String &p_type) const {
return ClassDB::is_parent_class(p_type, "AudioStream");
}
-Ref<Texture> EditorAudioStreamPreviewPlugin::generate(const RES &p_from) const {
+Ref<Texture> EditorAudioStreamPreviewPlugin::generate(const RES &p_from, const Size2 p_size) const {
Ref<AudioStream> stream = p_from;
ERR_FAIL_COND_V(stream.is_null(), Ref<Texture>());
- int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size");
- thumbnail_size *= EDSCALE;
PoolVector<uint8_t> img;
- int w = thumbnail_size;
- int h = thumbnail_size;
+
+ int w = p_size.x;
+ int h = p_size.y;
img.resize(w * h * 3);
PoolVector<uint8_t>::Write imgdata = img.write();
@@ -711,7 +696,7 @@ bool EditorMeshPreviewPlugin::handles(const String &p_type) const {
return ClassDB::is_parent_class(p_type, "Mesh"); //any Mesh
}
-Ref<Texture> EditorMeshPreviewPlugin::generate(const RES &p_from) const {
+Ref<Texture> EditorMeshPreviewPlugin::generate(const RES &p_from, const Size2 p_size) const {
Ref<Mesh> mesh = p_from;
ERR_FAIL_COND_V(mesh.is_null(), Ref<Texture>());
@@ -749,10 +734,17 @@ Ref<Texture> EditorMeshPreviewPlugin::generate(const RES &p_from) const {
VS::get_singleton()->instance_set_base(mesh_instance, RID());
- int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size");
- thumbnail_size *= EDSCALE;
img->convert(Image::FORMAT_RGBA8);
- img->resize(thumbnail_size, thumbnail_size);
+
+ Vector2 new_size = img->get_size();
+ if (new_size.x > p_size.x) {
+ new_size = Vector2(p_size.x, new_size.y * p_size.x / new_size.x);
+ }
+ if (new_size.y > p_size.y) {
+ new_size = Vector2(new_size.x * p_size.y / new_size.y, p_size.y);
+ }
+ img->resize(new_size.x, new_size.y, Image::INTERPOLATE_CUBIC);
+
post_process_preview(img);
Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture));
@@ -825,15 +817,12 @@ bool EditorFontPreviewPlugin::handles(const String &p_type) const {
return ClassDB::is_parent_class(p_type, "DynamicFontData");
}
-Ref<Texture> EditorFontPreviewPlugin::generate_from_path(const String &p_path) const {
+Ref<Texture> EditorFontPreviewPlugin::generate_from_path(const String &p_path, const Size2 p_size) const {
Ref<DynamicFontData> SampledFont;
SampledFont.instance();
SampledFont->set_font_path(p_path);
- int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size");
- thumbnail_size *= EDSCALE;
-
Ref<DynamicFont> sampled_font;
sampled_font.instance();
sampled_font->set_size(50);
@@ -864,7 +853,15 @@ Ref<Texture> EditorFontPreviewPlugin::generate_from_path(const String &p_path) c
ERR_FAIL_COND_V(img.is_null(), Ref<ImageTexture>());
img->convert(Image::FORMAT_RGBA8);
- img->resize(thumbnail_size, thumbnail_size);
+
+ Vector2 new_size = img->get_size();
+ if (new_size.x > p_size.x) {
+ new_size = Vector2(p_size.x, new_size.y * p_size.x / new_size.x);
+ }
+ if (new_size.y > p_size.y) {
+ new_size = Vector2(new_size.x * p_size.y / new_size.y, p_size.y);
+ }
+ img->resize(new_size.x, new_size.y, Image::INTERPOLATE_CUBIC);
post_process_preview(img);
@@ -874,9 +871,9 @@ Ref<Texture> EditorFontPreviewPlugin::generate_from_path(const String &p_path) c
return ptex;
}
-Ref<Texture> EditorFontPreviewPlugin::generate(const RES &p_from) const {
+Ref<Texture> EditorFontPreviewPlugin::generate(const RES &p_from, const Size2 p_size) const {
- return generate_from_path(p_from->get_path());
+ return generate_from_path(p_from->get_path(), p_size);
}
EditorFontPreviewPlugin::EditorFontPreviewPlugin() {
diff --git a/editor/plugins/editor_preview_plugins.h b/editor/plugins/editor_preview_plugins.h
index 8bd7943383..ed5d2a3ecd 100644
--- a/editor/plugins/editor_preview_plugins.h
+++ b/editor/plugins/editor_preview_plugins.h
@@ -39,7 +39,8 @@ class EditorTexturePreviewPlugin : public EditorResourcePreviewGenerator {
GDCLASS(EditorTexturePreviewPlugin, EditorResourcePreviewGenerator)
public:
virtual bool handles(const String &p_type) const;
- virtual Ref<Texture> generate(const RES &p_from) const;
+ virtual bool should_generate_small_preview() const;
+ virtual Ref<Texture> generate(const RES &p_from, const Size2 p_size) const;
EditorTexturePreviewPlugin();
};
@@ -48,7 +49,8 @@ class EditorImagePreviewPlugin : public EditorResourcePreviewGenerator {
GDCLASS(EditorImagePreviewPlugin, EditorResourcePreviewGenerator)
public:
virtual bool handles(const String &p_type) const;
- virtual Ref<Texture> generate(const RES &p_from) const;
+ virtual bool should_generate_small_preview() const;
+ virtual Ref<Texture> generate(const RES &p_from, const Size2 p_size) const;
EditorImagePreviewPlugin();
};
@@ -57,7 +59,8 @@ class EditorBitmapPreviewPlugin : public EditorResourcePreviewGenerator {
GDCLASS(EditorBitmapPreviewPlugin, EditorResourcePreviewGenerator)
public:
virtual bool handles(const String &p_type) const;
- virtual Ref<Texture> generate(const RES &p_from) const;
+ virtual bool should_generate_small_preview() const;
+ virtual Ref<Texture> generate(const RES &p_from, const Size2 p_size) const;
EditorBitmapPreviewPlugin();
};
@@ -66,8 +69,8 @@ class EditorPackedScenePreviewPlugin : public EditorResourcePreviewGenerator {
public:
virtual bool handles(const String &p_type) const;
- virtual Ref<Texture> generate(const RES &p_from) const;
- virtual Ref<Texture> generate_from_path(const String &p_path) const;
+ virtual Ref<Texture> generate(const RES &p_from, const Size2 p_size) const;
+ virtual Ref<Texture> generate_from_path(const String &p_path, const Size2 p_size) const;
EditorPackedScenePreviewPlugin();
};
@@ -95,7 +98,8 @@ protected:
public:
virtual bool handles(const String &p_type) const;
- virtual Ref<Texture> generate(const RES &p_from) const;
+ virtual bool should_generate_small_preview() const;
+ virtual Ref<Texture> generate(const RES &p_from, const Size2 p_size) const;
EditorMaterialPreviewPlugin();
~EditorMaterialPreviewPlugin();
@@ -104,7 +108,7 @@ public:
class EditorScriptPreviewPlugin : public EditorResourcePreviewGenerator {
public:
virtual bool handles(const String &p_type) const;
- virtual Ref<Texture> generate(const RES &p_from) const;
+ virtual Ref<Texture> generate(const RES &p_from, const Size2 p_size) const;
EditorScriptPreviewPlugin();
};
@@ -112,7 +116,7 @@ public:
class EditorAudioStreamPreviewPlugin : public EditorResourcePreviewGenerator {
public:
virtual bool handles(const String &p_type) const;
- virtual Ref<Texture> generate(const RES &p_from) const;
+ virtual Ref<Texture> generate(const RES &p_from, const Size2 p_size) const;
EditorAudioStreamPreviewPlugin();
};
@@ -139,7 +143,7 @@ protected:
public:
virtual bool handles(const String &p_type) const;
- virtual Ref<Texture> generate(const RES &p_from) const;
+ virtual Ref<Texture> generate(const RES &p_from, const Size2 p_size) const;
EditorMeshPreviewPlugin();
~EditorMeshPreviewPlugin();
@@ -162,8 +166,8 @@ protected:
public:
virtual bool handles(const String &p_type) const;
- virtual Ref<Texture> generate(const RES &p_from) const;
- virtual Ref<Texture> generate_from_path(const String &p_path) const;
+ virtual Ref<Texture> generate(const RES &p_from, const Size2 p_size) const;
+ virtual Ref<Texture> generate_from_path(const String &p_path, const Size2 p_size) const;
EditorFontPreviewPlugin();
~EditorFontPreviewPlugin();