Two fixes in drop-node-on-noodle:
authorTon Roosendaal <ton@blender.org>
Fri, 22 Jul 2011 16:39:06 +0000 (16:39 +0000)
committerTon Roosendaal <ton@blender.org>
Fri, 22 Jul 2011 16:39:06 +0000 (16:39 +0000)
- Intersection code was using undefined vector
  caused wrong lines to be picked
- Code now also copes with hidden sockets.
  If all fails, is just unhides a good socket.

source/blender/editors/space_node/node_edit.c

index 8cb7528c4d7c4be8ba2299b3a2018b748887bc88..4230a43d2ecaaec618b401e74d4d443fe0a9322b 100644 (file)
@@ -2494,13 +2494,33 @@ void NODE_OT_links_cut(wmOperatorType *ot)
 
 /* *********************  automatic node insert on dragging ******************* */
 
+/* assumes sockets in list */
 static bNodeSocket *socket_best_match(ListBase *sockets, int type)
 {
        bNodeSocket *sock;
        
+       /* first, match type */
        for(sock= sockets->first; sock; sock= sock->next)
-               if(type == sock->type)
+               if(!(sock->flag & SOCK_HIDDEN))
+                       if(type == sock->type)
+                               return sock;
+       
+       /* then just use first unhidden socket */
+       for(sock= sockets->first; sock; sock= sock->next)
+               if(!(sock->flag & SOCK_HIDDEN))
+                       return sock;
+
+       /* OK, let's unhide proper one */
+       for(sock= sockets->first; sock; sock= sock->next) {
+               if(type == sock->type) {
+                       sock->flag &= ~SOCK_HIDDEN;
                        return sock;
+               }
+       }
+       
+       /* just the first */
+       sock= sockets->first;
+       sock->flag &= ~SOCK_HIDDEN;
        
        return sockets->first;
 }
@@ -2577,7 +2597,7 @@ void ED_node_link_intersect_test(ScrArea *sa, int test)
        bNode *select;
        SpaceNode *snode= ed_node_link_conditions(sa, &select);
        bNodeLink *link, *selink=NULL;
-       float mcoords[5][2];
+       float mcoords[6][2];
        
        if(snode==NULL) return;
        
@@ -2596,12 +2616,16 @@ void ED_node_link_intersect_test(ScrArea *sa, int test)
        mcoords[2][1]= select->totr.ymax;
        mcoords[3][0]= select->totr.xmin;
        mcoords[3][1]= select->totr.ymax;
+       mcoords[4][0]= select->totr.xmin;
+       mcoords[4][1]= select->totr.ymin;
+       mcoords[5][0]= select->totr.xmax;
+       mcoords[5][1]= select->totr.ymax;
        
        /* we only tag a single link for intersect now */
        /* idea; use header dist when more? */
        for(link= snode->edittree->links.first; link; link=link->next) {
                
-               if(cut_links_intersect(link, mcoords, 5)) { /* 5 - silly intersect code */
+               if(cut_links_intersect(link, mcoords, 5)) { /* intersect code wants edges */
                        if(selink) 
                                break;
                        selink= link;