[Bf-blender-cvs] [c4d3d104017] master: Cleanup: Deduplicate Outliner item culling logic

Julian Eisel noreply at git.blender.org
Wed Mar 9 15:24:01 CET 2022


Commit: c4d3d104017c79c06127eadf30432b90c2875f3a
Author: Julian Eisel
Date:   Wed Mar 9 15:14:57 2022 +0100
Branches: master
https://developer.blender.org/rBc4d3d104017c79c06127eadf30432b90c2875f3a

Cleanup: Deduplicate Outliner item culling logic

For whatever reason the "in-view" check was using 2x the element height.
>From what I can see this isn't needed, so I'll remove it in a follow-up
commit.

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

M	source/blender/editors/space_outliner/outliner_draw.cc
M	source/blender/editors/space_outliner/outliner_intern.hh
M	source/blender/editors/space_outliner/outliner_utils.cc

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

diff --git a/source/blender/editors/space_outliner/outliner_draw.cc b/source/blender/editors/space_outliner/outliner_draw.cc
index 04d4da5e62f..7b62b28abc5 100644
--- a/source/blender/editors/space_outliner/outliner_draw.cc
+++ b/source/blender/editors/space_outliner/outliner_draw.cc
@@ -1721,7 +1721,7 @@ static void outliner_draw_userbuts(uiBlock *block,
 
   LISTBASE_FOREACH (TreeElement *, te, lb) {
     TreeStoreElem *tselem = TREESTORE(te);
-    if (te->ys + 2 * UI_UNIT_Y >= region->v2d.cur.ymin && te->ys <= region->v2d.cur.ymax) {
+    if (outliner_is_element_in_view(te, &region->v2d)) {
       if (tselem->type == TSE_SOME_ID) {
         uiBut *bt;
         ID *id = tselem->id;
@@ -1792,8 +1792,7 @@ static bool outliner_draw_overrides_buts(uiBlock *block,
 
   LISTBASE_FOREACH (TreeElement *, te, lb) {
     bool item_has_warnings = false;
-    const bool do_draw = (te->ys + 2 * UI_UNIT_Y >= region->v2d.cur.ymin &&
-                          te->ys <= region->v2d.cur.ymax);
+    const bool do_draw = outliner_is_element_in_view(te, &region->v2d);
     int but_flag = UI_BUT_DRAG_LOCK;
     const char *tip = nullptr;
 
@@ -1903,7 +1902,7 @@ static void outliner_draw_rnabuts(
 
   LISTBASE_FOREACH (TreeElement *, te, lb) {
     TreeStoreElem *tselem = TREESTORE(te);
-    if (te->ys + 2 * UI_UNIT_Y >= region->v2d.cur.ymin && te->ys <= region->v2d.cur.ymax) {
+    if (outliner_is_element_in_view(te, &region->v2d)) {
       if (TreeElementRNAProperty *te_rna_prop = tree_element_cast<TreeElementRNAProperty>(te)) {
         ptr = te_rna_prop->getPointerRNA();
         prop = te_rna_prop->getPropertyRNA();
diff --git a/source/blender/editors/space_outliner/outliner_intern.hh b/source/blender/editors/space_outliner/outliner_intern.hh
index 7a45531c608..b9ffea7c735 100644
--- a/source/blender/editors/space_outliner/outliner_intern.hh
+++ b/source/blender/editors/space_outliner/outliner_intern.hh
@@ -33,6 +33,7 @@ struct ViewLayer;
 struct bContext;
 struct bContextDataResult;
 struct bPoseChannel;
+struct View2D;
 struct wmKeyConfig;
 struct wmOperatorType;
 
@@ -642,9 +643,15 @@ float outliner_restrict_columns_width(const struct SpaceOutliner *space_outliner
  */
 TreeElement *outliner_find_element_with_flag(const ListBase *lb, short flag);
 /**
- * Find if element is visible in the outliner tree.
+ * Find if element is visible in the outliner tree, i.e. if all of its parents are expanded.
+ * Doesn't check if the item is in view-bounds, for that use #outliner_is_element_in_view().
  */
 bool outliner_is_element_visible(const TreeElement *te);
+/**
+ * Check if the element is displayed within the view bounds. Doesn't check if all parents are
+ * open/uncollapsed.
+ */
+bool outliner_is_element_in_view(const TreeElement *te, const struct View2D *v2d);
 /**
  * Scroll view vertically while keeping within total bounds.
  */
diff --git a/source/blender/editors/space_outliner/outliner_utils.cc b/source/blender/editors/space_outliner/outliner_utils.cc
index b49a2416b38..15a7a3bec15 100644
--- a/source/blender/editors/space_outliner/outliner_utils.cc
+++ b/source/blender/editors/space_outliner/outliner_utils.cc
@@ -386,6 +386,11 @@ bool outliner_is_element_visible(const TreeElement *te)
   return true;
 }
 
+bool outliner_is_element_in_view(const TreeElement *te, const View2D *v2d)
+{
+  return ((te->ys + 2 * UI_UNIT_Y) >= v2d->cur.ymin) && (te->ys <= v2d->cur.ymax);
+}
+
 bool outliner_item_is_co_over_name_icons(const TreeElement *te, float view_co_x)
 {
   /* Special case: count area left of Scene Collection as empty space */



More information about the Bf-blender-cvs mailing list