2.5
authorTon Roosendaal <ton@blender.org>
Fri, 6 Feb 2009 16:34:05 +0000 (16:34 +0000)
committerTon Roosendaal <ton@blender.org>
Fri, 6 Feb 2009 16:34:05 +0000 (16:34 +0000)
Node editor:

- Linking sockets back.
- Removed obsolete code
- Add node gives correct pointers for Render stuff

source/blender/blenkernel/BKE_node.h
source/blender/blenkernel/intern/node.c
source/blender/editors/space_node/drawnode.c
source/blender/editors/space_node/node_edit.c
source/blender/editors/space_node/node_header.c
source/blender/editors/space_node/node_intern.h
source/blender/editors/space_node/node_ops.c
source/blender/editors/space_node/node_select.c
source/blender/makesdna/DNA_space_types.h

index bf2da8925069664964b794fe8e7c48975eaa4a4e..7d0c5b83e6e9d44070ee6e864e0c7e65285e6c93 100644 (file)
@@ -52,9 +52,6 @@ struct GPUMaterial;
 struct GPUNode;
 struct GPUNodeStack;
 
-#define SOCK_IN                1
-#define SOCK_OUT       2
-
 /* ************** NODE TYPE DEFINITIONS ***** */
 
 typedef struct bNodeSocketType {
index d41dda4c81ea06c04755e5d59e1df2813d6efb89..65a935c1349042e7c802af3a8b41a81f4e971531 100644 (file)
@@ -1124,7 +1124,8 @@ bNodeTree *ntreeCopyTree(bNodeTree *ntree, int internal_select)
        
        /* check for copying links */
        for(link= ntree->links.first; link; link= link->next) {
-               if(link->fromnode->new_node && link->tonode->new_node) {
+               if(link->fromnode==NULL || link->tonode==NULL);
+               else if(link->fromnode->new_node && link->tonode->new_node) {
                        nlink= nodeAddLink(newtree, link->fromnode->new_node, NULL, link->tonode->new_node, NULL);
                        /* sockets were copied in order */
                        for(a=0, sock= link->fromnode->outputs.first; sock; sock= sock->next, a++) {
@@ -2269,8 +2270,10 @@ static int setExecutableNodes(bNodeTree *ntree, ThreadData *thd)
                        /* is sock in use? */
                        else if(sock->link) {
                                bNodeLink *link= sock->link;
+                               
                                /* this is the test for a cyclic case */
-                               if(link->fromnode->level >= link->tonode->level && link->tonode->level!=0xFFF) {
+                               if(link->fromnode==NULL || link->tonode==NULL);
+                               else if(link->fromnode->level >= link->tonode->level && link->tonode->level!=0xFFF) {
                                        if(link->fromnode->need_exec) {
                                                node->need_exec= 1;
                                                break;
index 028cba327acf0ae23d7ac5e2bb6ca6a9e6e94d90..4d5548baeabdb555a7592902d6a2cc4bbf67d8ab 100644 (file)
@@ -2562,17 +2562,12 @@ void node_draw_link_bezier(View2D *v2d, float vec[4][3], int th_col1, int th_col
 void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link)
 {
        float vec[4][3];
-       float mx=0.0f, my=0.0f;
        int do_shaded= 1, th_col1= TH_WIRE, th_col2= TH_WIRE;
        
        if(link->fromnode==NULL && link->tonode==NULL)
                return;
        
-       /* XXX fix -> notifier thingymajiggle this is dragging link */
        if(link->fromnode==NULL || link->tonode==NULL) {
-               // short mval[2];
-               // XXX getmouseco_areawin(mval);
-               // XXX areamouseco_to_ipoco(v2d, mval, &mx, &my);
                UI_ThemeColor(TH_WIRE);
                do_shaded= 0;
        }
@@ -2611,16 +2606,16 @@ void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link)
                vec[0][1]= link->fromsock->locy;
        }
        else {
-               vec[0][0]= mx;
-               vec[0][1]= my;
+               vec[0][0]= snode->mx;
+               vec[0][1]= snode->my;
        }
        if(link->tonode) {
                vec[3][0]= link->tosock->locx;
                vec[3][1]= link->tosock->locy;
        }
        else {
-               vec[3][0]= mx;
-               vec[3][1]= my;
+               vec[3][0]= snode->mx;
+               vec[3][1]= snode->my;
        }
        
        node_draw_link_bezier(v2d, vec, th_col1, th_col2, do_shaded);
index ed808b0dac86910dcda4288718da1658b1474d8c..0d4ae9372f8e25b667232fa642fb4c299a1132fe 100644 (file)
@@ -85,6 +85,8 @@
  
 #include "node_intern.h"
 
+#define SOCK_IN                1
+#define SOCK_OUT       2
 
 /* ***************** composite job manager ********************** */
 
@@ -295,7 +297,7 @@ static void load_node_image(char *str)      /* called from fileselect */
                BKE_image_signal(ima, node->storage, IMA_SIGNAL_RELOAD);
                
                NodeTagChanged(snode->edittree, node);
-               snode_handle_recalc(snode);
+               // XXX                  snode_handle_recalc(snode);
                // allqueue(REDRAWNODE, 0); 
        }
 }
@@ -401,7 +403,7 @@ static void composit_node_event(SpaceNode *snode, short event)
                        break;
                }
                case B_NODE_TREE_EXEC:
-                       snode_handle_recalc(snode);
+                       // XXX                  snode_handle_recalc(snode);
                        break;          
                default:
                        /* B_NODE_EXEC */
@@ -417,7 +419,7 @@ static void composit_node_event(SpaceNode *snode, short event)
                                        addqueue(curarea->win, UI_BUT_EVENT, B_NODE_TREE_EXEC);
                                        
                                        composite_node_render(snode, node);
-                                       snode_handle_recalc(snode);
+                                       // XXX                  snode_handle_recalc(snode);
                                        
                                        /* add another event, a render can go fullscreen and open new window */
                                        addqueue(curarea->win, UI_BUT_EVENT, B_NODE_TREE_EXEC);
@@ -427,7 +429,7 @@ static void composit_node_event(SpaceNode *snode, short event)
                                        if(node)
                                                NodeTagIDChanged(snode->nodetree, node->id);
                                        
-                                       snode_handle_recalc(snode);
+                                       // XXX                  snode_handle_recalc(snode);
                                }
                        }
                }                       
@@ -458,7 +460,7 @@ static void texture_node_event(SpaceNode *snode, short event)
                default:
                        /* B_NODE_EXEC */
                        ntreeTexCheckCyclics( snode->nodetree );
-                       snode_handle_recalc(snode);
+                       // XXX                  snode_handle_recalc(snode);
                        // allqueue(REDRAWNODE, 1);
                        break;
        }
@@ -677,7 +679,7 @@ void node_set_active(SpaceNode *snode, bNode *node)
                                        if(gnode)
                                                NodeTagIDChanged(snode->nodetree, gnode->id);
                                        
-                                       snode_handle_recalc(snode);
+                                       // XXX                  snode_handle_recalc(snode);
                                }
                                
                                /* addnode() doesnt link this yet... */
