diff options
author | Hans Goudey <h.goudey@me.com> | 2021-02-20 01:29:11 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-02-20 01:29:11 +0300 |
commit | 2d5b89be89c20f36c3607fd52666dcdb6c9a597d (patch) | |
tree | 95e79191ae6113644bc49e5edae6876a8b648fc1 /source/blender/editors/space_outliner/outliner_draw.c | |
parent | a961a2189cb38ffb368d6781aa57177bfefe0e36 (diff) |
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
Diffstat (limited to 'source/blender/editors/space_outliner/outliner_draw.c')
-rw-r--r-- | source/blender/editors/space_outliner/outliner_draw.c | 34 |
1 files changed, 7 insertions, 27 deletions
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. */ |