Merge remote-tracking branch 'origin/blender-v4.0-release'

This commit is contained in:
Julian Eisel
2023-10-12 14:41:07 +02:00

View File

@@ -36,11 +36,11 @@ namespace blender::ui::light_linking {
namespace {
class BaseCollectionDropTarget : public TreeViewItemDropTarget {
class CollectionDropTarget {
Collection &collection_;
public:
bool can_drop(const wmDrag &drag, const char **r_disabled_hint) const override
bool can_drop(const wmDrag &drag, const char **r_disabled_hint) const
{
if (drag.type != WM_DRAG_ID) {
return false;
@@ -62,11 +62,7 @@ class BaseCollectionDropTarget : public TreeViewItemDropTarget {
return true;
}
protected:
BaseCollectionDropTarget(AbstractTreeView &view, DropBehavior behavior, Collection &collection)
: TreeViewItemDropTarget(view, behavior), collection_(collection)
{
}
CollectionDropTarget(Collection &collection) : collection_(collection) {}
Collection &get_collection() const
{
@@ -74,11 +70,18 @@ class BaseCollectionDropTarget : public TreeViewItemDropTarget {
}
};
class InsertCollectionDropTarget : public BaseCollectionDropTarget {
/**
* Drop target for the view (when dropping into empty space of the view), not for an item.
*/
class InsertCollectionDropTarget : public DropTargetInterface {
CollectionDropTarget collection_target_;
public:
InsertCollectionDropTarget(AbstractTreeView &view, Collection &collection)
: BaseCollectionDropTarget(view, DropBehavior::Insert, collection)
InsertCollectionDropTarget(Collection &collection) : collection_target_(collection) {}
bool can_drop(const wmDrag &drag, const char **r_disabled_hint) const override
{
return collection_target_.can_drop(drag, r_disabled_hint);
}
std::string drop_tooltip(const DragInfo & /*drag*/) const override
@@ -92,8 +95,10 @@ class InsertCollectionDropTarget : public BaseCollectionDropTarget {
Scene *scene = CTX_data_scene(C);
LISTBASE_FOREACH (wmDragID *, drag_id, &drag.drag_data.ids) {
BKE_light_linking_add_receiver_to_collection(
bmain, &get_collection(), drag_id->id, COLLECTION_LIGHT_LINKING_STATE_INCLUDE);
BKE_light_linking_add_receiver_to_collection(bmain,
&collection_target_.get_collection(),
drag_id->id,
COLLECTION_LIGHT_LINKING_STATE_INCLUDE);
}
/* It is possible that the light linking collection is also used by the view layer.
@@ -107,15 +112,23 @@ class InsertCollectionDropTarget : public BaseCollectionDropTarget {
}
};
class ReorderCollectionDropTarget : public BaseCollectionDropTarget {
class ReorderCollectionDropTarget : public TreeViewItemDropTarget {
CollectionDropTarget collection_target_;
const ID &drop_id_;
public:
ReorderCollectionDropTarget(AbstractTreeView &view, Collection &collection, const ID &drop_id)
: BaseCollectionDropTarget(view, DropBehavior::Reorder, collection), drop_id_(drop_id)
: TreeViewItemDropTarget(view, DropBehavior::Reorder),
collection_target_(collection),
drop_id_(drop_id)
{
}
bool can_drop(const wmDrag &drag, const char **r_disabled_hint) const override
{
return collection_target_.can_drop(drag, r_disabled_hint);
}
std::string drop_tooltip(const DragInfo &drag) const override
{
const std::string_view drop_name = std::string_view(drop_id_.name + 2);
@@ -137,7 +150,7 @@ class ReorderCollectionDropTarget : public BaseCollectionDropTarget {
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
Collection &collection = get_collection();
Collection &collection = collection_target_.get_collection();
const eCollectionLightLinkingState link_state = COLLECTION_LIGHT_LINKING_STATE_INCLUDE;
LISTBASE_FOREACH (wmDragID *, drag_id, &drag.drag_data.ids) {
@@ -334,7 +347,7 @@ class CollectionView : public AbstractTreeView {
std::unique_ptr<DropTargetInterface> create_drop_target() override
{
return std::make_unique<InsertCollectionDropTarget>(*this, collection_);
return std::make_unique<InsertCollectionDropTarget>(collection_);
}
};