[Bf-blender-cvs] [3d916c0a966] blender-v2.91-release: Cleanup: Simplify outliner mode column drawing function

Hans Goudey noreply at git.blender.org
Thu Oct 22 22:46:53 CEST 2020


Commit: 3d916c0a966c96fa394d219be4029ca27d68d198
Author: Hans Goudey
Date:   Thu Oct 22 15:46:35 2020 -0500
Branches: blender-v2.91-release
https://developer.blender.org/rB3d916c0a966c96fa394d219be4029ca27d68d198

Cleanup: Simplify outliner mode column drawing function

Move the checks for whether to draw the button to the beginning of the
function and return early. Also use a shorthand variable for ob_active.

Committing to 2.91 as a patch for an upcoming bug fix depends on these
changes.

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

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

M	source/blender/editors/space_outliner/outliner_draw.c

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

diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c
index 09ccb950c18..3045529747d 100644
--- a/source/blender/editors/space_outliner/outliner_draw.c
+++ b/source/blender/editors/space_outliner/outliner_draw.c
@@ -1947,60 +1947,65 @@ static void outliner_draw_mode_column_toggle(uiBlock *block,
                                              TreeStoreElem *tselem,
                                              const bool lock_object_modes)
 {
-  const int active_mode = tvc->obact->mode;
-  bool draw_active_icon = true;
+  if (tselem->type != 0 || te->idcode != ID_OB) {
+    return;
+  }
 
-  if (tselem->type == 0 && te->idcode == ID_OB) {
-    Object *ob = (Object *)tselem->id;
+  Object *ob = (Object *)tselem->id;
+  Object *ob_active = tvc->obact;
 
-    /* When not locking object modes, objects can remain in non-object modes. For modes that do not
-     * allow multi-object editing, these other objects should still show be viewed as not in the
-     * mode. Otherwise multiple objects show the same mode icon in the outliner even though only
-     * one object is actually editable in the mode. */
-    if (!lock_object_modes && ob != tvc->obact && !(tvc->ob_edit || tvc->ob_pose)) {
-      draw_active_icon = false;
-    }
+  /* Not all objects support particle systems. */
+  if (ob_active->mode == OB_MODE_PARTICLE_EDIT && !psys_get_current(ob)) {
+    return;
+  }
 
-    if (ob->type == tvc->obact->type) {
-      int icon;
-      const char *tip;
+  /* Only for objects with the same type. */
+  if (ob->type != ob_active->type) {
+    return;
+  }
 
-      if (draw_active_icon && ob->mode == tvc->obact->mode) {
-        icon = UI_icon_from_object_mode(active_mode);
-        tip = TIP_("Remove from the current mode");
-      }
-      else {
-        /* Not all objects support particle systems */
-        if (active_mode == OB_MODE_PARTICLE_EDIT && !psys_get_current(ob)) {
-          return;
-        }
-        icon = ICON_DOT;
-        tip = TIP_(
-            "Change the object in the current mode\n"
-            "* Ctrl to add to the current mode");
-      }
+  bool draw_active_icon = ob->mode == ob_active->mode;
 
-      uiBut *but = uiDefIconBut(block,
-                                UI_BTYPE_ICON_TOGGLE,
-                                0,
-                                icon,
-                                0,
-                                te->ys,
-                                UI_UNIT_X,
-                                UI_UNIT_Y,
-                                NULL,
-                                0.0,
-                                0.0,
-                                0.0,
-                                0.0,
-                                tip);
-      UI_but_func_set(but, outliner_mode_toggle_fn, tselem, NULL);
-      UI_but_flag_enable(but, UI_BUT_DRAG_LOCK);
-
-      if (ID_IS_LINKED(&ob->id)) {
-        UI_but_disable(but, TIP_("Can't edit external library data"));
-      }
-    }
+  /* When not locking object modes, objects can remain in non-object modes. For modes that do not
+   * allow multi-object editing, these other objects should still show be viewed as not in the
+   * mode. Otherwise multiple objects show the same mode icon in the outliner even though only
+   * one object is actually editable in the mode. */
+  if (!lock_object_modes && ob != ob_active && !(tvc->ob_edit || tvc->ob_pose)) {
+    draw_active_icon = false;
+  }
+
+  int icon;
+  const char *tip;
+  if (draw_active_icon) {
+    icon = UI_icon_from_object_mode(ob_active->mode);
+    tip = TIP_("Remove from the current mode");
+  }
+  else {
+    icon = ICON_DOT;
+    tip = TIP_(
+        "Change the object in the current mode\n"
+        "* Ctrl to add to the current mode");
+  }
+
+  uiBut *but = uiDefIconBut(block,
+                            UI_BTYPE_ICON_TOGGLE,
+                            0,
+                            icon,
+                            0,
+                            te->ys,
+                            UI_UNIT_X,
+                            UI_UNIT_Y,
+                            NULL,
+                            0.0,
+                            0.0,
+                            0.0,
+                            0.0,
+                            tip);
+  UI_but_func_set(but, outliner_mode_toggle_fn, tselem, NULL);
+  UI_but_flag_enable(but, UI_BUT_DRAG_LOCK);
+
+  if (ID_IS_LINKED(&ob->id)) {
+    UI_but_disable(but, TIP_("Can't edit external library data"));
   }
 }



More information about the Bf-blender-cvs mailing list