@@ -907,7 +909,6 @@ bNode *next_node(bNodeTree *ntree)
        return NULL;
 }
 
-#if 0
 /* is rct in visible part of node? */
 static bNode *visible_node(SpaceNode *snode, rctf *rct)
 {
@@ -919,7 +920,6 @@ static bNode *visible_node(SpaceNode *snode, rctf *rct)
        }
        return tnode;
 }
-#endif
 
 void snode_home(ScrArea *sa, ARegion *ar, SpaceNode* snode)
 {
@@ -1032,187 +1032,8 @@ static void snode_bg_viewmove(SpaceNode *snode)
        
        window_set_cursor(win, oldcursor);
 }
+#endif;
 
-static void reset_sel_socket(SpaceNode *snode, int in_out)
-{
-       bNode *node;
-       bNodeSocket *sock;
-       
-       for(node= snode->edittree->nodes.first; node; node= node->next) {
-               if(in_out & SOCK_IN) {
-                       for(sock= node->inputs.first; sock; sock= sock->next)
-                               if(sock->flag & SOCK_SEL) sock->flag&= ~SOCK_SEL;
-               }
-               if(in_out & SOCK_OUT) {
-                       for(sock= node->outputs.first; sock; sock= sock->next)
-                               if(sock->flag & SOCK_SEL) sock->flag&= ~SOCK_SEL;
-               }
-       }
-}
-
-/* checks mouse position, and returns found node/socket */
-/* type is SOCK_IN and/or SOCK_OUT */
-static int find_indicated_socket(SpaceNode *snode, bNode **nodep, bNodeSocket **sockp, int in_out)
-{
-       bNode *node;
-       bNodeSocket *sock;
-       rctf rect;
-       short mval[2];
-       
-       getmouseco_areawin(mval);
-       
-       /* check if we click in a socket */
-       for(node= snode->edittree->nodes.first; node; node= node->next) {
-       
-               areamouseco_to_ipoco(G.v2d, mval, &rect.xmin, &rect.ymin);
-               
-               rect.xmin -= NODE_SOCKSIZE+3;
-               rect.ymin -= NODE_SOCKSIZE+3;
-               rect.xmax = rect.xmin + 2*NODE_SOCKSIZE+6;
-               rect.ymax = rect.ymin + 2*NODE_SOCKSIZE+6;
-               
-               if (!(node->flag & NODE_HIDDEN)) {
-                       /* extra padding inside and out - allow dragging on the text areas too */
-                       if (in_out == SOCK_IN) {
-                               rect.xmax += NODE_SOCKSIZE;
-                               rect.xmin -= NODE_SOCKSIZE*4;
-                       } else if (in_out == SOCK_OUT) {
-                               rect.xmax += NODE_SOCKSIZE*4;
-                               rect.xmin -= NODE_SOCKSIZE;
-                       }
-               }
-                       
-               if(in_out & SOCK_IN) {
-                       for(sock= node->inputs.first; sock; sock= sock->next) {
-                               if(!(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL))) {
-                                       if(BLI_in_rctf(&rect, sock->locx, sock->locy)) {
-                                               if(node == visible_node(snode, &rect)) {
-                                                       *nodep= node;
-                                                       *sockp= sock;
-                                                       return 1;
-                                               }
-                                       }
-                               }
-                       }
-               }
-               if(in_out & SOCK_OUT) {
-                       for(sock= node->outputs.first; sock; sock= sock->next) {
-                               if(!(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL))) {
-                                       if(BLI_in_rctf(&rect, sock->locx, sock->locy)) {
-                                               if(node == visible_node(snode, &rect)) {
-                                                       *nodep= node;
-                                                       *sockp= sock;
-                                                       return 1;
-                                               }
-                                       }
-                               }
-                       }
-               }
-       }
-       return 0;
-}
-
-/* ********************* transform ****************** */
-
-/* releases on event, only intern (for extern see below) */
-/* we need argument ntree to allow operations on edittree or nodetree */
-static void transform_nodes(bNodeTree *ntree, char mode, char *undostr)
-{
-       bNode *node;
-       float mxstart, mystart, mx, my, *oldlocs, *ol;
-       int cont=1, tot=0, cancel=0, firsttime=1;
-       short mval[2], mvalo[2];
-       
-       /* count total */
-       for(node= ntree->nodes.first; node; node= node->next)
-               if(node->flag & SELECT) tot++;
-       
-       if(tot==0) return;
-       
-       /* store oldlocs */
-       ol= oldlocs= MEM_mallocN(sizeof(float)*2*tot, "oldlocs transform");
-       for(node= ntree->nodes.first; node; node= node->next) {
-               if(node->flag & SELECT) {
-                       ol[0]= node->locx; ol[1]= node->locy;
-                       ol+= 2;
-               }
-       }
-       
-       getmouseco_areawin(mvalo);
-       areamouseco_to_ipoco(G.v2d, mvalo, &mxstart, &mystart);
-       
-       while(cont) {
-               
-               getmouseco_areawin(mval);
-               if(mval[0]!=mvalo[0] || mval[1]!=mvalo[1] || firsttime) {
-
-                       firsttime= 0;
-                       
-                       areamouseco_to_ipoco(G.v2d, mval, &mx, &my);
-                       mvalo[0]= mval[0];
-                       mvalo[1]= mval[1];
-                       
-                       for(ol= oldlocs, node= ntree->nodes.first; node; node= node->next) {
-                               if(node->flag & SELECT) {
-                                       node->locx= ol[0] + mx-mxstart;
-                                       node->locy= ol[1] + my-mystart;
-                                       ol+= 2;
-                               }
-                       }
-                       
-                       force_draw(0);
-               }
-               else
-                       PIL_sleep_ms(10);
-               
-               while (qtest()) {
-                       short val;
-                       unsigned short event= extern_qread(&val);
-                       
-                       switch (event) {
-                               case LEFTMOUSE:
-                               case SPACEKEY:
-                               case RETKEY:
-                                       cont=0;
-                                       break;
-                               case ESCKEY:
-                               case RIGHTMOUSE:
-                                       if(val) {
-                                               cancel=1;
-                                               cont=0;
-                                       }
-                                       break;
-                               default:
-                                       if(val) arrows_move_cursor(event);
-                                       break;
-                       }
-               }
-               
-       }
-       
-       if(cancel) {
-               for(ol= oldlocs, node= ntree->nodes.first; node; node= node->next) {
-                       if(node->flag & SELECT) {
-                               node->locx= ol[0];
-                               node->locy= ol[1];
-                               ol+= 2;
-                       }
-               }
-               
-       }
-       
-       // allqueue(REDRAWNODE, 1);
-       MEM_freeN(oldlocs);
-}
-
-/* external call, also for callback */
-void node_transform_ext(int mode, int unused)
-{
-       SpaceNode *snode= curarea->spacedata.first;
-       
-       transform_nodes(snode->edittree, 'g', "Move Node");
-}
-#endif /* 0 */
 
 /* releases on event, only 1 node */
 void scale_node(SpaceNode *snode, bNode *node)
