Fix T76578: Show bone visibility driver in outliner
authorNathan Craddock <nzcraddock@gmail.com>
Sat, 23 May 2020 16:07:51 +0000 (10:07 -0600)
committerNathan Craddock <nzcraddock@gmail.com>
Sat, 23 May 2020 16:36:54 +0000 (10:36 -0600)
Allow setting drivers and keyframes for the bone visibility restriction
icon in the outliner. Before the button was a simple icon button, but it
is now connected to the RNA property to show the driven or keyframed
state.

Also when hiding a bone from the outliner it would be deselected, but
from the properties editor it would remain selected. This moves the
deselection to the RNA update function to ensure the bone is always
deselected.

Differential Revision: https://developer.blender.org/D7825

release/scripts/startup/bl_ui/properties_data_bone.py
source/blender/editors/space_outliner/outliner_draw.c
source/blender/makesrna/intern/rna_armature.c

index aca358870c834030bfd2e675b703f03711900493..ff4425fbb73c2967fb1a204cfe3ebb6a5883df40 100644 (file)
@@ -267,7 +267,7 @@ class BONE_PT_display(BoneButtonsPanel, Panel):
         if bone:
 
             col = layout.column()
-            col.prop(bone, "hide", text="Hide")
+            col.prop(bone, "hide", text="Hide", toggle=0)
 
 
 class BONE_PT_display_custom_shape(BoneButtonsPanel, Panel):
index ce83cfc3c9787f2900d73ebd531d7f2150322147..49fee033de0050d12e6ed041495419522c0c5aa0 100644 (file)
@@ -178,20 +178,13 @@ static void restrictbutton_r_lay_cb(bContext *C, void *poin, void *UNUSED(poin2)
   WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, poin);
 }
 
-static void restrictbutton_bone_visibility_cb(bContext *C, void *poin, void *poin2)
+static void restrictbutton_bone_visibility_cb(bContext *C, void *poin, void *UNUSED(poin2))
 {
-  bArmature *arm = (bArmature *)poin;
-  Bone *bone = (Bone *)poin2;
-  if (bone->flag & BONE_HIDDEN_P) {
-    bone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
-  }
+  Bone *bone = (Bone *)poin;
 
   if (CTX_wm_window(C)->eventstate->ctrl) {
     restrictbutton_recursive_bone(bone, BONE_HIDDEN_P, (bone->flag & BONE_HIDDEN_P) != 0);
   }
-
-  WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL);
-  DEG_id_tag_update(&arm->id, ID_RECALC_COPY_ON_WRITE);
 }
 
 static void restrictbutton_bone_select_cb(bContext *C, void *UNUSED(poin), void *poin2)
@@ -859,6 +852,7 @@ typedef struct RestrictProperties {
       *layer_collection_hide_viewport;
   PropertyRNA *modifier_show_viewport, *modifier_show_render;
   PropertyRNA *constraint_enable;
+  PropertyRNA *bone_hide_viewport;
 } RestrictProperties;
 
 /* We don't care about the value of the property
@@ -877,6 +871,7 @@ typedef struct RestrictPropertiesActive {
   bool modifier_show_viewport;
   bool modifier_show_render;
   bool constraint_enable;
+  bool bone_hide_viewport;
 } RestrictPropertiesActive;
 
 static void outliner_restrict_properties_enable_collection_set(
@@ -1011,6 +1006,8 @@ static void outliner_draw_restrictbuts(uiBlock *block,
 
     props.constraint_enable = RNA_struct_type_find_property(&RNA_Constraint, "mute");
 
+    props.bone_hide_viewport = RNA_struct_type_find_property(&RNA_Bone, "hide");
+
     props.initialized = true;
   }
 
@@ -1279,27 +1276,32 @@ static void outliner_draw_restrictbuts(uiBlock *block,
         }
       }
       else if (tselem->type == TSE_POSE_CHANNEL) {
+        PointerRNA ptr;
         bPoseChannel *pchan = (bPoseChannel *)te->directdata;
         Bone *bone = pchan->bone;
         Object *ob = (Object *)tselem->id;
+        bArmature *arm = ob->data;
+
+        RNA_pointer_create(&arm->id, &RNA_Bone, bone, &ptr);
 
         if (soops->show_restrict_flags & SO_RESTRICT_VIEWPORT) {
-          bt = uiDefIconButBitI(block,
-                                UI_BTYPE_ICON_TOGGLE,
-                                BONE_HIDDEN_P,
-                                0,
-                                ICON_RESTRICT_VIEW_OFF,
-                                (int)(region->v2d.cur.xmax - restrict_offsets.viewport),
-                                te->ys,
-                                UI_UNIT_X,
-                                UI_UNIT_Y,
-                                &(bone->flag),
-                                0,
-                                0,
-                                0,
-                                0,
-                                TIP_("Restrict visibility in the 3D View"));
-          UI_but_func_set(bt, restrictbutton_bone_visibility_cb, ob->data, bone);
+          bt = uiDefIconButR_prop(block,
+                                  UI_BTYPE_ICON_TOGGLE,
+                                  0,
+                                  0,
+                                  (int)(region->v2d.cur.xmax - restrict_offsets.viewport),
+                                  te->ys,
+                                  UI_UNIT_X,
+                                  UI_UNIT_Y,
+                                  &ptr,
+                                  props.bone_hide_viewport,
+                                  -1,
+                                  0,
+                                  0,
+                                  -1,
+                                  -1,
+                                  TIP_("Restrict visibility in the 3D View"));
+          UI_but_func_set(bt, restrictbutton_bone_visibility_cb, bone, NULL);
           UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
           UI_but_drawflag_enable(bt, UI_BUT_ICON_REVERSE);
         }
index fe35af8c2e027f823cad90f990bcfb7307ef708d..cd7875d84e30773e33ad6916ae0ca6df1322db9b 100644 (file)
@@ -176,6 +176,20 @@ static void rna_Armature_redraw_data(Main *UNUSED(bmain), Scene *UNUSED(scene),
   WM_main_add_notifier(NC_GEOM | ND_DATA, id);
 }
 
+/* Unselect bones when hidden */
+static void rna_Bone_hide_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
+{
+  bArmature *arm = (bArmature *)ptr->owner_id;
+  Bone *bone = (Bone *)ptr->data;
+
+  if (bone->flag & BONE_HIDDEN_P) {
+    bone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
+  }
+
+  WM_main_add_notifier(NC_OBJECT | ND_POSE, arm);
+  DEG_id_tag_update(&arm->id, ID_RECALC_COPY_ON_WRITE);
+}
+
 /* called whenever a bone is renamed */
 static void rna_Bone_update_renamed(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
 {
@@ -1143,7 +1157,8 @@ static void rna_def_bone(BlenderRNA *brna)
       prop,
       "Hide",
       "Bone is not visible when it is not in Edit Mode (i.e. in Object or Pose Modes)");
-  RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
+  RNA_def_property_ui_icon(prop, ICON_RESTRICT_VIEW_OFF, -1);
+  RNA_def_property_update(prop, 0, "rna_Bone_hide_update");
 
   prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
   RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_SELECTED);