diff options
Diffstat (limited to 'source/blender/editors/space_node/node_edit.c')
-rw-r--r-- | source/blender/editors/space_node/node_edit.c | 58 |
1 files changed, 39 insertions, 19 deletions
diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index 8086ce3621a..3877e7abf5e 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -27,6 +27,11 @@ * ***** END GPL LICENSE BLOCK ***** */ +/** \file blender/editors/space_node/node_edit.c + * \ingroup spnode + */ + + #include <stdio.h> #include <stdlib.h> #include <math.h> @@ -1170,7 +1175,7 @@ static void sample_apply(bContext *C, wmOperator *op, wmEvent *event) fx = (bufx > 0.0f ? ((float)mx - 0.5f*ar->winx - snode->xof) / bufx + 0.5f : 0.0f); fy = (bufy > 0.0f ? ((float)my - 0.5f*ar->winy - snode->yof) / bufy + 0.5f : 0.0f); - if(fx>=0.0 && fy>=0.0 && fx<1.0 && fy<1.0) { + if(fx>=0.0f && fy>=0.0f && fx<1.0f && fy<1.0f) { float *fp; char *cp; int x= (int)(fx*ibuf->x), y= (int)(fy*ibuf->y); @@ -2023,15 +2028,6 @@ void NODE_OT_duplicate(wmOperatorType *ot) /* *************************** 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 node_remove_extra_links(SpaceNode *snode, bNodeSocket *tsock, bNodeLink *link) { bNodeLink *tlink; @@ -2072,7 +2068,7 @@ static int node_link_modal(bContext *C, wmOperator *op, wmEvent *event) { SpaceNode *snode= CTX_wm_space_node(C); ARegion *ar= CTX_wm_region(C); - NodeLinkDrag *nldrag= op->customdata; + bNodeLinkDrag *nldrag= op->customdata; bNode *tnode, *node; bNodeSocket *tsock= NULL, *sock; bNodeLink *link; @@ -2095,11 +2091,15 @@ static int node_link_modal(bContext *C, wmOperator *op, wmEvent *event) if( link->tosock!= tsock && (!tnode || (tnode!=node && link->tonode!=tnode)) ) { link->tonode= tnode; link->tosock= tsock; + if (link->prev==NULL && link->next==NULL) + BLI_addtail(&snode->edittree->links, link); ntreeSolveOrder(snode->edittree); /* for interactive red line warning */ } } } else { + BLI_remlink(&snode->edittree->links, link); + link->prev = link->next = NULL; link->tonode= NULL; link->tosock= NULL; } @@ -2111,12 +2111,16 @@ static int node_link_modal(bContext *C, wmOperator *op, wmEvent *event) if( link->fromsock!= tsock && (!tnode || (tnode!=node && link->fromnode!=tnode)) ) { link->fromnode= tnode; link->fromsock= tsock; + if (link->prev==NULL && link->next==NULL) + BLI_addtail(&snode->edittree->links, link); ntreeSolveOrder(snode->edittree); /* for interactive red line warning */ } } } } else { + BLI_remlink(&snode->edittree->links, link); + link->prev = link->next = NULL; link->fromnode= NULL; link->fromsock= NULL; } @@ -2143,10 +2147,14 @@ static int node_link_modal(bContext *C, wmOperator *op, wmEvent *event) if (link->tonode && link->tosock) { link->fromsock = nodeGroupExposeSocket(snode->edittree, link->tosock, SOCK_IN); link->fromnode = NULL; + if (link->prev==NULL && link->next==NULL) + BLI_addtail(&snode->edittree->links, link); } else if (link->fromnode && link->fromsock) { link->tosock = nodeGroupExposeSocket(snode->edittree, link->fromsock, SOCK_OUT); link->tonode = NULL; + if (link->prev==NULL && link->next==NULL) + BLI_addtail(&snode->edittree->links, link); } } else @@ -2156,8 +2164,8 @@ static int node_link_modal(bContext *C, wmOperator *op, wmEvent *event) node_tree_verify_groups(snode->nodetree); snode_notify(C, snode); - MEM_freeN(op->customdata); - op->customdata= NULL; + BLI_remlink(&snode->linkdrag, nldrag); + MEM_freeN(nldrag); return OPERATOR_FINISHED; } @@ -2166,7 +2174,7 @@ static int node_link_modal(bContext *C, wmOperator *op, wmEvent *event) } /* return 1 when socket clicked */ -static int node_link_init(SpaceNode *snode, NodeLinkDrag *nldrag) +static int node_link_init(SpaceNode *snode, bNodeLinkDrag *nldrag) { bNodeLink *link; @@ -2218,7 +2226,8 @@ static int node_link_invoke(bContext *C, wmOperator *op, wmEvent *event) { SpaceNode *snode= CTX_wm_space_node(C); ARegion *ar= CTX_wm_region(C); - NodeLinkDrag *nldrag= MEM_callocN(sizeof(NodeLinkDrag), "drag link op customdata"); + bNodeLinkDrag *nldrag= MEM_callocN(sizeof(bNodeLinkDrag), "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); @@ -2231,10 +2240,21 @@ static int node_link_invoke(bContext *C, wmOperator *op, wmEvent *event) 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); + if(nldrag->in_out==SOCK_OUT) { + nldrag->link= MEM_callocN(sizeof(bNodeLink), "link"); + nldrag->link->fromnode= nldrag->node; + nldrag->link->fromsock= nldrag->sock; + nldrag->link->tonode= NULL; + nldrag->link->tosock= NULL; + } + else { + nldrag->link= MEM_callocN(sizeof(bNodeLink), "link"); + nldrag->link->fromnode= NULL; + nldrag->link->fromsock= NULL; + nldrag->link->tonode= nldrag->node; + nldrag->link->tosock= nldrag->sock; + } + BLI_addtail(&snode->linkdrag, nldrag); /* add modal handler */ WM_event_add_modal_handler(C, op); |