@@ -1338,6 +1159,7 @@ Material *editnode_get_active_material(Material *ma)
        }
        return ma;
 }
+#endif /* 0 */
 
 /* used in buttons to check context, also checks for edited groups */
 bNode *editnode_get_active(bNodeTree *ntree)
@@ -1354,7 +1176,6 @@ bNode *editnode_get_active(bNodeTree *ntree)
                return nodeGetActive(ntree);
 }
 
-#endif /* 0 */
 
 /* no undo here! */
 void node_deselectall(SpaceNode *snode, int swap)
@@ -1377,7 +1198,6 @@ void node_deselectall(SpaceNode *snode, int swap)
                node->flag &= ~SELECT;
 }
 
-#if 0
 
 int node_has_hidden_sockets(bNode *node)
 {
@@ -1437,7 +1257,7 @@ static void node_hide_unhide_sockets(SpaceNode *snode, bNode *node)
 
 }
 
-static int do_header_node(SpaceNode *snode, bNode *node, float mx, float my)
+/*static*/ int do_header_node(SpaceNode *snode, bNode *node, float mx, float my)
 {
        rctf totr= node->totr;
        
@@ -1491,7 +1311,7 @@ static int do_header_node(SpaceNode *snode, bNode *node, float mx, float my)
        return 0;
 }
 
-static int do_header_hidden_node(SpaceNode *snode, bNode *node, float mx, float my)
+/*static*/ int do_header_hidden_node(SpaceNode *snode, bNode *node, float mx, float my)
 {
        rctf totr= node->totr;
        
@@ -1540,7 +1360,7 @@ static void node_link_viewer(SpaceNode *snode, bNode *tonode)
                        link->fromsock= tonode->outputs.first;
                        NodeTagChanged(snode->edittree, node);
                        
-                       snode_handle_recalc(snode);
+// XXX                 snode_handle_recalc(snode);
                }
        }
 }
@@ -1553,73 +1373,18 @@ void node_active_link_viewer(SpaceNode *snode)
                node_link_viewer(snode, node);
 }
 
-/* return 0: nothing done */
-static int node_mouse_select(SpaceNode *snode, unsigned short event)
-{
-       bNode *node;
-       float mx, my;
-       short mval[2];
-       
-       getmouseco_areawin(mval);
-       areamouseco_to_ipoco(G.v2d, mval, &mx, &my);
-       
-       for(next_node(snode->edittree); (node=next_node(NULL));) {
-               
-               /* first check for the headers or scaling widget */
-               if(node->flag & NODE_HIDDEN) {
-                       if(do_header_hidden_node(snode, node, mx, my))
-                               return 1;
-               }
-               else {
-                       if(do_header_node(snode, node, mx, my))
-                               return 1;
-               }
-               
-               /* node body */
-               if(BLI_in_rctf(&node->totr, mx, my))
-                       break;
-       }
-       if(node) {
-               if((G.qual & LR_SHIFTKEY)==0)
-                       node_deselectall(snode, 0);
-               
-               if(G.qual & LR_SHIFTKEY) {
-                       if(node->flag & SELECT)
-                               node->flag &= ~SELECT;
-                       else
-                               node->flag |= SELECT;
-               }
-               else 
-                       node->flag |= SELECT;
-               
-               node_set_active(snode, node);
-               
-               /* viewer linking */
-               if(G.qual & LR_CTRLKEY)
-                       node_link_viewer(snode, node);
-               
-               /* not so nice (no event), but function below delays redraw otherwise */
-               force_draw(0);
-               
-               std_rmouse_transform(node_transform_ext);       /* does undo push for select */
-               
-               return 1;
-       }
-       return 0;
-}
-
 /* return 0, nothing done */
