Blender V5.3
asset_shelf.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include <algorithm>
12#include <cfloat>
13
15#include "AS_asset_library.hh"
17
18#include "BLI_function_ref.hh"
19#include "BLI_listbase.hh"
20#include "BLI_string_utf8.hh"
21
22#include "BKE_context.hh"
23#include "BKE_idtype.hh"
24#include "BKE_main.hh"
25#include "BKE_screen.hh"
26
27#include "BLT_translation.hh"
28
29#include "DNA_screen_types.h"
30
31#include "ED_asset_list.hh"
32#include "ED_screen.hh"
33
34#include "RNA_access.hh"
35#include "RNA_prototypes.hh"
36
37#include "UI_interface.hh"
39#include "UI_resources.hh"
40#include "UI_tree_view.hh"
41#include "UI_view2d.hh"
42
43#include "WM_api.hh"
44#include "WM_message.hh"
45
46#include "ED_asset_shelf.hh"
47#include "asset_shelf.hh"
48
50
52
57
58/* -------------------------------------------------------------------- */
61
63{
65 return shelf_types;
66}
67
68void type_register(std::unique_ptr<AssetShelfType> type)
69{
71 shelf_types.append(std::move(type));
72}
73
74void type_unregister(const AssetShelfType &shelf_type)
75{
77 auto *const it = std::find_if(shelf_types.begin(),
78 shelf_types.end(),
79 [&](const std::unique_ptr<AssetShelfType> &iter_type) {
80 return iter_type.get() == &shelf_type;
81 });
82 BLI_assert(it != shelf_types.end());
83
84 shelf_types.remove(it - shelf_types.begin());
85}
86
87static bool type_poll_no_spacetype_check(const bContext &C, const AssetShelfType *shelf_type)
88{
89 if (!shelf_type) {
90 return false;
91 }
92
93#ifndef NDEBUG
95 BLI_assert_msg(std::find_if(shelf_types.begin(),
96 shelf_types.end(),
97 [&](const std::unique_ptr<AssetShelfType> &type) {
98 return type.get() == shelf_type;
99 }) != shelf_types.end(),
100 "Asset shelf type is not registered");
101#endif
102
103 return !shelf_type->poll || shelf_type->poll(&C, shelf_type);
104}
105
106bool type_poll_for_popup(const bContext &C, const AssetShelfType *shelf_type)
107{
108 return type_poll_no_spacetype_check(C, shelf_type);
109}
110
118 const AssetShelfType *shelf_type,
119 const int space_type)
120{
121 if (!shelf_type) {
122 return false;
123 }
124 if (shelf_type->space_type && (space_type != shelf_type->space_type)) {
125 return false;
126 }
127
128 return type_poll_no_spacetype_check(C, shelf_type);
129}
130
131bool type_asset_poll(const AssetShelfType &shelf_type,
133{
134
135 if (shelf_type.id_types_prefilter != 0) {
136 const uint64_t id_filter = BKE_idtype_idcode_to_idfilter(asset.get_id_type());
137 if ((shelf_type.id_types_prefilter & id_filter) == 0) {
138 return false;
139 }
140 }
141
142 if (shelf_type.asset_poll && !shelf_type.asset_poll(&shelf_type, &asset)) {
143 return false;
144 }
145
146 return true;
147}
148
150{
151 for (const std::unique_ptr<AssetShelfType> &shelf_type : static_shelf_types()) {
152 if (idname == shelf_type->idname) {
153 return shelf_type.get();
154 }
155 }
156 return nullptr;
157}
158
160{
161 if (shelf.type) {
162 return shelf.type;
163 }
164
165 for (const std::unique_ptr<AssetShelfType> &shelf_type : static_shelf_types()) {
166 if (STREQ(shelf.idname, shelf_type->idname)) {
167 shelf.type = shelf_type.get();
168 return shelf_type.get();
169 }
170 }
171
172 return nullptr;
173}
174
176{
177 AssetShelf *shelf = MEM_new<AssetShelf>(__func__);
179 shelf->settings.preview_size = type.default_preview_size ? type.default_preview_size :
181 shelf->settings.asset_library_reference = asset_system::all_library_reference();
182 shelf->type = &type;
183 shelf->preferred_row_count = 1;
184 STRNCPY_UTF8(shelf->idname, type.idname);
185 return shelf;
186}
187
189
190/* -------------------------------------------------------------------- */
193
199static void activate_shelf(RegionAssetShelf &shelf_regiondata, AssetShelf &shelf)
200{
201 shelf_regiondata.active_shelf = &shelf;
202 BLI_assert(BLI_findindex(&shelf_regiondata.shelves, &shelf) > -1);
203 BLI_remlink(&shelf_regiondata.shelves, &shelf);
204 BLI_addhead(&shelf_regiondata.shelves, &shelf);
205}
206
229 const eSpace_Type space_type,
230 RegionAssetShelf &shelf_regiondata,
231 FunctionRef<void(AssetShelf &new_shelf)> on_create,
232 FunctionRef<void(AssetShelf &shelf)> on_reactivate)
233{
234 /* NOTE: Don't access #AssetShelf.type directly, use #type_ensure(). */
235
236 /* Case 1: */
237 if (shelf_regiondata.active_shelf &&
239 C, ensure_shelf_has_type(*shelf_regiondata.active_shelf), space_type))
240 {
241 /* Not a strong precondition, but if this is wrong something weird might be going on. */
242 BLI_assert(shelf_regiondata.active_shelf == shelf_regiondata.shelves.first_);
243 return shelf_regiondata.active_shelf;
244 }
245
246 /* Case 2 (no active shelf or the poll of it isn't succeeding anymore. Poll all shelf types to
247 * determine a new active one): */
248 for (AssetShelf &shelf : shelf_regiondata.shelves) {
249 if (&shelf == shelf_regiondata.active_shelf) {
250 continue;
251 }
252
254 /* Found a valid previously activated shelf, reactivate it. */
255 activate_shelf(shelf_regiondata, shelf);
256 if (on_reactivate) {
257 on_reactivate(shelf);
258 }
259 return &shelf;
260 }
261 }
262
263 /* Case 3: */
264 for (const std::unique_ptr<AssetShelfType> &shelf_type : static_shelf_types()) {
265 if (type_poll_for_non_popup(C, shelf_type.get(), space_type)) {
266 AssetShelf *new_shelf = create_shelf_from_type(*shelf_type);
267 BLI_addhead(&shelf_regiondata.shelves, new_shelf);
268 /* Moves ownership to the regiondata. */
269 activate_shelf(shelf_regiondata, *new_shelf);
270 if (on_create) {
271 on_create(*new_shelf);
272 }
273 return new_shelf;
274 }
275 }
276
277 shelf_regiondata.active_shelf = nullptr;
278 return nullptr;
279}
280
282
283/* -------------------------------------------------------------------- */
286
287void *region_duplicate(void *regiondata)
288{
289 const RegionAssetShelf *shelf_regiondata = static_cast<RegionAssetShelf *>(regiondata);
290 if (!shelf_regiondata) {
291 return nullptr;
292 }
293
294 return regiondata_duplicate(shelf_regiondata);
295}
296
297void region_free(ARegion *region)
298{
299 RegionAssetShelf *shelf_regiondata = RegionAssetShelf::get_from_asset_shelf_region(*region);
300 if (shelf_regiondata) {
301 regiondata_free(shelf_regiondata);
302 }
303 region->regiondata = nullptr;
304}
305
310static bool asset_shelf_space_poll(const bContext *C, const SpaceLink *space_link)
311{
312 /* Is there any asset shelf type registered that returns true for it's poll? */
313 for (const std::unique_ptr<AssetShelfType> &shelf_type : static_shelf_types()) {
314 if (type_poll_for_non_popup(*C, shelf_type.get(), space_link->spacetype)) {
315 return true;
316 }
317 }
318
319 return false;
320}
321
323{
324 return asset_shelf_space_poll(params->context, params->area->spacedata.first());
325}
326
328{
329 ARegion *region = params->region;
330 const wmNotifier *wmn = params->notifier;
331
332 switch (wmn->category) {
333 case NC_SPACE:
334 if (wmn->data == ND_REGIONS_ASSET_SHELF) {
335 ED_region_tag_redraw(region);
336 }
337 break;
338 case NC_SCENE:
339 /* Asset shelf polls typically check the mode. */
340 if (ELEM(wmn->data, ND_MODE)) {
341 ED_region_tag_redraw(region);
342 }
343 break;
344 case NC_ASSET:
345 ED_region_tag_redraw(region);
346 break;
347 }
348}
349
351{
352 if (list::listen(params->notifier)) {
354 }
355 /* If the asset list didn't catch the notifier, let the region itself listen. */
356 else {
358 }
359}
360
362{
363 wmMsgBus *mbus = params->message_bus;
364 WorkSpace *workspace = params->workspace;
365 ARegion *region = params->region;
366
367 wmMsgSubscribeValue msg_sub_value_region_tag_redraw{};
368 msg_sub_value_region_tag_redraw.owner = region;
369 msg_sub_value_region_tag_redraw.user_data = region;
370 msg_sub_value_region_tag_redraw.notify = ED_region_do_msg_notify_tag_redraw;
372 mbus, &workspace->id, workspace, WorkSpace, tools, &msg_sub_value_region_tag_redraw);
373
374 {
375 wmMsgSubscribeValue msg_sub_value_region_clear_remote_libraries{};
376 msg_sub_value_region_clear_remote_libraries.owner = region;
377 msg_sub_value_region_clear_remote_libraries.user_data = region;
378 msg_sub_value_region_clear_remote_libraries.notify = [](/* Follow wmMsgNotifyFn spec */
379 bContext *C,
380 wmMsgSubscribeKey * /*msg_key*/,
381 wmMsgSubscribeValue *msg_val) {
382 ARegion *region = static_cast<ARegion *>(msg_val->owner);
383 RegionAssetShelf *shelf_regiondata = RegionAssetShelf::get_from_asset_shelf_region(*region);
384 AssetShelf *active_shelf = shelf_regiondata->active_shelf;
386 active_shelf->settings.asset_library_reference))
387 {
389 }
390 };
392 nullptr,
393 &U,
394 PreferencesSystem,
395 use_online_access,
396 &msg_sub_value_region_clear_remote_libraries);
398 nullptr,
399 &U,
400 PreferencesExperimental,
401 use_remote_asset_libraries,
402 &msg_sub_value_region_clear_remote_libraries);
403 }
404}
405
407{
408 /* Region-data should've been created by a previously called #region_on_poll_success(). */
409 RegionAssetShelf *shelf_regiondata = RegionAssetShelf::get_from_asset_shelf_region(*region);
411 shelf_regiondata,
412 "Region-data should've been created by a previously called `region_on_poll_success()`.");
413
414 AssetShelf *active_shelf = shelf_regiondata->active_shelf;
415
416 view2d_region_reinit(&region->v2d, ui::V2D_COMMONVIEW_PANELS_UI, region->winx, region->winy);
417
418 wmKeyMap *keymap = WM_keymap_ensure(
419 wm->runtime->defaultconf, "View2D Buttons List", SPACE_EMPTY, RGN_TYPE_WINDOW);
421
424 region->v2d.keepofs |= V2D_KEEPOFS_Y;
425
427 region->v2d.page_size_y = active_shelf ? tile_height(active_shelf->settings) :
429
430 /* Ensure the view is snapped to a page still, especially for DPI changes. */
432}
433
435{
436 const uiStyle *style = ui::style_get_dpi();
437 return style->buttonspacey / 2;
438}
439
441{
442 /* Use the same as the height, equal padding looks nice. */
443 return main_region_padding_y();
444}
445
446static int current_tile_draw_height(const ARegion *region)
447{
448 const RegionAssetShelf *shelf_regiondata = RegionAssetShelf::get_from_asset_shelf_region(
449 *region);
450 const float aspect = BLI_rctf_size_y(&region->v2d.cur) /
451 (BLI_rcti_size_y(&region->v2d.mask) + 1);
452
453 /* It can happen that this function is called before the region is actually initialized, when
454 * user clicks & drags slightly on the 'up arrow' icon of the shelf. */
455 const AssetShelf *active_shelf = shelf_regiondata ? shelf_regiondata->active_shelf : nullptr;
456 return (active_shelf ? tile_height(active_shelf->settings) : asset_shelf_default_tile_height()) /
457 (IS_EQF(aspect, 0) ? 1.0f : aspect);
458}
459
463static int calculate_row_count_from_tile_draw_height(const int region_height_scaled,
464 const int tile_draw_height)
465{
466 return std::max(1, int((region_height_scaled - 2 * main_region_padding_y()) / tile_draw_height));
467}
468
470 const int tile_draw_height)
471{
472 return (row_count * tile_draw_height + 2 * main_region_padding_y());
473}
474
475int region_snap(const ARegion *region, const int size, const int axis)
476{
477 /* Only on Y axis. */
478 if (axis != 1) {
479 return size;
480 }
481
482 /* Using scaled values only simplifies things. Simply divide the result by the scale again. */
483
484 const int tile_height = current_tile_draw_height(region);
485
486 const int row_count = calculate_row_count_from_tile_draw_height(size * UI_SCALE_FAC,
488
489 const int new_size_scaled = calculate_scaled_region_height_from_row_count(row_count,
491 return new_size_scaled / UI_SCALE_FAC;
492}
493
499static void region_resize_to_preferred(ScrArea *area, ARegion *region)
500{
501 const RegionAssetShelf *shelf_regiondata = RegionAssetShelf::get_from_asset_shelf_region(
502 *region);
503 const AssetShelf *active_shelf = shelf_regiondata->active_shelf;
504
505 BLI_assert(active_shelf->preferred_row_count > 0);
506 const int tile_height = current_tile_draw_height(region);
507
508 /* Prevent the AssetShelf from getting too high (and thus being hidden) in case many rows are
509 * used and preview size is increased. */
510 const int size_y_avail = ED_area_max_regionsize(area, region, AE_TOP_TO_BOTTOMRIGHT);
511 const short int max_row_count = calculate_row_count_from_tile_draw_height(
512 size_y_avail * UI_SCALE_FAC, tile_height);
513
515 std::min(max_row_count, active_shelf->preferred_row_count),
516 tile_height) /
518
519 if (region->sizey != new_size_y) {
520 region->sizey = new_size_y;
521 ED_area_tag_region_size_update(area, region);
522 }
523}
524
526{
527 const RegionAssetShelf *shelf_regiondata = RegionAssetShelf::get_from_asset_shelf_region(
528 *region);
529 AssetShelf *active_shelf = shelf_regiondata->active_shelf;
530 if (!active_shelf) {
531 return;
532 }
533
534 const int tile_height = current_tile_draw_height(region);
536 region->sizey * UI_SCALE_FAC, tile_height);
537}
538
539int tile_width(const AssetShelfSettings &settings)
540{
541 return ui::preview_tile_size_x(settings.preview_size);
542}
543
550
555
557{
558 /* One row by default (plus padding). */
560}
561
562void region_layout(const bContext *C, ARegion *region)
563{
564 RegionAssetShelf *shelf_regiondata = RegionAssetShelf::get_from_asset_shelf_region(*region);
566 shelf_regiondata,
567 "Region-data should've been created by a previously called `region_on_poll_success()`.");
568
569 AssetShelf *active_shelf = shelf_regiondata->active_shelf;
570 if (!active_shelf) {
571 return;
572 }
573
575
576 ui::Block *block = block_begin(C, region, __func__, ui::EmbossType::Emboss);
577
578 const uiStyle *style = ui::style_get_dpi();
579 const int padding_y = main_region_padding_y();
580 const int padding_x = main_region_padding_x();
581 ui::Layout &layout = ui::block_layout(block,
584 padding_x,
585 -padding_y,
586 region->winx - 2 * padding_x,
587 0,
588 0,
589 style);
590
591 build_asset_view(layout, active_shelf->settings.asset_library_reference, *active_shelf, *C);
592
593 int layout_height = ui::block_layout_resolve(block).y;
594 BLI_assert(layout_height <= 0);
595 ui::view2d_totRect_set(&region->v2d, region->winx - 1, layout_height - padding_y);
597
599
600 /* View2D matrix might have changed due to dynamic sized regions.
601 * Without this, tooltips jump around, see #129347. Reason is that #button_tooltip_refresh() is
602 * called as part of #block_end(), so the block's window matrix needs to be up-to-date. */
603 {
604 ui::view2d_view_ortho(&region->v2d);
606 }
607
608 block_end(C, block);
609}
610
611void region_draw(const bContext *C, ARegion *region)
612{
613 ED_region_clear(C, region, TH_BACK);
614
615 /* Set view2d view matrix for scrolling. */
616 ui::view2d_view_ortho(&region->v2d);
617
618 /* View2D matrix might have changed due to dynamic sized regions. */
620
622
623 /* Restore view matrix. */
625
626 ui::view2d_scrollers_draw(&region->v2d, nullptr);
627}
628
630{
631 RegionAssetShelf *shelf_regiondata = RegionAssetShelf::ensure_from_asset_shelf_region(*region);
632 if (!shelf_regiondata) {
634 return;
635 }
636
637 const int old_region_flag = region->flag;
638
639 ScrArea *area = CTX_wm_area(C);
641 *C,
642 eSpace_Type(area->spacetype),
643 *shelf_regiondata,
644 /*on_create=*/
645 [&](AssetShelf &new_shelf) {
646 /* Set region visibility for first time shelf is created (`'DEFAULT_VISIBLE'` option). */
647 SET_FLAG_FROM_TEST(region->flag,
648 (new_shelf.type->flag & ASSET_SHELF_TYPE_FLAG_DEFAULT_VISIBLE) == 0,
649 RGN_FLAG_HIDDEN);
650 },
651 /*on_reactivate=*/
652 [&](AssetShelf &shelf) {
653 /* Restore region visibility from previous asset shelf instantiation when reactivating. */
654 SET_FLAG_FROM_TEST(
655 region->flag, shelf.instance_flag & ASSETSHELF_REGION_IS_HIDDEN, RGN_FLAG_HIDDEN);
656 });
657
658 if (old_region_flag != region->flag) {
659 ED_region_visibility_change_update(const_cast<bContext *>(C), area, region);
660 }
661
662 if (shelf_regiondata->active_shelf) {
663 /* Remember current visibility state of the region in the shelf, so we can restore it on
664 * reactivation. */
668 }
669}
670
675
682
687
689{
690 /* Use a height that lets widgets sit just on top of the separator line drawn at the lower edge
691 * of the region (widgets will be centered).
692 *
693 * Note that this is usually a bit less than the header size. The asset shelf tends to look like
694 * a separate area, so making the shelf header smaller than a header helps. */
696}
697
699{
700 RegionAssetShelf *shelf_regiondata = RegionAssetShelf::get_from_asset_shelf_region(*region);
701 if (!shelf_regiondata) {
702 return;
703 }
704 regiondata_blend_read_data(reader, &shelf_regiondata);
705 region->regiondata = shelf_regiondata;
706}
707
709{
710 RegionAssetShelf *shelf_regiondata = RegionAssetShelf::get_from_asset_shelf_region(*region);
711 if (!shelf_regiondata) {
712 return;
713 }
714 regiondata_blend_write(writer, shelf_regiondata);
715}
716
718
719/* -------------------------------------------------------------------- */
722
724{
725 const ARegion *shelf_region = BKE_area_find_region_type(area, RGN_TYPE_ASSET_SHELF);
726 if (!shelf_region) {
727 /* Called in wrong context, area doesn't have a shelf. */
728 return nullptr;
729 }
730
731 if (shelf_region->flag & RGN_FLAG_POLL_FAILED) {
732 /* Don't return data when the region "doesn't exist" (poll failed). */
733 return nullptr;
734 }
735
736 const RegionAssetShelf *shelf_regiondata = RegionAssetShelf::get_from_asset_shelf_region(
737 *shelf_region);
738 if (!shelf_regiondata) {
739 return nullptr;
740 }
741
742 return shelf_regiondata->active_shelf;
743}
744
745int context(const bContext *C, const char *member, bContextDataResult *result)
746{
747 static const char *context_dir[] = {
748 "asset_shelf",
749 "asset_library_reference",
750 "asset",
751 nullptr,
752 };
753
754 if (CTX_data_dir(member)) {
755 CTX_data_dir_set(result, context_dir);
756 return CTX_RESULT_OK;
757 }
758
759 bScreen *screen = CTX_wm_screen(C);
760
761 if (CTX_data_equals(member, "asset_shelf")) {
763 if (!active_shelf) {
764 return CTX_RESULT_NO_DATA;
765 }
766
767 CTX_data_pointer_set(result, &screen->id, RNA_AssetShelf, active_shelf);
768 return CTX_RESULT_OK;
769 }
770
771 if (CTX_data_equals(member, "asset_library_reference")) {
773 if (!active_shelf) {
774 return CTX_RESULT_NO_DATA;
775 }
777 CTX_data_pointer_set(result, &screen->id, RNA_AssetLibraryReference, &library_ref);
778 return CTX_RESULT_OK;
779 }
780
781 if (CTX_data_equals(member, "asset")) {
782 const ARegion *region = CTX_wm_region(C);
784 if (!but) {
785 return CTX_RESULT_NO_DATA;
786 }
787
788 const bContextStore *but_context = button_context_get(but);
789 if (!but_context) {
790 return CTX_RESULT_NO_DATA;
791 }
792
793 const PointerRNA *asset_ptr = CTX_store_ptr_lookup(
794 but_context, "asset", RNA_AssetRepresentation);
795 if (!asset_ptr) {
796 return CTX_RESULT_NO_DATA;
797 }
798
800 return CTX_RESULT_OK;
801 }
802
804}
805
807{
808 return CTX_data_pointer_get_type(C, "asset_shelf", RNA_AssetShelf);
809}
810
812{
813 PointerRNA shelf_settings_ptr = active_shelf_ptr_from_context(C);
814 return static_cast<AssetShelf *>(shelf_settings_ptr.data);
815}
816
818
819/* -------------------------------------------------------------------- */
822
824{
825 const uiStyle *style = ui::style_get_dpi();
826 const int string_width = ui::fontstyle_string_width(&style->widget, name.c_str());
827 const int pad_x = UI_UNIT_X * 0.3f;
828 const int but_width = std::min(string_width + 2 * pad_x, UI_UNIT_X * 8);
829
830 ui::Button *but = uiDefBut(
831 &block,
833 name,
834 0,
835 0,
836 but_width,
837 UI_UNIT_Y,
838 nullptr,
839 0,
840 0,
841 TIP_("Enable catalog, making contained assets visible in the asset shelf"));
842
843 button_drawflag_enable(but, ui::BUT_ALIGN_DOWN);
844 button_flag_disable(but, ui::BUT_UNDO);
845
846 return but;
847}
848
850{
851 ui::Block *block = layout.block();
852 AssetShelfSettings &shelf_settings = shelf.settings;
853
854 /* "All" tab. */
855 {
856 ui::Button *but = add_tab_button(*block, IFACE_("All"));
857 button_func_set(but, [&shelf_settings](bContext &C) {
858 settings_set_all_catalog_active(shelf_settings);
860 });
861 button_func_pushed_state_set(but, [&shelf_settings](const ui::Button &) -> bool {
862 return settings_is_all_catalog_active(shelf_settings);
863 });
864 }
865
866 layout.separator();
867
868 /* Regular catalog tabs. */
870 ui::Button *but = add_tab_button(*block, path.name());
871
872 button_func_set(but, [&shelf_settings, path](bContext &C) {
873 settings_set_active_catalog(shelf_settings, path);
875 });
876 button_func_pushed_state_set(but, [&shelf_settings, path](const ui::Button &) -> bool {
877 return settings_is_active_catalog(shelf_settings, path);
878 });
879 });
880}
881
883
884/* -------------------------------------------------------------------- */
889
890static void asset_shelf_header_draw(const bContext *C, Header *header)
891{
892 ui::Layout &layout = *header->layout;
893 ui::Block *block = layout.block();
895
896 list::storage_fetch(library_ref, C);
897
898 block_emboss_set(block, ui::EmbossType::None);
899 layout.popover(C, "ASSETSHELF_PT_catalog_selector", "", ICON_COLLAPSEMENU);
900 block_emboss_set(block, ui::EmbossType::Emboss);
901
902 layout.separator();
903
905 if (AssetShelf *shelf = static_cast<AssetShelf *>(shelf_ptr.data)) {
906 add_catalog_tabs(*shelf, layout);
907 }
908
909 layout.separator_spacer();
910
911 layout.popover(C, "ASSETSHELF_PT_display", "", ICON_IMGDISPLAY);
912 ui::Layout &sub = layout.row(false);
913 /* Same as file/asset browser header. */
914 sub.ui_units_x_set(8);
915 sub.prop(&shelf_ptr, "search_filter", UI_ITEM_NONE, "", ICON_VIEWZOOM);
916}
917
918static void header_regiontype_register(ARegionType *region_type, const int space_type)
919{
921 STRNCPY_UTF8(ht->idname, "ASSETSHELF_HT_settings");
922 ht->space_type = space_type;
925 ht->poll = [](const bContext *C, HeaderType *) {
927 };
928
929 BLI_addtail(&region_type->headertypes, ht);
930}
931
932void types_register(ARegionType *region_type, const int space_type)
933{
934 header_regiontype_register(region_type, space_type);
936 popover_panel_register(region_type);
937}
938
940
941/* -------------------------------------------------------------------- */
944
945void type_unlink(const Main &bmain, const AssetShelfType &shelf_type)
946{
947 for (bScreen &screen : bmain.screens) {
948 for (ScrArea &area : screen.areabase) {
949 for (SpaceLink &sl : area.spacedata) {
950 ListBaseT<ARegion> *regionbase = (&sl == area.spacedata.first_) ? &area.regionbase :
951 &sl.regionbase;
952 for (ARegion &region : *regionbase) {
953 if (region.regiontype != RGN_TYPE_ASSET_SHELF) {
954 continue;
955 }
956
957 RegionAssetShelf *shelf_regiondata = RegionAssetShelf::get_from_asset_shelf_region(
958 region);
959 if (!shelf_regiondata) {
960 continue;
961 }
962 for (AssetShelf &shelf : shelf_regiondata->shelves) {
963 if (shelf.type == &shelf_type) {
964 shelf.type = nullptr;
965 }
966 }
967
968 BLI_assert((shelf_regiondata->active_shelf == nullptr) ||
969 (shelf_regiondata->active_shelf->type != &shelf_type));
970 }
971 }
972 }
973 }
974
975 type_popup_unlink(shelf_type);
976}
977
979
980/* -------------------------------------------------------------------- */
983
985{
987 for (wmWindow &win : wm->windows) {
988 const bScreen *screen = WM_window_get_active_screen(&win);
989 for (ScrArea &area : screen->areabase) {
992 }
993 }
994 }
995}
996
998
999} // namespace blender::ed::asset::shelf
Main runtime representation of an asset.
#define ASSET_SHELF_PREVIEW_SIZE_DEFAULT
#define STRNCPY_UTF8(dst, src)
#define TIP_(msgid)
#define IFACE_(msgid)
#define UI_SCALE_FAC
#define C
Definition RandGen.cpp:29
#define UI_UNIT_Y
#define UI_BUTTON_SECTION_SEPERATOR_LINE_WITH
#define UI_UNIT_X
#define UI_ITEM_NONE
#define ND_REGIONS_ASSET_SHELF
Definition WM_types.hh:586
#define ND_MODE
Definition WM_types.hh:464
#define NC_SCENE
Definition WM_types.hh:391
#define NC_ASSET
Definition WM_types.hh:417
#define NC_SPACE
Definition WM_types.hh:405
#define BLI_assert_unreachable()
#define SET_FLAG_FROM_TEST(value, test, flag)
#define ELEM(...)
#define IS_EQF(a, b)
#define BLI_assert_msg(a, msg)
#define STREQ(a, b)
constexpr const char * c_str() const
void append(const T &value)
void remove(const int64_t index)
AssetLibraryReference all_library_reference()
bool is_or_contains_remote_libraries(const AssetLibraryReference &reference)
internal::ShallowZeroInitializeTag shallow_zero_initialize()
Definition DNA_defs.h:159
void storage_fetch(const AssetLibraryReference *library_reference, const bContext *C)
void clear(const AssetLibraryReference *library_reference, const bContext *C)
bool listen(const wmNotifier *notifier)
static bool asset_shelf_space_poll(const bContext *C, const SpaceLink *space_link)
static int asset_shelf_default_tile_height()
void header_region(const bContext *C, ARegion *region)
AssetShelfType * type_find_from_idname(StringRef idname)
void region_init(wmWindowManager *wm, ARegion *region)
void region_blend_read_data(BlendDataReader *reader, ARegion *region)
static int current_tile_draw_height(const ARegion *region)
bool settings_is_all_catalog_active(const AssetShelfSettings &settings)
AssetShelf * create_shelf_from_type(AssetShelfType &type)
void type_popup_unlink(const AssetShelfType &shelf_type)
void popover_panel_register(ARegionType *region_type)
AssetLibraryReference & settings_ensure_valid_library_ref(AssetShelfSettings &settings)
void types_register(ARegionType *region_type, const int space_type)
static Vector< std::unique_ptr< AssetShelfType > > & static_shelf_types()
void regiondata_free(RegionAssetShelf *shelf_regiondata)
static void header_regiontype_register(ARegionType *region_type, const int space_type)
void region_listen(const wmRegionListenerParams *params)
static int calculate_row_count_from_tile_draw_height(const int region_height_scaled, const int tile_draw_height)
void settings_foreach_enabled_catalog_path(const AssetShelf &shelf, FunctionRef< void(const asset_system::AssetCatalogPath &catalog_path)> fn)
void region_on_poll_success(const bContext *C, ARegion *region)
void catalog_selector_panel_register(ARegionType *region_type)
void header_region_listen(const wmRegionListenerParams *params)
static void asset_shelf_header_draw(const bContext *C, Header *header)
void settings_set_all_catalog_active(AssetShelfSettings &settings)
void type_unregister(const AssetShelfType &shelf_type)
void region_blend_write(BlendWriter *writer, ARegion *region)
void type_unlink(const Main &bmain, const AssetShelfType &shelf_type)
int tile_height(const AssetShelfSettings &settings)
AssetShelf * active_shelf_from_context(const bContext *C)
static AssetShelf * update_active_shelf(const bContext &C, const eSpace_Type space_type, RegionAssetShelf &shelf_regiondata, FunctionRef< void(AssetShelf &new_shelf)> on_create, FunctionRef< void(AssetShelf &shelf)> on_reactivate)
void regiondata_blend_write(BlendWriter *writer, const RegionAssetShelf *shelf_regiondata)
static PointerRNA active_shelf_ptr_from_context(const bContext *C)
static bool type_poll_for_non_popup(const bContext &C, const AssetShelfType *shelf_type, const int space_type)
void region_on_user_resize(const ARegion *region)
AssetShelfType * ensure_shelf_has_type(AssetShelf &shelf)
int context(const bContext *C, const char *member, bContextDataResult *result)
int tile_width(const AssetShelfSettings &settings)
int region_snap(const ARegion *region, int size, int axis)
void type_register(std::unique_ptr< AssetShelfType > type)
void build_asset_view(ui::Layout &layout, const AssetLibraryReference &library_ref, const AssetShelf &shelf, const bContext &C)
bool settings_is_active_catalog(const AssetShelfSettings &settings, const asset_system::AssetCatalogPath &path)
void show_catalog_in_visible_shelves(const bContext &C, const StringRefNull catalog_path)
void * region_duplicate(void *regiondata)
void send_redraw_notifier(const bContext &C)
bool type_poll_for_popup(const bContext &C, const AssetShelfType *shelf_type)
static void asset_shelf_region_listen(const wmRegionListenerParams *params)
void settings_set_catalog_path_enabled(AssetShelf &shelf, const asset_system::AssetCatalogPath &path)
AssetShelf * active_shelf_from_area(const ScrArea *area)
bool regions_poll(const RegionPollParams *params)
static void region_resize_to_preferred(ScrArea *area, ARegion *region)
static void add_catalog_tabs(AssetShelf &shelf, ui::Layout &layout)
void header_region_init(wmWindowManager *wm, ARegion *region)
static bool type_poll_no_spacetype_check(const bContext &C, const AssetShelfType *shelf_type)
static int main_region_padding_y()
void regiondata_blend_read_data(BlendDataReader *reader, RegionAssetShelf **shelf_regiondata)
void settings_set_active_catalog(AssetShelfSettings &settings, const asset_system::AssetCatalogPath &path)
static int main_region_padding_x()
void region_draw(const bContext *C, ARegion *region)
void region_message_subscribe(const wmRegionMessageSubscribeParams *params)
RegionAssetShelf * regiondata_duplicate(const RegionAssetShelf *shelf_regiondata)
static ui::Button * add_tab_button(ui::Block &block, StringRefNull name)
static int calculate_scaled_region_height_from_row_count(const int row_count, const int tile_draw_height)
static void activate_shelf(RegionAssetShelf &shelf_regiondata, AssetShelf &shelf)
bool type_asset_poll(const AssetShelfType &shelf_type, const asset_system::AssetRepresentation &asset)
void region_layout(const bContext *C, ARegion *region)
void region_free(ARegion *region)
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
void view2d_curRect_validate(View2D *v2d)
Definition view2d.cc:810
void blocklist_update_window_matrix(const bContext *C, const ListBaseT< ui::Block > *lb)
void view2d_offset_y_snap_to_closest_page(View2D *v2d)
Definition view2d.cc:1977
int fontstyle_string_width(const uiFontStyle *fs, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
void view2d_view_restore(const bContext *C)
Definition view2d.cc:1147
int preview_tile_size_y_no_label(const int size_px=96)
void blocklist_draw(const bContext *C, const ListBaseT< ui::Block > *lb)
const uiStyle * style_get_dpi()
void view2d_scrollers_draw(View2D *v2d, const rcti *mask_custom)
Definition view2d.cc:1487
int2 block_layout_resolve(Block *block)
Button * region_views_find_active_item_but(const ARegion *region)
@ V2D_COMMONVIEW_PANELS_UI
Definition UI_view2d.hh:66
int preview_tile_size_y(const int size_px=96)
Layout & block_layout(Block *block, LayoutDirection direction, LayoutType type, int x, int y, int size, int em, int padding, const uiStyle *style)
int preview_tile_size_x(const int size_px=96)
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
uint64_t BKE_idtype_idcode_to_idfilter(short idcode)
Definition idtype.cc:473
unsigned __int64 uint64_t
Definition BKE_text.h:91
ScrArea * CTX_wm_area(const bContext *C)
const PointerRNA * CTX_store_ptr_lookup(const bContextStore *store, StringRef name, const StructRNA *type=nullptr)
void CTX_data_dir_set(bContextDataResult *result, const char **dir)
@ V2D_SNAP_TO_PAGESIZE_Y
int ED_area_max_regionsize(const ScrArea *area, const ARegion *scale_region, const AZEdge edge)
Definition area.cc:873
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:98
@ RGN_TYPE_ASSET_SHELF_HEADER
bool CTX_data_equals(const char *member, const char *str)
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
void ED_region_clear(const bContext *C, const ARegion *region, int colorid)
Definition area.cc:3181
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.hh:207
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
void ED_region_header_with_button_sections(const bContext *C, ARegion *region, ui::ButtonSectionsAlign align)
Definition area.cc:4398
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition BLI_rect.hh:215
wmWindowManager * CTX_wm_manager(const bContext *C)
void CTX_data_pointer_set_ptr(bContextDataResult *result, const PointerRNA *ptr)
void CTX_data_pointer_set(bContextDataResult *result, ID *id, StructRNA *type, void *data)
@ AE_TOP_TO_BOTTOMRIGHT
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:935
void ED_area_tag_region_size_update(ScrArea *area, ARegion *changed_region)
Definition area.cc:820
wmEventHandler_Keymap * WM_event_add_keymap_handler(ListBaseT< wmEventHandler > *handlers, wmKeyMap *keymap)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
bool CTX_data_dir(const char *member)
@ ASSETSHELF_REGION_IS_HIDDEN
void ED_region_visibility_change_update(bContext *C, ScrArea *area, ARegion *region)
Definition area.cc:2599
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:1024
SpaceLink * CTX_wm_space_data(const bContext *C)
@ V2D_SCROLL_VERTICAL_HIDE
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
void ED_region_header_init(ARegion *region)
Definition area.cc:4406
bScreen * CTX_wm_screen(const bContext *C)
@ RGN_FLAG_HIDDEN_BY_USER
@ RGN_FLAG_RESIZE_RESPECT_BUTTON_SECTIONS
@ CTX_RESULT_MEMBER_NOT_FOUND
@ CTX_RESULT_NO_DATA
void ED_region_do_msg_notify_tag_redraw(bContext *C, wmMsgSubscribeKey *msg_key, wmMsgSubscribeValue *msg_val)
Definition area.cc:394
bScreen * WM_window_get_active_screen(const wmWindow *win)
ARegion * CTX_wm_region(const bContext *C)
void ED_region_tag_redraw_no_rebuild(ARegion *region)
Definition area.cc:727
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
const AssetLibraryReference * CTX_wm_asset_library_ref(const bContext *C)
ListBaseT< HeaderType > headertypes
bke::ARegionRuntime * runtime
eRegion_Alignment alignment
AssetLibraryReference asset_library_reference
AssetShelfSettings_DisplayFlag display_flag
bool(*) poll(const bContext *C, const AssetShelfType *shelf_type)
bool(*) asset_poll(const AssetShelfType *shelf_type, const asset_system::AssetRepresentation *asset)
char idname[BKE_ST_MAXNAME]
AssetShelf_InstanceFlag instance_flag
struct AssetShelfType * type
AssetShelfSettings settings
bool(*) poll(const bContext *C, HeaderType *ht)
char idname[BKE_ST_MAXNAME]
void(*) draw(const bContext *C, Header *header)
ui::Layout * layout
ListBaseT< bScreen > screens
Definition BKE_main.hh:400
ListBaseT< AssetShelf > shelves
const bContext * context
ListBaseT< ARegion > regionbase
ListBaseT< SpaceLink > spacedata
eView2D_KeepOfs keepofs
eView2D_KeepZoom keepzoom
eView2D_Scroll scroll
ListBaseT< struct ScrArea > areabase
ListBaseT< wmEventHandler > handlers
ListBaseT< ui::Block > uiblocks
void ui_units_x_set(float width)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
Layout & row(bool align)
void popover(const bContext *C, PanelType *pt, std::optional< StringRef > name_opt, int icon)
unsigned int category
Definition WM_types.hh:371
unsigned int data
Definition WM_types.hh:371
short buttonspacey
uiFontStyle widget
#define WM_msg_subscribe_rna_prop(mbus, id_, data_, type_, prop_, value)