[Bf-blender-cvs] [2d5b89be89c] master: Cleanup: Disentangle outliner active status "get" and "set"

Hans Goudey noreply at git.blender.org
Fri Feb 19 23:29:40 CET 2021


Commit: 2d5b89be89c20f36c3607fd52666dcdb6c9a597d
Author: Hans Goudey
Date:   Fri Feb 19 16:29:11 2021 -0600
Branches: master
https://developer.blender.org/rB2d5b89be89c20f36c3607fd52666dcdb6c9a597d

Cleanup: Disentangle outliner active status "get" and "set"

Previously the same functions were used to both set and get the active
state for outliner tree elements. This has quite a few problems.
 - It's hard to tell when data is changed or simply read
 - It prevents using `const`
 - The code is full of if statements, making it longer and less readable.

This commit replaces the `tree_element_type_active` and
`tree_element_active` functions with `_get` and `_set` variants. One
has const arguments and returns the active state, the other deals only
with setting the state. While this refactor results in slightly more
lines of code, the result is much better in my opinion.

This commit also removes unused variables from arguments of the affected
functions.

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

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

M	source/blender/editors/space_outliner/outliner_draw.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_draw.c b/source/blender/editors/space_outliner/outliner_draw.c
index 0badff12b1f..031c94689b0 100644
--- a/source/blender/editors/space_outliner/outliner_draw.c
+++ b/source/blender/editors/space_outliner/outliner_draw.c
@@ -760,7 +760,7 @@ static void namebutton_fn(bContext *C, void *tsep, char *oldname)
           char newname[sizeof(bone->name)];
 
           /* always make current object active */
-          tree_element_active(C, &tvc, space_outliner, te, OL_SETSEL_NORMAL, true);
+          tree_element_activate(C, &tvc, te, OL_SETSEL_NORMAL, true);
 
           /* restore bone name */
           BLI_strncpy(newname, bone->name, sizeof(bone->name));
@@ -778,7 +778,7 @@ static void namebutton_fn(bContext *C, void *tsep, char *oldname)
           char newname[sizeof(pchan->name)];
 
           /* always make current pose-bone active */
-          tree_element_active(C, &tvc, space_outliner, te, OL_SETSEL_NORMAL, true);
+          tree_element_activate(C, &tvc, te, OL_SETSEL_NORMAL, true);
 
           BLI_assert(ob->type == OB_ARMATURE);
 
@@ -2872,16 +2872,11 @@ static void outliner_draw_iconrow(bContext *C,
           active = OL_DRAWSEL_ACTIVE;
         }
         else {
-          active = tree_element_active(C, tvc, space_outliner, te, OL_SETSEL_NONE, false);
+          active = tree_element_active_state_get(tvc, te, tselem);
         }
       }