-static int node_mouse_groupheader(SpaceNode *snode)
+/*static*/ int node_mouse_groupheader(SpaceNode *snode)
 {
        bNode *gnode;
        float mx, my;
-       short mval[2];
+// XXX short mval[2];
        
        gnode= snode_get_editgroup(snode);
        if(gnode==NULL) return 0;
        
-       getmouseco_areawin(mval);
-       areamouseco_to_ipoco(G.v2d, mval, &mx, &my);
+// XXX getmouseco_areawin(mval);
+// XXX areamouseco_to_ipoco(G.v2d, mval, &mx, &my);
        
        /* click in header or outside? */
        if(BLI_in_rctf(&gnode->totr, mx, my)==0) {
@@ -1628,26 +1393,79 @@ static int node_mouse_groupheader(SpaceNode *snode)
                rect.ymax += NODE_DY;
                if(BLI_in_rctf(&rect, mx, my)==0)
                        snode_make_group_editable(snode, NULL); /* toggles, so exits editmode */
-               else
-                       transform_nodes(snode->nodetree, 'g', "Move group");
+//             else
+// XXX                 transform_nodes(snode->nodetree, 'g', "Move group");
                
                return 1;
        }
        return 0;
 }
 
+/* checks snode->mouse position, and returns found node/socket */
+/* type is SOCK_IN and/or SOCK_OUT */
+static int find_indicated_socket(SpaceNode *snode, bNode **nodep, bNodeSocket **sockp, int in_out)
+{
+       bNode *node;
+       bNodeSocket *sock;
+       rctf rect;
+       
+       /* check if we click in a socket */
+       for(node= snode->edittree->nodes.first; node; node= node->next) {
+               
+               rect.xmin = snode->mx - NODE_SOCKSIZE+3;
+               rect.ymin = snode->my - NODE_SOCKSIZE+3;
+               rect.xmax = rect.xmin + 2*NODE_SOCKSIZE+6;
+               rect.ymax = rect.ymin + 2*NODE_SOCKSIZE+6;
+               
+               if (!(node->flag & NODE_HIDDEN)) {
+                       /* extra padding inside and out - allow dragging on the text areas too */
+                       if (in_out == SOCK_IN) {
+                               rect.xmax += NODE_SOCKSIZE;
+                               rect.xmin -= NODE_SOCKSIZE*4;
+                       } else if (in_out == SOCK_OUT) {
+                               rect.xmax += NODE_SOCKSIZE*4;
+                               rect.xmin -= NODE_SOCKSIZE;
+                       }
+               }
+               
+               if(in_out & SOCK_IN) {
+                       for(sock= node->inputs.first; sock; sock= sock->next) {
+                               if(!(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL))) {
+                                       if(BLI_in_rctf(&rect, sock->locx, sock->locy)) {
+                                               if(node == visible_node(snode, &rect)) {
+                                                       *nodep= node;
+                                                       *sockp= sock;
+                                                       return 1;
+                                               }
+                                       }
+                               }
+                       }
+               }
+               if(in_out & SOCK_OUT) {
+                       for(sock= node->outputs.first; sock; sock= sock->next) {
+                               if(!(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL))) {
+                                       if(BLI_in_rctf(&rect, sock->locx, sock->locy)) {
+                                               if(node == visible_node(snode, &rect)) {
+                                                       *nodep= node;
+                                                       *sockp= sock;
+                                                       return 1;
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+       return 0;
+}
+
 static int node_socket_hilights(SpaceNode *snode, int in_out)
 {
        bNode *node;
        bNodeSocket *sock, *tsock, *socksel= NULL;
-       float mx, my;
-       short mval[2], redraw= 0;
+       short redraw= 0;
        
        if(snode->edittree==NULL) return 0;
        
-       getmouseco_areawin(mval);
-       areamouseco_to_ipoco(G.v2d, mval, &mx, &my);
-       
        /* deselect socks */
        for(node= snode->edittree->nodes.first; node; node= node->next) {
                for(sock= node->inputs.first; sock; sock= sock->next) {
@@ -1666,6 +1484,8 @@ static int node_socket_hilights(SpaceNode *snode, int in_out)
                }
        }
        
+       // XXX mousepos should be set here!
+       
        if(find_indicated_socket(snode, &node, &tsock, in_out)) {
                tsock->flag |= SELECT;
                if(redraw==1 && tsock==socksel) redraw= 0;
@@ -1675,34 +1495,6 @@ static int node_socket_hilights(SpaceNode *snode, int in_out)
        return redraw;
 }
 
-void node_border_select(SpaceNode *snode)
-{
-       bNode *node;
-       rcti rect;
-       rctf rectf;
-       short val, mval[2];
-       
-       if ( (val = get_border(&rect, 3)) ) {
-               
-               mval[0]= rect.xmin;
-               mval[1]= rect.ymin;
-               areamouseco_to_ipoco(G.v2d, mval, &rectf.xmin, &rectf.ymin);
-               mval[0]= rect.xmax;
-               mval[1]= rect.ymax;
-               areamouseco_to_ipoco(G.v2d, mval, &rectf.xmax, &rectf.ymax);
-               
-               for(node= snode->edittree->nodes.first; node; node= node->next) {
-                       if(BLI_isect_rctf(&rectf, &node->totr, NULL)) {
-                               if(val==LEFTMOUSE)
-                                       node->flag |= SELECT;
-                               else
-                                       node->flag &= ~SELECT;
-                       }
-               }
-               // allqueue(REDRAWNODE, 1);
-       }               
-}
-
 /* ****************** Add *********************** */
 
 void snode_autoconnect(SpaceNode *snode, bNode *node_to, int flag)
@@ -1757,10 +1549,9 @@ void snode_autoconnect(SpaceNode *snode, bNode *node_to, int flag)
        ntreeSolveOrder(snode->edittree);
 }
 
-#endif /* 0 */
 
 /* can be called from menus too, but they should do own undopush and redraws */
-bNode *node_add_node(SpaceNode *snode, int type, float locx, float locy)
+bNode *node_add_node(SpaceNode *snode, Scene *scene, int type, float locx, float locy)
 {
        bNode *node= NULL, *gnode;
        
@@ -1798,13 +1589,16 @@ bNode *node_add_node(SpaceNode *snode, int type, float locx, float locy)
                snode_verify_groups(snode);
                node_set_active(snode, node);
                
+               if(snode->nodetree->type==NTREE_COMPOSIT) {
+                       if(ELEM(node->type, CMP_NODE_R_LAYERS, CMP_NODE_COMPOSITE))
+                               node->id = &scene->id;
+                       
+                       ntreeCompositForceHidden(snode->edittree, scene);
+               }
+                       
                if(node->id)
                        id_us_plus(node->id);
-               
-               // NODE_FIX_ME
-               // if(snode->nodetree->type==NTREE_COMPOSIT)
-               //      ntreeCompositForceHidden(snode->edittree, scene); // XXX was G.scene
-               
+                       
                NodeTagChanged(snode->edittree, node);
        }
        
@@ -1847,9 +1641,9 @@ void node_adduplicate(SpaceNode *snode)
        
        ntreeSolveOrder(snode->edittree);
        snode_verify_groups(snode);
-       snode_handle_recalc(snode);
+       // XXX                  snode_handle_recalc(snode);
 
-       transform_nodes(snode->edittree, 'g', "Duplicate");
+// XXX transform_nodes(snode->edittree, 'g', "Duplicate");
 }
 
 static void node_insert_convertor(SpaceNode *snode, bNodeLink *link)
@@ -1885,6 +1679,38 @@ static void node_insert_convertor(SpaceNode *snode, bNodeLink *link)
        }
 }
 
+
+#endif /* 0 */
+
+/* *************************** add link op ******************** */
+
+/* temp data to pass on to modal */
+typedef struct NodeLinkDrag
+{
+       bNode *node;
+       bNodeSocket *sock;
+       bNodeLink *link;
+       int in_out;
+} NodeLinkDrag;
+
+/*static*/ void reset_sel_socket(SpaceNode *snode, int in_out)
+{
+       bNode *node;
+       bNodeSocket *sock;
+       
+       for(node= snode->edittree->nodes.first; node; node= node->next) {
+               if(in_out & SOCK_IN) {
+                       for(sock= node->inputs.first; sock; sock= sock->next)
+                               if(sock->flag & SOCK_SEL) sock->flag&= ~SOCK_SEL;
+               }
+               if(in_out & SOCK_OUT) {
+                       for(sock= node->outputs.first; sock; sock= sock->next)
+                               if(sock->flag & SOCK_SEL) sock->flag&= ~SOCK_SEL;
+               }
+       }
+}
+
+
 static void node_remove_extra_links(SpaceNode *snode, bNodeSocket *tsock, bNodeLink *link)
 {
        bNodeLink *tlink;
@@ -1916,28 +1742,26 @@ static void node_remove_extra_links(SpaceNode *snode, bNodeSocket *tsock, bNodeL
 
 /* loop that adds a nodelink, called by function below  */
 /* in_out = starting socket */
-static int node_add_link_drag(SpaceNode *snode, bNode *node, bNodeSocket *sock, int in_out)
+static int node_link_modal(bContext *C, wmOperator *op, wmEvent *event)
 {
-       bNode *tnode;
-       bNodeSocket *tsock= NULL;
-       bNodeLink *link= NULL;
-       short mval[2], mvalo[2], firsttime=1;   /* firsttime reconnects a link broken by caller */
-       
-       /* we make a temporal link */
-       if(in_out==SOCK_OUT)
-               link= nodeAddLink(snode->edittree, node, sock, NULL, NULL);
-       else
-               link= nodeAddLink(snode->edittree, NULL, NULL, node, sock);
+       SpaceNode *snode= (SpaceNode*)CTX_wm_space_data(C);
+       ARegion *ar= CTX_wm_region(C);
+       NodeLinkDrag *nldrag= op->customdata;
+       bNode *tnode, *node;
+       bNodeSocket *tsock= NULL, *sock;
+       bNodeLink *link;
+       int in_out;
+
+       in_out= nldrag->in_out;
+       node= nldrag->node;
+       sock= nldrag->sock;
+       link= nldrag->link;
        
-       getmouseco_areawin(mvalo);
-       while (get_mbut() & L_MOUSE) {
-               
-               getmouseco_areawin(mval);
-               if(mval[0]!=mvalo[0] || mval[1]!=mvalo[1] || firsttime) {
-                       firsttime= 0;
-                       
-                       mvalo[0]= mval[0];
-                       mvalo[1]= mval[1];
+       UI_view2d_region_to_view(&ar->v2d, event->x - ar->winrct.xmin, event->y - ar->winrct.ymin, 
+                                                        &snode->mx, &snode->my);
+
+       switch (event->type) {
+               case MOUSEMOVE:
                        
                        if(in_out==SOCK_OUT) {
                                if(find_indicated_socket(snode, &tnode, &tsock, SOCK_IN)) {
@@ -1973,65 +1797,71 @@ static int node_add_link_drag(SpaceNode *snode, bNode *node, bNodeSocket *sock,
                        }
                        /* hilight target sockets only */
                        node_socket_hilights(snode, in_out==SOCK_OUT?SOCK_IN:SOCK_OUT);
+                       ED_region_tag_redraw(ar);
+                       break;
                        
-                       force_draw(0);
-               }
-               else BIF_wait_for_statechange();                
-       }
+               case LEFTMOUSE:
+               case RIGHTMOUSE:
+               case MIDDLEMOUSE:
        
-       /* remove link? */
-       if(link->tonode==NULL || link->fromnode==NULL) {
-               nodeRemLink(snode->edittree, link);
-       }
-       else {
-               /* send changed events for original tonode and new */
-               if(link->tonode) 
-                       NodeTagChanged(snode->edittree, link->tonode);
-               
-               /* we might need to remove a link */
-               if(in_out==SOCK_OUT) node_remove_extra_links(snode, tsock, link);
+                       /* remove link? */
+                       if(link->tonode==NULL || link->fromnode==NULL) {
+                               nodeRemLink(snode->edittree, link);
+                       }
+                       else {
+                               /* send changed events for original tonode and new */
+                               if(link->tonode) 
+                                       NodeTagChanged(snode->edittree, link->tonode);
+                               
+                               /* we might need to remove a link */
+                               if(in_out==SOCK_OUT) node_remove_extra_links(snode, link->tosock, link);
+                       }
+                       
+                       ntreeSolveOrder(snode->edittree);
+                       snode_verify_groups(snode);
+                       // XXX                  snode_handle_recalc(snode);
+                       ED_region_tag_redraw(ar);
+                       
+                       MEM_freeN(op->customdata);
+                       op->customdata= NULL;
+                       
+                       return OPERATOR_FINISHED;
        }
        
-       ntreeSolveOrder(snode->edittree);
-       snode_verify_groups(snode);
-       snode_handle_recalc(snode);
-       
-       return 1;
+       return OPERATOR_RUNNING_MODAL;
 }
 
 /* return 1 when socket clicked */
-static int node_add_link(SpaceNode *snode)
+static int node_link_init(SpaceNode *snode, NodeLinkDrag *nldrag)
 {
-       bNode *node;
        bNodeLink *link;
-       bNodeSocket *sock;
        
        /* output indicated? */
-       if(find_indicated_socket(snode, &node, &sock, SOCK_OUT)) {
-               if(nodeCountSocketLinks(snode->edittree, sock)<sock->limit)
-                       return node_add_link_drag(snode, node, sock, SOCK_OUT);
+       if(find_indicated_socket(snode, &nldrag->node, &nldrag->sock, SOCK_OUT)) {
+               if(nodeCountSocketLinks(snode->edittree, nldrag->sock) < nldrag->sock->limit)
+                       return SOCK_OUT;
                else {
                        /* find if we break a link */
                        for(link= snode->edittree->links.first; link; link= link->next) {
-                               if(link->fromsock==sock)
+                               if(link->fromsock==nldrag->sock)
                                        break;
                        }
                        if(link) {
-                               node= link->tonode;
-                               sock= link->tosock;
+                               nldrag->node= link->tonode;
+                               nldrag->sock= link->tosock;
                                nodeRemLink(snode->edittree, link);
-                               return node_add_link_drag(snode, node, sock, SOCK_IN);
+                               return SOCK_IN;
                        }
                }
        }
        /* or an input? */
-       else if(find_indicated_socket(snode, &node, &sock, SOCK_IN)) {
-               if(nodeCountSocketLinks(snode->edittree, sock)<sock->limit)
-                       return node_add_link_drag(snode, node, sock, SOCK_IN);
+       else if(find_indicated_socket(snode, &nldrag->node, &nldrag->sock, SOCK_IN)) {
+               if(nodeCountSocketLinks(snode->edittree, nldrag->sock) < nldrag->sock->limit)
+                       return SOCK_IN;
                else {
                        /* find if we break a link */
                        for(link= snode->edittree->links.first; link; link= link->next) {
-                               if(link->tosock==sock)
+                               if(link->tosock==nldrag->sock)
                                        break;
                        }
                        if(link) {
@@ -2039,10 +1869,10 @@ static int node_add_link(SpaceNode *snode)
                                if(link->tonode) 
                                        NodeTagChanged(snode->edittree, link->tonode);
                                
-                               node= link->fromnode;
-                               sock= link->fromsock;
+                               nldrag->node= link->fromnode;
+                               nldrag->sock= link->fromsock;
                                nodeRemLink(snode->edittree, link);
-                               return node_add_link_drag(snode, node, sock, SOCK_OUT);
+                               return SOCK_OUT;
                        }
                }
        }
@@ -2050,7 +1880,53 @@ static int node_add_link(SpaceNode *snode)
        return 0;
 }
 
-#endif /* 0 */
+static int node_link_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       SpaceNode *snode= (SpaceNode*)CTX_wm_space_data(C);
+       ARegion *ar= CTX_wm_region(C);
+       NodeLinkDrag *nldrag= MEM_callocN(sizeof(NodeLinkDrag), "drag link op customdata");
+       
+       UI_view2d_region_to_view(&ar->v2d, event->x - ar->winrct.xmin, event->y - ar->winrct.ymin, 
+                                                        &snode->mx, &snode->my);
+
+       nldrag->in_out= node_link_init(snode, nldrag);
+               
+       if(nldrag->in_out) {
+               op->customdata= nldrag;
+               
+               /* we make a temporal link */
+               if(nldrag->in_out==SOCK_OUT)
+                       nldrag->link= nodeAddLink(snode->edittree, nldrag->node, nldrag->sock, NULL, NULL);
+               else
+                       nldrag->link= nodeAddLink(snode->edittree, NULL, NULL, nldrag->node, nldrag->sock);
+               
+               /* add modal handler */
+               WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
+               
+               return OPERATOR_RUNNING_MODAL;
+       }
+       else {
+               MEM_freeN(nldrag);
+               return OPERATOR_CANCELLED|OPERATOR_PASS_THROUGH;
+       }
+}
+
+void NODE_OT_link(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Link Nodes";
+       ot->idname= "NODE_OT_link";
+       
+       /* api callbacks */
+       ot->invoke= node_link_invoke;
+       ot->modal= node_link_modal;
+//     ot->exec= node_link_exec;
+       ot->poll= ED_operator_node_active;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
 
 void node_delete(SpaceNode *snode)
 {
@@ -2177,7 +2053,7 @@ void node_make_link(SpaceNode *snode)
 
        ntreeSolveOrder(snode->edittree);
        snode_verify_groups(snode);
-       snode_handle_recalc(snode);
+       // XXX                  snode_handle_recalc(snode);
 
 }
 
@@ -2247,7 +2123,7 @@ static void node_border_link_delete(SpaceNode *snode)
                                }
                                ntreeSolveOrder(snode->edittree);
                                snode_verify_groups(snode);
-                               snode_handle_recalc(snode);
+                               // XXX                  snode_handle_recalc(snode);
                        }
                }
        }
@@ -2281,7 +2157,7 @@ void node_read_renderlayers(SpaceNode *snode)
        if(G.scene->id.flag & LIB_DOIT)
                RE_ReadRenderResult(G.scene, G.scene);
        
-       snode_handle_recalc(snode);
+       // XXX                  snode_handle_recalc(snode);
 }
 
 void node_read_fullsamplelayers(SpaceNode *snode)
@@ -2403,89 +2279,6 @@ void node_make_group(SpaceNode *snode)
 
 /* ******************** main event loop ****************** */
 
-/* special version to prevent overlapping buttons, has a bit of hack... */
-/* yes, check for example composit_node_event(), file window use... */
-static int node_uiDoBlocks(ScrArea *sa, short event)
-{
-       SpaceNode *snode= sa->spacedata.first;
-       ListBase *lb= &sa->uiblocks;
-       ListBase listb= *lb;
-       uiBlock *block;
-       bNode *node;
-       rctf rect;
-       void *prev, *next;
-       int retval= UI_NOTHING;
-       short mval[2];
-       
-       getmouseco_areawin(mval);
-       areamouseco_to_ipoco(G.v2d, mval, &rect.xmin, &rect.ymin);
-
-       /* this happens after filesel usage... */
-       if(lb->first==NULL) {
-               return UI_NOTHING;
-       }
-       
-       /* evil hack: try to do grease-pencil floating panel (like for nodes) */
-       block= uiGetBlock("nodes_panel_gpencil", sa);
-       if (block) {
-               /* try to process events here... if failed, just carry on */
-                       /* when there's menus, the prev pointer becomes zero! */
-               prev= ((struct Link *)block)->prev;
-               next= ((struct Link *)block)->next;
-               ((struct Link *)block)->prev= NULL;
-               ((struct Link *)block)->next= NULL;
-               
-               lb->first= lb->last= block;
-               retval= uiDoBlocks(lb, event, 1);
-               
-               ((struct Link *)block)->prev= prev;
-               ((struct Link *)block)->next= next;
-               
-               *lb= listb;
-               
-               /* if something happened, get the heck outta here */
-               if (retval != UI_NOTHING)
-                       return retval;
-       }
-       
-       
-       rect.xmin -= 2.0f;
-       rect.ymin -= 2.0f;
-       rect.xmax = rect.xmin + 4.0f;
-       rect.ymax = rect.ymin + 4.0f;
-       
-       for(node= snode->edittree->nodes.first; node; node= node->next) {
-               char str[32];
-               
-               /* retreive unique block name, see also drawnode.c */
-               sprintf(str, "node buttons %p", node);
-               block= uiGetBlock(str, sa);
-               
-               if(block) {
-                       if(node == visible_node(snode, &rect)) {
-
-                               /* when there's menus, the prev pointer becomes zero! */
-                               prev= ((struct Link *)block)->prev;
-                               next= ((struct Link *)block)->next;
-                               ((struct Link *)block)->prev= NULL;
-                               ((struct Link *)block)->next= NULL;
-                               
-                               lb->first= lb->last= block;
-                               retval= uiDoBlocks(lb, event, 1);
-                               
-                               ((struct Link *)block)->prev= prev;
-                               ((struct Link *)block)->next= next;
-
-                               break;
-                       }
-               }
-       }
-       
-       *lb= listb;
-       
-       return retval;
-}
-
 void winqreadnodespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
 {
        SpaceNode *snode= spacedata;
@@ -2514,7 +2307,7 @@ void winqreadnodespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        }
                        else if(fromlib) {
                                if(node_mouse_groupheader(snode)==0)
-                                       node_mouse_select(snode, event);
+                                       //node_mouse_select(snode, event);
                        }
                        else {
                                
@@ -2522,9 +2315,9 @@ void winqreadnodespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        if(gesture())
                                                break;
                                        
-                               if(node_add_link(snode)==0)
+//                             if(node_add_link(snode)==0)
                                        if(node_mouse_groupheader(snode)==0)
-                                               if(node_mouse_select(snode, event)==0)
+//                                             if(node_mouse_select(snode, event)==0)
                                                        node_border_link_delete(snode);
                        }
                        break;
@@ -2555,8 +2348,8 @@ void winqreadnodespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        actsock->flag|= SOCK_SEL;
                                }
                        }
-                       else if(!node_mouse_select(snode, event)) 
-                               toolbox_n();
+//                     else if(!node_mouse_select(snode, event)) 
+//                             toolbox_n();
 
                        break;
                case MIDDLEMOUSE:
@@ -2626,7 +2419,7 @@ void winqreadnodespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        }
                        break;
                case EKEY:
-                       snode_handle_recalc(snode);
+                       // XXX                  snode_handle_recalc(snode);
                        break;
                case FKEY:
                        node_make_link(snode);
@@ -2645,8 +2438,8 @@ void winqreadnodespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                else if(G.qual==LR_SHIFTKEY) {
                                        node_addgroup(snode);
                                }
-                               else
-                                       transform_nodes(snode->edittree, 'g', "Move Node");
+//                             else
+// XXX                                 transform_nodes(snode->edittree, 'g', "Move Node");
                        }
                        break;
                case HKEY:
index d25eefcb45ebe8a8b678c60761162b1d8d516f96..fb21b894ce7161ca896aa8b75f64b55227c75555 100644 (file)
@@ -141,7 +141,7 @@ void do_node_addmenu(bContext *C, void *arg, int event)
        // toolbox_mousepos(mval, 0 ); /* get initial mouse position */
        // areamouseco_to_ipoco(G.v2d, mval, &locx, &locy);
        // NODE_FIX_ME
-       node= node_add_node(snode, event, 0.0, 0.0);
+       node= node_add_node(snode, CTX_data_scene(C), event, 0.0, 0.0);
        
        /* uses test flag */
        // XXX snode_autoconnect(snode, node, NODE_TEST);
index fb48e4012ada0cabad1da6044309dc20f5e5e466..71035fd31656683dcaabcfc4b3ca7ae16f53fa40 100644 (file)
@@ -59,7 +59,6 @@ void NODE_OT_extend_select(struct wmOperatorType *ot);
 void NODE_OT_visibility_toggle(struct wmOperatorType *ot);
 void NODE_OT_fit_all(struct wmOperatorType *ot);
 void NODE_OT_border_select(struct wmOperatorType *ot);
