Fix T100430: Restore larger node socket snap hitbox

Restore old hitbox for connecting links to sockets.

Commit rBd9d97db018d2 improved the node socket snapping when nodes
are close together by decreasing the tolerance around the cursor when
checking for nodes in front, that might occlude the socket.
In doing so it also reduced the hitbox of the node socket itself that
extended outside of the node.

This commit restores the old node socket hitbox while keeping the
improved behavior when nodes are close together with the following
changes:
1) When looking for the socket under the cursor, iterate through the
nodes front to back, which prioritizes node sockets in the foreground.
2) Instead of checking for another node underneath the cursor it checks
if the socket is actually occluded by another node.

The way the occlusion test for sockets is tweaked you can now connect to
sockets that are only partially occluded, which is a bit more forgiving
than previously.

Reviewed By: Hans Goudey

Differential Revision: http://developer.blender.org/D15731
This commit is contained in:
Leon Schittek 2022-08-21 10:12:50 +02:00
parent acf083a5bf
commit 563404d8ad
Notes: blender-bot 2023-02-14 03:52:45 +01:00
Referenced by issue #100430, Regression: Node socket active/snapping area became smaller
1 changed files with 18 additions and 11 deletions

View File

@ -913,15 +913,24 @@ static void edit_node_properties_get(
/** \name Node Generic
* \{ */
/* is rct in visible part of node? */
static bNode *visible_node(SpaceNode &snode, const rctf &rct)
static bool socket_is_occluded(const bNodeSocket &sock,
const bNode &node_the_socket_belongs_to,
const SpaceNode &snode)
{
LISTBASE_FOREACH_BACKWARD (bNode *, node, &snode.edittree->nodes) {
if (BLI_rctf_isect(&node->totr, &rct, nullptr)) {
return node;
if (node == &node_the_socket_belongs_to) {
/* Nodes after this one are underneath and can't occlude the socket. */
return false;
}
rctf socket_hitbox;
const float socket_hitbox_radius = NODE_SOCKSIZE - 0.1f * U.widget_unit;
BLI_rctf_init_pt_radius(&socket_hitbox, float2(sock.locx, sock.locy), socket_hitbox_radius);
if (BLI_rctf_inside_rctf(&node->totr, &socket_hitbox)) {
return true;
}
}
return nullptr;
return false;
}
/** \} */
@ -1216,10 +1225,8 @@ bool node_find_indicated_socket(SpaceNode &snode,
*sockp = nullptr;
/* check if we click in a socket */
LISTBASE_FOREACH (bNode *, node, &snode.edittree->nodes) {
LISTBASE_FOREACH_BACKWARD (bNode *, node, &snode.edittree->nodes) {
BLI_rctf_init_pt_radius(&rect, cursor, size_sock_padded);
rctf node_visible;
BLI_rctf_init_pt_radius(&node_visible, cursor, size_sock_padded);
if (!(node->flag & NODE_HIDDEN)) {
/* extra padding inside and out - allow dragging on the text areas too */
@ -1238,7 +1245,7 @@ bool node_find_indicated_socket(SpaceNode &snode,
if (!nodeSocketIsHidden(sock)) {
if (sock->flag & SOCK_MULTI_INPUT && !(node->flag & NODE_HIDDEN)) {
if (cursor_isect_multi_input_socket(cursor, *sock)) {
if (node == visible_node(snode, node_visible)) {
if (!socket_is_occluded(*sock, *node, snode)) {
*nodep = node;
*sockp = sock;
return true;
@ -1246,7 +1253,7 @@ bool node_find_indicated_socket(SpaceNode &snode,
}
}
else if (BLI_rctf_isect_pt(&rect, sock->locx, sock->locy)) {
if (node == visible_node(snode, node_visible)) {
if (!socket_is_occluded(*sock, *node, snode)) {
*nodep = node;
*sockp = sock;
return true;
@ -1259,7 +1266,7 @@ bool node_find_indicated_socket(SpaceNode &snode,
LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) {
if (!nodeSocketIsHidden(sock)) {
if (BLI_rctf_isect_pt(&rect, sock->locx, sock->locy)) {
if (node == visible_node(snode, node_visible)) {
if (!socket_is_occluded(*sock, *node, snode)) {
*nodep = node;
*sockp = sock;
return true;