-      else if (tselem->type == TSE_GP_LAYER) {
-        bGPDlayer *gpl = te->directdata;
-        active = (gpl->flag & GP_LAYER_ACTIVE) ? OL_DRAWSEL_ACTIVE : OL_DRAWSEL_NONE;
-      }
       else {
-        active = tree_element_type_active(
-            C, tvc, space_outliner, te, tselem, OL_SETSEL_NONE, false);
+        active = tree_element_type_active_state_get(C, tvc, te, tselem);
       }
 
       if (!ELEM(tselem->type, 0, TSE_LAYER_COLLECTION, TSE_R_LAYER, TSE_GP_LAYER)) {
@@ -3029,14 +3024,7 @@ static void outliner_draw_tree_element(bContext *C,
 
     /* Colors for active/selected data. */
     if (tselem->type == 0) {
-      if (te->idcode == ID_SCE) {
-        if (tselem->id == (ID *)tvc->scene) {
-          /* Active scene. */
-          icon_bgcolor[3] = 0.2f;
-          active = OL_DRAWSEL_ACTIVE;
-        }
-      }
-      else if (te->idcode == ID_OB) {
+      if (te->idcode == ID_OB) {
         Object *ob = (Object *)tselem->id;
         Base *base = (te->directdata) ? (Base *)te->directdata :
                                         BKE_view_layer_base_find(tvc->view_layer, ob);
@@ -3066,23 +3054,15 @@ static void outliner_draw_tree_element(bContext *C,
         active = OL_DRAWSEL_ACTIVE;
       }
       else {
-        if (tree_element_active(C, tvc, space_outliner, te, OL_SETSEL_NONE, false)) {
+        if (tree_element_active_state_get(tvc, te, tselem)) {
           /* Active items like camera or material. */
           icon_bgcolor[3] = 0.2f;
           active = OL_DRAWSEL_ACTIVE;
         }
       }
     }
-    else if (tselem->type == TSE_GP_LAYER) {
-      /* Active grease pencil layer. */
-      if (((bGPDlayer *)te->directdata)->flag & GP_LAYER_ACTIVE) {
-        icon_bgcolor[3] = 0.2f;
-        active = OL_DRAWSEL_ACTIVE;
-      }
-    }
     else {
-      active = tree_element_type_active(C, tvc, space_outliner, te, tselem, OL_SETSEL_NONE, false);
-      /* Active collection. */
+      active = tree_element_type_active_state_get(C, tvc, te, tselem);
     }
 
     /* Active circle. */
diff --git a/source/blender/editors/space_outliner/outliner_intern.h b/source/blender/editors/space_outliner/outliner_intern.h
index 9413b7a9613..593c33bd3df 100644
--- a/source/blender/editors/space_outliner/outliner_intern.h
+++ b/source/blender/editors/space_outliner/outliner_intern.h
@@ -288,19 +288,24 @@ void outliner_collection_isolate_flag(struct Scene *scene,
 int tree_element_id_type_to_index(TreeElement *te);
 
 /* outliner_select.c -------------------------------------------- */
-eOLDrawState tree_element_type_active(struct bContext *C,
-                                      const TreeViewContext *tvc,
-                                      struct SpaceOutliner *space_outliner,
-                                      TreeElement *te,
-                                      TreeStoreElem *tselem,
-                                      const eOLSetState set,
-                                      bool recursive);
-eOLDrawState tree_element_active(struct bContext *C,
-                                 const TreeViewContext *tvc,
-                                 SpaceOutliner *space_outliner,
-                                 TreeElement *te,
-                                 const eOLSetState set,
-                                 const bool handle_all_types);
+void tree_element_type_active_set(struct bContext *C,
+                                  const TreeViewContext *tvc,
+                                  TreeElement *te,
+                                  TreeStoreElem *tselem,
+                                  const eOLSetState set,
+                                  bool recursive);
+eOLDrawState tree_element_type_active_state_get(const struct bContext *C,
+                                                const struct TreeViewContext *tvc,
+                                                const TreeElement *te,
+                                                const TreeStoreElem *tselem);
+void tree_element_activate(struct bContext *C,
+                           const TreeViewContext *tvc,
+                           TreeElement *te,
+                           const eOLSetState set,
+                           const bool handle_all_types);
+eOLDrawState tree_element_active_state_get(const TreeViewContext *tvc,
+                                           const TreeElement *te,
+                                           const TreeStoreElem *tselem);
 
 struct bPoseChannel *outliner_find_parent_bone(TreeElement *te, TreeElement **r_bone_te);
 
diff --git a/source/blender/editors/space_outliner/outliner_select.c b/source/blender/editors/space_outliner/outliner_select.c
index c09334b0e86..e31af48ab7e 100644
--- a/source/blender/editors/space_outliner/outliner_select.c
+++ b/source/blender/editors/space_outliner/outliner_select.c
@@ -222,32 +222,21 @@ void outliner_item_mode_toggle(bContext *C,
 /* ****************************************************** */
 /* Outliner Element Selection/Activation on Click */
 
-static eOLDrawState active_viewlayer(bContext *C,
-                                     Scene *UNUSED(scene),
-                                     ViewLayer *UNUSED(sl),
-                                     TreeElement *te,
-                                     const eOLSetState set)
+static void tree_element_viewlayer_activate(bContext *C, TreeElement *te)
 {
   /* paranoia check */
   if (te->idcode != ID_SCE) {
-    return OL_DRAWSEL_NONE;
+    return;
   }
 
   ViewLayer *view_layer = te->directdata;
+  wmWindow *win = CTX_wm_window(C);
+  Scene *scene = WM_window_get_active_scene(win);
 
-  if (set != OL_SETSEL_NONE) {
-    wmWindow *win = CTX_wm_window(C);
-    Scene *scene = WM_window_get_active_scene(win);
-
-    if (BLI_findindex(&scene->view_layers, view_layer) != -1) {
-      WM_window_set_active_view_layer(win, view_layer);
-      WM_event_add_notifier(C, NC_SCREEN | ND_LAYER, NULL);
-    }
-  }
-  else {
-    return CTX_data_view_layer(C) == view_layer;
+  if (BLI_findindex(&scene->view_layers, view_layer) != -1) {
+    WM_window_set_active_view_layer(win, view_layer);
+    WM_event_add_notifier(C, NC_SCREEN | ND_LAYER, NULL);
   }
-  return OL_DRAWSEL_NONE;
 }
 
 /**
@@ -297,13 +286,12 @@ static void do_outliner_ebone_select_recursive(bArmature *arm, EditBone *ebone_p
   }
 }
 
-static eOLDrawState tree_element_set_active_object(bContext *C,
-                                                   Scene *scene,
-                                                   ViewLayer *view_layer,
-                                                   SpaceOutliner *UNUSED(space_outliner),
-                                                   TreeElement *te,
-                                                   const eOLSetState set,
-                                                   bool recursive)
+static void tree_element_object_activate(bContext *C,
+                                         Scene *scene,
+                                         ViewLayer *view_layer,
+                                         TreeElement *te,
+                                         const eOLSetState set,
+                                         bool recursive)
 {
   TreeStoreElem *tselem = TREESTORE(te);
   TreeStoreElem *parent_tselem = NULL;
@@ -324,12 +312,12 @@ static eOLDrawState tree_element_set_active_object(bContext *C,
 
       /* Don't return when activating children of the previous active object. */
       if (ob == OBACT(view_layer) && set == OL_SETSEL_NONE) {
-        return OL_DRAWSEL_NONE;
+        return;
       }
     }
   }
   if (ob == NULL) {
-    return OL_DRAWSEL_NONE;
+    return;
   }
 
   sce = (Scene *)outliner_search_back(te, ID_SCE);
@@ -403,319 +391,197 @@ static eOLDrawState tree_element_set_active_object(bContext *C,
       WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
     }
   }
-  return OL_DRAWSEL_NORMAL;
 }
 
-static eOLDrawState tree_element_active_material(bContext *C,
-                                                 Scene *UNUSED(scene),
-                                                 ViewLayer *view_layer,
-                                                 TreeElement *te,
-                                                 const eOLSetState set)
+static void tree_element_material_activate(bContext *C, ViewLayer *view_layer, TreeElement *te)
 {
-  TreeElement *tes;
-  Object *ob;
-
   /* we search for the object parent */
-  ob = (Object *)outliner_search_back(te, ID_OB);
+  Object *ob = (Object *)outliner_search_back(te, ID_OB);
   /* Note : ob->matbits can be NULL when a local object points to a library mesh. */
   if (ob == NULL || ob != OBACT(view_layer) || ob->matbits == NULL) {
-    return OL_DRAWSEL_NONE; /* just paranoia */
+    return; /* just paranoia */
   }
 
- 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list