Blender V5.0
asset_ui_utils.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <string>
10
11#include "AS_asset_library.hh"
13
14#include "BKE_preferences.h"
15#include "BKE_preview_image.hh"
16
17#include "BLI_path_utils.hh"
18
19#include "BLT_translation.hh"
20
21#include "UI_interface_c.hh"
22#include "UI_interface_icons.hh"
23#include "UI_resources.hh"
24
25#include "DNA_userdef_types.h"
26
27#include "RNA_access.hh"
28
29#include "ED_asset.hh"
30
31namespace blender::ed::asset {
32
34 uiTooltipData &tip,
35 const bool include_name)
36{
37 if (include_name) {
40 }
41
42 const AssetMetaData &meta_data = asset.get_metadata();
43 if (meta_data.description) {
45 }
46
47 switch (asset.owner_asset_library().library_type()) {
50
51 const std::string full_blend_path = asset.full_library_path();
52
53 char dir[FILE_MAX], file[FILE_MAX];
54 BLI_path_split_dir_file(full_blend_path.c_str(), dir, sizeof(dir), file, sizeof(file));
55
56 if (file[0]) {
58 }
59 if (dir[0]) {
61 }
62 break;
63 }
67 tip, TIP_("Asset Library: Current File"), {}, UI_TIP_STYLE_NORMAL, UI_TIP_LC_VALUE);
68 break;
72 tip, TIP_("Asset Library: Essentials"), {}, UI_TIP_STYLE_NORMAL, UI_TIP_LC_VALUE);
73 break;
74 default:
75 /* Intentionally empty. */
76 break;
77 }
78}
79
81{
82 if (const PreviewImage *preview = asset.get_preview()) {
83 if (!BKE_previewimg_is_invalid(preview)) {
84 return preview->runtime->icon_id;
85 }
86 }
87
88 return ICON_NONE;
89}
90
92{
93 const BIFIconID preview_icon = asset_preview_icon_id(asset);
94 if (preview_icon != ICON_NONE) {
95 return preview_icon;
96 }
97
98 /* Preview image not found or invalid. Use type icon. */
99 return UI_icon_from_idcode(asset.get_id_type());
100}
101
103{
104 const int enum_value = RNA_enum_get(&ptr, "asset_library_reference");
107}
108
110{
111 const int enum_value = RNA_enum_get(&ptr, "asset_library_reference");
113}
114
116 const Main &bmain,
118 const StringRef edit_text,
119 const FunctionRef<void(StringPropertySearchVisitParams)> visit_fn)
120{
121 const asset_system::AssetLibrary *library = AS_asset_library_load(&bmain, lib);
122 if (!library) {
123 return;
124 }
125
126 if (!edit_text.is_empty()) {
127 const asset_system::AssetCatalogPath edit_path = edit_text;
128 if (!library->catalog_service().find_catalog_by_path(edit_path)) {
129 visit_fn(StringPropertySearchVisitParams{edit_path.str(), std::nullopt, ICON_ADD});
130 }
131 }
132
133 const asset_system::AssetCatalogTree &full_tree = library->catalog_service().catalog_tree();
134 full_tree.foreach_item([&](const asset_system::AssetCatalogTreeItem &item) {
135 visit_fn(StringPropertySearchVisitParams{item.catalog_path().str(), std::nullopt});
136 });
137}
138
139} // namespace blender::ed::asset
blender::asset_system::AssetLibrary * AS_asset_library_load(const Main *bmain, const AssetLibraryReference &library_reference)
Main runtime representation of an asset.
struct bUserAssetLibrary * BKE_preferences_asset_library_find_index(const struct UserDef *userdef, int index) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
bool BKE_previewimg_is_invalid(const PreviewImage *prv)
#define FILE_MAX
void BLI_path_split_dir_file(const char *filepath, char *dir, size_t dir_maxncpy, char *file, size_t file_maxncpy) ATTR_NONNULL(1
#define TIP_(msgid)
@ ASSET_LIBRARY_CUSTOM
@ ASSET_LIBRARY_ESSENTIALS
@ ASSET_LIBRARY_LOCAL
int BIFIconID
Definition ED_asset.hh:28
void UI_tooltip_text_field_add(uiTooltipData &data, std::string text, std::string suffix, const uiTooltipStyle style, const uiTooltipColorID color_id, const bool is_pad=false)
@ UI_TIP_STYLE_NORMAL
@ UI_TIP_STYLE_SPACER
@ UI_TIP_STYLE_HEADER
@ UI_TIP_LC_MAIN
@ UI_TIP_LC_VALUE
@ UI_TIP_LC_NORMAL
int UI_icon_from_idcode(int idcode)
#define U
constexpr bool is_empty() const
AssetCatalog * find_catalog_by_path(const AssetCatalogPath &path) const
void foreach_item(ItemIterFn callback) const
AssetCatalogService & catalog_service() const
AssetLibraryReference get_asset_library_ref_from_opptr(PointerRNA &ptr)
AssetLibraryReference library_reference_from_enum_value(int value)
void asset_tooltip(const asset_system::AssetRepresentation &asset, uiTooltipData &tip, const bool include_name)
void visit_library_catalogs_catalog_for_search(const Main &bmain, const AssetLibraryReference lib, const StringRef edit_text, const FunctionRef< void(StringPropertySearchVisitParams)> visit_fn)
const bUserAssetLibrary * get_asset_library_from_opptr(PointerRNA &ptr)
BIFIconID asset_preview_or_icon(const asset_system::AssetRepresentation &asset)
BIFIconID asset_preview_icon_id(const asset_system::AssetRepresentation &asset)
int RNA_enum_get(PointerRNA *ptr, const char *name)
The meta-data of an asset. By creating and giving this for a data-block (ID.asset_data),...
static DynamicLibrary lib
PointerRNA * ptr
Definition wm_files.cc:4238