Fix #32118, Reroute nodes inside groups get created in wonky places.
authorLukas Toenne <lukas.toenne@googlemail.com>
Fri, 20 Jul 2012 15:07:06 +0000 (15:07 +0000)
committerLukas Toenne <lukas.toenne@googlemail.com>
Fri, 20 Jul 2012 15:07:06 +0000 (15:07 +0000)
Previous attempt was not taking into account parent nodes of the group nodes (i.e. frames). The nodeFromView function should be used to convert between relative node location to absolute view space. Also added this in the node_add_node helper function, which is used in a number of operators for adding nodes in a specific location.

source/blender/editors/space_node/node_edit.c

index 512781f9b778456c3b1e26b1a512111061b73036..a0df2aefab149b9e0d5c0894484f1e2b9ca12590 100644 (file)
@@ -2549,14 +2549,16 @@ bNode *node_add_node(SpaceNode *snode, Main *bmain, Scene *scene, bNodeTemplate
        
        /* generics */
        if (node) {
-               node->locx = locx;
-               node->locy = locy + 60.0f;       // arbitrary.. so its visible, (0,0) is top of node
                node_select(node);
                
                gnode = node_tree_get_editgroup(snode->nodetree);
+               // arbitrary y offset of 60 so its visible
                if (gnode) {
-                       node->locx -= gnode->locx;
-                       node->locy -= gnode->locy;
+                       nodeFromView(gnode, locx, locy + 60.0f, &node->locx, &node->locy);
+               }
+               else {
+                       node->locx = locx;
+                       node->locy = locy + 60.0f;
                }
 
                ntreeUpdateTree(snode->edittree);
@@ -3173,11 +3175,12 @@ static int add_reroute_exec(bContext *C, wmOperator *op)
                                
                                ntemp.type = NODE_REROUTE;
                                rerouteNode = nodeAddNode(snode->edittree, &ntemp);
-                               rerouteNode->locx = insertPoint[0];
-                               rerouteNode->locy = insertPoint[1];
                                if (gnode) {
-                                       rerouteNode->locx -= gnode->locx;
-                                       rerouteNode->locy -= gnode->locy;
+                                       nodeFromView(gnode, insertPoint[0], insertPoint[1], &rerouteNode->locx, &rerouteNode->locy);
+                               }
+                               else {
+                                       rerouteNode->locx = insertPoint[0];
+                                       rerouteNode->locy = insertPoint[1];
                                }
                                
                                nodeAddLink(snode->edittree, link->fromnode, link->fromsock, rerouteNode, rerouteNode->inputs.first);