Blender V4.5
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 "UI_interface_c.hh"
20#include "UI_interface_icons.hh"
21#include "UI_resources.hh"
22
23#include "DNA_userdef_types.h"
24#include "ED_asset.hh"
25#include "RNA_access.hh"
26
27namespace blender::ed::asset {
28
30 uiTooltipData &tip,
31 const bool include_name)
32{
33 if (include_name) {
36 }
37
38 const AssetMetaData &meta_data = asset.get_metadata();
39 if (meta_data.description) {
41 }
42
43 switch (asset.owner_asset_library().library_type()) {
46
47 const std::string full_blend_path = asset.full_library_path();
48
49 char dir[FILE_MAX], file[FILE_MAX];
50 BLI_path_split_dir_file(full_blend_path.c_str(), dir, sizeof(dir), file, sizeof(file));
51
52 if (file[0]) {
54 }
55 if (dir[0]) {
57 }
58 break;
59 }
63 tip, "Asset Library: Current File", {}, UI_TIP_STYLE_NORMAL, UI_TIP_LC_VALUE);
64 break;
68 tip, "Asset Library: Essentials", {}, UI_TIP_STYLE_NORMAL, UI_TIP_LC_VALUE);
69 break;
70 default:
71 /* Intentionally empty. */
72 break;
73 }
74}
75
77{
78 if (const PreviewImage *preview = asset.get_preview()) {
79 if (!BKE_previewimg_is_invalid(preview)) {
80 return preview->runtime->icon_id;
81 }
82 }
83
84 return ICON_NONE;
85}
86
88{
89 const BIFIconID preview_icon = asset_preview_icon_id(asset);
90 if (preview_icon != ICON_NONE) {
91 return preview_icon;
92 }
93
94 /* Preview image not found or invalid. Use type icon. */
95 return UI_icon_from_idcode(asset.get_id_type());
96}
97
99{
100 const int enum_value = RNA_enum_get(&ptr, "asset_library_reference");
103}
104
106{
107 const int enum_value = RNA_enum_get(&ptr, "asset_library_reference");
109}
110
112 const Main &bmain,
114 const StringRef edit_text,
115 const FunctionRef<void(StringPropertySearchVisitParams)> visit_fn)
116{
117 const asset_system::AssetLibrary *library = AS_asset_library_load(&bmain, lib);
118 if (!library) {
119 return;
120 }
121
122 if (!edit_text.is_empty()) {
123 const asset_system::AssetCatalogPath edit_path = edit_text;
124 if (!library->catalog_service().find_catalog_by_path(edit_path)) {
125 visit_fn(StringPropertySearchVisitParams{edit_path.str(), std::nullopt, ICON_ADD});
126 }
127 }
128
129 const asset_system::AssetCatalogTree &full_tree = library->catalog_service().catalog_tree();
130 full_tree.foreach_item([&](const asset_system::AssetCatalogTreeItem &item) {
131 visit_fn(StringPropertySearchVisitParams{item.catalog_path().str(), std::nullopt});
132 });
133}
134
135} // 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
@ ASSET_LIBRARY_CUSTOM
@ ASSET_LIBRARY_ESSENTIALS
@ ASSET_LIBRARY_LOCAL
int BIFIconID
Definition ED_asset.hh:29
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:4227