diff options
author | Lukas Toenne <lukas.toenne@googlemail.com> | 2012-03-08 16:04:06 +0400 |
---|---|---|
committer | Lukas Toenne <lukas.toenne@googlemail.com> | 2012-03-08 16:04:06 +0400 |
commit | 085c94e09dd6e3e9fa9988ce320f0b5e5986eab4 (patch) | |
tree | 5bae686c4acf7bc18c35eceb6923248817a9066a /source/blender/editors/space_node | |
parent | c6d80d1db12b0ae4e80c5332b31149414733c0e3 (diff) |
Modified behaviour of the link-insertion operator (drag on link, request by Sebastian Koenig). This would previously attempt to find a socket with exactly matching type to the from/to sockets of the cut link, but this is annoying because it often links to the "secondary" sockets, such as Factor input in the Mix node. New behaviour is to choose the input/output for reconnection based on the "highest" (= most important) socket types (in order color, vector, value), like the autoconnect operator (FKEY) also does. It is far from ideal and will probably not work in all situations either, but until we have a detailed design for "best sockets to auto-link" this will have to do.
Diffstat (limited to 'source/blender/editors/space_node')
-rw-r--r-- | source/blender/editors/space_node/node_edit.c | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index 1593710a98a..26dd90a0d33 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -2698,34 +2698,35 @@ void NODE_OT_links_detach(wmOperatorType *ot) /* ********************* automatic node insert on dragging ******************* */ /* assumes sockets in list */ -static bNodeSocket *socket_best_match(ListBase *sockets, int type) +static bNodeSocket *socket_best_match(ListBase *sockets) { bNodeSocket *sock; + int type, maxtype=0; - /* first, match type */ - for(sock= sockets->first; sock; sock= sock->next) - if(!nodeSocketIsHidden(sock)) - if(type == sock->type) - return sock; + /* find type range */ + for (sock=sockets->first; sock; sock=sock->next) + maxtype = MAX2(sock->type, maxtype); - /* then just use first unhidden socket */ - for(sock= sockets->first; sock; sock= sock->next) - if(!nodeSocketIsHidden(sock)) - return sock; - - /* OK, let's unhide proper one */ - for(sock= sockets->first; sock; sock= sock->next) { - if(type == sock->type) { - sock->flag &= ~(SOCK_HIDDEN|SOCK_AUTO_HIDDEN); - return sock; + /* try all types, starting from 'highest' (i.e. colors, vectors, values) */ + for (type=maxtype; type >= 0; --type) { + for(sock= sockets->first; sock; sock= sock->next) { + if(!nodeSocketIsHidden(sock) && type==sock->type) { + return sock; + } } } - /* just the first */ - sock= sockets->first; - sock->flag &= ~(SOCK_HIDDEN|SOCK_AUTO_HIDDEN); + /* no visible sockets, unhide first of highest type */ + for (type=maxtype; type >= 0; --type) { + for(sock= sockets->first; sock; sock= sock->next) { + if(type==sock->type) { + sock->flag &= ~(SOCK_HIDDEN|SOCK_AUTO_HIDDEN); + return sock; + } + } + } - return sockets->first; + return NULL; } /* prevent duplicate testing code below */ @@ -2783,10 +2784,10 @@ void ED_node_link_insert(ScrArea *sa) sockto= link->tosock; link->tonode= select; - link->tosock= socket_best_match(&select->inputs, link->fromsock->type); + link->tosock= socket_best_match(&select->inputs); link->flag &= ~NODE_LINKFLAG_HILITE; - nodeAddLink(snode->edittree, select, socket_best_match(&select->outputs, sockto->type), node, sockto); + nodeAddLink(snode->edittree, select, socket_best_match(&select->outputs), node, sockto); ntreeUpdateTree(snode->edittree); /* needed for pointers */ snode_update(snode, select); ED_node_changed_update(snode->id, select); |