[Bf-blender-cvs] [8ddf492e7cf] asset-shelf: Basic asset shelf prototype
Julian Eisel
noreply at git.blender.org
Tue Jan 17 16:25:29 CET 2023
Commit: 8ddf492e7cf677f34315dcf5a8726ce45982ab7a
Author: Julian Eisel
Date: Tue Jan 17 15:18:17 2023 +0100
Branches: asset-shelf
https://developer.blender.org/rB8ddf492e7cf677f34315dcf5a8726ce45982ab7a
Basic asset shelf prototype
Adds the necessary bits to be able to show an asset shelf template via
the pose library add-on.
===================================================================
M source/blender/blenloader/intern/versioning_300.cc
M source/blender/blenloader/intern/versioning_defaults.cc
M source/blender/editors/asset/ED_asset_list.h
M source/blender/editors/asset/intern/asset_list.cc
M source/blender/editors/include/ED_screen.h
M source/blender/editors/include/UI_interface.h
M source/blender/editors/interface/CMakeLists.txt
M source/blender/editors/interface/interface_layout.cc
A source/blender/editors/interface/interface_template_asset_shelf.cc
M source/blender/editors/interface/interface_template_asset_view.cc
M source/blender/editors/screen/area.c
M source/blender/editors/space_view3d/space_view3d.cc
M source/blender/makesdna/DNA_asset_defaults.h
M source/blender/makesrna/intern/rna_ui_api.c
===================================================================
diff --git a/source/blender/blenloader/intern/versioning_300.cc b/source/blender/blenloader/intern/versioning_300.cc
index 19f075241af..7393f4fc171 100644
--- a/source/blender/blenloader/intern/versioning_300.cc
+++ b/source/blender/blenloader/intern/versioning_300.cc
@@ -3926,10 +3926,18 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain)
if (new_asset_shelf != nullptr) {
new_asset_shelf->alignment = RGN_ALIGN_BOTTOM;
new_asset_shelf->flag |= RGN_FLAG_HIDDEN;
+ new_asset_shelf->flag = RGN_FLAG_HIDDEN | RGN_FLAG_DYNAMIC_SIZE;
}
}
}
}
}
+
+ /* Should we really use the "All" library by default? Consider loading time and memory usage.
+ */
+ LISTBASE_FOREACH (WorkSpace *, workspace, &bmain->workspaces) {
+ workspace->asset_library_ref.type = ASSET_LIBRARY_ALL;
+ workspace->asset_library_ref.custom_library_index = -1;
+ }
}
}
diff --git a/source/blender/blenloader/intern/versioning_defaults.cc b/source/blender/blenloader/intern/versioning_defaults.cc
index f6fe45ddcdf..fb5599d1d77 100644
--- a/source/blender/blenloader/intern/versioning_defaults.cc
+++ b/source/blender/blenloader/intern/versioning_defaults.cc
@@ -260,6 +260,9 @@ void BLO_update_defaults_workspace(WorkSpace *workspace, const char *app_templat
BKE_workspace_tool_remove(workspace, static_cast<bToolRef *>(workspace->tools.first));
}
+ workspace->asset_library_ref.type = ASSET_LIBRARY_ALL;
+ workspace->asset_library_ref.custom_library_index = -1;
+
/* For 2D animation template. */
if (STREQ(workspace->id.name + 2, "Drawing")) {
workspace->object_mode = OB_MODE_PAINT_GPENCIL;
diff --git a/source/blender/editors/asset/ED_asset_list.h b/source/blender/editors/asset/ED_asset_list.h
index 635dc3bff32..b33f909c50b 100644
--- a/source/blender/editors/asset/ED_asset_list.h
+++ b/source/blender/editors/asset/ED_asset_list.h
@@ -55,8 +55,7 @@ struct ImBuf *ED_assetlist_asset_image_get(const AssetHandle *asset_handle);
/**
* \return True if the region needs a UI redraw.
*/
-bool ED_assetlist_listen(const struct AssetLibraryReference *library_reference,
- const struct wmNotifier *notifier);
+bool ED_assetlist_listen(const struct wmNotifier *notifier);
/**
* \return The number of assets stored in the asset list for \a library_reference, or -1 if there
* is no list fetched for it.
diff --git a/source/blender/editors/asset/intern/asset_list.cc b/source/blender/editors/asset/intern/asset_list.cc
index 64934316413..3b3a434f0cc 100644
--- a/source/blender/editors/asset/intern/asset_list.cc
+++ b/source/blender/editors/asset/intern/asset_list.cc
@@ -116,7 +116,7 @@ class AssetList : NonCopyable {
bool isLoaded() const;
asset_system::AssetLibrary *asset_library() const;
void iterate(AssetListIterFn fn) const;
- bool listen(const wmNotifier ¬ifier) const;
+ static bool listen(const wmNotifier ¬ifier);
int size() const;
void tagMainDataDirty() const;
void remapID(ID *id_old, ID *id_new) const;
@@ -249,7 +249,7 @@ void AssetList::clear(bContext *C)
/**
* \return True if the asset-list needs a UI redraw.
*/
-bool AssetList::listen(const wmNotifier ¬ifier) const
+bool AssetList::listen(const wmNotifier ¬ifier)
{
switch (notifier.category) {
case NC_ID: {
@@ -481,14 +481,9 @@ ImBuf *ED_assetlist_asset_image_get(const AssetHandle *asset_handle)
return filelist_geticon_image_ex(asset_handle->file_data);
}
-bool ED_assetlist_listen(const AssetLibraryReference *library_reference,
- const wmNotifier *notifier)
+bool ED_assetlist_listen(const wmNotifier *notifier)
{
- AssetList *list = AssetListStorage::lookup_list(*library_reference);
- if (list) {
- return list->listen(*notifier);
- }
- return false;
+ return AssetList::listen(*notifier);
}
int ED_assetlist_size(const AssetLibraryReference *library_reference)
diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h
index 6dfaab663f6..a85acb500c3 100644
--- a/source/blender/editors/include/ED_screen.h
+++ b/source/blender/editors/include/ED_screen.h
@@ -122,6 +122,8 @@ void ED_region_header(const struct bContext *C, struct ARegion *region);
void ED_region_header_layout(const struct bContext *C, struct ARegion *region);
void ED_region_header_draw(const struct bContext *C, struct ARegion *region);
+void ED_region_asset_shelf_listen(const struct wmRegionListenerParams *params);
+
void ED_region_cursor_set(struct wmWindow *win, struct ScrArea *area, struct ARegion *region);
/**
* Exported to all editors, uses fading default.
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 0705052921e..41fe5f88373 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -2161,6 +2161,7 @@ int uiLayoutGetAlignment(uiLayout *layout);
bool uiLayoutGetFixedSize(uiLayout *layout);
bool uiLayoutGetKeepAspect(uiLayout *layout);
int uiLayoutGetWidth(uiLayout *layout);
+int uiLayoutGetRootHeight(uiLayout *layout);
float uiLayoutGetScaleX(uiLayout *layout);
float uiLayoutGetScaleY(uiLayout *layout);
float uiLayoutGetUnitsX(uiLayout *layout);
@@ -2598,6 +2599,9 @@ void uiTemplateAssetView(struct uiLayout *layout,
struct PointerRNA *r_activate_op_properties,
const char *drag_opname,
struct PointerRNA *r_drag_op_properties);
+void uiTemplateAssetShelf(uiLayout *layout,
+ const struct bContext *C,
+ const struct AssetFilterSettings *filter_settings);
/**
* \return: A RNA pointer for the operator properties.
diff --git a/source/blender/editors/interface/CMakeLists.txt b/source/blender/editors/interface/CMakeLists.txt
index e3c809b6ccd..e07e2adc9aa 100644
--- a/source/blender/editors/interface/CMakeLists.txt
+++ b/source/blender/editors/interface/CMakeLists.txt
@@ -60,6 +60,7 @@ set(SRC
interface_region_tooltip.cc
interface_regions.cc
interface_style.cc
+ interface_template_asset_shelf.cc
interface_template_asset_view.cc
interface_template_attribute_search.cc
interface_template_list.cc
diff --git a/source/blender/editors/interface/interface_layout.cc b/source/blender/editors/interface/interface_layout.cc
index f4b96899545..f870bb5e434 100644
--- a/source/blender/editors/interface/interface_layout.cc
+++ b/source/blender/editors/interface/interface_layout.cc
@@ -4088,7 +4088,7 @@ static void ui_litem_layout_box(uiLayout *litem)
const uiStyle *style = litem->root->style;
int boxspace = style->boxspace;
- if (litem->root->type == UI_LAYOUT_HEADER) {
+ if (litem->root->type == UI_LAYOUT_HEADER && false) {
boxspace = 0;
}
@@ -5117,6 +5117,11 @@ int uiLayoutGetWidth(uiLayout *layout)
return layout->w;
}
+int uiLayoutGetRootHeight(uiLayout *layout)
+{
+ return layout->root->layout->h;
+}
+
float uiLayoutGetScaleX(uiLayout *layout)
{
return layout->scale[0];
diff --git a/source/blender/editors/interface/interface_template_asset_shelf.cc b/source/blender/editors/interface/interface_template_asset_shelf.cc
new file mode 100644
index 00000000000..26676a9d8e3
--- /dev/null
+++ b/source/blender/editors/interface/interface_template_asset_shelf.cc
@@ -0,0 +1,101 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/** \file
+ * \ingroup edinterface
+ */
+
+#include "BKE_context.h"
+
+#include "DNA_space_types.h"
+
+#include "ED_asset.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+#include "interface_intern.hh"
+
+/* TODO copy of #asset_view_item_but_drag_set(). */
+static void asset_tile_but_drag_set(uiBut &but, AssetHandle &asset_handle)
+{
+ ID *id = ED_asset_handle_get_local_id(&asset_handle);
+ if (id != nullptr) {
+ UI_but_drag_set_id(&but, id);
+ return;
+ }
+
+ char blend_path[FILE_MAX_LIBEXTRA];
+ /* Context can be null here, it's only needed for a File Browser specific hack that should go
+ * away before too long. */
+ ED_asset_handle_get_full_library_path(&asset_handle, blend_path);
+
+ if (blend_path[0]) {
+ ImBuf *imbuf = ED_assetlist_asset_image_get(&asset_handle);
+ UI_but_drag_set_asset(&but,
+ &asset_handle,
+ BLI_strdup(blend_path),
+ FILE_ASSET_IMPORT_APPEND,
+ ED_asset_handle_get_preview_icon_id(&asset_handle),
+ imbuf,
+ 1.0f);
+ }
+}
+
+static void asset_tile_draw(uiLayout &layout,
+ AssetHandle &asset_handle,
+ const int width,
+ const int height,
+ const bool show_names)
+{
+ uiBlock *block = uiLayoutGetBlock(&layout);
+ uiBut *but = uiDefIconTextBut(block,
+ UI_BTYPE_PREVIEW_TILE,
+ 0,
+ ED_asset_handle_get_preview_icon_id(&asset_handle),
+ show_names ? ED_asset_handle_get_name(&asset_handle) : "",
+ 0,
+ 0,
+ width,
+ height,
+ nullptr,
+ 0,
+ 0,
+ 0,
+ 0,
+ "");
+ ui_def_but_icon(but,
+ ED_asset_handle_get_preview_icon_id(&asset_handle),
+ /* NOLINTNEXTLINE: bugprone-suspicious-enum-usage */
+ UI_HAS_ICON | UI_BUT_ICON_PREVIEW);
+ asset_tile_but_drag_set(*but, asset_handle);
+}
+
+void uiTemplateAssetShelf(uiLayout *layout,
+ const bContext *C,
+ const AssetFilterSettings *filter_settings)
+{
+ const AssetLibraryReference *library_ref = CTX_wm_asset_library_ref(C);
+
+ ED_assetlist_storage_fetch(library_r
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list