-void NODE_OT_delete_selection(struct wmOperatorType *ot);
 
 /* drawnode.c */
 void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link);
@@ -68,7 +67,7 @@ void draw_nodespace_back_pix(ScrArea *sa, SpaceNode *snode);
 
 /* node_edit.c */
 bNode *next_node(bNodeTree *ntree);
-bNode *node_add_node(SpaceNode *snode, int type, float locx, float locy);
+bNode *node_add_node(SpaceNode *snode, Scene *scene, int type, float locx, float locy);
 void snode_set_context(SpaceNode *snode, Scene *scene);
 void scale_node(SpaceNode *snode, bNode *node);
 void snode_make_group_editable(SpaceNode *snode, bNode *gnode);
@@ -81,6 +80,9 @@ void node_texture_default(Tex *tx);
 void snode_composite_job(const struct bContext *C, ScrArea *sa);
 bNode *snode_get_editgroup(SpaceNode *snode);
 
+void NODE_OT_link(struct wmOperatorType *ot);
+void NODE_OT_delete_selection(struct wmOperatorType *ot);
+
 // XXXXXX
 
 // XXX from BSE_node.h
index 09a5d12bd3485ffc5f251bf567fe7dea7e33f38c..14ef607eb4c71532abdb5b7d07225b31969fa594 100644 (file)
@@ -56,6 +56,7 @@ void node_operatortypes(void)
        WM_operatortype_append(NODE_OT_fit_all);
        WM_operatortype_append(NODE_OT_border_select);
        WM_operatortype_append(NODE_OT_delete_selection);
