[Bf-blender-cvs] [7c6b8d8db5a] soc-2020-outliner: Cleanup: Refactor parent bone into shared function

Nathan Craddock noreply at git.blender.org
Fri Aug 14 03:24:11 CEST 2020


Commit: 7c6b8d8db5a4b5e1b45cd44f7422714e2b26ee02
Author: Nathan Craddock
Date:   Thu Aug 13 19:15:05 2020 -0600
Branches: soc-2020-outliner
https://developer.blender.org/rB7c6b8d8db5a4b5e1b45cd44f7422714e2b26ee02

Cleanup: Refactor parent bone into shared function

===================================================================

M	source/blender/editors/space_outliner/outliner_dragdrop.c
M	source/blender/editors/space_outliner/outliner_intern.h
M	source/blender/editors/space_outliner/outliner_select.c

===================================================================

diff --git a/source/blender/editors/space_outliner/outliner_dragdrop.c b/source/blender/editors/space_outliner/outliner_dragdrop.c
index f2275ca1864..e533a7e0aa2 100644
--- a/source/blender/editors/space_outliner/outliner_dragdrop.c
+++ b/source/blender/editors/space_outliner/outliner_dragdrop.c
@@ -1386,17 +1386,9 @@ static int outliner_item_drag_drop_invoke(bContext *C,
            TSE_CONSTRAINT_BASE,
            TSE_EFFECT,
            TSE_EFFECT_BASE)) {
-    /* Check if parent is a bone */
-    TreeElement *te_bone = te->parent;
-    bPoseChannel *pchan = NULL;
-    while (te_bone) {
-      TreeStoreElem *tselem_bone = TREESTORE(te_bone);
-      if (tselem_bone->type == TSE_POSE_CHANNEL) {
-        pchan = (bPoseChannel *)te_bone->directdata;
-        break;
-      }
-      te_bone = te_bone->parent;
-    }
+
+    TreeElement *te_bone = NULL;
+    bPoseChannel *pchan = outliner_find_parent_bone(te, &te_bone);
     outliner_drop_data_init(drag, (Object *)tselem->id, pchan, te, tselem, te->directdata);
   }
   else if (ELEM(GS(data.drag_id->name), ID_OB, ID_GR)) {
diff --git a/source/blender/editors/space_outliner/outliner_intern.h b/source/blender/editors/space_outliner/outliner_intern.h
index 86bdff7df8f..64b06618948 100644
--- a/source/blender/editors/space_outliner/outliner_intern.h
+++ b/source/blender/editors/space_outliner/outliner_intern.h
@@ -276,6 +276,8 @@ eOLDrawState tree_element_active(struct bContext *C,
                                  const eOLSetState set,
                                  const bool handle_all_types);
 
+struct bPoseChannel *outliner_find_parent_bone(TreeElement *te, TreeElement **r_bone_te);
+
 void outliner_item_select(struct bContext *C,
                           struct SpaceOutliner *space_outliner,
                           struct TreeElement *te,
diff --git a/source/blender/editors/space_outliner/outliner_select.c b/source/blender/editors/space_outliner/outliner_select.c
index 4745ecb820a..30df35cdb00 100644
--- a/source/blender/editors/space_outliner/outliner_select.c
+++ b/source/blender/editors/space_outliner/outliner_select.c
@@ -1192,6 +1192,23 @@ eOLDrawState tree_element_type_active(bContext *C,
   return OL_DRAWSEL_NONE;
 }
 
+bPoseChannel *outliner_find_parent_bone(TreeElement *te, TreeElement **r_bone_te)
+{
+  TreeStoreElem *tselem;
+
+  te = te->parent;
+  while (te) {
+    tselem = TREESTORE(te);
+    if (tselem->type == TSE_POSE_CHANNEL) {
+      *r_bone_te = te;
+      return (bPoseChannel *)te->directdata;
+    }
+    te = te->parent;
+  }
+
+  return NULL;
+}
+
 static void outliner_set_properties_tab(bContext *C, TreeElement *te, TreeStoreElem *tselem)
 {
   PointerRNA ptr;
@@ -1241,26 +1258,15 @@ static void outliner_set_properties_tab(bContext *C, TreeElement *te, TreeStoreE
         break;
       case TSE_CONSTRAINT_BASE:
       case TSE_CONSTRAINT: {
-        RNA_id_pointer_create(tselem->id, &ptr);
-        bool is_bone_constraint = false;
-
-        /* Check if parent is a bone */
-        te = te->parent;
-        while (te) {
-          tselem = TREESTORE(te);
-          if (tselem->type == TSE_POSE_CHANNEL) {
-            bPoseChannel *pchan = (bPoseChannel *)te->directdata;
-            RNA_pointer_create(tselem->id, &RNA_PoseBone, pchan, &ptr);
+        TreeElement *bone_te = NULL;
+        bPoseChannel *pchan = outliner_find_parent_bone(te, &bone_te);
 
-            is_bone_constraint = true;
-            break;
-          }
-          te = te->parent;
-        }
-        if (is_bone_constraint) {
+        if (pchan) {
+          RNA_pointer_create(TREESTORE(bone_te)->id, &RNA_PoseBone, pchan, &ptr);
           ED_buttons_set_context(C, &ptr, BCONTEXT_BONE_CONSTRAINT);
         }
         else {
+          RNA_id_pointer_create(tselem->id, &ptr);
           ED_buttons_set_context(C, &ptr, BCONTEXT_CONSTRAINT);
         }
         break;



More information about the Bf-blender-cvs mailing list