[Bf-blender-cvs] [587b213fe16] master: Fix: Node sorting broken after node identifier commit

Hans Goudey noreply at git.blender.org
Fri Dec 2 00:57:06 CET 2022


Commit: 587b213fe1684ba631b12c40f1db785ec3406614
Author: Hans Goudey
Date:   Thu Dec 1 17:55:33 2022 -0600
Branches: master
https://developer.blender.org/rB587b213fe1684ba631b12c40f1db785ec3406614

Fix: Node sorting broken after node identifier commit

90ea1b76434fe175 broke the sorting that happens as nodes are selected.
The compare function for stable sort had different requirements than
the previous implementation.

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

M	source/blender/editors/space_node/node_draw.cc

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

diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc
index be778a75039..31a146ed6a2 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -187,7 +187,8 @@ static void node_socket_add_tooltip_in_node_editor(TreeDrawContext * /*tree_draw
                                                    const bNodeSocket *sock,
                                                    uiLayout *layout);
 
-static bool compare_nodes(const bNode *a, const bNode *b)
+/** Return true when \a a should be behind \a b and false otherwise. */
+static bool compare_node_depth(const bNode *a, const bNode *b)
 {
   /* These tell if either the node or any of the parent nodes is selected.
    * A selected parent means an unselected node is also in foreground! */
@@ -200,7 +201,7 @@ static bool compare_nodes(const bNode *a, const bNode *b)
   for (bNode *parent = a->parent; parent; parent = parent->parent) {
     /* If B is an ancestor, it is always behind A. */
     if (parent == b) {
-      return true;
+      return false;
     }
     /* Any selected ancestor moves the node forward. */
     if (parent->flag & NODE_ACTIVE) {
@@ -213,7 +214,7 @@ static bool compare_nodes(const bNode *a, const bNode *b)
   for (bNode *parent = b->parent; parent; parent = parent->parent) {
     /* If A is an ancestor, it is always behind B. */
     if (parent == a) {
-      return false;
+      return true;
     }
     /* Any selected ancestor moves the node forward. */
     if (parent->flag & NODE_ACTIVE) {
@@ -226,17 +227,23 @@ static bool compare_nodes(const bNode *a, const bNode *b)
 
   /* One of the nodes is in the background and the other not. */
   if ((a->flag & NODE_BACKGROUND) && !(b->flag & NODE_BACKGROUND)) {
-    return false;
-  }
-  if (!(a->flag & NODE_BACKGROUND) && (b->flag & NODE_BACKGROUND)) {
     return true;
   }
+  if ((b->flag & NODE_BACKGROUND) && !(a->flag & NODE_BACKGROUND)) {
+    return false;
+  }
 
   /* One has a higher selection state (active > selected > nothing). */
-  if (!b_active && a_active) {
+  if (a_active && !b_active) {
+    return false;
+  }
+  if (b_active && !a_active) {
     return true;
   }
   if (!b_select && (a_active || a_select)) {
+    return false;
+  }
+  if (!a_select && (b_active || b_select)) {
     return true;
   }
 
@@ -246,7 +253,7 @@ static bool compare_nodes(const bNode *a, const bNode *b)
 void node_sort(bNodeTree &ntree)
 {
   Array<bNode *> sort_nodes = ntree.all_nodes();
-  std::stable_sort(sort_nodes.begin(), sort_nodes.end(), compare_nodes);
+  std::stable_sort(sort_nodes.begin(), sort_nodes.end(), compare_node_depth);
 
   /* If nothing was changed, exit early. Otherwise the node tree's runtime
    * node vector needs to be rebuilt, since it cannot be reordered in place. */



More information about the Bf-blender-cvs mailing list