diff options
author | Hans Goudey <h.goudey@me.com> | 2021-02-19 22:56:49 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-02-19 22:56:49 +0300 |
commit | 34580748dcf0a3656dd634fc90cb00ec27367376 (patch) | |
tree | 75d813f3697481084410943c61a42d3bbf5f748c /source/blender/editors/space_outliner/outliner_draw.c | |
parent | 55700ac3906f182be8d3dff6f7d63cc27463d91b (diff) |
Fix T83027: Incorrect outliner collection state after operator
The "Hide Collection" operators assigned to the number keys in edit mode
trigger a redraw of the outliner, but as an optimization, they do *not*
trigger a rebuild of the tree.
This optimization is valid because unlike the collection exclude toggle,
the heirarchy is not affected by collection visibility. However, it means
that currently you must trigger a rebuild to get the correct "grayed out"
status after using the operator.
Rather than trigger a rebuild in this case to solve the bug, this patch
moves the decision for whether to gray out the text of a tree element
to the draw step rather than the build step. This means that any change
to the corresponding properties doesn't require a full tree rebuild.
Note that changing the "hide_viewport" property from the outliner still
causes a tree rebuild. I think that's because of the checks in
`outliner_collection_set_flag_recursive_fn`.
That could be optimized in the future.
Differential Revision: https://developer.blender.org/D10240
Diffstat (limited to 'source/blender/editors/space_outliner/outliner_draw.c')
-rw-r--r-- | source/blender/editors/space_outliner/outliner_draw.c | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c index 76c710b3db1..844f2ee8209 100644 --- a/source/blender/editors/space_outliner/outliner_draw.c +++ b/source/blender/editors/space_outliner/outliner_draw.c @@ -2958,6 +2958,41 @@ static void outliner_set_coord_tree_element(TreeElement *te, int startx, int sta } } +static bool element_should_draw_faded(const TreeViewContext *tvc, + const TreeElement *te, + const TreeStoreElem *tselem) +{ + if (tselem->type == 0) { + switch (te->idcode) { + case ID_OB: { + const Object *ob = (const Object *)tselem->id; + /* Lookup in view layer is logically const as it only checks a cache. */ + const Base *base = (te->directdata) ? (const Base *)te->directdata : + BKE_view_layer_base_find( + (ViewLayer *)tvc->view_layer, (Object *)ob); + const bool is_visible = (base != NULL) && (base->flag & BASE_VISIBLE_VIEWLAYER); + if (!is_visible) { + return true; + } + } + } + } + switch (tselem->type) { + case TSE_LAYER_COLLECTION: { + const LayerCollection *layer_collection = (const LayerCollection *)te->directdata; + const bool is_visibe = layer_collection->runtime_flag & LAYER_COLLECTION_VISIBLE_VIEW_LAYER; + const bool is_excluded = layer_collection->flag & LAYER_COLLECTION_EXCLUDE; + return !is_visibe || is_excluded; + } + } + + if (te->flag & TE_CHILD_NOT_IN_COLLECTION) { + return true; + } + + return false; +} + static void outliner_draw_tree_element(bContext *C, uiBlock *block, const uiFontStyle *fstyle, @@ -2981,10 +3016,7 @@ static void outliner_draw_tree_element(bContext *C, outliner_icon_background_colors(icon_bgcolor, icon_border); if (*starty + 2 * UI_UNIT_Y >= region->v2d.cur.ymin && *starty <= region->v2d.cur.ymax) { - const float alpha_fac = ((te->flag & TE_DISABLED) || (te->flag & TE_CHILD_NOT_IN_COLLECTION) || - draw_grayed_out) ? - 0.5f : - 1.0f; + const float alpha_fac = element_should_draw_faded(tvc, te, tselem) ? 0.5f : 1.0f; int xmax = region->v2d.cur.xmax; if ((tselem->flag & TSE_TEXTBUT) && (*te_edit == NULL)) { |