[Bf-blender-cvs] [ee1d5fb9e46] master: UI: Fix cosmetic papercuts of the reroute node

Leon Schittek noreply at git.blender.org
Tue Mar 29 23:44:31 CEST 2022


Commit: ee1d5fb9e4671a60fc3083dde78c227d9ef73aa2
Author: Leon Schittek
Date:   Tue Mar 29 23:39:50 2022 +0200
Branches: master
https://developer.blender.org/rBee1d5fb9e4671a60fc3083dde78c227d9ef73aa2

UI: Fix cosmetic papercuts of the reroute node

Fix small cosmetic issues with the reroute node:
1. Remove special case that allowed curved links to attach vertically.
2. Center align the reroute node's label.

The vertically attached node links could lead to kinks in the otherwise
smooth curves. This would break the visual flow and make the link
potentially intersect the node's label.

The center alignment of the label gives more consistent results for
different label lengths and also reduces the chance of the label
interfering with the node links.

Reviewed By: Hans Goudey, Pablo Vazquez

Differential Revision: D14457

===================================================================

M	source/blender/editors/space_node/drawnode.cc
M	source/blender/editors/space_node/node_draw.cc

===================================================================

diff --git a/source/blender/editors/space_node/drawnode.cc b/source/blender/editors/space_node/drawnode.cc
index 365a17c0a04..d4b7640cfe3 100644
--- a/source/blender/editors/space_node/drawnode.cc
+++ b/source/blender/editors/space_node/drawnode.cc
@@ -1556,7 +1556,6 @@ bool node_link_bezier_handles(const View2D *v2d,
   }
 
   /* in v0 and v3 we put begin/end points */
-  int toreroute, fromreroute;
   if (link.fromsock) {
     vec[0][0] = link.fromsock->locx;
     vec[0][1] = link.fromsock->locy;
@@ -1567,14 +1566,12 @@ bool node_link_bezier_handles(const View2D *v2d,
           link.fromsock->total_inputs);
       copy_v2_v2(vec[0], position);
     }
-    fromreroute = (link.fromnode && link.fromnode->type == NODE_REROUTE);
   }
   else {
     if (snode == nullptr) {
       return false;
     }
     copy_v2_v2(vec[0], cursor);
-    fromreroute = 0;
   }
   if (link.tosock) {
     vec[3][0] = link.tosock->locx;
@@ -1586,14 +1583,12 @@ bool node_link_bezier_handles(const View2D *v2d,
           link.tosock->total_inputs);
       copy_v2_v2(vec[3], position);
     }
-    toreroute = (link.tonode && link.tonode->type == NODE_REROUTE);
   }
   else {
     if (snode == nullptr) {
       return false;
     }
     copy_v2_v2(vec[3], cursor);
-    toreroute = 0;
   }
 
   /* may be called outside of drawing (so pass spacetype) */
@@ -1607,37 +1602,12 @@ bool node_link_bezier_handles(const View2D *v2d,
   }
 
   const float dist = curving * 0.10f * fabsf(vec[0][0] - vec[3][0]);
-  const float deltax = vec[3][0] - vec[0][0];
-  const float deltay = vec[3][1] - vec[0][1];
-  /* check direction later, for top sockets */
-  if (fromreroute) {
-    if (fabsf(deltax) > fabsf(deltay)) {
-      vec[1][1] = vec[0][1];
-      vec[1][0] = vec[0][0] + (deltax > 0 ? dist : -dist);
-    }
-    else {
-      vec[1][0] = vec[0][0];
-      vec[1][1] = vec[0][1] + (deltay > 0 ? dist : -dist);
-    }
-  }
-  else {
-    vec[1][0] = vec[0][0] + dist;
-    vec[1][1] = vec[0][1];
-  }
-  if (toreroute) {
-    if (fabsf(deltax) > fabsf(deltay)) {
-      vec[2][1] = vec[3][1];
-      vec[2][0] = vec[3][0] + (deltax > 0 ? -dist : dist);
-    }
-    else {
-      vec[2][0] = vec[3][0];
-      vec[2][1] = vec[3][1] + (deltay > 0 ? -dist : dist);
-    }
-  }
-  else {
-    vec[2][0] = vec[3][0] - dist;
-    vec[2][1] = vec[3][1];
-  }
+
+  vec[1][0] = vec[0][0] + dist;
+  vec[1][1] = vec[0][1];
+
+  vec[2][0] = vec[3][0] - dist;
+  vec[2][1] = vec[3][1];
 
   if (v2d && min_ffff(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) > v2d->cur.xmax) {
     return false; /* clipped */
diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc
index 7f0c426922b..d39304284ad 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -2574,20 +2574,14 @@ static void reroute_node_draw(
   if (node.label[0] != '\0') {
     /* draw title (node label) */
     BLI_strncpy(showname, node.label, sizeof(showname));
-    uiDefBut(&block,
-             UI_BTYPE_LABEL,
-             0,
-             showname,
-             (int)(rct.xmin - NODE_DYS),
-             (int)(rct.ymax),
-             (short)512,
-             (short)NODE_DY,
-             nullptr,
-             0,
-             0,
-             0,
-             0,
-             nullptr);
+    const short width = 512;
+    const int x = BLI_rctf_cent_x(&node.totr) - (width / 2);
+    const int y = node.totr.ymax;
+
+    uiBut *label_but = uiDefBut(
+        &block, UI_BTYPE_LABEL, 0, showname, x, y, width, (short)NODE_DY, NULL, 0, 0, 0, 0, NULL);
+
+    UI_but_drawflag_disable(label_but, UI_BUT_TEXT_LEFT);
   }
 
   /* only draw input socket. as they all are placed on the same position.



More information about the Bf-blender-cvs mailing list