20#include "RNA_prototypes.hh"
27#include <fmt/format.h>
45 void build_tree_node_recursive(TreeViewItemContainer &parent,
const int bcoll_index);
49 void build_bcolls_with_selected_bones();
82 const int bcoll_index);
84 std::optional<eWM_DragDataType>
get_drag_type()
const override;
111 if (drag_arm_bcoll->
armature != drop_bonecoll_.armature) {
112 *r_disabled_hint =
"Cannot drag & drop bone collections between Armatures.";
117 if (drag_arm_bcoll->
bcoll_index == drop_bonecoll_.bcoll_index) {
125 *r_disabled_hint =
"Cannot drag a collection onto a descendent";
144 return fmt::format(fmt::runtime(
TIP_(
"Move {} into {}")), drag_name, drop_name);
146 return fmt::format(fmt::runtime(
TIP_(
"Move {} above {}")), drag_name, drop_name);
148 return fmt::format(fmt::runtime(
TIP_(
"Move {} below {}")), drag_name, drop_name);
158 bArmature *arm = drop_bonecoll_.armature;
160 const int from_bcoll_index = drag_arm_bcoll->
bcoll_index;
161 const int to_bcoll_index = drop_bonecoll_.bcoll_index;
163 int new_bcoll_index = -1;
180 arm, from_bcoll_index, -1, from_parent_index, to_bcoll_index);
189 if (new_bcoll_index < 0) {
206 bool has_any_selected_bones_;
210 : armature_(armature),
211 bcoll_index_(bcoll_index),
212 bone_collection_(*armature.collection_array[bcoll_index]),
213 has_any_selected_bones_(has_any_selected_bones)
215 this->
label_ = bone_collection_.name;
222 uiBut *name_label =
uiItemL_ex(sub, bone_collection_.name, ICON_NONE,
false,
false);
233 icon = ICON_LAYER_ACTIVE;
235 else if (has_any_selected_bones_) {
236 icon = ICON_LAYER_USED;
241 sub->
label(
"", icon);
248 visibility_sub->
active_set(!is_solo_active && bone_collection_.is_visible_ancestors());
250 const int icon = bone_collection_.is_visible() ? ICON_HIDE_OFF : ICON_HIDE_ON;
257 const int icon = bone_collection_.is_solo() ? ICON_SOLO_ON : ICON_SOLO_OFF;
274 return armature_.runtime.active_collection_index == bcoll_index_;
282 &armature_.id, &RNA_BoneCollections, &armature_);
288 ED_undo_push(&
C,
"Change Armature's Active Bone Collection");
293 const bool is_collapsed = !bone_collection_.is_expanded();
315 &armature_.id, &RNA_BoneCollection, &bone_collection_);
343 return bone_collection_.name;
359 return std::make_unique<BoneCollectionDragController>(tree_view, armature_, bcoll_index_);
367 return std::make_unique<BoneCollectionDropTarget>(
383 build_bcolls_with_selected_bones();
385 for (
int bcoll_index = 0; bcoll_index <
armature_.collection_root_count; bcoll_index++) {
386 build_tree_node_recursive(*
this, bcoll_index);
391 const int bcoll_index)
396 armature_, bcoll_index, has_any_selected_bones);
400 build_tree_node_recursive(bcoll_tree_item, child_index);
409void BoneCollectionTreeView::build_bcolls_with_selected_bones()
429 if ((bone->flag & BONE_SELECTED) == 0) {
434 bcolls_with_selected_bones_.add(ref->bcoll);
441 const int bcoll_index)
454 *drag_data = drag_arm_bcoll_;
470 if (armature ==
nullptr) {
479 "Bone Collection Tree View",
480 std::make_unique<blender::ui::bonecollections::BoneCollectionTreeView>(*armature));
C++ functions to deal with Armature collections (i.e. the successor of bone layers).
bool ANIM_armature_bonecoll_is_editable(const bArmature *armature, const BoneCollection *bcoll)
void ANIM_armature_bonecoll_is_expanded_set(BoneCollection *bcoll, bool is_expanded)
int ANIM_armature_bonecoll_move_before_after_index(bArmature *armature, int from_index, int to_index, MoveLocation before_after)
void ANIM_armature_bonecoll_remove(bArmature *armature, BoneCollection *bcoll)
bool ANIM_armature_bonecoll_contains_active_bone(const bArmature *armature, const BoneCollection *bcoll)
void ANIM_armature_bonecoll_active_index_set(bArmature *armature, int bone_collection_index)
#define LISTBASE_FOREACH(type, var, list)
struct BoneCollectionReference BoneCollectionReference
void ED_undo_push(bContext *C, const char *str)
blender::ui::AbstractGridView * UI_block_add_view(uiBlock &block, blender::StringRef idname, std::unique_ptr< blender::ui::AbstractGridView > grid_view)
void uiTemplateBoneCollectionTree(uiLayout *layout, bContext *C)
void UI_but_flag_enable(uiBut *but, int flag)
void UI_menutype_draw(bContext *C, MenuType *mt, uiLayout *layout)
uiBut * uiItemL_ex(uiLayout *layout, blender::StringRef name, int icon, bool highlight, bool redalert)
@ WM_DRAG_BONE_COLLECTION
#define ND_BONE_COLLECTION
bArmature * ED_armature_context(const bContext *C)
bool contains(const Key &key) const
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, uiLayout &layout, bool add_box=true)
ItemT & add_tree_item(Args &&...args)
friend class AbstractTreeViewItem
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) 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
void build_row(uiLayout &row) override
std::unique_ptr< TreeViewItemDropTarget > create_drop_target() override
std::optional< bool > should_be_active() const override
StringRef get_rename_string() const override
void on_collapse_change(bContext &C, const bool is_collapsed) override
void build_context_menu(bContext &C, uiLayout &column) const 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
Set< BoneCollection * > bcolls_with_selected_bones_
BoneCollectionTreeView(bArmature &armature)
void build_tree() override
void * MEM_callocN(size_t len, const char *str)
static void ANIM_armature_foreach_bone(ListBase *bones, CB callback)
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)
void RNA_property_int_set(PointerRNA *ptr, PropertyRNA *prop, int value)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *value)
struct BoneCollection ** collection_array
const DropLocation drop_location
ArmatureBoneCollection(bArmature *armature, int bcoll_index)
ArmatureBoneCollection()=default
const BoneCollection & bcoll() const
void label(blender::StringRef name, int icon)
void active_set(bool active)
uiLayout & row(bool align)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)