Blender V5.3
file_draw.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <algorithm>
10#include <cerrno>
11#include <cstring>
12#include <string>
13
14#include <fmt/format.h>
15
16#include "BLI_rect.hh"
17#include "DNA_space_enums.h"
19#include "MEM_guardedalloc.h"
20
21#include "AS_asset_library.hh"
23#include "AS_remote_library.hh"
24
25#include "BLI_fileops.hh"
26#include "BLI_fileops_types.hh"
27#include "BLI_listbase.hh"
28#include "BLI_math_color_c.hh"
29#include "BLI_math_vector_c.hh"
30#include "BLI_path_utils.hh"
31#include "BLI_string.hh"
32#include "BLI_string_utf8.hh"
33#include "BLI_utildefines.hh"
34
35#ifdef WIN32
36# include "BLI_winstuff.hh"
37#endif
38
39#include "BIF_glutil.hh"
40
41#include "BKE_blendfile.hh"
42#include "BKE_context.hh"
43#include "BKE_global.hh"
44#include "BKE_icons.hh"
45#include "BKE_preferences.h"
46#include "BKE_report.hh"
47
48#include "BLO_readfile.hh"
49
50#include "BLT_date_string.hh"
51#include "BLT_lang.hh"
52#include "BLT_translation.hh"
53
54#include "BLF_api.hh"
55
56#include "IMB_imbuf.hh"
57#include "IMB_imbuf_types.hh"
58#include "IMB_metadata.hh"
59#include "IMB_thumbs.hh"
60
61#include "DNA_userdef_types.h"
63
64#include "RNA_access.hh"
65#include "RNA_prototypes.hh"
66
67#include "ED_asset.hh"
68#include "ED_fileselect.hh"
69#include "ED_screen.hh"
70
71#include "UI_interface.hh"
72#include "UI_interface_c.hh"
73#include "UI_interface_icons.hh"
75#include "UI_resources.hh"
76#include "UI_view2d.hh"
77
78#include "WM_api.hh"
79#include "WM_types.hh"
80
81#include "GPU_immediate.hh"
82#include "GPU_immediate_util.hh"
83#include "GPU_state.hh"
84
85#include "file_banner.hh"
86#include "filelist.hh"
87
88#include "file_intern.hh" /* own include */
89
90namespace blender {
91
93
95 SpaceFile *sfile,
96 FileSelectParams *params,
97 ui::Block *block)
98{
99 ui::Button *but;
100
101 BLI_assert_msg(params != nullptr,
102 "File select parameters not set. The caller is expected to check this.");
103 BLI_assert(params == sfile->params || params == &sfile->asset_params->base_params);
104
105 PointerRNA space_ptr = RNA_pointer_create_discrete(&screen->id, RNA_SpaceFileBrowser, sfile);
107 space_ptr, RNA_FileSelectParams, params);
108
109 /* callbacks for operator check functions */
110 block_func_set(block, file_draw_check_cb, nullptr, nullptr);
111
112 but = uiDefButR(block,
114 "",
115 0,
116 0,
117 UI_UNIT_X * 10,
118 UI_UNIT_Y,
119 &params_rna_ptr,
120 "directory",
121 0,
122 0.0f,
123 float(FILE_MAX),
124 TIP_("File path"));
125
126 BLI_assert(!button_flag_is_set(but, ui::BUT_UNDO));
127 BLI_assert(!but_is_utf8(but));
128
129 button_func_complete_set(but, autocomplete_directory, nullptr);
130 button_funcN_set(but, file_directory_enter_handle, nullptr, but);
131 /* Keep editing after Tab completes a directory. */
132 button_flag_enable(but, ui::BUT_TEXTEDIT_AUTOCOMPLETE_KEEP_ACTIVE);
133
134 /* TODO: directory editing is non-functional while a library is loaded
135 * until this is properly supported just disable it. */
136 if (sfile && sfile->files && filelist_lib(sfile->files)) {
137 button_flag_enable(but, ui::BUT_DISABLED);
138 }
139
140 /* clear func */
141 block_func_set(block, nullptr, nullptr, nullptr);
142}
143
148
150{
152 data->sfile = sfile;
153 data->file = file;
154 return data;
155}
156
158 ui::TooltipData &tip,
159 ui::Button * /*but*/,
160 void *argN)
161{
162 FileTooltipData *file_data = static_cast<FileTooltipData *>(argN);
163 const SpaceFile *sfile = file_data->sfile;
164 const FileList *files = sfile->files;
166 const FileDirEntry *file = file_data->file;
167
168 BLI_assert_msg(!file->asset, "Asset tooltip should never be overridden here.");
169
170 /* Check the FileDirEntry first to see if the preview is already loaded. */
172
173 /* Only free if it is loaded later. */
174 bool free_imbuf = (thumb == nullptr);
175
176 tooltip_text_field_add(tip, file->name, {}, ui::TIP_STYLE_HEADER, ui::TIP_LC_MAIN);
177 tooltip_text_field_add(tip, {}, {}, ui::TIP_STYLE_SPACER, ui::TIP_LC_NORMAL);
178
179 if (!(file->typeflag & FILE_TYPE_BLENDERLIB)) {
180
181 char full_path[FILE_MAX_LIBEXTRA];
182 filelist_file_get_full_path(files, file, full_path);
183
184 if (params->recursion_level > 0) {
185 char root[FILE_MAX];
186 BLI_path_split_dir_part(full_path, root, FILE_MAX);
187 tooltip_text_field_add(tip, root, {}, ui::TIP_STYLE_NORMAL, ui::TIP_LC_NORMAL);
188 }
189
190 if (file->redirection_path) {
191 tooltip_text_field_add(
192 tip,
193 fmt::format(fmt::runtime(TIP_("Link target: {}")), file->redirection_path),
194 {},
197 }
198 if (file->attributes & FILE_ATTR_OFFLINE) {
199 tooltip_text_field_add(
200 tip, TIP_("This file is offline"), {}, ui::TIP_STYLE_NORMAL, ui::TIP_LC_ALERT);
201 }
202 if (file->attributes & FILE_ATTR_READONLY) {
203 tooltip_text_field_add(
204 tip, TIP_("This file is read-only"), {}, ui::TIP_STYLE_NORMAL, ui::TIP_LC_ALERT);
205 }
207 tooltip_text_field_add(tip,
208 TIP_("This is a restricted system file"),
209 {},
212 }
213
215 char version_str[128] = {0};
216 if (!thumb) {
217 /* Load the thumbnail from cache if existing, but don't create if not. */
218 thumb = IMB_thumb_read(full_path, THB_LARGE);
219 }
220 if (thumb) {
221 /* Look for version in existing thumbnail if available. */
223 thumb->metadata(), "Thumb::Blender::Version", version_str, sizeof(version_str));
224 }
225
226 if (!version_str[0] && !(file->attributes & FILE_ATTR_OFFLINE)) {
227 /* Load Blender version directly from the file. */
228 short version = BLO_version_from_file(full_path);
229 if (version != 0) {
230 SNPRINTF_UTF8(version_str, "%d.%01d", version / 100, version % 100);
231 }
232 }
233
234 if (version_str[0]) {
235 tooltip_text_field_add(tip,
236 fmt::format("Blender {}", version_str),
237 {},
240 tooltip_text_field_add(tip, {}, {}, ui::TIP_STYLE_SPACER, ui::TIP_LC_NORMAL);
241 }
242 }
243 else if (file->typeflag & FILE_TYPE_IMAGE) {
244 if (!thumb) {
245 /* Load the thumbnail from cache if existing, create if not. */
246 thumb = IMB_thumb_manage(full_path, THB_LARGE, THB_SOURCE_IMAGE);
247 }
248 if (thumb) {
249 char value1[128];
250 char value2[128];
252 thumb->metadata(), "Thumb::Image::Width", value1, sizeof(value1)) &&
254 thumb->metadata(), "Thumb::Image::Height", value2, sizeof(value2)))
255 {
256 tooltip_text_field_add(tip,
257 fmt::format("{} \u00D7 {}", value1, value2),
258 {},
261 tooltip_text_field_add(tip, {}, {}, ui::TIP_STYLE_SPACER, ui::TIP_LC_NORMAL);
262 }
263 }
264 }
265 else if (file->typeflag & FILE_TYPE_MOVIE) {
266 if (!thumb) {
267 /* This could possibly take a while. */
268 thumb = IMB_thumb_manage(full_path, THB_LARGE, THB_SOURCE_MOVIE);
269 }
270 if (thumb) {
271 char value1[128];
272 char value2[128];
273 char value3[128];
275 thumb->metadata(), "Thumb::Video::Width", value1, sizeof(value1)) &&
277 thumb->metadata(), "Thumb::Video::Height", value2, sizeof(value2)))
278 {
279 tooltip_text_field_add(tip,
280 fmt::format("{} \u00D7 {}", value1, value2),
281 {},
284 }
286 thumb->metadata(), "Thumb::Video::Frames", value1, sizeof(value1)) &&
288 thumb->metadata(), "Thumb::Video::FPS", value2, sizeof(value2)) &&
290 thumb->metadata(), "Thumb::Video::Duration", value3, sizeof(value3)))
291 {
292 tooltip_text_field_add(
293 tip,
294 fmt::format(fmt::runtime(TIP_("{} Frames @ {} FPS")), value1, value2),
295 {},
298 tooltip_text_field_add(tip,
299 fmt::format(fmt::runtime(TIP_("{} seconds")), value3),
300 {},
303 tooltip_text_field_add(tip, {}, {}, ui::TIP_STYLE_SPACER, ui::TIP_LC_NORMAL);
304 }
305 }
306 }
307 else if (file->typeflag & FILE_TYPE_FTFONT) {
308 float color[4];
309 const bTheme *btheme = ui::theme::theme_get();
311 thumb = IMB_font_preview(file->redirection_path ? file->redirection_path : full_path,
312 512 * UI_SCALE_FAC,
313 color,
314 TIP_("The five boxing wizards jump quickly! 0123456789"));
315 free_imbuf = true;
316 }
317
318 const time_t file_time = (time_t)file->time;
319 const std::tm mod_time = date_string::localtime_safe(file_time);
320 const time_t ts_now = time(nullptr);
321 const std::tm now = date_string::localtime_safe(ts_now);
322 const char *lang = BLT_lang_get();
323 std::string modified_s = blender::date_string::datetime(mod_time,
324 lang,
325 date_string::DateFormat(U.date_format),
326 date_string::TimeFormat(U.time_format),
327 &now,
328 TIP_("Today"),
329 TIP_("Yesterday"));
330 tooltip_text_field_add(tip,
331 fmt::format(fmt::runtime(TIP_("Modified: {}")), modified_s),
332 {},
335
336 if (!(file->typeflag & FILE_TYPE_DIR) && file->size > 0) {
337 char size[16];
338 BLI_filelist_entry_size_to_string(nullptr, file->size, false, size);
339 if (file->size < 10000) {
341 BLI_str_format_uint64_grouped(size_full, file->size);
342 tooltip_text_field_add(
343 tip,
344 fmt::format(fmt::runtime(TIP_("Size: {} ({} bytes)")), size, size_full),
345 {},
348 }
349 else {
350 tooltip_text_field_add(tip,
351 fmt::format(fmt::runtime(TIP_("Size: {}")), size),
352 {},
355 }
356 }
357 }
358
359 if (thumb && file->typeflag & FILE_TYPE_FTFONT) {
360 const float scale = (512.0f * UI_SCALE_FAC) / float(std::max(thumb->x, thumb->y));
361 ui::TooltipImage image_data;
362 image_data.ibuf = thumb;
363 image_data.width = short(float(thumb->x) * scale);
364 image_data.height = short(float(thumb->y) * scale);
366 image_data.premultiplied = false;
367 image_data.text_color = true;
368 image_data.border = false;
369 tooltip_text_field_add(tip, {}, {}, ui::TIP_STYLE_SPACER, ui::TIP_LC_NORMAL);
370 tooltip_image_field_add(tip, image_data);
371 }
372 else if (thumb && params->display != FILE_IMGDISPLAY) {
373 tooltip_text_field_add(tip, {}, {}, ui::TIP_STYLE_SPACER, ui::TIP_LC_NORMAL);
374 tooltip_text_field_add(tip, {}, {}, ui::TIP_STYLE_SPACER, ui::TIP_LC_NORMAL);
375
376 ui::TooltipImage image_data;
377 float scale = (96.0f * UI_SCALE_FAC) / float(std::max(thumb->x, thumb->y));
378 image_data.ibuf = thumb;
379 image_data.width = short(float(thumb->x) * scale);
380 image_data.height = short(float(thumb->y) * scale);
381 image_data.border = true;
383 image_data.premultiplied = true;
384 tooltip_image_field_add(tip, image_data);
385 }
386
387 if (thumb && free_imbuf) {
388 IMB_freeImBuf(thumb);
389 }
390}
391
393 ui::TooltipData &tip,
394 ui::Button * /*but*/,
395 void *argN)
396{
397 const auto *asset = static_cast<asset_system::AssetRepresentation *>(argN);
398 ed::asset::asset_tooltip(*asset, tip);
399}
400
401static void draw_tile_background(const rcti *draw_rect, bool is_selected, bool is_highlighted)
402{
404 float color_background_1[4], color_background_2[4], color_outline[4];
405 const float roundness = wcol.roundness * U.widget_unit;
406 rctf draw_rect_fl;
407 BLI_rctf_rcti_copy(&draw_rect_fl, draw_rect);
408
409 if (is_selected) {
410 rgba_uchar_to_float(color_background_1, wcol.inner_sel);
411 rgba_uchar_to_float(color_outline, wcol.outline_sel);
412 std::swap(wcol.shadetop, wcol.shadedown);
413 }
414 else {
415 rgba_uchar_to_float(color_background_1, wcol.inner);
416 rgba_uchar_to_float(color_outline, wcol.outline);
417 }
418
419 /* Gradient fill, if list_item is set to shaded in the theme. */
420 if (wcol.shaded == 0) {
421 copy_v4_v4(color_background_2, color_background_1);
422 }
423 else {
424 constexpr float inv_255 = 1.0f / 255.0f;
425 float color_base[3];
426 copy_v3_v3(color_base, color_background_1);
427
428 for (int i = 0; i < 3; i++) {
429 color_background_1[i] = std::clamp(color_base[i] + wcol.shadetop * inv_255, 0.0f, 1.0f);
430 color_background_2[i] = std::clamp(color_base[i] + wcol.shadedown * inv_255, 0.0f, 1.0f);
431 }
432 }
433
434 /* Hover effect. Force opacity of inner color at least 10%. */
435 if (is_highlighted) {
436 color_background_1[3] = std::min(color_background_1[3] + 0.1f, 1.0f);
437 }
438
439 color_background_2[3] = color_background_1[3];
440
441 draw_roundbox_corner_set(ui::CNR_ALL);
443 &draw_rect_fl, color_background_1, color_background_2, 1.0f, color_outline, 1.0f, roundness);
444}
445
447 const SpaceFile *sfile,
448 const FileDirEntry *file,
449 const char *path,
450 const ImBuf *preview_image,
451 int icon,
452 float scale)
453{
454 ID *id;
455
456 if ((id = filelist_file_get_id(file))) {
457 button_drag_set_id(but, id);
458 if (preview_image) {
459 button_drag_attach_image(but, preview_image, scale);
460 }
461 }
462 else if (sfile->browse_mode == FILE_BROWSE_MODE_ASSETS &&
463 (file->typeflag & FILE_TYPE_ASSET) != 0)
464 {
465 const int import_method = ED_fileselect_asset_import_method_get(sfile, file);
466 BLI_assert(import_method > -1);
467 if (import_method > -1) {
468 AssetImportSettings import_settings{};
469 import_settings.method = eAssetImportMethod(import_method);
470 import_settings.use_instance_collections =
471 (sfile->asset_params->import_flags &
472 (ELEM(import_method, ASSET_IMPORT_LINK, ASSET_IMPORT_PACK) ?
475
476 button_drag_set_asset(but, file->asset, import_settings, icon, file->preview_icon_id);
477 }
478 }
479 else if (preview_image) {
480 button_drag_set_image(but, path, icon, preview_image, scale);
481 }
482 else {
483 /* path is no more static, cannot give it directly to but... */
484 button_drag_set_path(but, path);
485 }
486}
487
488static void file_but_tooltip_func_set(const SpaceFile *sfile,
489 const FileDirEntry *file,
490 ui::Button *but)
491{
492 if (file->asset) {
493 button_func_tooltip_custom_set(but, file_draw_asset_tooltip_custom_func, file->asset, nullptr);
494 }
495 else {
496 button_func_tooltip_custom_set(but,
498 file_tooltip_data_create(sfile, file),
500 }
501}
502
504 ui::Block *block,
505 const char * /*path*/,
506 const FileDirEntry *file,
507 const rcti *tile_draw_rect,
508 int icon,
509 int width,
510 int height,
511 int padx,
512 bool dimmed)
513{
514 ui::Button *but;
515
516 const int x = tile_draw_rect->xmin + padx;
517 const int y = tile_draw_rect->ymin +
518 round_fl_to_int((BLI_rcti_size_y(tile_draw_rect) - height) / 2.0f);
519
520 if (icon < BIFICONID_LAST_STATIC) {
521 /* Small built-in icon. Draw centered in given width. */
522 but = uiDefIconBut(block,
524 icon,
525 x,
526 y,
527 width,
528 height,
529 nullptr,
530 0.0f,
531 0.0f,
532 std::nullopt);
533 /* Center the icon. */
534 button_drawflag_disable(but, ui::BUT_ICON_LEFT);
535 }
536 else {
537 /* Larger preview icon. Fills available width/height. */
538 but = uiDefIconPreviewBut(block,
540 icon,
541 x,
542 y,
543 width,
544 height,
545 nullptr,
546 0.0f,
547 0.0f,
548 std::nullopt);
549 }
550 button_label_alpha_factor_set(but, dimmed ? 0.3f : 1.0f);
551 file_but_tooltip_func_set(sfile, file, but);
552
553 return but;
554}
555
556static ui::Button *file_add_overlay_icon_but(ui::Block *block, int pos_x, int pos_y, int icon)
557{
558 ui::Button *but = uiDefIconBut(block,
560 icon,
561 pos_x,
562 pos_y,
565 nullptr,
566 0.0f,
567 0.0f,
568 std::nullopt);
569 /* Otherwise a left hand padding will be added. */
570 button_drawflag_disable(but, ui::BUT_ICON_LEFT);
571 button_label_alpha_factor_set(but, 0.6f);
572 const uchar light[4] = {255, 255, 255, 255};
573 button_color_set(but, light);
574
575 return but;
576}
577
578static void file_draw_string(int sx,
579 int sy,
580 const char *string,
581 float width,
582 int height,
583 ui::FontStyleAlign align,
584 const uchar col[4])
585{
586 uiFontStyle fs;
587 rcti rect;
589
590 if (string[0] == '\0' || width < 1) {
591 return;
592 }
593
594 const uiStyle *style = ui::style_get();
595 fs = style->widget;
596
597 STRNCPY(filename, string);
598 ui::text_clip_middle_ex(&fs, filename, width, UI_ICON_SIZE, sizeof(filename), '\0');
599
600 /* no text clipping needed, fontstyle_draw does it but is a bit too strict
601 * (for buttons it works) */
602 rect.xmin = sx;
603 rect.xmax = sx + round_fl_to_int(width);
604 rect.ymin = sy - height;
605 rect.ymax = sy;
606
607 ui::FontStyleDrawParams font_style_params{};
608 font_style_params.align = align;
609
610 fontstyle_draw(&fs, &rect, filename, sizeof(filename), col, &font_style_params);
611}
612
617 const char *string,
618 ui::FontStyleAlign align,
619 const uchar col[4])
620{
621 if (string[0] == '\0' || BLI_rcti_size_x(rect) < 1) {
622 return;
623 }
624
625 const uiStyle *style = ui::style_get();
626 uiFontStyle fs = style->widget;
627
628 fontstyle_draw_multiline_clipped(&fs, rect, string, col, align);
629}
630
631static rcti file_measure_string_multiline(const StringRef string, const int wrap_width)
632{
633 if (string[0] == '\0' || wrap_width < 1) {
634 return {.xmin = 0, .xmax = 0, .ymin = 0, .ymax = 0};
635 }
636
637 const uiStyle *style = ui::style_get();
638 const int font_id = style->widget.uifont_id;
639
640 rcti textbox;
641 BLF_wordwrap(font_id,
642 wrap_width,
644 BLF_enable(font_id, BLF_WORD_WRAP);
645 BLF_boundbox(font_id, string.data(), string.size(), &textbox);
646 BLF_disable(font_id, BLF_WORD_WRAP);
647
648 return textbox;
649}
650
656static void file_draw_string_multiline(int sx,
657 int sy,
658 const StringRef string,
659 int wrap_width,
660 int line_height,
661 const uchar text_col[4],
662 int *r_sx,
663 int *r_sy)
664{
665 rcti rect;
666
667 if (string[0] == '\0' || wrap_width < 1) {
668 return;
669 }
670
671 const uiStyle *style = ui::style_get();
672 const rcti textbox = file_measure_string_multiline(string, wrap_width);
673
674 /* no text clipping needed, fontstyle_draw does it but is a bit too strict
675 * (for buttons it works) */
676 rect.xmin = sx;
677 rect.xmax = sx + wrap_width;
678 /* Need to increase the clipping rect by one more line, since the #fontstyle_draw_ex() will
679 * actually start drawing at (ymax - line-height). */
680 rect.ymin = sy - BLI_rcti_size_y(&textbox) - line_height;
681 rect.ymax = sy;
682
683 ui::FontStyleDrawParams font_style_params{};
684 font_style_params.align = ui::UI_STYLE_TEXT_LEFT;
685 font_style_params.word_wrap = true;
686
688 fontstyle_draw_ex(&style->widget,
689 &rect,
690 string.data(),
691 string.size(),
692 text_col,
693 &font_style_params,
694 nullptr,
695 nullptr,
696 &result);
697 if (r_sx) {
698 *r_sx = result.width;
699 }
700 if (r_sy) {
701 *r_sy = rect.ymin + line_height;
702 }
703}
704
705static std::tuple<int, int, float> preview_image_scaled_dimensions_get(const int image_width,
706 const int image_height,
707 const FileLayout &layout)
708{
709 const float ui_imbx = image_width * UI_SCALE_FAC;
710 const float ui_imby = image_height * UI_SCALE_FAC;
711
712 float scale;
713 float scaledx, scaledy;
714 if (((ui_imbx > layout.prv_w) || (ui_imby > layout.prv_h)) ||
715 ((ui_imbx < layout.prv_w) || (ui_imby < layout.prv_h)))
716 {
717 if (image_width > image_height) {
718 scaledx = float(layout.prv_w);
719 scaledy = (float(image_height) / float(image_width)) * layout.prv_w;
720 scale = scaledx / image_width;
721 }
722 else {
723 scaledy = float(layout.prv_h);
724 scaledx = (float(image_width) / float(image_height)) * layout.prv_h;
725 scale = scaledy / image_height;
726 }
727 }
728 else {
729 scaledx = ui_imbx;
730 scaledy = ui_imby;
732 }
733
734 return std::make_tuple(int(scaledx), int(scaledy), scale);
735}
736
737static void file_add_preview_drag_but(const SpaceFile *sfile,
738 ui::Block *block,
739 const FileDirEntry *file,
740 const char *path,
741 const rcti *tile_draw_rect,
742 const int file_type_icon)
743{
744 /* Invisible button for dragging. */
745 ui::Button *but = uiDefBut(block,
747 "",
748 tile_draw_rect->xmin,
749 tile_draw_rect->ymin,
750 BLI_rcti_size_x(tile_draw_rect),
751 BLI_rcti_size_y(tile_draw_rect),
752 nullptr,
753 0.0,
754 0.0,
755 std::nullopt);
756
757 const ImBuf *preview_image = filelist_file_get_preview_image(file);
758 const ImBuf *drag_image = (preview_image || file->asset) ?
759 preview_image :
760 /* Larger directory or document icon. */
762 const float scale = drag_image ? (PREVIEW_DRAG_DRAW_SIZE * UI_SCALE_FAC) /
763 std::max(drag_image->x, drag_image->y) :
764 1.0f;
765 file_but_enable_drag(but, sfile, file, path, drag_image, file_type_icon, scale);
766 file_but_tooltip_func_set(sfile, file, but);
767}
768
770 const FileLayout *layout,
771 const FileDirEntry *file,
772 const rcti *tile_draw_rect)
773{
774 const int preview_center_x = BLI_rcti_cent_x(tile_draw_rect);
775 const int preview_center_y = tile_draw_rect->ymax - layout->tile_border_y - layout->prv_h * 0.5f;
776 const int icon_width = ICON_DEFAULT_WIDTH_SCALE * 2.0f;
777 const int icon_height = ICON_DEFAULT_HEIGHT_SCALE * 2.0f;
778 const int icon_x = preview_center_x - icon_width * 0.5f;
779 const int icon_y = preview_center_y - icon_height * 0.5f;
780
781 ui::Button *but = uiDefIconButO(block,
783 "ASSET_OT_asset_download",
785 ICON_DOWNLOAD,
786 icon_x,
787 icon_y,
788 icon_width,
789 icon_height,
790 std::nullopt);
793 ui::button_icon_scale_set(but, 1.5f);
795}
796
797static void file_draw_preview(const FileDirEntry *file,
798 const rcti *tile_draw_rect,
799 const IconBufferRef &preview,
800 FileLayout *layout,
801 const bool dimmed)
802{
803 const auto [scaled_width, scaled_height, scale] = preview_image_scaled_dimensions_get(
804 preview.width, preview.height, *layout);
805
806 /* Additional offset to keep the scaled image centered. Difference between maximum
807 * width/height and the actual width/height, divided by two for centering. */
808 const float ofs_x = (float(layout->prv_w) - float(scaled_width)) / 2.0f;
809 const float ofs_y = (float(layout->prv_h) - float(scaled_height)) / 2.0f;
810 const int xmin = tile_draw_rect->xmin + layout->prv_border_x + int(ofs_x + 0.5f);
811 const int ymin = tile_draw_rect->ymax - layout->prv_border_y - layout->prv_h + int(ofs_y + 0.5f);
812
814
815 float document_img_col[4] = {1.0f, 1.0f, 1.0f, 1.0f};
816 if (file->typeflag & FILE_TYPE_FTFONT) {
817 ui::theme::get_color_4fv(TH_TEXT, document_img_col);
818 }
819 if (dimmed) {
820 document_img_col[3] *= 0.3f;
821 }
822
824 /* Draw checker pattern behind image previews in case they have transparency. */
826 float(xmin), float(ymin), float(xmin + scaled_width), float(ymin + scaled_height));
827 }
828
829 if (file->typeflag & FILE_TYPE_BLENDERLIB) {
830 /* Datablock preview images use premultiplied alpha. */
832 }
833
834 const gpu::TextureFormat format = gpu::TextureFormat::UNORM_8_8_8_8;
835 BLI_assert_msg(preview.channels == 4, "preview images are expected to be 4 channels");
836
838 drawer.draw(float(xmin),
839 float(ymin),
840 preview.width,
841 preview.height,
842 format,
843 true,
844 preview.buffer.data(),
845 scale,
846 scale,
847 document_img_col);
848
849 const bool show_outline = (file->typeflag & (FILE_TYPE_IMAGE | FILE_TYPE_OBJECT_IO |
851 /* Contrasting outline around some preview types. */
852 if (show_outline) {
854
855 GPUVertFormat *format = immVertexFormat();
856 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
858 float border_color[4] = {1.0f, 1.0f, 1.0f, 0.15f};
859 float bgcolor[4];
861 if (srgb_to_grayscale(bgcolor) > 0.5f) {
862 border_color[0] = 0.0f;
863 border_color[1] = 0.0f;
864 border_color[2] = 0.0f;
865 }
866 immUniformColor4fv(border_color);
868 float(xmin),
869 float(ymin),
870 float(xmin + scaled_width + 1),
871 float(ymin + scaled_height + 1));
873 }
874
876}
877
878static void file_draw_special_image(const FileDirEntry *file,
879 const rcti *tile_draw_rect,
880 const int file_type_icon,
881 const float icon_aspect,
882 const FileLayout *layout,
883 const bool dimmed,
884 eDirEntry_SelectFlag file_selflag)
885{
886 float document_img_col[4] = {1.0f, 1.0f, 1.0f, 1.0f};
887 const bool selected = file_selflag & FILE_SEL_SELECTED;
888 if (file->typeflag & FILE_TYPE_DIR) {
889 ui::theme::get_color_4fv(TH_ICON_FOLDER, document_img_col);
890 }
891 else {
893 rgba_uchar_to_float(document_img_col, !selected ? wcol.text : wcol.text_sel);
894 }
895
896 if (dimmed) {
897 document_img_col[3] *= 0.3f;
898 }
899
901
902 const int cent_x = tile_draw_rect->xmin + layout->prv_border_x + (layout->prv_w / 2.0f) + 0.5f;
903 const int cent_y = tile_draw_rect->ymax - layout->prv_border_y - (layout->prv_h / 2.0f) + 0.5f;
904 const float aspect = icon_aspect / UI_SCALE_FAC;
905
906 {
907 /* Draw large folder or document icon. */
908 const int icon_large = (file->typeflag & FILE_TYPE_DIR) ? ICON_FILE_FOLDER_LARGE :
909 ICON_FILE_LARGE;
910
911 uchar icon_col[4];
912 rgba_float_to_uchar(icon_col, document_img_col);
913
914 const float scale = 4.0f;
915 const float ofs_y = (file->typeflag & FILE_TYPE_DIR ? -0.02f : 0.0f) * layout->prv_h;
916
917 ui::icon_draw_ex(cent_x - (ICON_DEFAULT_WIDTH * scale / aspect / 2.0f),
918 cent_y - (ICON_DEFAULT_HEIGHT * scale / aspect / 2.0f) + ofs_y,
919 icon_large,
920 icon_aspect / UI_SCALE_FAC / scale,
921 document_img_col[3],
922 0.0f,
923 icon_col,
924 false,
926 }
927
928 if (file_type_icon) {
929 /* Small icon in the middle of large image, scaled to fit container and UI scale */
930 float icon_opacity = 0.4f;
931 uchar icon_color[4] = {0, 0, 0, 255};
932 if (srgb_to_grayscale(document_img_col) < 0.5f) {
933 icon_color[0] = 255;
934 icon_color[1] = 255;
935 icon_color[2] = 255;
936 }
937
938 const float scale = file->typeflag & FILE_TYPE_DIR ? 1.5f : 2.0f;
939 const float ofs_y = (file->typeflag & FILE_TYPE_DIR ? -0.035f : -0.135f) * layout->prv_h;
940
941 ui::icon_draw_ex(cent_x - (ICON_DEFAULT_WIDTH * scale / aspect / 2.0f),
942 cent_y - (ICON_DEFAULT_HEIGHT * scale / aspect / 2.0f) + ofs_y,
943 file_type_icon,
944 icon_aspect / UI_SCALE_FAC / scale,
945 icon_opacity,
946 0.0f,
947 icon_color,
948 false,
950 }
951
953}
954
955static void file_draw_loading_icon(const rcti *tile_draw_rect,
956 const float preview_icon_aspect,
957 const FileLayout *layout)
958{
959 uchar icon_color[4] = {0, 0, 0, 255};
960 /* Contrast with background since we are not showing the large document image. */
962
963 const int cent_x = tile_draw_rect->xmin + layout->prv_border_x + (layout->prv_w / 2.0f) + 0.5f;
964 const int cent_y = tile_draw_rect->ymax - layout->prv_border_y - (layout->prv_h / 2.0f) + 0.5f;
965 const float aspect = preview_icon_aspect / UI_SCALE_FAC;
966
967 ui::icon_draw_ex(cent_x - (ICON_DEFAULT_WIDTH / aspect / 2.0f),
968 cent_y - (ICON_DEFAULT_HEIGHT / aspect / 2.0f),
969 ICON_PREVIEW_LOADING,
970 aspect,
971 1.0f,
972 0.0f,
973 icon_color,
974 false,
976}
977
978static void file_draw_indicator_icons(const FileList *files,
979 const FileDirEntry *file,
980 const FileLayout *layout,
981 const rcti *tile_draw_rect,
982 const float preview_icon_aspect,
983 const int file_type_icon,
984 const bool has_special_file_image,
985 const eDirEntry_SelectFlag file_selflag)
986{
987 const bool is_offline = (file->attributes & FILE_ATTR_OFFLINE);
988 const bool is_link = (file->attributes & FILE_ATTR_ANY_LINK);
989 const bool is_loading = filelist_file_is_preview_pending(files, file);
990 const bool selected = file_selflag & FILE_SEL_SELECTED;
991
993 const uchar *icon_color = !selected ? wcol.text : wcol.text_sel;
994 const uchar icon_color_lightness = srgb_to_grayscale_byte(icon_color);
995 const bool show_icon_border = (icon_color_lightness > 96);
996
997 /* Don't draw these icons if the preview image is small. They are just indicators and shouldn't
998 * cover the preview. */
999 if (preview_icon_aspect < 2.0f) {
1000 const float icon_x = float(tile_draw_rect->xmin) + (3.0f * UI_SCALE_FAC);
1001 const float icon_y = float(tile_draw_rect->ymax) - layout->prv_border_y - layout->prv_h;
1002 if (is_offline) {
1003 /* Icon at bottom to indicate the file is offline. */
1004 ui::icon_draw_ex(icon_x,
1005 icon_y,
1006 ICON_INTERNET,
1007 1.0f / UI_SCALE_FAC,
1008 1.0f,
1009 0.0f,
1010 icon_color,
1011 show_icon_border,
1013 }
1014 else if (is_link) {
1015 /* Icon at bottom to indicate it is a shortcut, link, or alias. */
1016 ui::icon_draw_ex(icon_x,
1017 icon_y,
1018 ICON_FILE_ALIAS,
1019 1.0f / UI_SCALE_FAC,
1020 0.6f,
1021 0.0f,
1022 nullptr,
1023 false,
1025 }
1026 else if (file_type_icon) {
1027 /* Smaller, fainter type icon at bottom-left.
1028 *
1029 * Always draw while loading, the preview shows a loading icon and doesn't indicate the type
1030 * yet then. After loading, the special file image may already draw the type icon in
1031 * #file_draw_preview(), don't draw it again here. Also don't draw it for font files, they
1032 * render a font preview already, the type indicator would be redundant.
1033 */
1034 if (is_loading || !(has_special_file_image || (file->typeflag & FILE_TYPE_FTFONT))) {
1035 ui::icon_draw_ex(icon_x,
1036 icon_y,
1037 file_type_icon,
1038 1.0f / UI_SCALE_FAC,
1039 1.0f,
1040 0.0f,
1041 icon_color,
1042 show_icon_border,
1044 }
1045 }
1046 }
1047
1048 {
1049 const float icon_x = float(tile_draw_rect->xmax) - (16.0f * UI_SCALE_FAC);
1050 const float icon_y = float(tile_draw_rect->ymax) - (20.0f * UI_SCALE_FAC);
1051
1052 const bool is_current_main_data = filelist_file_get_id(file) != nullptr;
1053 if (is_current_main_data) {
1054 /* Smaller, fainter icon at the top-right indicating that the file represents data from the
1055 * current file (from current #Main in fact). */
1056 ui::icon_draw_ex(icon_x,
1057 icon_y,
1058 ICON_CURRENT_FILE,
1059 1.0f / UI_SCALE_FAC,
1060 1.0f,
1061 0.0f,
1062 icon_color,
1063 show_icon_border,
1065 }
1066 else if ((file->typeflag & FILE_TYPE_ASSET_ONLINE) != 0) {
1067 ui::icon_draw_ex(icon_x,
1068 icon_y,
1069 ICON_INTERNET,
1070 1.0f / UI_SCALE_FAC,
1071 1.0f,
1072 0.0f,
1073 icon_color,
1074 show_icon_border,
1076 }
1077 else if (file->asset &&
1079 {
1080 /* This on-disk asset no longer matches the asset listing it was downloaded from. */
1081 ui::icon_draw_ex(icon_x,
1082 icon_y,
1083 ICON_STATUS_WARNING_FILLED,
1084 1.0f / UI_SCALE_FAC,
1085 1.0f,
1086 0.0f,
1087 icon_color,
1088 show_icon_border,
1090 }
1091 }
1092}
1093
1095{
1096 char newname[FILE_MAX + 12];
1097 char orgname[FILE_MAX + 12];
1098 char filename[FILE_MAX + 12];
1100 wmWindow *win = CTX_wm_window(&C);
1101 SpaceFile *sfile = reinterpret_cast<SpaceFile *>(CTX_wm_space_data(&C));
1102 ARegion *region = CTX_wm_region(&C);
1104
1105 BLI_path_join(orgname, sizeof(orgname), params->dir, oldname.c_str());
1106 STRNCPY(filename, params->renamefile);
1108 BLI_path_join(newname, sizeof(newname), params->dir, filename);
1109
1110 if (!STREQ(orgname, newname)) {
1111 errno = 0;
1112 if ((BLI_rename(orgname, newname) != 0) || !BLI_exists(newname)) {
1114 RPT_ERROR, "Could not rename: %s", errno ? strerror(errno) : "unknown error");
1116 /* Renaming failed, reset the name for further renaming handling. */
1117 STRNCPY(params->renamefile, oldname.c_str());
1118 }
1119 else {
1120 /* If rename is successful, set renamefile to newly renamed entry.
1121 * This is used later to select and scroll to the file.
1122 */
1123 STRNCPY(params->renamefile, filename);
1124 }
1125
1126 /* Ensure we select and scroll to the renamed file.
1127 * This is done even if the rename fails as we want to make sure that the file we tried to
1128 * rename is still selected and in view. (it can move if something added files/folders to the
1129 * directory while we were renaming).
1130 */
1132 /* to make sure we show what is on disk */
1133 ED_fileselect_clear(wm, sfile);
1134 ED_region_tag_redraw(region);
1135 }
1136}
1137
1138static void draw_background(FileLayout *layout, View2D *v2d)
1139{
1140 const int item_height = layout->tile_h + (2 * layout->tile_border_y);
1141 int i;
1142 int sy;
1143
1144 uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
1146 float col_alternating[4];
1149
1150 /* alternating flat shade background */
1151 for (i = 2; (i <= layout->rows + 1); i += 2) {
1152 sy = int(v2d->cur.ymax) - layout->offset_top - i * item_height - layout->list_padding_top;
1153
1154 /* Offset pattern slightly to add scroll effect. */
1155 sy += round_fl_to_int(item_height * (v2d->tot.ymax - v2d->cur.ymax) / item_height);
1156
1157 immRectf(pos,
1158 v2d->cur.xmin,
1159 float(sy),
1160 v2d->cur.xmax,
1161 float(sy + layout->tile_h + 2 * layout->tile_border_y));
1162 }
1163
1165}
1166
1167static void draw_dividers(FileLayout *layout, View2D *v2d)
1168{
1169 /* vertical column dividers */
1170
1171 const int step = (layout->tile_w + 2 * layout->tile_border_x);
1172
1173 uint vertex_len = 0;
1174 int sx = int(v2d->tot.xmin);
1175 while (sx < v2d->cur.xmax) {
1176 sx += step;
1177 vertex_len += 4; /* vertex_count = 2 points per line * 2 lines per divider */
1178 }
1179
1180 if (vertex_len > 0) {
1181 float v1[2], v2[2];
1182 float col_hi[3], col_lo[3];
1183
1186
1187 v1[1] = v2d->cur.ymax - layout->tile_border_y;
1188 v2[1] = v2d->cur.ymin;
1189
1190 GPUVertFormat *format = immVertexFormat();
1191 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
1192 uint color = GPU_vertformat_attr_add(format, "color", gpu::VertAttrType::SFLOAT_32_32_32);
1193
1195 immBegin(GPU_PRIM_LINES, vertex_len);
1196
1197 sx = int(v2d->tot.xmin);
1198 while (sx < v2d->cur.xmax) {
1199 sx += step;
1200
1201 v1[0] = v2[0] = sx;
1203 immVertex2fv(pos, v1);
1204 immAttr3fv(color, col_lo);
1205 immVertex2fv(pos, v2);
1206
1207 v1[0] = v2[0] = sx + 1;
1209 immVertex2fv(pos, v1);
1210 immAttr3fv(color, col_hi);
1211 immVertex2fv(pos, v2);
1212 }
1213
1214 immEnd();
1216 }
1217}
1218
1219static void draw_fixed_header_background(const View2D *v2d, const float height)
1220{
1221 uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
1222
1225
1226 immRectf(pos, v2d->cur.xmin, v2d->cur.ymax - height, v2d->cur.xmax, v2d->cur.ymax);
1227
1229}
1230
1232 FileLayout *layout,
1233 const View2D *v2d,
1234 const uchar text_col[4])
1235{
1236 const float divider_pad = 0.2 * layout->attribute_column_header_h;
1237 int sx = v2d->cur.xmin, sy = v2d->cur.ymax;
1238
1239 for (int column_type = 0; column_type < ATTRIBUTE_COLUMN_MAX; column_type++) {
1240 if (!file_attribute_column_type_enabled(params, FileAttributeColumnType(column_type), layout))
1241 {
1242 continue;
1243 }
1244 const FileAttributeColumn *column = &layout->attribute_columns[column_type];
1245
1246 /* Active sort type triangle */
1247 if (params->sort == column->sort_type) {
1248 float tri_color[4];
1249
1250 rgba_uchar_to_float(tri_color, text_col);
1251 ui::draw_icon_tri(sx + column->width - (0.3f * U.widget_unit) -
1253 sy + (0.1f * U.widget_unit) - (layout->attribute_column_header_h / 2),
1254 (params->flag & FILE_SORT_INVERT) ? 't' : 'v',
1255 tri_color);
1256 }
1257
1259 sy - layout->tile_border_y,
1260 IFACE_(column->name),
1261 column->width - 2 * ATTRIBUTE_COLUMN_PADDING,
1262 layout->attribute_column_header_h - layout->tile_border_y,
1264 text_col);
1265
1266 /* Separator line */
1267 if (column_type != COLUMN_NAME) {
1269 immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
1270
1274 immVertex2f(pos, sx - 1, sy - divider_pad);
1275 immVertex2f(pos, sx - 1, sy - layout->attribute_column_header_h + divider_pad);
1276 immEnd();
1278 }
1279
1280 sx += column->width;
1281 }
1282
1283 /* Vertical separator lines line */
1284 {
1285 uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
1289 immVertex2f(pos, v2d->cur.xmin, sy);
1290 immVertex2f(pos, v2d->cur.xmax, sy);
1291 immVertex2f(pos, v2d->cur.xmin, sy - layout->attribute_column_header_h);
1292 immVertex2f(pos, v2d->cur.xmax, sy - layout->attribute_column_header_h);
1293 immEnd();
1295 }
1296}
1297
1303 /* Generated string will be cached in the file, so non-const. */
1304 FileDirEntry *file,
1305 const bool compact,
1306 const bool update_stat_strings)
1307{
1308 switch (column) {
1309 case COLUMN_DATETIME:
1310 if (!(file->typeflag & FILE_TYPE_BLENDERLIB) && !FILENAME_IS_CURRPAR(file->relpath)) {
1311 if (file->draw_data.datetime_str[0] == '\0' || update_stat_strings) {
1312 const time_t file_time = (time_t)file->time;
1313 const std::tm mod_time = date_string::localtime_safe(file_time);
1314 const time_t ts_now = time(nullptr);
1315 const std::tm now = date_string::localtime_safe(ts_now);
1316 const char *lang = BLT_lang_get();
1317 std::string modified_s =
1318 compact ? date_string::date(mod_time, lang, date_string::DateFormat(U.date_format)) :
1319 date_string::datetime(mod_time,
1320 lang,
1321 date_string::DateFormat(U.date_format),
1322 date_string::TimeFormat(U.time_format),
1323 &now,
1324 TIP_("Today"),
1325 TIP_("Yesterday"));
1326 STRNCPY_UTF8(file->draw_data.datetime_str, modified_s.c_str());
1327 }
1328 return file->draw_data.datetime_str;
1329 }
1330 break;
1331 case COLUMN_SIZE:
1334 {
1335 if (file->draw_data.size_str[0] == '\0' || update_stat_strings) {
1337 nullptr, file->size, compact, file->draw_data.size_str);
1338 }
1339
1340 return file->draw_data.size_str;
1341 }
1342 break;
1343 default:
1344 break;
1345 }
1346
1347 return nullptr;
1348}
1349
1350static void draw_details_columns(const FileSelectParams *params,
1351 const FileLayout *layout,
1352 FileDirEntry *file,
1353 const rcti *tile_draw_rect,
1354 const uchar text_col[4])
1355{
1356 const bool compact = FILE_LAYOUT_COMPACT(layout);
1357 const bool update_stat_strings = layout->width != layout->curr_size;
1358 int sx = tile_draw_rect->xmin - layout->tile_border_x;
1359
1360 for (int column_type = 0; column_type < ATTRIBUTE_COLUMN_MAX; column_type++) {
1361 const FileAttributeColumn *column = &layout->attribute_columns[column_type];
1362
1363 /* Name column is not a detail column (should already be drawn), always skip here. */
1364 if (column_type == COLUMN_NAME) {
1365 sx += column->width;
1366 continue;
1367 }
1368 if (!file_attribute_column_type_enabled(params, FileAttributeColumnType(column_type), layout))
1369 {
1370 continue;
1371 }
1372
1374 FileAttributeColumnType(column_type), file, compact, update_stat_strings);
1375
1376 if (str) {
1378 tile_draw_rect->ymax,
1379 IFACE_(str),
1380 column->width - 2 * ATTRIBUTE_COLUMN_PADDING,
1381 layout->tile_h,
1383 text_col);
1384 }
1385
1386 sx += column->width;
1387 }
1388}
1389
1390static rcti tile_draw_rect_get(const View2D *v2d, const FileLayout *layout, const int file_idx)
1391{
1392 int tile_pos_x, tile_pos_y;
1393 ED_fileselect_layout_tilepos(layout, file_idx, &tile_pos_x, &tile_pos_y);
1394 tile_pos_x += int(v2d->tot.xmin);
1395 tile_pos_y = int(v2d->tot.ymax - tile_pos_y);
1396
1397 rcti rect;
1398 rect.xmin = tile_pos_x;
1399 rect.xmax = rect.xmin + layout->tile_w;
1400 rect.ymax = tile_pos_y;
1401 rect.ymin = rect.ymax - layout->tile_h;
1402
1403 return rect;
1404}
1405
1410 const eFileDisplayType display_type,
1411 const FileLayout *layout,
1412 const int file_idx,
1413 const int icon_ofs_x)
1414{
1415 rcti tile_rect = tile_draw_rect_get(v2d, layout, file_idx);
1416
1417 rcti rect = tile_rect;
1418 if (display_type == FILE_IMGDISPLAY) {
1419 rect.ymin += round_fl_to_int(layout->prv_border_y * 0.5f);
1420 rect.ymax = rect.ymin + layout->text_line_height * layout->text_lines_count;
1421 }
1422 else {
1423 rect.xmin += icon_ofs_x + 1;
1424 rect.xmax = tile_rect.xmin + round_fl_to_int(layout->attribute_columns[COLUMN_NAME].width) -
1425 layout->tile_border_x;
1426 }
1427
1428 return rect;
1429}
1430
1431void file_draw_list(const bContext *C, ARegion *region)
1432{
1434 wmWindow *win = CTX_wm_window(C);
1435 SpaceFile *sfile = CTX_wm_space_file(C);
1437 FileLayout *layout = ED_fileselect_get_layout(sfile, region);
1438 View2D *v2d = &region->v2d;
1439 FileList *files = sfile->files;
1440 FileDirEntry *file;
1441 ui::Block *block = block_begin(C, region, __func__, ui::EmbossType::Emboss);
1442 int numfiles;
1443 int numfiles_layout;
1444 int offset;
1445 int i;
1446 ui::FontStyleAlign align;
1447 bool do_drag;
1448 uchar text_col[4];
1450 const bool draw_columnheader = (params->display == FILE_VERTICALDISPLAY);
1451 const float thumb_icon_aspect = std::min(64.0f / float(params->thumbnail_size), 4.0f);
1452
1453 numfiles = filelist_files_ensure(files);
1454
1455 if (params->display != FILE_IMGDISPLAY) {
1456 draw_background(layout, v2d);
1457 draw_dividers(layout, v2d);
1458 }
1459
1461 layout, int(region->v2d.cur.xmin), int(-region->v2d.cur.ymax) + layout->offset_top);
1462 offset = std::max(offset, 0);
1463
1464 numfiles_layout = ED_fileselect_layout_numfiles(layout, region);
1465
1466 /* adjust, so the next row is already drawn when scrolling */
1467 if (layout->flag & FILE_LAYOUT_HOR) {
1468 numfiles_layout += layout->rows;
1469 }
1470 else {
1471 numfiles_layout += layout->flow_columns;
1472 }
1473
1474 filelist_file_cache_slidingwindow_set(files, numfiles_layout);
1475
1477
1478 if (numfiles > 0) {
1479 const bool success = filelist_file_cache_block(
1480 files, min_ii(offset + (numfiles_layout / 2), numfiles - 1));
1481 BLI_assert(success);
1482 UNUSED_VARS_NDEBUG(success);
1483
1485
1486 /* Handle preview timer here,
1487 * since it's filelist_file_cache_block() and filelist_cache_previews_update()
1488 * which controls previews task.
1489 * Note that online assets don't use this system.
1490 */
1491 {
1492 const bool previews_running = filelist_cache_previews_running(files) &&
1494 // printf("%s: preview task: %d\n", __func__, previews_running);
1495 if (previews_running && !sfile->previews_timer) {
1497 wm, win, NC_SPACE | ND_SPACE_FILE_PREVIEW, 0.01);
1498 }
1499 if (!previews_running && sfile->previews_timer) {
1500 /* Preview is not running, no need to keep generating update events! */
1501 // printf("%s: Inactive preview task, sleeping!\n", __func__);
1503 sfile->previews_timer = nullptr;
1504 }
1505 }
1506 }
1507
1509
1510 /* Default text color, used for the empty/not-ready message and column headers when the
1511 * per-file loop below does not run (empty directory, no search matches, still loading). */
1513
1514 const bool filelist_loading = !filelist_is_ready(files);
1515
1516 for (i = offset; (i < numfiles) && (i < offset + numfiles_layout); i++) {
1517 const int padx = 0.1f * UI_UNIT_X;
1518 int icon_ofs = 0;
1519
1520 const rcti tile_draw_rect = tile_draw_rect_get(v2d, layout, i);
1521
1522 file = filelist_file(files, i);
1523 eDirEntry_SelectFlag file_selflag = filelist_entry_select_get(sfile->files, file, CHECK_ALL);
1524 if (params->highlight_file == i) {
1525 file_selflag |= FILE_SEL_HIGHLIGHTED;
1526 }
1527
1528 char path[FILE_MAX_LIBEXTRA];
1529 filelist_file_get_full_path(files, file, path);
1530
1531 const bool is_selected = file_selflag & FILE_SEL_SELECTED;
1532 const bool is_highlighted = file_selflag & FILE_SEL_HIGHLIGHTED;
1533 copy_v4_v4_uchar(text_col, is_selected ? wcol.text_sel : wcol.text);
1534
1535 if (!(file_selflag & FILE_SEL_EDITING)) {
1536 BLI_assert(i == 0 || !FILENAME_IS_CURRPAR(file->relpath));
1537 draw_tile_background(&tile_draw_rect, is_selected, is_highlighted);
1538 }
1539 draw_roundbox_corner_set(ui::CNR_NONE);
1540
1541 /* don't drag parent or refresh items */
1542 do_drag = !FILENAME_IS_CURRPAR(file->relpath);
1543 const bool is_hidden = (file->attributes & FILE_ATTR_HIDDEN);
1544
1545 if (FILE_IMGDISPLAY == params->display) {
1546 if ((file->typeflag & FILE_TYPE_ASSET_ONLINE) && !filelist_loading) {
1548 /* Trigger the preview loader to wait until the download is done and load the preview from
1549 * disk. Has to be done explicitly here because the preview isn't attached to a button. */
1550 if (!file->asset->is_local_id()) {
1551 if (PreviewImage *preview = file->asset->get_preview()) {
1552 ui::icon_render_id_ex(C, nullptr, nullptr, ICON_SIZE_PREVIEW, true, preview);
1553 }
1554 }
1555 }
1556
1557 const int file_type_icon = filelist_geticon_file_type(files, i, false);
1558 std::optional<IconBufferRef> preview_buf = file->preview_icon_id ?
1561 std::nullopt;
1562
1563 bool has_special_file_image = false;
1564
1565 const bool is_loading = filelist_file_is_preview_pending(files, file);
1566 if (is_loading) {
1567 file_draw_loading_icon(&tile_draw_rect, thumb_icon_aspect, layout);
1568 }
1569 else if (preview_buf) {
1570 file_draw_preview(file, &tile_draw_rect, *preview_buf, layout, is_hidden);
1571 }
1572 else {
1573 /* Larger folder or document icon, with file/folder type icon in the middle (if any). */
1575 &tile_draw_rect,
1576 file_type_icon,
1577 thumb_icon_aspect,
1578 layout,
1579 is_hidden,
1580 file_selflag);
1581 has_special_file_image = true;
1582 }
1583
1585 file,
1586 layout,
1587 &tile_draw_rect,
1588 thumb_icon_aspect,
1589 file_type_icon,
1590 has_special_file_image,
1591 file_selflag);
1592
1593 if (do_drag) {
1594 file_add_preview_drag_but(sfile, block, file, path, &tile_draw_rect, file_type_icon);
1595 }
1596
1597 if (is_highlighted && file->asset && file->asset->needs_download()) {
1598 file_add_asset_download_but(block, layout, file, &tile_draw_rect);
1599 }
1600 }
1601 else {
1602 const BIFIconID icon = [&]() {
1603 if (file->asset) {
1604 file->asset->ensure_previewable(*C);
1605
1606 if (filelist_loading) {
1607 return BIFIconID(ICON_PREVIEW_LOADING);
1608 }
1610 }
1611 return filelist_geticon_file_type(files, i, true);
1612 }();
1613
1614 icon_ofs += layout->prv_w + 2 * padx;
1615
1616 /* Add dummy draggable button covering the icon and the label. */
1617 if (do_drag) {
1618 const uiStyle *style = ui::style_get();
1619 const int str_width = ui::fontstyle_string_width(&style->widget, file->name);
1620 const int drag_width = std::min(
1621 str_width + icon_ofs,
1623 if (drag_width > 0) {
1624 /* Uses full row height (tile height plus 2 * tile border padding) so there's no space
1625 * between rows. */
1626 ui::Button *drag_but = uiDefBut(block,
1628 "",
1629 tile_draw_rect.xmin,
1630 tile_draw_rect.ymin - layout->tile_border_y,
1631 drag_width,
1632 layout->tile_h + layout->tile_border_y * 2,
1633 nullptr,
1634 0,
1635 0,
1636 std::nullopt);
1637 button_dragflag_enable(drag_but, ui::BUT_DRAG_FULL_BUT);
1638 file_but_enable_drag(drag_but, sfile, file, path, nullptr, icon, UI_SCALE_FAC);
1639 file_but_tooltip_func_set(sfile, file, drag_but);
1640 }
1641 }
1642
1643 /* Add this after the fake draggable button, so the icon button tooltip is displayed. */
1644 ui::Button *icon_but = file_add_icon_but(sfile,
1645 block,
1646 path,
1647 file,
1648 &tile_draw_rect,
1649 icon,
1650 layout->prv_w,
1651 layout->prv_h,
1652 padx,
1653 is_hidden);
1654 if (do_drag) {
1655 /* For some reason the dragging is unreliable for the icon button if we don't explicitly
1656 * enable dragging, even though the dummy drag button above covers the same area. */
1657 file_but_enable_drag(icon_but, sfile, file, path, nullptr, icon, UI_SCALE_FAC);
1658 }
1659
1660 if (layout->prv_w >= round_fl_to_int(ICON_DEFAULT_WIDTH_SCALE * 2) &&
1661 (filelist_loading || icon >= BIFICONID_LAST_STATIC))
1662 {
1663 const BIFIconID type_icon = filelist_geticon_file_type(files, i, true);
1665 tile_draw_rect.xmin + padx - 2,
1666 tile_draw_rect.ymin - 2 * UI_SCALE_FAC,
1667 type_icon);
1668 }
1669 }
1670
1671 const rcti text_rect = text_draw_rect_get(
1672 v2d, eFileDisplayType(params->display), layout, i, icon_ofs);
1673
1674 if (file_selflag & FILE_SEL_EDITING) {
1675 const int but_height =
1676 (params->display == FILE_IMGDISPLAY) ?
1677 layout->text_line_height * 1.4f :
1678 /* Just a little smaller than the tile height, clamped to #UI_UNIT_Y as maximum. */
1679 std::min(short(BLI_rcti_size_y(&text_rect) - 1.0f * UI_SCALE_FAC), UI_UNIT_Y);
1680 ui::Button *but = uiDefBut(block,
1682 "",
1683 text_rect.xmin,
1684 /* First line only, when name is displayed in multiple lines. */
1685 text_rect.ymax - but_height,
1686 BLI_rcti_size_x(&text_rect),
1687 but_height,
1688 params->renamefile,
1689 1.0f,
1690 float(sizeof(params->renamefile)),
1691 "");
1692 text_button_func_rename_set(but, renamebutton_cb);
1693 button_flag_enable(but, ui::BUT_NO_UTF8); /* Allow non UTF8 names. */
1694 button_flag_disable(but, ui::BUT_UNDO);
1695 if (false == button_active_only(C, region, block, but)) {
1696 /* Note that this is the only place where we can also handle a cancelled renaming. */
1697
1698 file_params_rename_end(wm, win, sfile, file);
1699
1700 /* After the rename button is removed, we need to make sure the view is redrawn once more,
1701 * in case selection changed. Usually UI code would trigger that redraw, but the rename
1702 * operator may have been called from a different region.
1703 * Tagging regions for redrawing while drawing is rightfully prevented. However, this
1704 * active button removing basically introduces handling logic to drawing code. So a
1705 * notifier should be an acceptable workaround. */
1707
1708 file_selflag = filelist_entry_select_get(sfile->files, file, CHECK_ALL);
1709 }
1710 }
1711
1712 /* file_selflag might have been modified by branch above. */
1713 if ((file_selflag & FILE_SEL_EDITING) == 0) {
1714 if (layout->text_lines_count == 1) {
1715 file_draw_string(text_rect.xmin,
1716 text_rect.ymax,
1717 file->name,
1718 BLI_rcti_size_x(&text_rect),
1719 BLI_rcti_size_y(&text_rect),
1720 align,
1721 text_col);
1722 }
1723 else {
1724 file_draw_string_mulitline_clipped(&text_rect, file->name, align, text_col);
1725 }
1726 }
1727
1729 if (params->display != FILE_IMGDISPLAY) {
1730 draw_details_columns(params, layout, file, &tile_draw_rect, text_col);
1731 }
1732 }
1733
1734 if (numfiles < 1) {
1735 const rcti tile_draw_rect = tile_draw_rect_get(v2d, layout, 0);
1736 const uiStyle *style = ui::style_get();
1737
1738 const bool is_filtered = params->filter_search[0] != '\0';
1739
1740 uchar text_col_mod[4];
1741 copy_v4_v4_uchar(text_col_mod, text_col);
1742 if (!is_filtered) {
1743 text_col_mod[3] /= 2;
1744 }
1745
1746 const char *message = [&]() {
1747 if (!filelist_is_ready(files)) {
1748 return IFACE_("Loading...");
1749 }
1750 if (is_filtered) {
1751 return IFACE_("No results match the search filter");
1752 }
1754 if (asset_params && (asset_params->asset_access == AssetAccess::OnlyOnline)) {
1755 return IFACE_("No items. Note: The \"Only Online\" filter option is enabled.");
1756 }
1757 if (asset_params && (asset_params->asset_access == AssetAccess::OnlyOffline)) {
1758 return IFACE_("No items. Note: The \"Only Offline\" filter option is enabled.");
1759 }
1760 return IFACE_("No items");
1761 }();
1762
1764 tile_draw_rect.xmin + UI_UNIT_X,
1765 tile_draw_rect.ymax - UI_UNIT_Y,
1766 message,
1767 text_col_mod);
1768 }
1769
1771
1772 block_end(C, block);
1773 block_draw(C, block);
1774
1775 /* Draw last, on top of file list. */
1776 if (draw_columnheader) {
1778 draw_columnheader_columns(params, layout, v2d, text_col);
1779 }
1780
1781 if (numfiles != -1) {
1782 /* Only save current size if there is something to show. */
1783 layout->curr_size = layout->width;
1784 }
1785}
1786
1787void file_draw_banner(const bContext *C, const SpaceFile *sfile, ARegion *region)
1788{
1789 /* Passed into lambda as block ID-name. */
1790 static const char *funcname = __func__;
1791
1792 file_banners_for_first_visible(*sfile, [&](const BannerType &banner) {
1794
1795 ui::Block *block = block_begin(C, region, funcname, ui::EmbossType::Emboss);
1796 ui::Layout &layout = ui::block_layout(
1797 block,
1800 sfile->layout->tile_border_x,
1801 -sfile->layout->tile_border_y + region->v2d.cur.ymax,
1802 std::max(0, region->winx - 2 * sfile->layout->tile_border_x),
1803 0,
1804 0,
1806
1807 banner.layout(*sfile, layout.row(false));
1808
1809 block_layout_resolve(block);
1810 block_end(C, block);
1811 block_draw(C, block);
1812 });
1813}
1814
1816 const SpaceFile *sfile,
1817 ARegion *region,
1818 FileAssetSelectParams *asset_params,
1819 bool is_project_library)
1820{
1821 char library_ui_path[FILE_MAX_LIBEXTRA];
1822 file_path_to_ui_path(asset_params->base_params.dir, library_ui_path, sizeof(library_ui_path));
1823
1824 uchar text_col[4];
1826
1827 const View2D *v2d = &region->v2d;
1828 const int pad = sfile->layout->tile_border_x;
1829 const int width = BLI_rctf_size_x(&v2d->tot) - (2 * pad);
1830 const int line_height = sfile->layout->text_line_height;
1831 int sx = v2d->tot.xmin + pad;
1832 /* For some reason no padding needed. */
1833 int sy = v2d->tot.ymax;
1834
1835 {
1836 const char *message = RPT_("Path to asset library does not exist:");
1837 file_draw_string_multiline(sx, sy, message, width, line_height, text_col, nullptr, &sy);
1838
1839 sy -= line_height;
1841 sx, sy, library_ui_path, width, line_height, ui::UI_STYLE_TEXT_LEFT, text_col);
1842 }
1843
1844 /* Separate a bit further. */
1845 sy -= line_height * 2.2f;
1846
1847 {
1848 ui::icon_draw(sx, sy - UI_UNIT_Y, ICON_STATUS_INFO);
1849
1850 const char *suggestion = RPT_(
1851 "Asset Libraries are local directories that can contain .blend files with assets inside.\n"
1852 "Manage Asset Libraries from the Asset Libraries section in the Preferences");
1854 sx + UI_UNIT_X, sy, suggestion, width - UI_UNIT_X, line_height, text_col, nullptr, &sy);
1855
1856 ui::Block *block = block_begin(C, region, __func__, ui::EmbossType::Emboss);
1857 wmOperatorType *ot;
1858 if (is_project_library) {
1859 ot = WM_operatortype_find("SCREEN_OT_project_settings_show", false);
1860 }
1861 else {
1862 ot = WM_operatortype_find("SCREEN_OT_userpref_show", false);
1863 }
1864 ui::Button *but = uiDefIconTextButO_ptr(block,
1866 ot,
1868 ICON_PREFERENCES,
1869 WM_operatortype_name(ot, nullptr),
1870 sx + UI_UNIT_X,
1871 sy - line_height - UI_UNIT_Y * 1.2f,
1872 UI_UNIT_X * 8,
1873 UI_UNIT_Y,
1874 std::nullopt);
1875 PointerRNA *but_opptr = button_operator_ptr_ensure(but);
1876 if (is_project_library) {
1877 RNA_string_set(but_opptr, "section", "Asset Libraries");
1878 }
1879 else {
1880 RNA_enum_set(but_opptr, "section", USER_SECTION_ASSETS);
1881 }
1882
1883 block_end(C, block);
1884 block_draw(C, block);
1885 }
1886}
1887
1889 const SpaceFile *sfile,
1890 ARegion *region)
1891{
1892 using namespace blender;
1893
1894 uchar text_col[4];
1896
1897 const View2D *v2d = &region->v2d;
1898 const int pad_x = sfile->layout->tile_border_x * 2;
1899 const int pad_y = sfile->layout->tile_border_y * 2;
1900 const int available_width = BLI_rctf_size_x(&v2d->tot) - (2 * pad_x);
1901 const int line_height = sfile->layout->text_line_height;
1902 const char *message = RPT_(
1903 "Allow Online Access in order to browse and download online assets, or turn off the "
1904 "\"Remote Assets\" filter to show only the downloaded assets.\n\nYou can adjust this "
1905 "later from the \"System\" preferences.");
1906
1907 const int box_width = std::min(available_width, UI_UNIT_X * 28);
1908 /* The width we have available inside the box. */
1909 const int wrap_width = box_width - 2 * pad_x;
1910 const rcti message_textbox = file_measure_string_multiline(message, wrap_width);
1911 /* The text box doesn't seem to encompass all text, apparently half a line too little. */
1912 const int message_height = BLI_rcti_size_y(&message_textbox) + 0.5f * line_height;
1913
1914 const int heading_height = UI_UNIT_Y;
1915 const int box_height = heading_height + message_height +
1916 /* Extra spacing after header and after main message. */
1917 2 * pad_y +
1918 /* Button height. */
1919 UI_UNIT_Y +
1920 /* Top and bottom padding. */
1921 2 * pad_y;
1922
1923 int sx = round_fl_to_int(BLI_rctf_cent_x(&v2d->tot) - box_width / 2.0f);
1924 int sy = round_fl_to_int(BLI_rctf_cent_y(&v2d->tot) + box_height / 2.0f);
1925
1926 ui::Block *block = ui::block_begin(C, region, __func__, ui::EmbossType::Emboss);
1927
1928 uiDefBut(block,
1930 "",
1931 sx,
1932 sy - box_height,
1933 box_width,
1934 box_height,
1935 nullptr,
1936 0.0,
1937 0.0,
1938 "");
1939
1940 /* Top left padding within the box. */
1941 sx += pad_x;
1942 sy -= pad_y;
1943
1944 {
1945 uiDefIconTextBut(block,
1947 ICON_INTERNET_OFFLINE,
1948 "Internet Access Required",
1949 sx,
1950 sy - heading_height,
1951 wrap_width,
1952 heading_height,
1953 nullptr,
1954 {});
1955
1956 const int button_width = (wrap_width - pad_x) * 0.5f;
1957 ui::Button *but = uiDefIconTextButO(block,
1959 "WM_OT_context_set_boolean",
1961 ICON_X,
1962 "Continue Offline",
1963 sx,
1964 sy + pad_y - box_height + pad_y,
1965 button_width,
1966 UI_UNIT_Y,
1967 {});
1969 RNA_string_set(but_opptr, "data_path", "preferences.extensions.use_online_access_handled");
1970 RNA_boolean_set(but_opptr, "value", true);
1971
1972 uiDefIconTextButO(block,
1974 "extensions.userpref_allow_online",
1976 ICON_CHECKMARK,
1977 "Allow Online Access",
1978 sx + button_width + pad_x,
1979 sy + pad_y - box_height + pad_y,
1980 button_width,
1981 UI_UNIT_Y,
1982 {});
1983 }
1984
1985 ui::block_end(C, block);
1986 ui::block_draw(C, block);
1987
1988 /* Draw multi-line text on top of widget drawing. */
1990 sy - heading_height - pad_y,
1991 message,
1992 wrap_width,
1993 line_height,
1994 text_col,
1995 nullptr,
1996 nullptr);
1997}
1998
2000 const SpaceFile *sfile,
2001 ARegion *region,
2003{
2004 using namespace blender;
2005
2006 uchar text_col[4];
2008
2009 const View2D *v2d = &region->v2d;
2010 const int pad_x = sfile->layout->tile_border_x * 2;
2011 const int pad_y = sfile->layout->tile_border_y * 2;
2012 const int available_width = BLI_rctf_size_x(&v2d->tot) - (2 * pad_x);
2013 const int line_height = sfile->layout->text_line_height;
2014 StringRefNull message =
2015 RemoteLibraryLoadingStatus::failure_message(library->remote_url).value_or("Unknown reason");
2016
2017 const int message_width = ui::fontstyle_string_width(&ui::style_get()->widget, message.c_str());
2018 const int box_width = std::min({available_width, UI_UNIT_X * 28, message_width + (2 * pad_x)});
2019 /* The width we have available inside the box. */
2020 const int wrap_width = box_width - 2 * pad_x;
2021 const rcti message_textbox = file_measure_string_multiline(message, wrap_width);
2022 /* The text box doesn't seem to encompass all text, apparently half a line too little. */
2023 const int message_height = BLI_rcti_size_y(&message_textbox) + 0.5f * line_height;
2024
2025 const int heading_height = UI_UNIT_Y;
2026 const int box_height = heading_height + message_height +
2027 /* Extra spacing after header. */
2028 pad_y +
2029 /* Top and bottom padding. */
2030 2 * pad_y;
2031
2032 int sx = round_fl_to_int(BLI_rctf_cent_x(&v2d->tot) - box_width / 2.0f);
2033 int sy = round_fl_to_int(BLI_rctf_cent_y(&v2d->tot) + box_height / 2.0f);
2034
2035 ui::Block *block = ui::block_begin(C, region, __func__, ui::EmbossType::Emboss);
2036
2037 uiDefBut(block,
2039 "",
2040 sx,
2041 sy - box_height,
2042 box_width,
2043 box_height,
2044 nullptr,
2045 0.0,
2046 0.0,
2047 "");
2048
2049 /* Top left padding within the box. */
2050 sx += pad_x;
2051 sy -= pad_y;
2052
2053 {
2054 uiDefIconTextBut(block,
2056 ICON_STATUS_ERROR_FILLED,
2057 "Asset Library Download Failed",
2058 sx,
2059 sy - heading_height,
2060 wrap_width,
2061 heading_height,
2062 nullptr,
2063 {});
2064 }
2065
2066 ui::block_end(C, block);
2067 ui::block_draw(C, block);
2068
2069 /* Draw multi-line text on top of widget drawing. */
2071 sy - heading_height - pad_y,
2072 message,
2073 wrap_width,
2074 line_height,
2075 text_col,
2076 nullptr,
2077 nullptr);
2078}
2079
2081 const SpaceFile *sfile,
2082 ARegion *region,
2083 const char *blendfile_path,
2084 ReportList *reports)
2085{
2086 uchar text_col[4];
2088
2089 const View2D *v2d = &region->v2d;
2090 const int pad = sfile->layout->tile_border_x;
2091 const int width = BLI_rctf_size_x(&v2d->tot) - (2 * pad);
2092 const int line_height = sfile->layout->text_line_height;
2093 int sx = v2d->tot.xmin + pad;
2094 /* For some reason no padding needed. */
2095 int sy = v2d->tot.ymax;
2096
2097 {
2098 const char *message = RPT_("Unreadable Blender library file:");
2099 file_draw_string_multiline(sx, sy, message, width, line_height, text_col, nullptr, &sy);
2100
2101 sy -= line_height;
2102 file_draw_string(sx, sy, blendfile_path, width, line_height, ui::UI_STYLE_TEXT_LEFT, text_col);
2103 }
2104
2105 /* Separate a bit further. */
2106 sy -= line_height * 2.2f;
2107
2108 for (Report &report : reports->list) {
2109 const short report_type = report.type;
2110 if (report_type <= RPT_INFO) {
2111 continue;
2112 }
2113
2114 int icon = ICON_STATUS_INFO;
2115 if (report_type > RPT_WARNING) {
2116 icon = ICON_STATUS_WARNING_FILLED;
2117 }
2118 ui::icon_draw(sx, sy - UI_UNIT_Y, icon);
2119
2121 sy,
2122 RPT_(report.message),
2123 width - UI_UNIT_X,
2124 line_height,
2125 text_col,
2126 nullptr,
2127 &sy);
2128 sy -= line_height;
2129 }
2130}
2131
2133 const AssetLibraryReference &asset_library_ref)
2134{
2135 if (asset_library_ref.type != ASSET_LIBRARY_CUSTOM) {
2136 return nullptr;
2137 }
2138
2140 &U, asset_library_ref.custom_library_index);
2141 if (!library) {
2142 return nullptr;
2143 }
2144
2145 return library;
2146}
2147
2149 const SpaceFile *sfile,
2150 ARegion *region,
2151 const auto setup_view)
2152{
2154
2156
2157 if (!library) {
2158 /* We do not need to draw or check for any error in non user defined asset libraries.
2159 * This is because we do not expect the paths to ever be invalid for these.
2160 */
2161 return false;
2162 }
2163
2164 const bool is_remote_library = library->flag & ASSET_LIBRARY_USE_REMOTE_URL;
2165 const bool is_project_library = library->flag & ASSET_LIBRARY_PROJECT_DEFINED;
2166
2167 if (is_remote_library) {
2168 /* With remote libraries, there may be already-downloaded assets available that should be
2169 * displayed. Don't show the "internet access required" hint until done loading, and only if
2170 * there are no already-downloaded assets to display. */
2171 if (!filelist_is_ready(sfile->files) || !filelist_files_num_entries(sfile->files)) {
2172 return false;
2173 }
2174
2175 const bool is_online_allowed = G.f & G_FLAG_INTERNET_ALLOW;
2176 const bool was_choice_made = U.extension_flag & USER_EXTENSION_FLAG_ONLINE_ACCESS_HANDLED;
2177 if (!is_online_allowed && !was_choice_made) {
2178 setup_view();
2180 return true;
2181 }
2184 {
2185 setup_view();
2187 return true;
2188 }
2189 }
2190
2191 const bool is_on_disk_library = !ELEM(asset_params->asset_library_ref.type,
2194 !is_remote_library;
2195
2196 /* Check if the asset library exists. */
2197 if (is_on_disk_library && !filelist_is_dir(sfile->files, asset_params->base_params.dir)) {
2198 setup_view();
2199 file_draw_invalid_asset_library_hint(C, sfile, region, asset_params, is_project_library);
2200 return true;
2201 }
2202
2203 /* We didn't draw any messages. */
2204 return false;
2205}
2206
2207bool file_draw_hint_if_invalid(const bContext *C, const SpaceFile *sfile, ARegion *region)
2208{
2209 char blendfile_path[FILE_MAX_LIBEXTRA];
2210 const bool is_asset_browser = ED_fileselect_is_asset_browser(sfile);
2211 const bool is_library_browser = !is_asset_browser &&
2212 filelist_islibrary(sfile->files, blendfile_path, nullptr);
2213 /* Call this before drawing a hint, otherwise drawing will not be visible. */
2214 const auto setup_view = [region]() {
2215 ui::view2d_totRect_set(&region->v2d, region->winx, region->winy);
2216 ui::view2d_view_ortho(&region->v2d);
2217 };
2218
2219 if (is_asset_browser && show_asset_library_message(C, sfile, region, setup_view)) {
2220 return true;
2221 }
2222
2223 /* Check if the blendfile library is valid (has entries). */
2224 if (is_library_browser) {
2225 if (!filelist_is_ready(sfile->files)) {
2226 return false;
2227 }
2228
2229 const int numfiles = filelist_files_num_entries(sfile->files);
2230 if (numfiles > 0) {
2231 return false;
2232 }
2233
2234 /* This could all be part of the file-list loading:
2235 * - When loading fails this could be saved in the file-list, e.g. when
2236 * `BLO_blendhandle_from_file()` returns null in `filelist_readjob_list_lib()`, a
2237 * `FL_HAS_INVALID_LIBRARY` file-list flag could be set.
2238 * - Reports from it could also be stored in `FileList` rather than being ignored
2239 * (`RPT_STORE` must be set!).
2240 * - Then we could just check for `is_library_browser` and the `FL_HAS_INVALID_LIBRARY` flag
2241 * here, and draw the hint with the reports in the file-list. (We would not draw a hint for
2242 * recursive loading, even if the file-list has the "has invalid library" flag set, which
2243 * seems like the wanted behavior.)
2244 * - The call to BKE_blendfile_is_readable() would not be needed then.
2245 */
2246 if (!sfile->runtime->is_blendfile_status_set) {
2249 blendfile_path, &sfile->runtime->is_blendfile_readable_reports);
2250 sfile->runtime->is_blendfile_status_set = true;
2251 }
2252 if (!sfile->runtime->is_blendfile_readable) {
2253 setup_view();
2255 C, sfile, region, blendfile_path, &sfile->runtime->is_blendfile_readable_reports);
2256 return true;
2257 }
2258 }
2259
2260 return false;
2261}
2262
2263} // namespace blender
Main runtime representation of an asset.
File and directory operations.
#define FILE_ATTR_ANY_LINK
Some types for dealing with directories.
#define FILE_MAXFILE
#define FILE_MAX
#define BLI_path_join(...)
#define FILENAME_IS_CURRPAR(_n)
#define BLI_STR_FORMAT_UINT64_GROUPED_SIZE
Definition BLI_string.hh:22
#define SNPRINTF_UTF8(dst, format,...)
#define STRNCPY_UTF8(dst, src)
Compatibility-like things for windows.
external readfile function prototypes.
#define RPT_(msgid)
#define TIP_(msgid)
#define IFACE_(msgid)
#define FILE_MAX_LIBEXTRA
#define UI_SCALE_FAC
#define UI_ICON_SIZE
#define FILE_LAYOUT_HOR
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define UI_UNIT_Y
#define UI_UNIT_X
#define ICON_DEFAULT_HEIGHT
#define ICON_DEFAULT_WIDTH_SCALE
#define UI_NO_ICON_OVERLAY_TEXT
#define PREVIEW_DRAG_DRAW_SIZE
#define ICON_DEFAULT_HEIGHT_SCALE
#define ICON_DEFAULT_WIDTH
#define ND_SPACE_FILE_PREVIEW
Definition WM_types.hh:583
#define ND_SPACE_FILE_PARAMS
Definition WM_types.hh:566
#define NC_SPACE
Definition WM_types.hh:405
int pad[32 - sizeof(int)]
#define UNUSED_VARS_NDEBUG(...)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
#define STREQ(a, b)
void draw(float x, float y, int img_w, int img_h, gpu::TextureFormat gpu_format, bool use_filter, const void *rect, float scale_x, float scale_y, const float color[4])
Definition glutil.cc:45
constexpr const char * c_str() const
void ensure_previewable(const bContext &C, ReportList *reports=nullptr)
static std::optional< StringRefNull > failure_message(StringRef url)
static std::optional< RemoteLibraryLoadingStatus::Status > status(StringRef url)
constexpr const T * data() const
#define str(s)
#define FILE_LAYOUT_COMPACT(_layout)
#define ATTRIBUTE_COLUMN_PADDING
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
float3x3 scale(float3x3 mat, float2 scale)
std::string datetime(const std::tm &date_time, StringRef locale_iso={}, DateFormat date_format=DateFormat::Default, TimeFormat time_format=TimeFormat::H24, const std::tm *now=nullptr, StringRef today={}, StringRef yesterday={})
std::tm localtime_safe(time_t time)
std::string date(const std::tm &date_time, StringRef locale_iso={}, DateFormat format=DateFormat::Default)
void asset_tooltip(const asset_system::AssetRepresentation &asset, ui::TooltipData &tip, const bool include_name)
void operator_asset_reference_props_set(const asset_system::AssetRepresentation &asset, PointerRNA &ptr)
BIFIconID asset_preview_or_icon(const asset_system::AssetRepresentation &asset)
std::string filename(const std::string_view &str, size_t pos)
void get_color_4ubv(int colorid, unsigned char col[4])
void get_color_4fv(int colorid, float col[4])
void get_color_shade_3fv(int colorid, int offset, float col[3])
const bTheme * theme_get()
void view2d_view_ortho(const View2D *v2d)
Definition view2d.cc:1080
void view2d_totRect_set(View2D *v2d, int width, int height)
Definition view2d.cc:1021
const uiStyle * style_get()
int fontstyle_string_width(const uiFontStyle *fs, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
PointerRNA * button_operator_ptr_ensure(Button *but)
void icon_draw_ex(float x, float y, int icon_id, float aspect, float alpha, float desaturate, const uchar mono_color[4], bool mono_border, const IconTextOverlay *text_overlay, const bool inverted=false, float scale=1.0f)
void button_icon_scale_set(Button *but, float scale)
float text_clip_middle_ex(const uiFontStyle *fstyle, char *str, float okwidth, float minwidth, size_t str_maxncpy, char rpart_sep, bool clip_right_if_tight=true, bool shorten_template_variables=false)
const uiStyle * style_get_dpi()
void draw_icon_tri(float x, float y, char dir, const float[4], float aspect=1.0f)
Block * block_begin(const bContext *C, ARegion *region, std::string name, EmbossType emboss)
void icon_render_id_ex(const bContext *C, Scene *scene, ID *id_to_render, const enum eIconSizes size, const bool use_job, PreviewImage *r_preview_image)
void fontstyle_draw_simple(const uiFontStyle *fs, float x, float y, const char *str, const uchar col[4])
void draw_roundbox_4fv_ex(const rctf *rect, const float inner1[4], const float inner2[4], float shade_dir, const float outline[4], float outline_width, float rad)
void block_draw(const bContext *C, Block *block)
void block_end(const bContext *C, Block *block, bool postpone_callbacks=false)
void icon_draw(float x, float y, int icon_id)
Layout & block_layout(Block *block, LayoutDirection direction, LayoutType type, int x, int y, int size, int em, int padding, const uiStyle *style)
@ BUT_TEXTEDIT_AUTOCOMPLETE_KEEP_ACTIVE
void button_pushbutton_draw_as_overlay_set(Button *but, bool value)
BMesh Iterators.
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void WM_global_reportf(eReportType type, const char *format,...)
void BLF_boundbox(int fontid, const char *str, size_t str_len, rcti *r_box, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
Definition blf.cc:805
int ED_fileselect_layout_offset(FileLayout *layout, int x, int y)
Definition filesel.cc:853
void WM_report_banner_show(wmWindowManager *wm, wmWindow *win)
MINLINE void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
void file_draw_check_cb(bContext *C, void *arg1, void *arg2)
Definition file_ops.cc:1799
void immUniformThemeColorBlend(int color_id1, int color_id2, float fac)
char * STRNCPY(char(&dst)[N], const char *src)
ImBuf * IMB_font_preview(const char *filepath, unsigned int width, const float color[4], const char *sample_text=nullptr)
static void file_draw_invalid_asset_library_hint(const bContext *C, const SpaceFile *sfile, ARegion *region, FileAssetSelectParams *asset_params, bool is_project_library)
int ED_fileselect_layout_numfiles(FileLayout *layout, ARegion *region)
Definition filesel.cc:767
void WM_event_add_notifier_ex(wmWindowManager *wm, const wmWindow *win, uint type, void *reference)
@ ICON_SIZE_PREVIEW
@ RPT_WARNING
Definition BKE_report.hh:40
static void file_draw_asset_library_remote_loading_failed_hint(const bContext *C, const SpaceFile *sfile, ARegion *region, const bUserAssetLibrary *library)
void immEnd()
FileLayout * ED_fileselect_get_layout(SpaceFile *sfile, ARegion *region)
Definition filesel.cc:1185
bool filelist_cache_previews_update(FileList *filelist)
Definition filelist.cc:1743
static rcti file_measure_string_multiline(const StringRef string, const int wrap_width)
Definition file_draw.cc:631
static void file_draw_loading_icon(const rcti *tile_draw_rect, const float preview_icon_aspect, const FileLayout *layout)
Definition file_draw.cc:955
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
std::string WM_operatortype_name(wmOperatorType *ot, PointerRNA *properties)
ImBuf * filelist_file_get_preview_image(const FileDirEntry *file)
Definition filelist.cc:284
bool filelist_is_dir(const FileList *filelist, const char *path)
Definition filelist.cc:1128
MINLINE int round_fl_to_int(float a)
MINLINE unsigned char srgb_to_grayscale_byte(const unsigned char rgb[3])
short BLO_version_from_file(const char *filepath)
Definition readfile.cc:1485
@ ASSET_LIBRARY_PROJECT_DEFINED
@ ASSET_LIBRARY_USE_REMOTE_URL
static rcti text_draw_rect_get(const View2D *v2d, const eFileDisplayType display_type, const FileLayout *layout, const int file_idx, const int icon_ofs_x)
void BLF_wordwrap(int fontid, int wrap_width, BLFWrapMode mode=BLFWrapMode::Minimal)
Definition blf.cc:957
void WM_event_timer_remove_notifier(wmWindowManager *wm, wmWindow *win, wmTimer *timer)
void imm_draw_box_checker_2d(float x1, float y1, float x2, float y2, bool clear_alpha=false)
void filelist_online_asset_preview_request(const bContext *C, FileDirEntry *entry)
Definition filelist.cc:722
void immAttrSkip(uint attr_id)
GPUVertFormat * immVertexFormat()
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
bool ED_fileselect_is_asset_browser(const SpaceFile *sfile)
Definition filesel.cc:486
bool BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:404
void BLF_batch_draw_begin()
Definition blf.cc:536
bool file_draw_hint_if_invalid(const bContext *C, const SpaceFile *sfile, ARegion *region)
void immBegin(GPUPrimType, uint vertex_len)
ImBuf * IMB_thumb_read(const char *file_or_lib_path, ThumbSize size)
Definition thumbs.cc:567
struct bUserAssetLibrary * BKE_preferences_asset_library_find_index(const struct UserDef *userdef, int index) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
void ED_fileselect_layout_tilepos(const FileLayout *layout, int tile, int *x, int *y)
Definition filesel.cc:905
wmWindow * CTX_wm_window(const bContext *C)
@ FILE_BROWSE_MODE_ASSETS
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
void BKE_reports_clear(ReportList *reports)
Definition report.cc:118
void file_directory_enter_handle(bContext *C, void *arg_unused, void *arg_but)
Definition file_ops.cc:2954
static void file_draw_tooltip_custom_func(bContext &, ui::TooltipData &tip, ui::Button *, void *argN)
Definition file_draw.cc:157
static const bUserAssetLibrary * assetlib_ref_as_library(const AssetLibraryReference &asset_library_ref)
void immUniformColor4fv(const float rgba[4])
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
static void renamebutton_cb(bContext &C, StringRefNull oldname)
int filelist_geticon_file_type(FileList *filelist, int index, bool is_main)
Definition filelist.cc:439
MINLINE float srgb_to_grayscale(const float rgb[3])
int autocomplete_directory(bContext *C, char *str, void *arg_v)
Definition filesel.cc:1266
void BLF_disable(int fontid, FontFlags flag)
Definition blf.cc:331
void MEM_delete_void(void *vmemh)
@ ASSET_LIBRARY_CUSTOM
@ ASSET_LIBRARY_LOCAL
@ USER_EXTENSION_FLAG_ONLINE_ACCESS_HANDLED
eDirEntry_SelectFlag filelist_entry_select_get(FileList *filelist, FileDirEntry *entry, FileCheckType check)
Definition filelist.cc:2066
void immUnbindProgram()
void BLI_rctf_rcti_copy(struct rctf *dst, const struct rcti *src)
wmTimer * WM_event_timer_add_notifier(wmWindowManager *wm, wmWindow *win, const uint type, const double time_step)
@ GPU_BLEND_NONE
Definition GPU_state.hh:88
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:90
@ GPU_BLEND_ALPHA_PREMULT
Definition GPU_state.hh:91
static void file_draw_string_multiline(int sx, int sy, const StringRef string, int wrap_width, int line_height, const uchar text_col[4], int *r_sx, int *r_sy)
Definition file_draw.cc:656
void file_path_to_ui_path(const char *path, char *r_path, int r_path_maxncpy)
Definition file_utils.cc:36
Global G
Definition blender.cc:57
@ FILE_ATTR_HIDDEN
@ FILE_ATTR_READONLY
@ FILE_ATTR_OFFLINE
@ FILE_ATTR_SYSTEM
@ FILE_ATTR_RESTRICTED
void immAttr3fv(uint attr_id, const float data[3])
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.hh:207
static ui::Button * file_add_icon_but(const SpaceFile *sfile, ui::Block *block, const char *, const FileDirEntry *file, const rcti *tile_draw_rect, int icon, int width, int height, int padx, bool dimmed)
Definition file_draw.cc:503
bool BKE_blendfile_is_readable(const char *path, ReportList *reports)
Definition blendfile.cc:157
void void BLI_path_split_dir_part(const char *filepath, char *dir, size_t dir_maxncpy) ATTR_NONNULL(1
void IMB_freeImBuf(ImBuf *ibuf)
void file_params_rename_end(wmWindowManager *wm, wmWindow *win, SpaceFile *sfile, const FileDirEntry *rename_file)
Definition filesel.cc:1406
FileDirEntry * filelist_file(FileList *filelist, int index)
Definition filelist.cc:1349
void immVertex2f(uint attr_id, float x, float y)
bool filelist_cache_previews_done(FileList *filelist)
Definition filelist.cc:1812
unsigned char uchar
Definition BKE_text.h:58
int BLI_rename(const char *from, const char *to) ATTR_NONNULL()
Definition fileops_c.cc:474
void file_banners_for_first_visible(const SpaceFile &sfile, FunctionRef< void(const BannerType &)> fn)
static const char * filelist_get_details_column_string(FileAttributeColumnType column, FileDirEntry *file, const bool compact, const bool update_stat_strings)
@ CHECK_ALL
Definition filelist.hh:45
static void draw_background(FileLayout *layout, View2D *v2d)
BMesh const char void * data
static std::tuple< int, int, float > preview_image_scaled_dimensions_get(const int image_width, const int image_height, const FileLayout &layout)
Definition file_draw.cc:705
ImBuf * filelist_geticon_special_file_image_ex(const FileDirEntry *file)
Definition filelist.cc:300
bool filelist_islibrary(FileList *filelist, char *dir, char **r_group)
Definition filelist.cc:2120
wmWindowManager * CTX_wm_manager(const bContext *C)
bool filelist_file_cache_block(FileList *filelist, int index)
Definition filelist.cc:1502
bool filelist_is_ready(const FileList *filelist)
Definition filelist.cc:1220
void ED_fileselect_clear(wmWindowManager *wm, SpaceFile *sfile)
Definition filesel.cc:1335
void immUniformThemeColorShade(int color_id, int offset)
int ED_fileselect_asset_import_method_get(const SpaceFile *sfile, const FileDirEntry *file)
Definition filesel.cc:531
static void draw_columnheader_columns(const FileSelectParams *params, FileLayout *layout, const View2D *v2d, const uchar text_col[4])
static void draw_details_columns(const FileSelectParams *params, const FileLayout *layout, FileDirEntry *file, const rcti *tile_draw_rect, const uchar text_col[4])
static void file_but_enable_drag(ui::Button *but, const SpaceFile *sfile, const FileDirEntry *file, const char *path, const ImBuf *preview_image, int icon, float scale)
Definition file_draw.cc:446
@ FILE_ASSET_IMPORT_INSTANCE_COLLECTIONS_ON_APPEND
@ FILE_ASSET_IMPORT_INSTANCE_COLLECTIONS_ON_LINK
static void file_draw_string(int sx, int sy, const char *string, float width, int height, ui::FontStyleAlign align, const uchar col[4])
Definition file_draw.cc:578
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
static void file_draw_preview(const FileDirEntry *file, const rcti *tile_draw_rect, const IconBufferRef &preview, FileLayout *layout, const bool dimmed)
Definition file_draw.cc:797
void file_params_invoke_rename_postscroll(wmWindowManager *wm, wmWindow *win, SpaceFile *sfile)
Definition filesel.cc:1393
BlendHandle * filelist_lib(FileList *filelist)
Definition filelist.cc:1063
int filelist_files_ensure(FileList *filelist)
Definition filelist.cc:1235
FileAttributeColumnType
@ ATTRIBUTE_COLUMN_MAX
static void draw_fixed_header_background(const View2D *v2d, const float height)
static rcti tile_draw_rect_get(const View2D *v2d, const FileLayout *layout, const int file_idx)
void ED_file_path_button(bScreen *screen, SpaceFile *sfile, FileSelectParams *params, ui::Block *block)
Definition file_draw.cc:94
MINLINE void copy_v4_v4_uchar(unsigned char r[4], const unsigned char a[4])
FileSelectParams * ED_fileselect_get_active_params(const SpaceFile *sfile)
Definition filesel.cc:393
void BLF_batch_draw_end()
Definition blf.cc:549
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.hh:203
void file_draw_list(const bContext *C, ARegion *region)
static void file_draw_invalid_library_hint(const bContext *, const SpaceFile *sfile, ARegion *region, const char *blendfile_path, ReportList *reports)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
static void file_add_preview_drag_but(const SpaceFile *sfile, ui::Block *block, const FileDirEntry *file, const char *path, const rcti *tile_draw_rect, const int file_type_icon)
Definition file_draw.cc:737
int BIFIconID
Definition ED_asset.hh:30
@ THB_SOURCE_IMAGE
Definition IMB_thumbs.hh:33
@ THB_SOURCE_MOVIE
Definition IMB_thumbs.hh:34
static void file_but_tooltip_func_set(const SpaceFile *sfile, const FileDirEntry *file, ui::Button *but)
Definition file_draw.cc:488
SpaceLink * CTX_wm_space_data(const bContext *C)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
static ui::Button * file_add_overlay_icon_but(ui::Block *block, int pos_x, int pos_y, int icon)
Definition file_draw.cc:556
bool filelist_file_is_preview_pending(const FileList *filelist, const FileDirEntry *file)
Definition filelist.cc:261
static void file_add_asset_download_but(ui::Block *block, const FileLayout *layout, const FileDirEntry *file, const rcti *tile_draw_rect)
Definition file_draw.cc:769
FileAssetSelectParams * ED_fileselect_get_asset_params(const SpaceFile *sfile)
Definition filesel.cc:416
ImBuf * IMB_thumb_manage(const char *file_or_lib_path, ThumbSize size, ThumbSource source, const ThumbCancellationToken *cancel_token=nullptr)
Definition thumbs.cc:601
@ G_FLAG_INTERNET_ALLOW
static void file_draw_indicator_icons(const FileList *files, const FileDirEntry *file, const FileLayout *layout, const rcti *tile_draw_rect, const float preview_icon_aspect, const int file_type_icon, const bool has_special_file_image, const eDirEntry_SelectFlag file_selflag)
Definition file_draw.cc:978
ATTR_WARN_UNUSED_RESULT const BMVert * v2
static void file_draw_special_image(const FileDirEntry *file, const rcti *tile_draw_rect, const int file_type_icon, const float icon_aspect, const FileLayout *layout, const bool dimmed, eDirEntry_SelectFlag file_selflag)
Definition file_draw.cc:878
void imm_draw_box_wire_2d(uint pos, float x1, float y1, float x2, float y2)
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition BLI_rect.hh:211
void file_draw_banner(const bContext *C, const SpaceFile *sfile, ARegion *region)
static void file_draw_asset_library_internet_access_required_hint(const bContext *C, const SpaceFile *sfile, ARegion *region)
bool filelist_cache_previews_running(FileList *filelist)
Definition filelist.cc:1805
ID * filelist_file_get_id(const FileDirEntry *file)
Definition filelist.cc:1409
const char * BLT_lang_get()
Definition blt_lang.cc:268
BLI_INLINE float BLI_rctf_cent_y(const struct rctf *rct)
Definition BLI_rect.hh:198
static void draw_dividers(FileLayout *layout, View2D *v2d)
@ FILE_TYPE_ASSET_ONLINE
@ FILE_TYPE_BLENDER_BACKUP
bool IMB_metadata_get_field(const IDProperty *metadata, const char *key, char *value, size_t value_maxncpy)
void filelist_file_cache_slidingwindow_set(FileList *filelist, size_t window_size)
Definition filelist.cc:1442
PointerRNA RNA_pointer_create_with_parent(const PointerRNA &parent, StructRNA *type, void *data)
SpaceFile * CTX_wm_space_file(const bContext *C)
MINLINE void copy_v4_v4(float r[4], const float a[4])
void GPU_blend(GPUBlend blend)
Definition gpu_state.cc:44
bool BLI_path_make_safe_filename(char *filename) ATTR_NONNULL(1)
BLI_INLINE int BLI_rcti_cent_x(const struct rcti *rct)
Definition BLI_rect.hh:186
static void draw_tile_background(const rcti *draw_rect, bool is_selected, bool is_highlighted)
Definition file_draw.cc:401
void immVertex2fv(uint attr_id, const float data[2])
bool file_attribute_column_type_enabled(const FileSelectParams *params, FileAttributeColumnType column, const FileLayout *layout)
Definition filesel.cc:931
void filelist_file_get_full_path(const FileList *filelist, const FileDirEntry *file, char r_filepath[1282])
MINLINE int min_ii(int a, int b)
static void file_draw_asset_tooltip_custom_func(bContext &, ui::TooltipData &tip, ui::Button *, void *argN)
Definition file_draw.cc:392
static FileTooltipData * file_tooltip_data_create(const SpaceFile *sfile, const FileDirEntry *file)
Definition file_draw.cc:149
void immRectf(uint pos, float x1, float y1, float x2, float y2)
ARegion * CTX_wm_region(const bContext *C)
BLI_INLINE float BLI_rctf_cent_x(const struct rctf *rct)
Definition BLI_rect.hh:194
int filelist_files_num_entries(FileList *filelist)
Definition filelist.cc:1068
std::optional< IconBufferRef > BKE_icon_get_buffer(int icon_id, eIconSizes size)
Definition icons.cc:454
void BLF_enable(int fontid, FontFlags flag)
Definition blf.cc:322
@ BLF_WORD_WRAP
Definition BLF_enums.hh:42
static void file_draw_string_mulitline_clipped(const rcti *rect, const char *string, ui::FontStyleAlign align, const uchar col[4])
Definition file_draw.cc:616
@ BIFICONID_LAST_STATIC
MINLINE void rgba_float_to_uchar(unsigned char r_col[4], const float col_f[4])
size_t BLI_str_format_uint64_grouped(char dst[BLI_STR_FORMAT_UINT64_GROUPED_SIZE], uint64_t num) ATTR_NONNULL(1)
static bool show_asset_library_message(const bContext *C, const SpaceFile *sfile, ARegion *region, const auto setup_view)
void BLI_filelist_entry_size_to_string(const struct stat *st, uint64_t st_size_fallback, bool compact, char r_size[FILELIST_DIRENTRY_SIZE_LEN])
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
uiWidgetColors wcol_list_item
uiWidgetColors wcol_tooltip
ThemeUI tui
void(*) layout(const SpaceFile &, ui::Layout &)
AssetLibraryReference asset_library_ref
eFileAssetImportFlags import_flags
asset_system::AssetRepresentation * asset
struct blender::FileDirEntry::@160236320132271345207305066317263254357061006370 draw_data
FileAttributeColumn attribute_columns[ATTRIBUTE_COLUMN_MAX]
eFileSel_Params_Flag flag
const FileDirEntry * file
Definition file_draw.cc:146
const SpaceFile * sfile
Definition file_draw.cc:145
Span< uint8_t > buffer
Definition BKE_icons.hh:127
const IDProperty * metadata() const
ListBaseT< Report > list
Definition BKE_report.hh:79
const char * message
Definition BKE_report.hh:73
ReportList is_blendfile_readable_reports
eFileBrowse_Mode browse_mode
FileSelectParams * params
struct FileLayout * layout
struct wmTimer * previews_timer
SpaceFile_Runtime * runtime
FileAssetSelectParams * asset_params
struct FileList * files
Layout & row(bool align)
TooltipImageBackground background
uiFontStyle widget
unsigned char inner_sel[4]
unsigned char inner[4]
unsigned char outline[4]
unsigned char outline_sel[4]
unsigned char text[4]
unsigned char text_sel[4]
unsigned char shaded