Merge branch 'master' into geometry-nodes-simulation

This commit is contained in:
Hans Goudey 2022-12-01 17:57:14 -06:00
commit e9c3e4f14e
1 changed files with 15 additions and 8 deletions

View File

@ -201,7 +201,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! */
@ -214,7 +215,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) {
@ -227,7 +228,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) {
@ -240,17 +241,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;
}
@ -260,7 +267,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. */