From ff2f9141deacb9932653e60c436fa31ee6e5413b Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Wed, 28 Jun 2023 12:15:34 -0700 Subject: [PATCH 01/13] updated to fix merge conflicts --- source/blender/blenloader/BLO_readfile.h | 9 +- source/blender/blenloader/intern/readfile.cc | 11 ++ .../blender/editors/space_file/file_draw.cc | 149 +++++++++++++++++- source/blender/imbuf/intern/anim_movie.cc | 22 +++ 4 files changed, 184 insertions(+), 7 deletions(-) diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h index e714ef15e5f..0155febcbbc 100644 --- a/source/blender/blenloader/BLO_readfile.h +++ b/source/blender/blenloader/BLO_readfile.h @@ -520,7 +520,14 @@ void BLO_sanitize_experimental_features_userpref_blend(struct UserDef *userdef); */ struct BlendThumbnail *BLO_thumbnail_from_file(const char *filepath); -/** Default theme, see: `release/datafiles/userdef/userdef_default_theme.c`. */ +/** + * Does a very light reading of given .blend file to extract its version. + * + * \param filepath: The path of the blend file to extract version from. + * \return The file version + */ +short BLO_version_from_file(const char *filepath); + extern const struct bTheme U_theme_default; /** Default preferences, defined by: `release/datafiles/userdef/userdef_default.c`. */ extern const struct UserDef U_default; diff --git a/source/blender/blenloader/intern/readfile.cc b/source/blender/blenloader/intern/readfile.cc index 2354c174fa4..fae6d21827e 100644 --- a/source/blender/blenloader/intern/readfile.cc +++ b/source/blender/blenloader/intern/readfile.cc @@ -1356,6 +1356,17 @@ BlendThumbnail *BLO_thumbnail_from_file(const char *filepath) return data; } +short BLO_version_from_file(const char *filepath) +{ + short version = 0; + FileData *fd = blo_filedata_from_file_minimal(filepath); + if (fd) { + version = fd->fileversion; + blo_filedata_free(fd); + } + return version; +} + /** \} */ /* -------------------------------------------------------------------- */ diff --git a/source/blender/editors/space_file/file_draw.cc b/source/blender/editors/space_file/file_draw.cc index 766ff9e705f..07ffe476a38 100644 --- a/source/blender/editors/space_file/file_draw.cc +++ b/source/blender/editors/space_file/file_draw.cc @@ -9,6 +9,7 @@ #include #include #include +#include #include "MEM_guardedalloc.h" @@ -27,11 +28,16 @@ #include "BKE_blendfile.h" #include "BKE_context.h" +#include "BLO_readfile.h" + #include "BLT_translation.h" #include "BLF_api.h" +#include "IMB_imbuf.h" #include "IMB_imbuf_types.h" +#include "IMB_metadata.h" +#include "IMB_thumbs.h" #include "DNA_userdef_types.h" #include "DNA_windowmanager_types.h" @@ -107,11 +113,138 @@ void ED_file_path_button(bScreen *screen, UI_block_func_set(block, nullptr, nullptr, nullptr); } -/* Dummy helper - we need dynamic tooltips here. */ +typedef struct file_tooltip_data { + const SpaceFile *sfile; + const FileDirEntry *file; + ImBuf *preview; +} file_tooltip_data; + +static file_tooltip_data *file_tooltip_data_create(const SpaceFile *sfile, + const FileDirEntry *file, + ImBuf *preview) +{ + file_tooltip_data *data = (file_tooltip_data *)MEM_mallocN(sizeof(file_tooltip_data), + "tooltip_data"); + data->sfile = sfile; + data->file = file; + data->preview = preview; + return data; +} + static char *file_draw_tooltip_func(bContext * /*C*/, void *argN, const char * /*tip*/) { - char *dyn_tooltip = static_cast(argN); - return BLI_strdup(dyn_tooltip); + file_tooltip_data *data = static_cast(argN); + const SpaceFile *sfile = data->sfile; + const FileList *files = sfile->files; + const FileSelectParams *params = ED_fileselect_get_active_params(sfile); + const FileDirEntry *file = data->file; + + if (file->asset) { + return nullptr; + } + std::string complete_string(file->name); + + if (!(file->typeflag & FILE_TYPE_BLENDERLIB)) { + + char full_path[FILE_MAX_LIBEXTRA]; + filelist_file_get_full_path(files, file, full_path); + + if (params->recursion_level > 0) { + char root[FILE_MAX]; + BLI_path_split_dir_part(full_path, root, FILE_MAX); + complete_string += std::string("\n") + root; + } + + if (file->redirection_path) { + complete_string += '\n' + std::string("\n") + N_("Link target:") + file->redirection_path; + } + if (file->attributes & FILE_ATTR_OFFLINE) { + complete_string += std::string("\n") + N_("This file is offline."); + } + if (file->attributes & FILE_ATTR_READONLY) { + complete_string += std::string("\n") + N_("This file is Read-Only."); + } + if (file->attributes & (FILE_ATTR_SYSTEM | FILE_ATTR_RESTRICTED)) { + complete_string += std::string("\n") + N_("This is a restricted system file."); + } + + if (file->typeflag & (FILE_TYPE_BLENDER | FILE_TYPE_BLENDER_BACKUP) && + !(file->attributes & FILE_ATTR_OFFLINE)) + { + /* Load Blender version directly from the file. */ + short version = BLO_version_from_file(full_path); + if (version != 0) { + complete_string += std::string("\n") + "Blender: " + std::to_string(version / 100) + "." + + std::to_string(version % 100); + } + } + + if (file->typeflag & FILE_TYPE_IMAGE) { + ImBuf *thumb = (file->attributes & FILE_ATTR_OFFLINE) ? + IMB_thumb_read(full_path, THB_LARGE) : + IMB_thumb_manage(full_path, THB_LARGE, THB_SOURCE_IMAGE); + char value1[128]; + char value2[128]; + if (IMB_metadata_get_field(thumb->metadata, "Thumb::Image::Width", value1, sizeof(value1)) && + IMB_metadata_get_field(thumb->metadata, "Thumb::Image::Height", value2, sizeof(value2))) + { + complete_string += std::string("\n") + N_("Dimensions") + ": "; + complete_string += std::string(value1) + " \u00D7 " + std::string(value2); + } + IMB_freeImBuf(thumb); + } + + if (file->typeflag & FILE_TYPE_MOVIE) { + ImBuf *thumb = (file->attributes & FILE_ATTR_OFFLINE) ? + IMB_thumb_read(full_path, THB_LARGE) : + IMB_thumb_manage(full_path, THB_LARGE, THB_SOURCE_MOVIE); + char value1[128]; + char value2[128]; + char value3[128]; + if (IMB_metadata_get_field(thumb->metadata, "Codec", value1, sizeof(value1))) + { + complete_string += std::string("\n") + N_("Codec") + ": "; + complete_string += std::string(value1); + } + if (IMB_metadata_get_field(thumb->metadata, "Thumb::Image::Width", value1, sizeof(value1)) && + IMB_metadata_get_field(thumb->metadata, "Thumb::Image::Height", value2, sizeof(value2))) + { + complete_string += std::string("\n") + N_("Dimensions") + ": "; + complete_string += std::string(value1) + " \u00D7 " + std::string(value2); + } + if (IMB_metadata_get_field(thumb->metadata, "Frames", value1, sizeof(value1)) && + IMB_metadata_get_field(thumb->metadata, "FPS", value2, sizeof(value2)) && + IMB_metadata_get_field(thumb->metadata, "Duration", value3, sizeof(value3))) + { + complete_string += std::string("\n") + N_("Frames") + ": "; + complete_string += value1 + std::string(" @ ") + value2 + " " + N_("FPS"); + complete_string += std::string(" (") + value3 + " " + N_("Seconds") ") "; + } + IMB_freeImBuf(thumb); + } + + char date_st[FILELIST_DIRENTRY_DATE_LEN], time_st[FILELIST_DIRENTRY_TIME_LEN]; + bool is_today, is_yesterday; + BLI_filelist_entry_datetime_to_string( + NULL, file->time, false, time_st, date_st, &is_today, &is_yesterday); + complete_string += std::string("\n") + N_("Modified") + std::string(": "); + if (is_today || is_yesterday) { + complete_string += (is_today ? N_("Today") : N_("Yesterday")) + std::string(" "); + } + complete_string += date_st + std::string(" ") + time_st; + + if (!(file->typeflag & FILE_TYPE_DIR) && file->size > 0) { + char size[16]; + char size_full[16]; + BLI_filelist_entry_size_to_string(NULL, file->size, false, size); + BLI_str_format_uint64_grouped(size_full, file->size); + complete_string += std::string("\n") + N_("Size") + std::string(": ") + std::string(size) + + std::string(" (") + std::string(size_full) + std::string(" ") + + N_("Bytes") + std::string(")"); + } + } + + return BLI_strdupn(complete_string.c_str(), complete_string.size()); } static char *file_draw_asset_tooltip_func(bContext * /*C*/, void *argN, const char * /*tip*/) @@ -171,7 +304,7 @@ static void file_but_enable_drag(uiBut *but, static uiBut *file_add_icon_but(const SpaceFile *sfile, uiBlock *block, - const char *path, + const char * /*path*/, const FileDirEntry *file, const rcti *tile_draw_rect, int icon, @@ -194,7 +327,8 @@ static uiBut *file_add_icon_but(const SpaceFile *sfile, UI_but_func_tooltip_set(but, file_draw_asset_tooltip_func, file->asset, nullptr); } else { - UI_but_func_tooltip_set(but, file_draw_tooltip_func, BLI_strdup(path), MEM_freeN); + UI_but_func_tooltip_set( + but, file_draw_tooltip_func, file_tooltip_data_create(sfile, file, NULL), MEM_freeN); } return but; @@ -334,7 +468,10 @@ static void file_add_preview_drag_but(const SpaceFile *sfile, UI_but_func_tooltip_set(but, file_draw_asset_tooltip_func, file->asset, nullptr); } else { - UI_but_func_tooltip_set(but, file_draw_tooltip_func, BLI_strdup(path), MEM_freeN); + UI_but_func_tooltip_set(but, + file_draw_tooltip_func, + file_tooltip_data_create(sfile, file, preview_image), + MEM_freeN); } } diff --git a/source/blender/imbuf/intern/anim_movie.cc b/source/blender/imbuf/intern/anim_movie.cc index 5d258f70973..31a3ef253ba 100644 --- a/source/blender/imbuf/intern/anim_movie.cc +++ b/source/blender/imbuf/intern/anim_movie.cc @@ -1587,6 +1587,28 @@ ImBuf *IMB_anim_previewframe(anim *anim) IMB_freeImBuf(ibuf); position = anim->duration_in_frames / 2; ibuf = IMB_anim_absolute(anim, position, IMB_TC_NONE, IMB_PROXY_NONE); + + char value[128]; + IMB_metadata_ensure(&ibuf->metadata); + SNPRINTF(value, "%i", anim->x); + IMB_metadata_set_field(ibuf->metadata, "Thumb::Image::Width", value); + SNPRINTF(value, "%i", anim->y); + IMB_metadata_set_field(ibuf->metadata, "Thumb::Image::Height", value); + SNPRINTF(value, "%i", anim->duration_in_frames); + IMB_metadata_set_field(ibuf->metadata, "Frames", value); + +#ifdef WITH_FFMPEG + AVStream *v_st = anim->pFormatCtx->streams[anim->videoStream]; + AVRational frame_rate = av_guess_frame_rate(anim->pFormatCtx, v_st, NULL); + if (frame_rate.num != 0) { + double duration = anim->duration_in_frames / av_q2d(frame_rate); + SNPRINTF(value, "%g", av_q2d(frame_rate)); + IMB_metadata_set_field(ibuf->metadata, "FPS", value); + SNPRINTF(value, "%g", duration); + IMB_metadata_set_field(ibuf->metadata, "Duration", value); + IMB_metadata_set_field(ibuf->metadata, "Codec", anim->pCodec->long_name); + } +#endif } return ibuf; } -- 2.30.2 From 784ed3c5d435e7395a23040d47eaa0164ac134ed Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Wed, 23 Aug 2023 14:55:52 -0700 Subject: [PATCH 02/13] Updated to the current state of main. --- source/blender/editors/space_file/file_draw.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/editors/space_file/file_draw.cc b/source/blender/editors/space_file/file_draw.cc index 3f7e7756b42..593fed1a444 100644 --- a/source/blender/editors/space_file/file_draw.cc +++ b/source/blender/editors/space_file/file_draw.cc @@ -118,12 +118,12 @@ void ED_file_path_button(bScreen *screen, typedef struct file_tooltip_data { const SpaceFile *sfile; const FileDirEntry *file; - ImBuf *preview; + const ImBuf *preview; } file_tooltip_data; static file_tooltip_data *file_tooltip_data_create(const SpaceFile *sfile, const FileDirEntry *file, - ImBuf *preview) + const ImBuf *preview) { file_tooltip_data *data = (file_tooltip_data *)MEM_mallocN(sizeof(file_tooltip_data), "tooltip_data"); -- 2.30.2 From 43d7e78d0827b4fe2ffdb4e747ef1db0071327e0 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Thu, 14 Sep 2023 09:10:26 -0700 Subject: [PATCH 03/13] Text case changes suggested by Pablo. --- source/blender/editors/space_file/file_draw.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/space_file/file_draw.cc b/source/blender/editors/space_file/file_draw.cc index e6245430f28..1f5353bd92e 100644 --- a/source/blender/editors/space_file/file_draw.cc +++ b/source/blender/editors/space_file/file_draw.cc @@ -163,7 +163,7 @@ static char *file_draw_tooltip_func(bContext * /*C*/, void *argN, const char * / complete_string += std::string("\n") + N_("This file is offline."); } if (file->attributes & FILE_ATTR_READONLY) { - complete_string += std::string("\n") + N_("This file is Read-Only."); + complete_string += std::string("\n") + N_("This file is read-only."); } if (file->attributes & (FILE_ATTR_SYSTEM | FILE_ATTR_RESTRICTED)) { complete_string += std::string("\n") + N_("This is a restricted system file."); @@ -219,7 +219,7 @@ static char *file_draw_tooltip_func(bContext * /*C*/, void *argN, const char * / { complete_string += std::string("\n") + N_("Frames") + ": "; complete_string += value1 + std::string(" @ ") + value2 + " " + N_("FPS"); - complete_string += std::string(" (") + value3 + " " + N_("Seconds") ") "; + complete_string += std::string(" (") + value3 + " " + N_("seconds") ") "; } IMB_freeImBuf(thumb); } @@ -241,7 +241,7 @@ static char *file_draw_tooltip_func(bContext * /*C*/, void *argN, const char * / BLI_str_format_uint64_grouped(size_full, file->size); complete_string += std::string("\n") + N_("Size") + std::string(": ") + std::string(size) + std::string(" (") + std::string(size_full) + std::string(" ") + - N_("Bytes") + std::string(")"); + N_("bytes") + std::string(")"); } } -- 2.30.2 From 82c672b9498a9a21cb0638fb10ccce20c69a6755 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Fri, 15 Sep 2023 14:34:25 -0700 Subject: [PATCH 04/13] Updated to use new custom tooltips. --- .../blender/editors/space_file/file_draw.cc | 142 ++++++++++++------ 1 file changed, 99 insertions(+), 43 deletions(-) diff --git a/source/blender/editors/space_file/file_draw.cc b/source/blender/editors/space_file/file_draw.cc index 1f5353bd92e..e04e97ee28e 100644 --- a/source/blender/editors/space_file/file_draw.cc +++ b/source/blender/editors/space_file/file_draw.cc @@ -117,33 +117,35 @@ void ED_file_path_button(bScreen *screen, typedef struct file_tooltip_data { const SpaceFile *sfile; const FileDirEntry *file; - const ImBuf *preview; } file_tooltip_data; static file_tooltip_data *file_tooltip_data_create(const SpaceFile *sfile, - const FileDirEntry *file, - const ImBuf *preview) + const FileDirEntry *file) { file_tooltip_data *data = (file_tooltip_data *)MEM_mallocN(sizeof(file_tooltip_data), "tooltip_data"); data->sfile = sfile; data->file = file; - data->preview = preview; return data; } -static char *file_draw_tooltip_func(bContext * /*C*/, void *argN, const char * /*tip*/) +static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData *tip, void *argN) { - file_tooltip_data *data = static_cast(argN); - const SpaceFile *sfile = data->sfile; + file_tooltip_data *file_data = static_cast(argN); + const SpaceFile *sfile = file_data->sfile; const FileList *files = sfile->files; const FileSelectParams *params = ED_fileselect_get_active_params(sfile); - const FileDirEntry *file = data->file; + const FileDirEntry *file = file_data->file; if (file->asset) { - return nullptr; + return; } - std::string complete_string(file->name); + + UI_tooltip_text_field_add( + tip, BLI_strdup(file->name), nullptr, UI_TIP_STYLE_HEADER, UI_TIP_LC_MAIN); + + /* Add pad variable to the very next field only. */ + bool pad = true; if (!(file->typeflag & FILE_TYPE_BLENDERLIB)) { @@ -153,20 +155,42 @@ static char *file_draw_tooltip_func(bContext * /*C*/, void *argN, const char * / if (params->recursion_level > 0) { char root[FILE_MAX]; BLI_path_split_dir_part(full_path, root, FILE_MAX); - complete_string += std::string("\n") + root; + UI_tooltip_text_field_add( + tip, BLI_strdup(root), nullptr, UI_TIP_STYLE_NORMAL, UI_TIP_LC_NORMAL, pad); + pad = false; } if (file->redirection_path) { - complete_string += '\n' + std::string("\n") + N_("Link target:") + file->redirection_path; + UI_tooltip_text_field_add(tip, + BLI_sprintfN("%s: %s", N_("Link target"), file->redirection_path), + nullptr, + UI_TIP_STYLE_NORMAL, + UI_TIP_LC_NORMAL, pad); + pad = false; } if (file->attributes & FILE_ATTR_OFFLINE) { - complete_string += std::string("\n") + N_("This file is offline."); + UI_tooltip_text_field_add(tip, + BLI_strdup(N_("This file is offline")), + nullptr, + UI_TIP_STYLE_NORMAL, + UI_TIP_LC_ALERT, pad); + pad = false; } if (file->attributes & FILE_ATTR_READONLY) { - complete_string += std::string("\n") + N_("This file is read-only."); + UI_tooltip_text_field_add(tip, + BLI_strdup(N_("This file is read-only")), + nullptr, + UI_TIP_STYLE_NORMAL, + UI_TIP_LC_ALERT, pad); + pad = false; } if (file->attributes & (FILE_ATTR_SYSTEM | FILE_ATTR_RESTRICTED)) { - complete_string += std::string("\n") + N_("This is a restricted system file."); + UI_tooltip_text_field_add(tip, + BLI_strdup(N_("This is a restricted system file")), + nullptr, + UI_TIP_STYLE_NORMAL, + UI_TIP_LC_ALERT, pad); + pad = false; } if (file->typeflag & (FILE_TYPE_BLENDER | FILE_TYPE_BLENDER_BACKUP) && @@ -175,8 +199,12 @@ static char *file_draw_tooltip_func(bContext * /*C*/, void *argN, const char * / /* Load Blender version directly from the file. */ short version = BLO_version_from_file(full_path); if (version != 0) { - complete_string += std::string("\n") + "Blender: " + std::to_string(version / 100) + "." + - std::to_string(version % 100); + UI_tooltip_text_field_add(tip, + BLI_sprintfN("Blender: %d.%01d", version / 100, version % 100), + nullptr, + UI_TIP_STYLE_NORMAL, + UI_TIP_LC_NORMAL, pad); + pad = false; } } @@ -189,8 +217,13 @@ static char *file_draw_tooltip_func(bContext * /*C*/, void *argN, const char * / if (IMB_metadata_get_field(thumb->metadata, "Thumb::Image::Width", value1, sizeof(value1)) && IMB_metadata_get_field(thumb->metadata, "Thumb::Image::Height", value2, sizeof(value2))) { - complete_string += std::string("\n") + N_("Dimensions") + ": "; - complete_string += std::string(value1) + " \u00D7 " + std::string(value2); + UI_tooltip_text_field_add( + tip, + BLI_sprintfN("%s: %s \u00D7 %s", N_("Dimensions"), value1, value2), + nullptr, + UI_TIP_STYLE_NORMAL, + UI_TIP_LC_NORMAL, pad); + pad = false; } IMB_freeImBuf(thumb); } @@ -202,50 +235,75 @@ static char *file_draw_tooltip_func(bContext * /*C*/, void *argN, const char * / char value1[128]; char value2[128]; char value3[128]; - if (IMB_metadata_get_field(thumb->metadata, "Codec", value1, sizeof(value1))) - { - complete_string += std::string("\n") + N_("Codec") + ": "; - complete_string += std::string(value1); - } if (IMB_metadata_get_field(thumb->metadata, "Thumb::Image::Width", value1, sizeof(value1)) && IMB_metadata_get_field(thumb->metadata, "Thumb::Image::Height", value2, sizeof(value2))) { - complete_string += std::string("\n") + N_("Dimensions") + ": "; - complete_string += std::string(value1) + " \u00D7 " + std::string(value2); + UI_tooltip_text_field_add( + tip, + BLI_sprintfN("%s: %s \u00D7 %s", N_("Dimensions"), value1, value2), + nullptr, + UI_TIP_STYLE_NORMAL, + UI_TIP_LC_NORMAL, pad); + pad = false; } if (IMB_metadata_get_field(thumb->metadata, "Frames", value1, sizeof(value1)) && IMB_metadata_get_field(thumb->metadata, "FPS", value2, sizeof(value2)) && IMB_metadata_get_field(thumb->metadata, "Duration", value3, sizeof(value3))) { - complete_string += std::string("\n") + N_("Frames") + ": "; - complete_string += value1 + std::string(" @ ") + value2 + " " + N_("FPS"); - complete_string += std::string(" (") + value3 + " " + N_("seconds") ") "; + UI_tooltip_text_field_add(tip, + BLI_sprintfN("%s: %s @ %s %s (%s %s)", + N_("Frames"), + value1, + value2, + N_("FPS"), + value3, + N_("seconds")), + nullptr, + UI_TIP_STYLE_NORMAL, + UI_TIP_LC_NORMAL, pad); + pad = false; + } + if (IMB_metadata_get_field(thumb->metadata, "Codec", value1, sizeof(value1))) + { + UI_tooltip_text_field_add(tip, + BLI_sprintfN("%s: %s", N_("Codec"), value1), + nullptr, + UI_TIP_STYLE_NORMAL, + UI_TIP_LC_NORMAL, pad); + pad = false; } IMB_freeImBuf(thumb); } char date_st[FILELIST_DIRENTRY_DATE_LEN], time_st[FILELIST_DIRENTRY_TIME_LEN]; bool is_today, is_yesterday; + std::string day_string = (""); BLI_filelist_entry_datetime_to_string( NULL, file->time, false, time_st, date_st, &is_today, &is_yesterday); - complete_string += std::string("\n") + N_("Modified") + std::string(": "); if (is_today || is_yesterday) { - complete_string += (is_today ? N_("Today") : N_("Yesterday")) + std::string(" "); + day_string = (is_today ? N_("Today") : N_("Yesterday")) + std::string(" "); } - complete_string += date_st + std::string(" ") + time_st; + UI_tooltip_text_field_add( + tip, + BLI_sprintfN("%s: %s%s %s", N_("Modified"), day_string.c_str(), date_st, time_st), + nullptr, + UI_TIP_STYLE_NORMAL, + UI_TIP_LC_NORMAL, pad); + pad = false; if (!(file->typeflag & FILE_TYPE_DIR) && file->size > 0) { char size[16]; char size_full[16]; BLI_filelist_entry_size_to_string(NULL, file->size, false, size); BLI_str_format_uint64_grouped(size_full, file->size); - complete_string += std::string("\n") + N_("Size") + std::string(": ") + std::string(size) + - std::string(" (") + std::string(size_full) + std::string(" ") + - N_("bytes") + std::string(")"); + UI_tooltip_text_field_add( + tip, + BLI_sprintfN("%s: %s (%s %s)", N_("Size"), size, size_full, N_("bytes")), + nullptr, + UI_TIP_STYLE_NORMAL, + UI_TIP_LC_NORMAL); } } - - return BLI_strdupn(complete_string.c_str(), complete_string.size()); } static char *file_draw_asset_tooltip_func(bContext * /*C*/, void *argN, const char * /*tip*/) @@ -328,8 +386,8 @@ static uiBut *file_add_icon_but(const SpaceFile *sfile, UI_but_func_tooltip_set(but, file_draw_asset_tooltip_func, file->asset, nullptr); } else { - UI_but_func_tooltip_set( - but, file_draw_tooltip_func, file_tooltip_data_create(sfile, file, NULL), MEM_freeN); + UI_but_func_tooltip_custom_set( + but, file_draw_tooltip_custom_func, file_tooltip_data_create(sfile, file), MEM_freeN); } return but; @@ -469,10 +527,8 @@ static void file_add_preview_drag_but(const SpaceFile *sfile, UI_but_func_tooltip_set(but, file_draw_asset_tooltip_func, file->asset, nullptr); } else { - UI_but_func_tooltip_set(but, - file_draw_tooltip_func, - file_tooltip_data_create(sfile, file, preview_image), - MEM_freeN); + UI_but_func_tooltip_custom_set( + but, file_draw_tooltip_custom_func, file_tooltip_data_create(sfile, file), MEM_freeN); } } -- 2.30.2 From d220792e2841d235bc989a330ae1141bba1f9183 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Mon, 18 Sep 2023 11:00:52 -0700 Subject: [PATCH 05/13] Changes to meta keys. Also put Blender version in thumbnail. --- .../blender/editors/space_file/file_draw.cc | 42 +++++++++++++------ source/blender/imbuf/intern/anim_movie.cc | 26 ++++++------ .../blender/windowmanager/intern/wm_files.cc | 14 +++++++ 3 files changed, 57 insertions(+), 25 deletions(-) diff --git a/source/blender/editors/space_file/file_draw.cc b/source/blender/editors/space_file/file_draw.cc index e04e97ee28e..b0268a0dd68 100644 --- a/source/blender/editors/space_file/file_draw.cc +++ b/source/blender/editors/space_file/file_draw.cc @@ -193,17 +193,33 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData pad = false; } - if (file->typeflag & (FILE_TYPE_BLENDER | FILE_TYPE_BLENDER_BACKUP) && - !(file->attributes & FILE_ATTR_OFFLINE)) + if (file->typeflag & (FILE_TYPE_BLENDER | FILE_TYPE_BLENDER_BACKUP)) { - /* Load Blender version directly from the file. */ - short version = BLO_version_from_file(full_path); - if (version != 0) { + char version_st[128] = {0}; + ImBuf *thumb = IMB_thumb_read(full_path, THB_LARGE); + + if (thumb) { + /* Look for version in existing thumbnail if available. */ + IMB_metadata_get_field( + thumb->metadata, "Thumb::Blender::Version", version_st, sizeof(version_st)); + IMB_freeImBuf(thumb); + } + + if (!version_st[0] && !(file->attributes & FILE_ATTR_OFFLINE)) { + /* Load Blender version directly from the file. */ + short version = BLO_version_from_file(full_path); + if (version != 0) { + SNPRINTF(version_st, "%d.%01d", version / 100, version % 100); + } + } + + if (version_st[0]) { UI_tooltip_text_field_add(tip, - BLI_sprintfN("Blender: %d.%01d", version / 100, version % 100), + BLI_sprintfN("Blender: %s", version_st), nullptr, UI_TIP_STYLE_NORMAL, - UI_TIP_LC_NORMAL, pad); + UI_TIP_LC_NORMAL, + pad); pad = false; } } @@ -235,8 +251,8 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData char value1[128]; char value2[128]; char value3[128]; - if (IMB_metadata_get_field(thumb->metadata, "Thumb::Image::Width", value1, sizeof(value1)) && - IMB_metadata_get_field(thumb->metadata, "Thumb::Image::Height", value2, sizeof(value2))) + if (IMB_metadata_get_field(thumb->metadata, "Thumb::Video::Width", value1, sizeof(value1)) && + IMB_metadata_get_field(thumb->metadata, "Thumb::Video::Height", value2, sizeof(value2))) { UI_tooltip_text_field_add( tip, @@ -246,9 +262,9 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData UI_TIP_LC_NORMAL, pad); pad = false; } - if (IMB_metadata_get_field(thumb->metadata, "Frames", value1, sizeof(value1)) && - IMB_metadata_get_field(thumb->metadata, "FPS", value2, sizeof(value2)) && - IMB_metadata_get_field(thumb->metadata, "Duration", value3, sizeof(value3))) + if (IMB_metadata_get_field(thumb->metadata, "Thumb::Video::Frames", value1, sizeof(value1)) && + IMB_metadata_get_field(thumb->metadata, "Thumb::Video::FPS", value2, sizeof(value2)) && + IMB_metadata_get_field(thumb->metadata, "Thumb::Video::Duration", value3, sizeof(value3))) { UI_tooltip_text_field_add(tip, BLI_sprintfN("%s: %s @ %s %s (%s %s)", @@ -263,7 +279,7 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData UI_TIP_LC_NORMAL, pad); pad = false; } - if (IMB_metadata_get_field(thumb->metadata, "Codec", value1, sizeof(value1))) + if (IMB_metadata_get_field(thumb->metadata, "Thumb::Video::Codec", value1, sizeof(value1))) { UI_tooltip_text_field_add(tip, BLI_sprintfN("%s: %s", N_("Codec"), value1), diff --git a/source/blender/imbuf/intern/anim_movie.cc b/source/blender/imbuf/intern/anim_movie.cc index e87551e901c..0a23af3bdfc 100644 --- a/source/blender/imbuf/intern/anim_movie.cc +++ b/source/blender/imbuf/intern/anim_movie.cc @@ -1538,22 +1538,24 @@ ImBuf *IMB_anim_previewframe(anim *anim) char value[128]; IMB_metadata_ensure(&ibuf->metadata); SNPRINTF(value, "%i", anim->x); - IMB_metadata_set_field(ibuf->metadata, "Thumb::Image::Width", value); + IMB_metadata_set_field(ibuf->metadata, "Thumb::Video::Width", value); SNPRINTF(value, "%i", anim->y); - IMB_metadata_set_field(ibuf->metadata, "Thumb::Image::Height", value); + IMB_metadata_set_field(ibuf->metadata, "Thumb::Video::Height", value); SNPRINTF(value, "%i", anim->duration_in_frames); - IMB_metadata_set_field(ibuf->metadata, "Frames", value); + IMB_metadata_set_field(ibuf->metadata, "Thumb::Video::Frames", value); #ifdef WITH_FFMPEG - AVStream *v_st = anim->pFormatCtx->streams[anim->videoStream]; - AVRational frame_rate = av_guess_frame_rate(anim->pFormatCtx, v_st, NULL); - if (frame_rate.num != 0) { - double duration = anim->duration_in_frames / av_q2d(frame_rate); - SNPRINTF(value, "%g", av_q2d(frame_rate)); - IMB_metadata_set_field(ibuf->metadata, "FPS", value); - SNPRINTF(value, "%g", duration); - IMB_metadata_set_field(ibuf->metadata, "Duration", value); - IMB_metadata_set_field(ibuf->metadata, "Codec", anim->pCodec->long_name); + if (anim->pFormatCtx && anim->curtype == ANIM_FFMPEG) { + AVStream *v_st = anim->pFormatCtx->streams[anim->videoStream]; + AVRational frame_rate = av_guess_frame_rate(anim->pFormatCtx, v_st, NULL); + if (frame_rate.num != 0) { + double duration = anim->duration_in_frames / av_q2d(frame_rate); + SNPRINTF(value, "%g", av_q2d(frame_rate)); + IMB_metadata_set_field(ibuf->metadata, "Thumb::Video::FPS", value); + SNPRINTF(value, "%g", duration); + IMB_metadata_set_field(ibuf->metadata, "Thumb::Video::Duration", value); + IMB_metadata_set_field(ibuf->metadata, "Thumb::Video::Codec", anim->pCodec->long_name); + } } #endif } diff --git a/source/blender/windowmanager/intern/wm_files.cc b/source/blender/windowmanager/intern/wm_files.cc index 299ea1267d5..0926ec8761f 100644 --- a/source/blender/windowmanager/intern/wm_files.cc +++ b/source/blender/windowmanager/intern/wm_files.cc @@ -92,6 +92,7 @@ #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" +#include "IMB_metadata.h" #include "IMB_thumbs.h" #include "ED_asset.hh" @@ -1708,6 +1709,12 @@ static ImBuf *blend_file_thumb_from_screenshot(bContext *C, BlendThumbnail **r_t /* File-system thumbnail image can be 256x256. */ IMB_scaleImBuf(ibuf, ex * 2, ey * 2); + /* Save metadata for quick access. */ + char version_st[10] = {0}; + SNPRINTF(version_st, "%d.%01d", BLENDER_VERSION / 100, BLENDER_VERSION % 100); + IMB_metadata_ensure(&ibuf->metadata); + IMB_metadata_set_field(ibuf->metadata, "Thumb::Blender::Version", version_st); + /* Thumbnail inside blend should be 128x128. */ ImBuf *thumb_ibuf = IMB_dupImBuf(ibuf); IMB_scaleImBuf(thumb_ibuf, ex, ey); @@ -1815,6 +1822,13 @@ static ImBuf *blend_file_thumb_from_camera(const bContext *C, /* dirty oversampling */ ImBuf *thumb_ibuf; thumb_ibuf = IMB_dupImBuf(ibuf); + + /* Save metadata for quick access. */ + char version_st[10] = {0}; + SNPRINTF(version_st, "%d.%01d", BLENDER_VERSION / 100, BLENDER_VERSION % 100); + IMB_metadata_ensure(&ibuf->metadata); + IMB_metadata_set_field(ibuf->metadata, "Thumb::Blender::Version", version_st); + /* BLEN_THUMB_SIZE is size of thumbnail inside blend file: 128x128. */ IMB_scaleImBuf(thumb_ibuf, BLEN_THUMB_SIZE, BLEN_THUMB_SIZE); thumb = BKE_main_thumbnail_from_imbuf(nullptr, thumb_ibuf); -- 2.30.2 From d2d9c2048c8898b2845fca8bb130898d31eb1111 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Wed, 20 Sep 2023 16:40:50 -0700 Subject: [PATCH 06/13] Restoring a comment I accidentally removed. --- source/blender/blenloader/BLO_readfile.h | 1 + 1 file changed, 1 insertion(+) diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h index d0e67b4f76f..830276f485c 100644 --- a/source/blender/blenloader/BLO_readfile.h +++ b/source/blender/blenloader/BLO_readfile.h @@ -540,6 +540,7 @@ struct BlendThumbnail *BLO_thumbnail_from_file(const char *filepath); */ short BLO_version_from_file(const char *filepath); +/** Default theme, see: `release/datafiles/userdef/userdef_default_theme.c`. */ extern const struct bTheme U_theme_default; /** Default preferences, defined by: `release/datafiles/userdef/userdef_default.c`. */ extern const struct UserDef U_default; -- 2.30.2 From d2291b93171a64a96d620118e59a182bbd39badd Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Fri, 13 Oct 2023 18:03:28 -0700 Subject: [PATCH 07/13] Updated to use new tooltip spacers. --- .../blender/editors/space_file/file_draw.cc | 139 +++++++++--------- 1 file changed, 67 insertions(+), 72 deletions(-) diff --git a/source/blender/editors/space_file/file_draw.cc b/source/blender/editors/space_file/file_draw.cc index 5ea1b4b5d59..bd231de7d5b 100644 --- a/source/blender/editors/space_file/file_draw.cc +++ b/source/blender/editors/space_file/file_draw.cc @@ -143,9 +143,7 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData UI_tooltip_text_field_add( tip, BLI_strdup(file->name), nullptr, UI_TIP_STYLE_HEADER, UI_TIP_LC_MAIN); - - /* Add pad variable to the very next field only. */ - bool pad = true; + UI_tooltip_text_field_add(tip, nullptr, nullptr, UI_TIP_STYLE_SPACER, UI_TIP_LC_NORMAL); if (!(file->typeflag & FILE_TYPE_BLENDERLIB)) { @@ -156,8 +154,7 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData char root[FILE_MAX]; BLI_path_split_dir_part(full_path, root, FILE_MAX); UI_tooltip_text_field_add( - tip, BLI_strdup(root), nullptr, UI_TIP_STYLE_NORMAL, UI_TIP_LC_NORMAL, pad); - pad = false; + tip, BLI_strdup(root), nullptr, UI_TIP_STYLE_NORMAL, UI_TIP_LC_NORMAL); } if (file->redirection_path) { @@ -165,39 +162,34 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData BLI_sprintfN("%s: %s", N_("Link target"), file->redirection_path), nullptr, UI_TIP_STYLE_NORMAL, - UI_TIP_LC_NORMAL, pad); - pad = false; + UI_TIP_LC_NORMAL); } if (file->attributes & FILE_ATTR_OFFLINE) { UI_tooltip_text_field_add(tip, BLI_strdup(N_("This file is offline")), nullptr, UI_TIP_STYLE_NORMAL, - UI_TIP_LC_ALERT, pad); - pad = false; + UI_TIP_LC_ALERT); } if (file->attributes & FILE_ATTR_READONLY) { UI_tooltip_text_field_add(tip, BLI_strdup(N_("This file is read-only")), nullptr, UI_TIP_STYLE_NORMAL, - UI_TIP_LC_ALERT, pad); - pad = false; + UI_TIP_LC_ALERT); } if (file->attributes & (FILE_ATTR_SYSTEM | FILE_ATTR_RESTRICTED)) { UI_tooltip_text_field_add(tip, BLI_strdup(N_("This is a restricted system file")), nullptr, UI_TIP_STYLE_NORMAL, - UI_TIP_LC_ALERT, pad); - pad = false; + UI_TIP_LC_ALERT); } if (file->typeflag & (FILE_TYPE_BLENDER | FILE_TYPE_BLENDER_BACKUP)) { char version_st[128] = {0}; ImBuf *thumb = IMB_thumb_read(full_path, THB_LARGE); - if (thumb) { /* Look for version in existing thumbnail if available. */ IMB_metadata_get_field( @@ -218,9 +210,7 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData BLI_sprintfN("Blender: %s", version_st), nullptr, UI_TIP_STYLE_NORMAL, - UI_TIP_LC_NORMAL, - pad); - pad = false; + UI_TIP_LC_NORMAL); } } @@ -228,67 +218,73 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData ImBuf *thumb = (file->attributes & FILE_ATTR_OFFLINE) ? IMB_thumb_read(full_path, THB_LARGE) : IMB_thumb_manage(full_path, THB_LARGE, THB_SOURCE_IMAGE); - char value1[128]; - char value2[128]; - if (IMB_metadata_get_field(thumb->metadata, "Thumb::Image::Width", value1, sizeof(value1)) && - IMB_metadata_get_field(thumb->metadata, "Thumb::Image::Height", value2, sizeof(value2))) - { - UI_tooltip_text_field_add( - tip, - BLI_sprintfN("%s: %s \u00D7 %s", N_("Dimensions"), value1, value2), - nullptr, - UI_TIP_STYLE_NORMAL, - UI_TIP_LC_NORMAL, pad); - pad = false; + if (thumb) { + char value1[128]; + char value2[128]; + if (IMB_metadata_get_field( + thumb->metadata, "Thumb::Image::Width", value1, sizeof(value1)) && + IMB_metadata_get_field( + thumb->metadata, "Thumb::Image::Height", value2, sizeof(value2))) + { + UI_tooltip_text_field_add( + tip, + BLI_sprintfN("%s: %s \u00D7 %s", N_("Dimensions"), value1, value2), + nullptr, + UI_TIP_STYLE_NORMAL, + UI_TIP_LC_NORMAL); + } + IMB_freeImBuf(thumb); } - IMB_freeImBuf(thumb); } if (file->typeflag & FILE_TYPE_MOVIE) { ImBuf *thumb = (file->attributes & FILE_ATTR_OFFLINE) ? IMB_thumb_read(full_path, THB_LARGE) : IMB_thumb_manage(full_path, THB_LARGE, THB_SOURCE_MOVIE); - char value1[128]; - char value2[128]; - char value3[128]; - if (IMB_metadata_get_field(thumb->metadata, "Thumb::Video::Width", value1, sizeof(value1)) && - IMB_metadata_get_field(thumb->metadata, "Thumb::Video::Height", value2, sizeof(value2))) - { - UI_tooltip_text_field_add( - tip, - BLI_sprintfN("%s: %s \u00D7 %s", N_("Dimensions"), value1, value2), - nullptr, - UI_TIP_STYLE_NORMAL, - UI_TIP_LC_NORMAL, pad); - pad = false; + if (thumb) { + char value1[128]; + char value2[128]; + char value3[128]; + if (IMB_metadata_get_field( + thumb->metadata, "Thumb::Video::Width", value1, sizeof(value1)) && + IMB_metadata_get_field( + thumb->metadata, "Thumb::Video::Height", value2, sizeof(value2))) + { + UI_tooltip_text_field_add( + tip, + BLI_sprintfN("%s: %s \u00D7 %s", N_("Dimensions"), value1, value2), + nullptr, + UI_TIP_STYLE_NORMAL, + UI_TIP_LC_NORMAL); + } + if (IMB_metadata_get_field( + thumb->metadata, "Thumb::Video::Frames", value1, sizeof(value1)) && + IMB_metadata_get_field(thumb->metadata, "Thumb::Video::FPS", value2, sizeof(value2)) && + IMB_metadata_get_field( + thumb->metadata, "Thumb::Video::Duration", value3, sizeof(value3))) + { + UI_tooltip_text_field_add(tip, + BLI_sprintfN("%s: %s @ %s %s (%s %s)", + N_("Frames"), + value1, + value2, + N_("FPS"), + value3, + N_("seconds")), + nullptr, + UI_TIP_STYLE_NORMAL, + UI_TIP_LC_NORMAL); + } + if (IMB_metadata_get_field(thumb->metadata, "Thumb::Video::Codec", value1, sizeof(value1))) + { + UI_tooltip_text_field_add(tip, + BLI_sprintfN("%s: %s", N_("Codec"), value1), + nullptr, + UI_TIP_STYLE_NORMAL, + UI_TIP_LC_NORMAL); + } + IMB_freeImBuf(thumb); } - if (IMB_metadata_get_field(thumb->metadata, "Thumb::Video::Frames", value1, sizeof(value1)) && - IMB_metadata_get_field(thumb->metadata, "Thumb::Video::FPS", value2, sizeof(value2)) && - IMB_metadata_get_field(thumb->metadata, "Thumb::Video::Duration", value3, sizeof(value3))) - { - UI_tooltip_text_field_add(tip, - BLI_sprintfN("%s: %s @ %s %s (%s %s)", - N_("Frames"), - value1, - value2, - N_("FPS"), - value3, - N_("seconds")), - nullptr, - UI_TIP_STYLE_NORMAL, - UI_TIP_LC_NORMAL, pad); - pad = false; - } - if (IMB_metadata_get_field(thumb->metadata, "Thumb::Video::Codec", value1, sizeof(value1))) - { - UI_tooltip_text_field_add(tip, - BLI_sprintfN("%s: %s", N_("Codec"), value1), - nullptr, - UI_TIP_STYLE_NORMAL, - UI_TIP_LC_NORMAL, pad); - pad = false; - } - IMB_freeImBuf(thumb); } char date_st[FILELIST_DIRENTRY_DATE_LEN], time_st[FILELIST_DIRENTRY_TIME_LEN]; @@ -304,8 +300,7 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData BLI_sprintfN("%s: %s%s %s", N_("Modified"), day_string.c_str(), date_st, time_st), nullptr, UI_TIP_STYLE_NORMAL, - UI_TIP_LC_NORMAL, pad); - pad = false; + UI_TIP_LC_NORMAL); if (!(file->typeflag & FILE_TYPE_DIR) && file->size > 0) { char size[16]; -- 2.30.2 From 2e39b47e097c0a9e5bf707c1de6a08cabc612a6d Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Sat, 14 Oct 2023 14:54:37 -0700 Subject: [PATCH 08/13] Show the thumbnail if in list views. --- .../blender/editors/space_file/file_draw.cc | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/source/blender/editors/space_file/file_draw.cc b/source/blender/editors/space_file/file_draw.cc index bd231de7d5b..6541b854414 100644 --- a/source/blender/editors/space_file/file_draw.cc +++ b/source/blender/editors/space_file/file_draw.cc @@ -136,6 +136,7 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData const FileList *files = sfile->files; const FileSelectParams *params = ED_fileselect_get_active_params(sfile); const FileDirEntry *file = file_data->file; + ImBuf *thumb = nullptr; if (file->asset) { return; @@ -189,12 +190,11 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData if (file->typeflag & (FILE_TYPE_BLENDER | FILE_TYPE_BLENDER_BACKUP)) { char version_st[128] = {0}; - ImBuf *thumb = IMB_thumb_read(full_path, THB_LARGE); + thumb = IMB_thumb_read(full_path, THB_LARGE); if (thumb) { /* Look for version in existing thumbnail if available. */ IMB_metadata_get_field( thumb->metadata, "Thumb::Blender::Version", version_st, sizeof(version_st)); - IMB_freeImBuf(thumb); } if (!version_st[0] && !(file->attributes & FILE_ATTR_OFFLINE)) { @@ -213,11 +213,10 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData UI_TIP_LC_NORMAL); } } - - if (file->typeflag & FILE_TYPE_IMAGE) { - ImBuf *thumb = (file->attributes & FILE_ATTR_OFFLINE) ? - IMB_thumb_read(full_path, THB_LARGE) : - IMB_thumb_manage(full_path, THB_LARGE, THB_SOURCE_IMAGE); + else if (file->typeflag & FILE_TYPE_IMAGE) { + thumb = (file->attributes & FILE_ATTR_OFFLINE) ? + IMB_thumb_read(full_path, THB_LARGE) : + IMB_thumb_manage(full_path, THB_LARGE, THB_SOURCE_IMAGE); if (thumb) { char value1[128]; char value2[128]; @@ -233,14 +232,12 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData UI_TIP_STYLE_NORMAL, UI_TIP_LC_NORMAL); } - IMB_freeImBuf(thumb); } } - - if (file->typeflag & FILE_TYPE_MOVIE) { - ImBuf *thumb = (file->attributes & FILE_ATTR_OFFLINE) ? - IMB_thumb_read(full_path, THB_LARGE) : - IMB_thumb_manage(full_path, THB_LARGE, THB_SOURCE_MOVIE); + else if (file->typeflag & FILE_TYPE_MOVIE) { + thumb = (file->attributes & FILE_ATTR_OFFLINE) ? + IMB_thumb_read(full_path, THB_LARGE) : + IMB_thumb_manage(full_path, THB_LARGE, THB_SOURCE_MOVIE); if (thumb) { char value1[128]; char value2[128]; @@ -283,7 +280,6 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData UI_TIP_STYLE_NORMAL, UI_TIP_LC_NORMAL); } - IMB_freeImBuf(thumb); } } @@ -315,6 +311,18 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData UI_TIP_LC_NORMAL); } } + + if (thumb && params->display != FILE_IMGDISPLAY) { + float scale = (96.0f * UI_SCALE_FAC) / float(MAX2(thumb->x, thumb->y)); + short size[2] = {short(float(thumb->x) * scale), short(float(thumb->y) * scale)}; + UI_tooltip_text_field_add(tip, nullptr, nullptr, UI_TIP_STYLE_SPACER, UI_TIP_LC_NORMAL); + UI_tooltip_text_field_add(tip, nullptr, nullptr, UI_TIP_STYLE_SPACER, UI_TIP_LC_NORMAL); + UI_tooltip_image_field_add(tip, thumb, size); + } + + if (thumb) { + IMB_freeImBuf(thumb); + } } static char *file_draw_asset_tooltip_func(bContext * /*C*/, void *argN, const char * /*tip*/) -- 2.30.2 From ba76fada61e6cae43a969c7d0b209b48ccbb3d17 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Tue, 28 Nov 2023 14:40:29 -0800 Subject: [PATCH 09/13] Changes requested by review --- .../blender/editors/space_file/file_draw.cc | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/source/blender/editors/space_file/file_draw.cc b/source/blender/editors/space_file/file_draw.cc index 1b997ef9003..841a58c5b81 100644 --- a/source/blender/editors/space_file/file_draw.cc +++ b/source/blender/editors/space_file/file_draw.cc @@ -114,10 +114,10 @@ void ED_file_path_button(bScreen *screen, UI_block_func_set(block, nullptr, nullptr, nullptr); } -typedef struct file_tooltip_data { +struct file_tooltip_data { const SpaceFile *sfile; const FileDirEntry *file; -} file_tooltip_data; +}; static file_tooltip_data *file_tooltip_data_create(const SpaceFile *sfile, const FileDirEntry *file) @@ -136,11 +136,14 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData const FileList *files = sfile->files; const FileSelectParams *params = ED_fileselect_get_active_params(sfile); const FileDirEntry *file = file_data->file; - ImBuf *thumb = nullptr; - if (file->asset) { - return; - } + BLI_assert_msg(!file->asset, "Asset tooltip should never be overridden here."); + + /* Check the FileDirEntry first to see if the preview is already loaded. */ + ImBuf *thumb = filelist_file_getimage(file); + + /* Only free if it is loaded later. */ + bool free_imbuf = (thumb == nullptr); UI_tooltip_text_field_add( tip, BLI_strdup(file->name), nullptr, UI_TIP_STYLE_HEADER, UI_TIP_LC_MAIN); @@ -190,7 +193,10 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData if (file->typeflag & (FILE_TYPE_BLENDER | FILE_TYPE_BLENDER_BACKUP)) { char version_st[128] = {0}; - thumb = IMB_thumb_read(full_path, THB_LARGE); + if (!thumb) { + /* Load the thumbnail from cache if existing, but don't create if not. */ + thumb = IMB_thumb_read(full_path, THB_LARGE); + } if (thumb) { /* Look for version in existing thumbnail if available. */ IMB_metadata_get_field( @@ -214,9 +220,10 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData } } else if (file->typeflag & FILE_TYPE_IMAGE) { - thumb = (file->attributes & FILE_ATTR_OFFLINE) ? - IMB_thumb_read(full_path, THB_LARGE) : - IMB_thumb_manage(full_path, THB_LARGE, THB_SOURCE_IMAGE); + if (!thumb) { + /* Load the thumbnail from cache if existing, create if not. */ + thumb = IMB_thumb_manage(full_path, THB_LARGE, THB_SOURCE_IMAGE); + } if (thumb) { char value1[128]; char value2[128]; @@ -235,9 +242,9 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData } } else if (file->typeflag & FILE_TYPE_MOVIE) { - thumb = (file->attributes & FILE_ATTR_OFFLINE) ? - IMB_thumb_read(full_path, THB_LARGE) : - IMB_thumb_manage(full_path, THB_LARGE, THB_SOURCE_MOVIE); + if (!thumb) { + thumb = IMB_thumb_manage(full_path, THB_LARGE, THB_SOURCE_MOVIE); + } if (thumb) { char value1[128]; char value2[128]; @@ -320,7 +327,7 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData UI_tooltip_image_field_add(tip, thumb, size); } - if (thumb) { + if (thumb && free_imbuf) { IMB_freeImBuf(thumb); } } -- 2.30.2 From 46521f57a1ac5e3521f38e65c8a2b28b9ad69ce8 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Tue, 28 Nov 2023 14:44:20 -0800 Subject: [PATCH 10/13] format changes --- source/blender/editors/space_file/file_draw.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/blender/editors/space_file/file_draw.cc b/source/blender/editors/space_file/file_draw.cc index 841a58c5b81..200ea24de9d 100644 --- a/source/blender/editors/space_file/file_draw.cc +++ b/source/blender/editors/space_file/file_draw.cc @@ -190,8 +190,7 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData UI_TIP_LC_ALERT); } - if (file->typeflag & (FILE_TYPE_BLENDER | FILE_TYPE_BLENDER_BACKUP)) - { + if (file->typeflag & (FILE_TYPE_BLENDER | FILE_TYPE_BLENDER_BACKUP)) { char version_st[128] = {0}; if (!thumb) { /* Load the thumbnail from cache if existing, but don't create if not. */ -- 2.30.2 From d05c4d77a7eacd4888b3d18e9516bd70e337607d Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Tue, 28 Nov 2023 14:47:35 -0800 Subject: [PATCH 11/13] comment changes --- source/blender/editors/space_file/file_draw.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/source/blender/editors/space_file/file_draw.cc b/source/blender/editors/space_file/file_draw.cc index 200ea24de9d..9df390dd968 100644 --- a/source/blender/editors/space_file/file_draw.cc +++ b/source/blender/editors/space_file/file_draw.cc @@ -242,6 +242,7 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData } else if (file->typeflag & FILE_TYPE_MOVIE) { if (!thumb) { + /* This could possibly take a while. */ thumb = IMB_thumb_manage(full_path, THB_LARGE, THB_SOURCE_MOVIE); } if (thumb) { -- 2.30.2 From 30b8baa5cb8d2b2eebb9a9bd43c33fd5c37dca6a Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Thu, 7 Dec 2023 16:40:33 -0800 Subject: [PATCH 12/13] Changes suggested by Julian --- .../blender/editors/space_file/file_draw.cc | 71 ++++++++++--------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/source/blender/editors/space_file/file_draw.cc b/source/blender/editors/space_file/file_draw.cc index 9df390dd968..18e8d004baf 100644 --- a/source/blender/editors/space_file/file_draw.cc +++ b/source/blender/editors/space_file/file_draw.cc @@ -212,10 +212,11 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData if (version_st[0]) { UI_tooltip_text_field_add(tip, - BLI_sprintfN("Blender: %s", version_st), + BLI_sprintfN("Blender %s", version_st), nullptr, UI_TIP_STYLE_NORMAL, UI_TIP_LC_NORMAL); + UI_tooltip_text_field_add(tip, nullptr, nullptr, UI_TIP_STYLE_SPACER, UI_TIP_LC_NORMAL); } } else if (file->typeflag & FILE_TYPE_IMAGE) { @@ -233,10 +234,11 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData { UI_tooltip_text_field_add( tip, - BLI_sprintfN("%s: %s \u00D7 %s", N_("Dimensions"), value1, value2), + BLI_sprintfN("%s \u00D7 %s", value1, value2), nullptr, UI_TIP_STYLE_NORMAL, UI_TIP_LC_NORMAL); + UI_tooltip_text_field_add(tip, nullptr, nullptr, UI_TIP_STYLE_SPACER, UI_TIP_LC_NORMAL); } } } @@ -256,7 +258,7 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData { UI_tooltip_text_field_add( tip, - BLI_sprintfN("%s: %s \u00D7 %s", N_("Dimensions"), value1, value2), + BLI_sprintfN("%s \u00D7 %s", value1, value2), nullptr, UI_TIP_STYLE_NORMAL, UI_TIP_LC_NORMAL); @@ -267,25 +269,18 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData IMB_metadata_get_field( thumb->metadata, "Thumb::Video::Duration", value3, sizeof(value3))) { + UI_tooltip_text_field_add( + tip, + BLI_sprintfN("%s %s @ %s %s", value1, N_("Frames"), value2, N_("FPS")), + nullptr, + UI_TIP_STYLE_NORMAL, + UI_TIP_LC_NORMAL); UI_tooltip_text_field_add(tip, - BLI_sprintfN("%s: %s @ %s %s (%s %s)", - N_("Frames"), - value1, - value2, - N_("FPS"), - value3, - N_("seconds")), - nullptr, - UI_TIP_STYLE_NORMAL, - UI_TIP_LC_NORMAL); - } - if (IMB_metadata_get_field(thumb->metadata, "Thumb::Video::Codec", value1, sizeof(value1))) - { - UI_tooltip_text_field_add(tip, - BLI_sprintfN("%s: %s", N_("Codec"), value1), + BLI_sprintfN("%s %s", value3, N_("seconds")), nullptr, UI_TIP_STYLE_NORMAL, UI_TIP_LC_NORMAL); + UI_tooltip_text_field_add(tip, nullptr, nullptr, UI_TIP_STYLE_SPACER, UI_TIP_LC_NORMAL); } } } @@ -298,24 +293,36 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData if (is_today || is_yesterday) { day_string = (is_today ? N_("Today") : N_("Yesterday")) + std::string(" "); } - UI_tooltip_text_field_add( - tip, - BLI_sprintfN("%s: %s%s %s", N_("Modified"), day_string.c_str(), date_st, time_st), - nullptr, - UI_TIP_STYLE_NORMAL, - UI_TIP_LC_NORMAL); + UI_tooltip_text_field_add(tip, + BLI_sprintfN("%s: %s%s%s", + N_("Modified"), + day_string.c_str(), + (is_today || is_yesterday) ? "" : date_st, + (is_today || is_yesterday) ? time_st : ""), + nullptr, + UI_TIP_STYLE_NORMAL, + UI_TIP_LC_NORMAL); if (!(file->typeflag & FILE_TYPE_DIR) && file->size > 0) { char size[16]; - char size_full[16]; BLI_filelist_entry_size_to_string(NULL, file->size, false, size); - BLI_str_format_uint64_grouped(size_full, file->size); - UI_tooltip_text_field_add( - tip, - BLI_sprintfN("%s: %s (%s %s)", N_("Size"), size, size_full, N_("bytes")), - nullptr, - UI_TIP_STYLE_NORMAL, - UI_TIP_LC_NORMAL); + if (file->size < 10000) { + char size_full[16]; + BLI_str_format_uint64_grouped(size_full, file->size); + UI_tooltip_text_field_add( + tip, + BLI_sprintfN("%s: %s (%s %s)", N_("Size"), size, size_full, N_("bytes")), + nullptr, + UI_TIP_STYLE_NORMAL, + UI_TIP_LC_NORMAL); + } + else { + UI_tooltip_text_field_add(tip, + BLI_sprintfN("%s: %s", N_("Size"), size), + nullptr, + UI_TIP_STYLE_NORMAL, + UI_TIP_LC_NORMAL); + } } } -- 2.30.2 From b71356e06d5eeb039d912ad3af85581dfb20d24b Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Tue, 2 Jan 2024 16:22:29 -0800 Subject: [PATCH 13/13] Updated to current state of main. formatting change. --- .../blender/editors/space_file/file_draw.cc | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/source/blender/editors/space_file/file_draw.cc b/source/blender/editors/space_file/file_draw.cc index 767428edd70..3e83e4fa830 100644 --- a/source/blender/editors/space_file/file_draw.cc +++ b/source/blender/editors/space_file/file_draw.cc @@ -232,12 +232,11 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData IMB_metadata_get_field( thumb->metadata, "Thumb::Image::Height", value2, sizeof(value2))) { - UI_tooltip_text_field_add( - tip, - BLI_sprintfN("%s \u00D7 %s", value1, value2), - nullptr, - UI_TIP_STYLE_NORMAL, - UI_TIP_LC_NORMAL); + UI_tooltip_text_field_add(tip, + BLI_sprintfN("%s \u00D7 %s", value1, value2), + nullptr, + UI_TIP_STYLE_NORMAL, + UI_TIP_LC_NORMAL); UI_tooltip_text_field_add(tip, nullptr, nullptr, UI_TIP_STYLE_SPACER, UI_TIP_LC_NORMAL); } } @@ -256,12 +255,11 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData IMB_metadata_get_field( thumb->metadata, "Thumb::Video::Height", value2, sizeof(value2))) { - UI_tooltip_text_field_add( - tip, - BLI_sprintfN("%s \u00D7 %s", value1, value2), - nullptr, - UI_TIP_STYLE_NORMAL, - UI_TIP_LC_NORMAL); + UI_tooltip_text_field_add(tip, + BLI_sprintfN("%s \u00D7 %s", value1, value2), + nullptr, + UI_TIP_STYLE_NORMAL, + UI_TIP_LC_NORMAL); } if (IMB_metadata_get_field( thumb->metadata, "Thumb::Video::Frames", value1, sizeof(value1)) && -- 2.30.2