Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarley Acheson <harley.acheson@gmail.com>2021-08-27 21:25:30 +0300
committerHarley Acheson <harley.acheson@gmail.com>2021-08-27 21:25:30 +0300
commit400605c3a6a88ba0cd6729fc7389a1c808e4abe5 (patch)
tree97859a3005b8551f9dd5526a9a259290a0dc0040
parent071007e0eff9dd474f4a3d1f479649242be22717 (diff)
UI: Reduce Node Contents Jiggling When Moved
This patch just clamps and rounds node contents and socket locations so they don't appear to jiggle around when you move them. This issue happens because node sizing and positioning are in floats while text content must be pixel-aligned. See D11684 for more details and comparisons. Differential Revision: https://developer.blender.org/D11684 Reviewed by Julian Eisel
-rw-r--r--source/blender/editors/space_node/node_draw.cc29
-rw-r--r--source/blender/editors/space_node/node_intern.h2
2 files changed, 20 insertions, 11 deletions
diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc
index b67117f1ad0..5b4e3b3b6f5 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -360,7 +360,11 @@ static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node)
/* Get "global" coordinates. */
float locx, locy;
node_to_view(node, 0.0f, 0.0f, &locx, &locy);
- float dy = locy;
+ /* Round the node origin because text contents are always pixel-aligned. */
+ locx = round(locx);
+ locy = round(locy);
+
+ int dy = locy;
/* Header. */
dy -= NODE_DY;
@@ -412,9 +416,9 @@ static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node)
/* Ensure minimum socket height in case layout is empty. */
buty = min_ii(buty, dy - NODE_DY);
- nsock->locx = locx + NODE_WIDTH(node);
- /* Place the socket circle in the middle of the layout. */
- nsock->locy = 0.5f * (dy + buty);
+ /* Round the socket location to stop it from jiggling. */
+ nsock->locx = round(locx + NODE_WIDTH(node));
+ nsock->locy = round(0.5f * (dy + buty));
dy = buty;
if (nsock->next) {
@@ -549,8 +553,8 @@ static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node)
buty = min_ii(buty, dy - NODE_DY);
nsock->locx = locx;
- /* Place the socket circle in the middle of the layout. */
- nsock->locy = 0.5f * (dy + buty);
+ /* Round the socket vertical position to stop it from jiggling. */
+ nsock->locy = round(0.5f * (dy + buty));
dy = buty - multi_input_socket_offset * 0.5;
if (nsock->next) {
@@ -587,6 +591,9 @@ static void node_update_hidden(bNode *node)
/* Get "global" coords. */
float locx, locy;
node_to_view(node, 0.0f, 0.0f, &locx, &locy);
+ /* Round the node origin because text contents are always pixel-aligned. */
+ locx = round(locx);
+ locy = round(locy);
/* Calculate minimal radius. */
LISTBASE_FOREACH (bNodeSocket *, nsock, &node->inputs) {
@@ -617,8 +624,9 @@ static void node_update_hidden(bNode *node)
LISTBASE_FOREACH (bNodeSocket *, nsock, &node->outputs) {
if (!nodeSocketIsHidden(nsock)) {
- nsock->locx = node->totr.xmax - hiddenrad + sinf(rad) * hiddenrad;
- nsock->locy = node->totr.ymin + hiddenrad + cosf(rad) * hiddenrad;
+ /* Round the socket location to stop it from jiggling. */
+ nsock->locx = round(node->totr.xmax - hiddenrad + sinf(rad) * hiddenrad);
+ nsock->locy = round(node->totr.ymin + hiddenrad + cosf(rad) * hiddenrad);
rad += drad;
}
}
@@ -628,8 +636,9 @@ static void node_update_hidden(bNode *node)
LISTBASE_FOREACH (bNodeSocket *, nsock, &node->inputs) {
if (!nodeSocketIsHidden(nsock)) {
- nsock->locx = node->totr.xmin + hiddenrad + sinf(rad) * hiddenrad;
- nsock->locy = node->totr.ymin + hiddenrad + cosf(rad) * hiddenrad;
+ /* Round the socket location to stop it from jiggling. */
+ nsock->locx = round(node->totr.xmin + hiddenrad + sinf(rad) * hiddenrad);
+ nsock->locy = round(node->totr.ymin + hiddenrad + cosf(rad) * hiddenrad);
rad += drad;
}
}
diff --git a/source/blender/editors/space_node/node_intern.h b/source/blender/editors/space_node/node_intern.h
index df20420e472..d35fd729131 100644
--- a/source/blender/editors/space_node/node_intern.h
+++ b/source/blender/editors/space_node/node_intern.h
@@ -328,7 +328,7 @@ extern const char *node_context_dir[];
#define BASIS_RAD (0.2f * U.widget_unit)
#define NODE_DYS (U.widget_unit / 2)
#define NODE_DY U.widget_unit
-#define NODE_SOCKDY (0.08f * U.widget_unit)
+#define NODE_SOCKDY (0.1f * U.widget_unit)
#define NODE_WIDTH(node) (node->width * UI_DPI_FAC)
#define NODE_HEIGHT(node) (node->height * UI_DPI_FAC)
#define NODE_MARGIN_X (1.10f * U.widget_unit)