Cleanup: nice bool return value from ed_node_link_conditions function instead of using the space pointer for this.

This commit is contained in:
Lukas Toenne
2013-11-07 09:02:29 +00:00
parent be09e694b1
commit 9708f7921d

View File

@@ -1173,52 +1173,57 @@ void NODE_OT_detach(wmOperatorType *ot)
/* prevent duplicate testing code below */ /* prevent duplicate testing code below */
static SpaceNode *ed_node_link_conditions(ScrArea *sa, bNode **select) static bool ed_node_link_conditions(ScrArea *sa, SpaceNode **r_snode, bNode **r_select)
{ {
SpaceNode *snode = sa ? sa->spacedata.first : NULL; SpaceNode *snode = sa ? sa->spacedata.first : NULL;
bNode *node; bNode *node, *select = NULL;
bNodeLink *link; bNodeLink *link;
/* no unlucky accidents */ *r_snode = snode;
if (sa == NULL || sa->spacetype != SPACE_NODE) return NULL; *r_select = NULL;
*select = NULL; /* no unlucky accidents */
if (sa == NULL || sa->spacetype != SPACE_NODE)
return false;
for (node = snode->edittree->nodes.first; node; node = node->next) { for (node = snode->edittree->nodes.first; node; node = node->next) {
if (node->flag & SELECT) { if (node->flag & SELECT) {
if (*select) if (select)
break; break;
else else
*select = node; select = node;
} }
} }
/* only one selected */ /* only one selected */
if (node || *select == NULL) return NULL; if (node || select == NULL)
return false;
/* correct node */ /* correct node */
if ((*select)->inputs.first == NULL || (*select)->outputs.first == NULL) return NULL; if (select->inputs.first == NULL || select->outputs.first == NULL)
return false;
/* test node for links */ /* test node for links */
for (link = snode->edittree->links.first; link; link = link->next) { for (link = snode->edittree->links.first; link; link = link->next) {
if (nodeLinkIsHidden(link)) if (nodeLinkIsHidden(link))
continue; continue;
if (link->tonode == *select || link->fromnode == *select) if (link->tonode == select || link->fromnode == select)
return NULL; return false;
} }
return snode; *r_select = select;
return true;
} }
/* test == 0, clear all intersect flags */ /* test == 0, clear all intersect flags */
void ED_node_link_intersect_test(ScrArea *sa, int test) void ED_node_link_intersect_test(ScrArea *sa, int test)
{ {
bNode *select; bNode *select;
SpaceNode *snode = ed_node_link_conditions(sa, &select); SpaceNode *snode;
bNodeLink *link, *selink = NULL; bNodeLink *link, *selink = NULL;
float mcoords[6][2]; float mcoords[6][2];
if (snode == NULL) return; if (!ed_node_link_conditions(sa, &snode, &select)) return;
/* clear flags */ /* clear flags */
for (link = snode->edittree->links.first; link; link = link->next) for (link = snode->edittree->links.first; link; link = link->next)
@@ -1293,11 +1298,11 @@ static bNodeSocket *socket_best_match(ListBase *sockets)
void ED_node_link_insert(ScrArea *sa) void ED_node_link_insert(ScrArea *sa)
{ {
bNode *node, *select; bNode *node, *select;
SpaceNode *snode = ed_node_link_conditions(sa, &select); SpaceNode *snode;
bNodeLink *link; bNodeLink *link;
bNodeSocket *sockto; bNodeSocket *sockto;
if (snode == NULL) return; if (!ed_node_link_conditions(sa, &snode, &select)) return;
/* get the link */ /* get the link */
for (link = snode->edittree->links.first; link; link = link->next) for (link = snode->edittree->links.first; link; link = link->next)