20#include "RNA_prototypes.hh"
27#include <fmt/format.h>
51 void build_tree_node_recursive(TreeViewItemContainer &parent,
const int bcoll_index);
55 void build_bcolls_with_selected_bones();
88 const int bcoll_index);
90 std::optional<eWM_DragDataType>
get_drag_type()
const override;
117 if (drag_arm_bcoll->
armature != drop_bonecoll_.armature) {
118 *r_disabled_hint =
"Cannot drag & drop bone collections between Armatures.";
123 if (drag_arm_bcoll->
bcoll_index == drop_bonecoll_.bcoll_index) {
131 *r_disabled_hint =
"Cannot drag a collection onto a descendent";
150 return fmt::format(fmt::runtime(
TIP_(
"Move {} into {}")), drag_name, drop_name);
152 return fmt::format(fmt::runtime(
TIP_(
"Move {} above {}")), drag_name, drop_name);
154 return fmt::format(fmt::runtime(
TIP_(
"Move {} below {}")), drag_name, drop_name);
164 bArmature *arm = drop_bonecoll_.armature;
166 const int from_bcoll_index = drag_arm_bcoll->
bcoll_index;
167 const int to_bcoll_index = drop_bonecoll_.bcoll_index;
169 int new_bcoll_index = -1;
186 arm, from_bcoll_index, -1, from_parent_index, to_bcoll_index);
195 if (new_bcoll_index < 0) {
212 bool has_any_selected_bones_;
216 : armature_(armature),
217 bcoll_index_(bcoll_index),
218 bone_collection_(*armature.collection_array[bcoll_index]),
219 has_any_selected_bones_(has_any_selected_bones)
221 this->
label_ = bone_collection_.name;
228 Button *name_label =
uiItemL_ex(&sub, bone_collection_.name, ICON_NONE,
false,
false);
239 icon = ICON_LAYER_ACTIVE;
241 else if (has_any_selected_bones_) {
242 icon = ICON_LAYER_USED;
254 visibility_sub.
active_set(!is_solo_active && bone_collection_.is_visible_ancestors());
256 const int icon = bone_collection_.is_visible() ? ICON_HIDE_OFF : ICON_HIDE_ON;
263 const int icon = bone_collection_.is_solo() ? ICON_SOLO_ON : ICON_SOLO_OFF;
280 return armature_.runtime->active_collection_index == bcoll_index_;
288 &armature_.id, RNA_BoneCollections, &armature_);
294 ED_undo_push(&
C,
"Change Armature's Active Bone Collection");
299 const bool is_collapsed = !bone_collection_.is_expanded();
321 &armature_.id, RNA_BoneCollection, &bone_collection_);
349 return bone_collection_.name;
365 return std::make_unique<BoneCollectionDragController>(tree_view, armature_, bcoll_index_);
373 return std::make_unique<BoneCollectionDropTarget>(
392 build_bcolls_with_selected_bones();
395 build_tree_node_recursive(*
this, bcoll_index);
400 const int bcoll_index)
405 armature_, bcoll_index, has_any_selected_bones);
409 build_tree_node_recursive(bcoll_tree_item, child_index);
418void BoneCollectionTreeView::build_bcolls_with_selected_bones()
458 const int bcoll_index)
471 *drag_data = drag_arm_bcoll_;
485 if (armature ==
nullptr) {
490 if (armature_object && armature_object->
data != &armature->
id) {
492 armature_object =
nullptr;
499 "Bone Collection Tree View",
500 std::make_unique<bonecollections::BoneCollectionTreeView>(*armature, armature_object));
C++ functions to deal with Armature collections (i.e. the successor of bone layers).
#define ND_BONE_COLLECTION
constexpr const char * c_str() const
Abstract base class for defining a customizable tree-view item.
bool is_collapsed() const
AbstractTreeView & get_tree_view() const
virtual bool set_collapsed(bool collapsed)
void set_default_rows(int default_rows)
AbstractViewItemDragController(AbstractView &view)
void set_context_menu_title(const std::string &title)
static void build_tree_view(const bContext &C, AbstractTreeView &tree_view, Layout &layout, bool add_box=true)
ItemT & add_tree_item(Args &&...args)
friend class AbstractTreeView
TreeViewItemDropTarget(AbstractTreeViewItem &view_item, DropBehavior behavior=DropBehavior::Insert)
BoneCollectionDragController(BoneCollectionTreeView &tree_view, bArmature &armature, const int bcoll_index)
void * create_drag_data() const override
void on_drag_start(bContext &C, AbstractViewItem &item) override
std::optional< eWM_DragDataType > get_drag_type() const override
bool on_drop(bContext *C, const DragInfo &drag_info) const override
bool can_drop(const wmDrag &drag, const char **r_disabled_hint) const override
std::string drop_tooltip(const DragInfo &drag_info) const override
BoneCollectionDropTarget(AbstractTreeViewItem &item, DropBehavior behavior, const ArmatureBoneCollection &drop_bonecoll)
bool supports_renaming() const override
std::unique_ptr< TreeViewItemDropTarget > create_drop_target() override
void build_row(Layout &row) override
std::optional< bool > should_be_active() const override
void build_context_menu(bContext &C, Layout &column) const override
StringRef get_rename_string() const override
void on_collapse_change(bContext &C, const bool is_collapsed) override
BoneCollectionItem(bArmature &armature, const int bcoll_index, const bool has_any_selected_bones)
bool rename(const bContext &C, StringRefNull new_name) override
bool set_collapsed(const bool collapsed) override
void delete_item(bContext *C) override
std::unique_ptr< AbstractViewItemDragController > create_drag_controller() const override
void on_activate(bContext &C) override
std::optional< bool > should_be_collapsed() const override
bool listen(const wmNotifier ¬ifier) const override
BoneCollectionTreeView(bArmature &armature, Object *armature_object)
Set< BoneCollection * > bcolls_with_selected_bones_
Object * armature_object_
void build_tree() override
bool armature_bonecoll_is_descendant_of(const bArmature *armature, int potential_parent_index, int potential_descendant_index)
int armature_bonecoll_find_parent_index(const bArmature *armature, int bcoll_index)
int armature_bonecoll_move_to_parent(bArmature *armature, int from_bcoll_index, int to_child_num, int from_parent_index, int to_parent_index)
AbstractGridView * block_add_view(Block &block, StringRef idname, std::unique_ptr< AbstractGridView > grid_view)
void template_bone_collection_tree(Layout *layout, bContext *C)
void button_flag_enable(Button *but, int64_t flag)
Button * uiItemL_ex(Layout *layout, StringRef name, int icon, bool highlight, bool redalert)
void menutype_draw(bContext *C, MenuType *mt, Layout *layout)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void ANIM_armature_bonecoll_is_expanded_set(BoneCollection *bcoll, bool is_expanded)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
void ANIM_armature_bonecoll_active_index_set(bArmature *armature, int bone_collection_index)
MenuType * WM_menutype_find(const StringRef idname, bool quiet)
void ANIM_armature_bonecoll_remove(bArmature *armature, BoneCollection *bcoll)
@ WM_DRAG_BONE_COLLECTION
void RNA_property_int_set(PointerRNA *ptr, PropertyRNA *prop, int value)
void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *value)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void ED_undo_push(bContext *C, const char *str, UndoEncodeHints hints=UndoEncodeHints(0))
bArmature * ED_armature_context(const bContext *C)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
bool ANIM_armature_bonecoll_contains_active_bone(const bArmature *armature, const BoneCollection *bcoll)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
ID_Type GS(const char *name)
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value)
int ANIM_armature_bonecoll_move_before_after_index(bArmature *armature, int from_index, int to_index, MoveLocation before_after)
Object * CTX_data_active_object(const bContext *C)
bool ANIM_armature_bonecoll_is_editable(const bArmature *armature, const BoneCollection *bcoll)
struct BoneCollection * bcoll
ListBaseT< BoneCollectionReference > collections
ListBaseT< BoneCollectionReference > bone_collections
ListBaseT< EditBone > * edbo
struct BoneCollection ** collection_array
int collection_root_count
ListBaseT< bPoseChannel > chanbase
const DropLocation drop_location
void label(StringRef name, int icon)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
void active_set(bool active)
ArmatureBoneCollection(bArmature *armature, int bcoll_index)
ArmatureBoneCollection()=default
const BoneCollection & bcoll() const