[Bf-blender-cvs] [7c8ad971153] asset-browser-snap-dragging: Merge branch 'master' into asset-browser-snap-dragging
Julian Eisel
noreply at git.blender.org
Mon Oct 11 13:12:47 CEST 2021
Commit: 7c8ad9711539cd5a2d8a9274370326bb9dffa234
Author: Julian Eisel
Date: Mon Oct 11 10:57:33 2021 +0200
Branches: asset-browser-snap-dragging
https://developer.blender.org/rB7c8ad9711539cd5a2d8a9274370326bb9dffa234
Merge branch 'master' into asset-browser-snap-dragging
===================================================================
===================================================================
diff --cc source/blender/blenkernel/BKE_asset.h
index fdc7ed8c145,42eea41b7a7..722d142b56c
--- a/source/blender/blenkernel/BKE_asset.h
+++ b/source/blender/blenkernel/BKE_asset.h
@@@ -20,9 -20,10 +20,11 @@@
#pragma once
+#include "BLI_compiler_attrs.h"
#include "BLI_utildefines.h"
+ #include "DNA_asset_types.h"
+
#ifdef __cplusplus
extern "C" {
#endif
@@@ -59,12 -48,14 +61,18 @@@ struct AssetTagEnsureResult BKE_asset_m
const char *name);
void BKE_asset_metadata_tag_remove(struct AssetMetaData *asset_data, struct AssetTag *tag);
+ /** Clean up the catalog ID (white-spaces removed, length reduced, etc.) and assign it. */
+ void BKE_asset_metadata_catalog_id_clear(struct AssetMetaData *asset_data);
+ void BKE_asset_metadata_catalog_id_set(struct AssetMetaData *asset_data,
+ bUUID catalog_id,
+ const char *catalog_simple_name);
+
void BKE_asset_library_reference_init_default(struct AssetLibraryReference *library_ref);
+void BKE_asset_metadata_idprop_ensure(struct AssetMetaData *asset_data, struct IDProperty *prop);
+struct IDProperty *BKE_asset_metadata_idprop_find(const struct AssetMetaData *asset_data,
+ const char *name) ATTR_WARN_UNUSED_RESULT;
+
struct PreviewImage *BKE_asset_metadata_preview_get_from_id(const struct AssetMetaData *asset_data,
const struct ID *owner_id);
diff --cc source/blender/blenkernel/intern/asset.cc
index 6974feb9e5d,ae9ded3c754..16b4adab874
--- a/source/blender/blenkernel/intern/asset.cc
+++ b/source/blender/blenkernel/intern/asset.cc
@@@ -115,25 -119,27 +119,46 @@@ void BKE_asset_library_reference_init_d
memcpy(library_ref, DNA_struct_default_get(AssetLibraryReference), sizeof(*library_ref));
}
+ void BKE_asset_metadata_catalog_id_clear(struct AssetMetaData *asset_data)
+ {
+ asset_data->catalog_id = BLI_uuid_nil();
+ asset_data->catalog_simple_name[0] = '\0';
+ }
+
+ void BKE_asset_metadata_catalog_id_set(struct AssetMetaData *asset_data,
+ const ::bUUID catalog_id,
+ const char *catalog_simple_name)
+ {
+ asset_data->catalog_id = catalog_id;
+
+ constexpr size_t max_simple_name_length = sizeof(asset_data->catalog_simple_name);
+
+ /* The substr() call is necessary to make copy() copy the first N characters (instead of refusing
+ * to copy and producing an empty string). */
+ StringRef trimmed_id =
+ StringRef(catalog_simple_name).trim().substr(0, max_simple_name_length - 1);
+ trimmed_id.copy(asset_data->catalog_simple_name, max_simple_name_length);
+ }
+
+void BKE_asset_metadata_idprop_ensure(AssetMetaData *asset_data, IDProperty *prop)
+{
+ if (!asset_data->properties) {
+ IDPropertyTemplate val = {0};
+ asset_data->properties = IDP_New(IDP_GROUP, &val, "AssetMetaData.properties");
+ }
+ /* Important: The property may already exist. For now just allow always allow a newly allocated
+ * property, and replace the existing one as a way of updating. */
+ IDP_ReplaceInGroup(asset_data->properties, prop);
+}
+
+IDProperty *BKE_asset_metadata_idprop_find(const AssetMetaData *asset_data, const char *name)
+{
+ if (!asset_data->properties) {
+ return nullptr;
+ }
+ return IDP_GetPropertyFromGroup(asset_data->properties, name);
+}
+
/* Queries -------------------------------------------- */
PreviewImage *BKE_asset_metadata_preview_get_from_id(const AssetMetaData *UNUSED(asset_data),
diff --cc source/blender/editors/asset/ED_asset_mark_clear.h
index 04dd2d3b759,d8b8f15a109..d51b652dd6c
--- a/source/blender/editors/asset/ED_asset_mark_clear.h
+++ b/source/blender/editors/asset/ED_asset_mark_clear.h
@@@ -26,13 -26,25 +26,28 @@@ extern "C"
struct ID;
struct bContext;
+struct Main;
+ /**
+ * Mark the datablock as asset.
+ *
+ * To ensure the datablock is saved, this sets Fake User.
+ *
+ * \return whether the datablock was marked as asset; false when it is not capable of becoming an
+ * asset, or when it already was an asset. */
bool ED_asset_mark_id(const struct bContext *C, struct ID *id);
+
+ /**
+ * Remove the asset metadata, turning the ID into a "normal" ID.
+ *
+ * This clears the Fake User. If for some reason the datablock is meant to be saved anyway, the
+ * caller is responsible for explicitly setting the Fake User.
+ *
+ * \return whether the asset metadata was actually removed; false when the ID was not an asset. */
bool ED_asset_clear_id(struct ID *id);
+void ED_assets_pre_save(struct Main *bmain);
+
bool ED_asset_can_mark_single_from_context(const struct bContext *C);
#ifdef __cplusplus
diff --cc source/blender/editors/interface/interface.c
index b7338076d62,07bb9040da8..84036eb5c5b
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@@ -6192,14 -6284,15 +6285,21 @@@ void UI_but_drag_set_asset(uiBut *but
struct ImBuf *imb,
float scale)
{
- wmDragAsset *asset_drag = MEM_mallocN(sizeof(*asset_drag), "wmDragAsset");
+ wmDragAsset *asset_drag = WM_drag_create_asset_data(asset, path, import_type);
+
+ /* FIXME: This is temporary evil solution to get scene/viewlayer/etc in the copy callback of the
+ * #wmDropBox.
+ * TODO: Handle link/append in operator called at the end of the drop process, and NOT in its
+ * copy callback.
+ * */
+ asset_drag->evil_C = but->block->evil_C;
+ BLI_strncpy(asset_drag->name, ED_asset_handle_get_name(asset), sizeof(asset_drag->name));
+ asset_drag->metadata = metadata;
+ asset_drag->path = path;
+ asset_drag->id_type = ED_asset_handle_get_id_type(asset);
+ asset_drag->import_type = import_type;
+
but->dragtype = WM_DRAG_ASSET;
ui_def_but_icon(but, icon, 0); /* no flag UI_HAS_ICON, so icon doesn't draw in button */
if (but->dragflag & UI_BUT_DRAGPOIN_FREE) {
diff --cc source/blender/windowmanager/WM_api.h
index 7a2e0954c41,b79f5762955..5a93f11f6f1
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@@ -726,17 -743,22 +746,26 @@@ struct ID *WM_drag_get_local_ID(const s
struct ID *WM_drag_get_local_ID_from_event(const struct wmEvent *event, short idcode);
bool WM_drag_is_ID_type(const struct wmDrag *drag, int idcode);
+ wmDragAsset *WM_drag_create_asset_data(const struct AssetHandle *asset,
+ const char *path,
+ int import_type);
struct wmDragAsset *WM_drag_get_asset_data(const struct wmDrag *drag, int idcode);
+struct AssetMetaData *WM_drag_get_asset_meta_data(const struct wmDrag *drag, int idcode);
struct ID *WM_drag_get_local_ID_or_import_from_asset(const struct wmDrag *drag, int idcode);
void WM_drag_free_imported_drag_ID(struct Main *bmain,
struct wmDrag *drag,
struct wmDropBox *drop);
+ void WM_drag_add_asset_list_item(wmDrag *drag,
+ const struct bContext *C,
+ const struct AssetLibraryReference *asset_library_ref,
+ const struct AssetHandle *asset);
+ const ListBase *WM_drag_asset_list_get(const wmDrag *drag);
+
+const struct wmDrag *WM_drag_with_gizmogroup_find(
+ const struct wmWindowManager *wm, const char name[MAX_NAME]) ATTR_WARN_UNUSED_RESULT;
+
const char *WM_drag_get_item_name(struct wmDrag *drag);
/* Set OpenGL viewport and scissor */
diff --cc source/blender/windowmanager/WM_types.h
index 6cad2cc82a6,c4612485e5a..24bf36455dd
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@@ -932,10 -982,35 +982,36 @@@ typedef struct wmDragAsset
/* Always freed. */
const char *path;
int id_type;
+ struct AssetMetaData *metadata;
int import_type; /* eFileAssetImportType */
+
+ /* FIXME: This is temporary evil solution to get scene/view-layer/etc in the copy callback of the
+ * #wmDropBox.
+ * TODO: Handle link/append in operator called at the end of the drop process, and NOT in its
+ * copy callback.
+ * */
+ struct bContext *evil_C;
} wmDragAsset;
+ /**
+ * For some specific cases we support dragging multiple assets (#WM_DRAG_ASSET_LIST). There is no
+ * proper support for dragging multiple items in the `wmDrag`/`wmDrop` API yet, so this is really
+ * just to enable specific features for assets.
+ *
+ * This struct basically contains a tagged union to either store a local ID pointer, or information
+ * about an externally stored asset.
+ */
+ typedef struct wmDragAssetListItem {
+ struct wmDragAssetListItem *next, *prev;
+
+ union {
+ struct ID *local_id;
+ wmDragAsset *external_info;
+ } asset_data;
+
+ bool is_external;
+ } wmDragAssetListItem;
+
typedef char *(*WMDropboxTooltipFunc)(struct bContext *,
struct wmDrag *,
const struct wmEvent *event,
@@@ -969,10 -1037,10 +1045,12 @@@ typedef struct wmDrag
/** List of wmDragIDs, all are guaranteed to have the same ID type. */
ListBase ids;
+ /** List of `wmDragAssetListItem`s. */
+ ListBase asset_items;
} wmDrag;
+typedef void (*wmDropBoxCopyFn)(struct wmDrag *, struct wmDropBox *);
+
/**
* Dropboxes are like keymaps, part of the screen/area/region definition.
* Allocation and free is on startup and exit.
diff --cc source/blender/windowmanager/gizmo/WM_gizmo_types.h
index 575b411ed8b,b667872a914..cdbfc19e4bc
--- a/source/blender/windowmanager/gizmo/WM_gizmo_types.h
+++ b/source/blender/windowmanager/gizmo/WM_gizmo_types.h
@@@ -146,13 -153,8 +153,13 @@@ typedef enum eWM_GizmoFlagGroupTypeFla
* for selection operations. This means gizmos that use this check don't interfere
* with click drag events by popping up under the cursor and catching the tweak event.
*/
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list