+       WM_operatortype_append(NODE_OT_link);
 }
 
 void node_keymap(struct wmWindowManager *wm)
@@ -68,7 +69,9 @@ void node_keymap(struct wmWindowManager *wm)
        RNA_enum_set(WM_keymap_add_item(keymap, "NODE_OT_extend_select", ACTIONMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "select_type", NODE_SELECT_MOUSE);
        RNA_enum_set(WM_keymap_add_item(keymap, "NODE_OT_extend_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "select_type", NODE_SELECT_MOUSE);
        
+       WM_keymap_add_item(keymap, "NODE_OT_link", ACTIONMOUSE, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "NODE_OT_visibility_toggle", ACTIONMOUSE, KM_PRESS, 0, 0);
+       
        WM_keymap_add_item(keymap, "NODE_OT_fit_all", HOMEKEY, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "NODE_OT_border_select", BKEY, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "NODE_OT_delete_selection", XKEY, KM_PRESS, 0, 0);
index 0d0ff25de61d22030b9a526c2bb14258be608cd8..0006d227d1acf5bb7eaeeb5ede8678b9cbb1bea9 100644 (file)
@@ -124,8 +124,10 @@ static int node_select_exec(bContext *C, wmOperator *op)
                        break;
        }
 
-       WM_event_add_notifier(C, NC_SCENE|ND_NODES, NULL); /* Do we need to pass the scene? */
-
+       /* need refresh/a notifier vs compo notifier */
+       // XXX WM_event_add_notifier(C, NC_SCENE|ND_NODES, NULL); /* Do we need to pass the scene? */
+       ED_region_tag_redraw(ar);
+       
        /* allow tweak event to work too */
        return OPERATOR_FINISHED|OPERATOR_PASS_THROUGH;
 }
index e45be7972ef0eab19d8710edff4e47268c9be245..63ad5015649257177fc7503513c6181565f9a98f 100644 (file)
@@ -349,6 +349,7 @@ typedef struct SpaceNode {
        void *curfont;
        
        float xof, yof; /* offset for drawing the backdrop */
+       float mx, my;   /* mousepos for drawing socketless link */
        
        struct bNodeTree *nodetree, *edittree;
        int treetype, pad;                      /* treetype: as same nodetree->type */