UI: Asset Shelf (Experimental Feature) #104831
|
@ -44,14 +44,12 @@ class AssetView : public ui::AbstractGridView {
|
||||||
* end of the string, for `fnmatch()` to work. */
|
* end of the string, for `fnmatch()` to work. */
|
||||||
char search_string[sizeof(AssetShelfSettings::search_string) + 2] = "";
|
char search_string[sizeof(AssetShelfSettings::search_string) + 2] = "";
|
||||||
std::optional<asset_system::AssetCatalogFilter> catalog_filter_ = std::nullopt;
|
std::optional<asset_system::AssetCatalogFilter> catalog_filter_ = std::nullopt;
|
||||||
/* XXX Temporary: Only for #asset_poll__() callback. Should use traits instead. */
|
|
||||||
bContext &evil_C_;
|
|
||||||
|
|
||||||
friend class AssetViewItem;
|
friend class AssetViewItem;
|
||||||
friend class AssetDragController;
|
friend class AssetDragController;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AssetView(const AssetLibraryReference &library_ref, const AssetShelf &shelf, bContext &evil_C);
|
AssetView(const AssetLibraryReference &library_ref, const AssetShelf &shelf);
|
||||||
|
|
||||||
void build_items() override;
|
void build_items() override;
|
||||||
bool begin_filtering(const bContext &C) const override;
|
bool begin_filtering(const bContext &C) const override;
|
||||||
|
@ -84,13 +82,11 @@ class AssetDragController : public ui::AbstractViewItemDragController {
|
||||||
AssetDragController(ui::AbstractGridView &view, AssetRepresentation &asset);
|
AssetDragController(ui::AbstractGridView &view, AssetRepresentation &asset);
|
||||||
|
|
||||||
eWM_DragDataType get_drag_type() const override;
|
eWM_DragDataType get_drag_type() const override;
|
||||||
void *create_drag_data() const override;
|
void *create_drag_data(bContext &C) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
AssetView::AssetView(const AssetLibraryReference &library_ref,
|
AssetView::AssetView(const AssetLibraryReference &library_ref, const AssetShelf &shelf)
|
||||||
const AssetShelf &shelf,
|
: library_ref_(library_ref), shelf_(shelf)
|
||||||
bContext &evil_C)
|
|
||||||
: library_ref_(library_ref), shelf_(shelf), evil_C_(evil_C)
|
|
||||||
{
|
{
|
||||||
if (shelf.settings.search_string[0]) {
|
if (shelf.settings.search_string[0]) {
|
||||||
BLI_strncpy_ensure_pad(
|
BLI_strncpy_ensure_pad(
|
||||||
|
@ -252,8 +248,7 @@ void build_asset_view(uiLayout &layout,
|
||||||
const float tile_width = ED_asset_shelf_default_tile_width();
|
const float tile_width = ED_asset_shelf_default_tile_width();
|
||||||
const float tile_height = ED_asset_shelf_default_tile_height();
|
const float tile_height = ED_asset_shelf_default_tile_height();
|
||||||
|
|
||||||
std::unique_ptr asset_view = std::make_unique<AssetView>(
|
std::unique_ptr asset_view = std::make_unique<AssetView>(library_ref, shelf);
|
||||||
library_ref, shelf, const_cast<bContext &>(C));
|
|
||||||
asset_view->set_catalog_filter(catalog_filter_from_shelf_settings(shelf.settings, *library));
|
asset_view->set_catalog_filter(catalog_filter_from_shelf_settings(shelf.settings, *library));
|
||||||
asset_view->set_tile_size(tile_width, tile_height);
|
asset_view->set_tile_size(tile_width, tile_height);
|
||||||
|
|
||||||
|
@ -279,7 +274,7 @@ eWM_DragDataType AssetDragController::get_drag_type() const
|
||||||
return local_id ? WM_DRAG_ID : WM_DRAG_ASSET;
|
return local_id ? WM_DRAG_ID : WM_DRAG_ASSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *AssetDragController::create_drag_data() const
|
void *AssetDragController::create_drag_data(bContext &C) const
|
||||||
{
|
{
|
||||||
ID *local_id = AS_asset_representation_local_id_get(&asset_);
|
ID *local_id = AS_asset_representation_local_id_get(&asset_);
|
||||||
if (local_id) {
|
if (local_id) {
|
||||||
|
@ -289,9 +284,7 @@ void *AssetDragController::create_drag_data() const
|
||||||
const eAssetImportMethod import_method =
|
const eAssetImportMethod import_method =
|
||||||
AS_asset_representation_import_method_get(&asset_).value_or(ASSET_IMPORT_APPEND_REUSE);
|
AS_asset_representation_import_method_get(&asset_).value_or(ASSET_IMPORT_APPEND_REUSE);
|
||||||
|
|
||||||
const AssetView &asset_view = get_view<AssetView>();
|
return WM_drag_create_asset_data(&asset_, import_method, &C);
|
||||||
return static_cast<void *>(
|
|
||||||
WM_drag_create_asset_data(&asset_, import_method, &asset_view.evil_C_));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace blender::ed::asset::shelf
|
} // namespace blender::ed::asset::shelf
|
||||||
|
|
|
@ -272,7 +272,7 @@ class AbstractViewItemDragController {
|
||||||
virtual ~AbstractViewItemDragController() = default;
|
virtual ~AbstractViewItemDragController() = default;
|
||||||
|
|
||||||
virtual eWM_DragDataType get_drag_type() const = 0;
|
virtual eWM_DragDataType get_drag_type() const = 0;
|
||||||
virtual void *create_drag_data() const = 0;
|
virtual void *create_drag_data(bContext &C) const = 0;
|
||||||
virtual void on_drag_start();
|
virtual void on_drag_start();
|
||||||
|
|
||||||
/** Request the view the item is registered for as type #ViewType. Throws a `std::bad_cast`
|
/** Request the view the item is registered for as type #ViewType. Throws a `std::bad_cast`
|
||||||
|
|
|
@ -308,7 +308,7 @@ class ViewItemAPIWrapper {
|
||||||
WM_event_start_drag(&C,
|
WM_event_start_drag(&C,
|
||||||
ICON_NONE,
|
ICON_NONE,
|
||||||
drag_controller->get_drag_type(),
|
drag_controller->get_drag_type(),
|
||||||
drag_controller->create_drag_data(),
|
drag_controller->create_drag_data(C),
|
||||||
0,
|
0,
|
||||||
WM_DRAG_FREE_DATA);
|
WM_DRAG_FREE_DATA);
|
||||||
drag_controller->on_drag_start();
|
drag_controller->on_drag_start();
|
||||||
|
|
|
@ -104,7 +104,7 @@ class AssetCatalogDragController : public ui::AbstractViewItemDragController {
|
||||||
AssetCatalogTreeItem &catalog_item);
|
AssetCatalogTreeItem &catalog_item);
|
||||||
|
|
||||||
eWM_DragDataType get_drag_type() const override;
|
eWM_DragDataType get_drag_type() const override;
|
||||||
void *create_drag_data() const override;
|
void *create_drag_data(bContext &C) const override;
|
||||||
void on_drag_start() override;
|
void on_drag_start() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -551,7 +551,7 @@ eWM_DragDataType AssetCatalogDragController::get_drag_type() const
|
||||||
return WM_DRAG_ASSET_CATALOG;
|
return WM_DRAG_ASSET_CATALOG;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *AssetCatalogDragController::create_drag_data() const
|
void *AssetCatalogDragController::create_drag_data(bContext & /*C*/) const
|
||||||
{
|
{
|
||||||
wmDragAssetCatalog *drag_catalog = (wmDragAssetCatalog *)MEM_callocN(sizeof(*drag_catalog),
|
wmDragAssetCatalog *drag_catalog = (wmDragAssetCatalog *)MEM_callocN(sizeof(*drag_catalog),
|
||||||
__func__);
|
__func__);
|
||||||
|
|
Loading…
Reference in New Issue