Fix T44921: Node editor, nodes position not maintained after Material panel changes
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 2 Jun 2015 07:32:43 +0000 (12:32 +0500)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 2 Jun 2015 07:32:43 +0000 (12:32 +0500)
Also improved a bit behavior of adding new nodes, now they will not overlap that
badly. Still not ideal, but further improvements better not to happen at bcon4.

source/blender/editors/space_node/node_templates.c

index 8b68ac013c24ed9eb0c7b35c1505774b631d0438..ea91a735bbec6e911a6270041927df7729d2e884 100644 (file)
@@ -214,8 +214,22 @@ static void node_socket_add_replace(const bContext *C, bNodeTree *ntree, bNode *
        }
        else if (!node_from) {
                node_from = nodeAddStaticNode(C, ntree, type);
-               node_from->locx = node_to->locx - (node_from->typeinfo->width + 50);
-               node_from->locy = node_to->locy;
+               if (node_prev != NULL) {
+                       /* If we're replacing existing node, use it's location. */
+                       node_from->locx = node_prev->locx;
+                       node_from->locy = node_prev->locy;
+                       node_from->offsetx = node_prev->offsetx;
+                       node_from->offsety = node_prev->offsety;
+               }
+               else {
+                       /* Avoid exact intersection of nodes.
+                        * TODO(sergey): Still not ideal, but better than nothing.
+                        */
+                       int index = BLI_findindex(&node_to->inputs, sock_to);
+                       BLI_assert(index != -1);
+                       node_from->locx = node_to->locx - (node_from->typeinfo->width + 50);
+                       node_from->locy = node_to->locy - (node_from->typeinfo->height * index);
+               }
                
                node_link_item_apply(node_from, item);
        }