[Bf-blender-cvs] [dcd3d096cd8] temp-long-link-dimming: ignore dimmed links in operators
Jacques Lucke
noreply at git.blender.org
Wed Jul 7 15:31:06 CEST 2021
Commit: dcd3d096cd8ff3543a48c3063e684923064218bb
Author: Jacques Lucke
Date: Wed Jul 7 15:20:13 2021 +0200
Branches: temp-long-link-dimming
https://developer.blender.org/rBdcd3d096cd8ff3543a48c3063e684923064218bb
ignore dimmed links in operators
===================================================================
M source/blender/editors/space_node/drawnode.cc
M source/blender/editors/space_node/node_add.cc
M source/blender/editors/space_node/node_edit.cc
M source/blender/editors/space_node/node_intern.h
M source/blender/editors/space_node/node_relationships.cc
===================================================================
diff --git a/source/blender/editors/space_node/drawnode.cc b/source/blender/editors/space_node/drawnode.cc
index ae780750823..29489635cf5 100644
--- a/source/blender/editors/space_node/drawnode.cc
+++ b/source/blender/editors/space_node/drawnode.cc
@@ -4118,8 +4118,7 @@ void nodelink_batch_end(SpaceNode *snode)
g_batch_link.enabled = false;
}
-static void nodelink_batch_add_link(const View2D *v2d,
- const SpaceNode *snode,
+static void nodelink_batch_add_link(const SpaceNode *snode,
const float p0[2],
const float p1[2],
const float p2[2],
@@ -4128,23 +4127,14 @@ static void nodelink_batch_add_link(const View2D *v2d,
int th_col2,
int th_col3,
bool drawarrow,
- bool drawmuted)
+ bool drawmuted,
+ float dim_factor)
{
/* Only allow these colors. If more is needed, you need to modify the shader accordingly. */
BLI_assert(ELEM(th_col1, TH_WIRE_INNER, TH_WIRE, TH_ACTIVE, TH_EDGE_SELECT, TH_REDALERT));
BLI_assert(ELEM(th_col2, TH_WIRE_INNER, TH_WIRE, TH_ACTIVE, TH_EDGE_SELECT, TH_REDALERT));
BLI_assert(ELEM(th_col3, TH_WIRE, TH_REDALERT, -1));
- const float min_endpoint_distance = std::min(
- std::max(BLI_rctf_length_x(&v2d->cur, p0[0]), BLI_rctf_length_y(&v2d->cur, p0[1])),
- std::max(BLI_rctf_length_x(&v2d->cur, p3[0]), BLI_rctf_length_y(&v2d->cur, p3[1])));
-
- float dim_factor = 1.0f;
- if (min_endpoint_distance > 0.0f) {
- const float viewport_width = BLI_rctf_size_x(&v2d->cur);
- dim_factor = clamp_f(1.0f - min_endpoint_distance / viewport_width * 10.0f, 0.1f, 1.0f);
- }
-
g_batch_link.count++;
copy_v2_v2((float *)GPU_vertbuf_raw_step(&g_batch_link.p0_step), p0);
copy_v2_v2((float *)GPU_vertbuf_raw_step(&g_batch_link.p1_step), p1);
@@ -4172,6 +4162,8 @@ void node_draw_link_bezier(const View2D *v2d,
int th_col2,
int th_col3)
{
+ const float dim_factor = node_link_dim_factor(v2d, link);
+
float vec[4][2];
const bool highlighted = link->flag & NODE_LINK_TEMP_HIGHLIGHT;
if (node_link_bezier_handles(v2d, snode, link, vec)) {
@@ -4184,8 +4176,7 @@ void node_draw_link_bezier(const View2D *v2d,
if (g_batch_link.enabled && !highlighted) {
/* Add link to batch. */
- nodelink_batch_add_link(v2d,
- snode,
+ nodelink_batch_add_link(snode,
vec[0],
vec[1],
vec[2],
@@ -4194,7 +4185,8 @@ void node_draw_link_bezier(const View2D *v2d,
th_col2,
th_col3,
drawarrow,
- drawmuted);
+ drawmuted,
+ dim_factor);
}
else {
/* Draw single link. */
@@ -4219,7 +4211,7 @@ void node_draw_link_bezier(const View2D *v2d,
GPU_batch_uniform_1f(batch, "arrowSize", ARROW_SIZE);
GPU_batch_uniform_1i(batch, "doArrow", drawarrow);
GPU_batch_uniform_1i(batch, "doMuted", drawmuted);
- GPU_batch_uniform_1f(batch, "dim_factor", 1.0f);
+ GPU_batch_uniform_1f(batch, "dim_factor", dim_factor);
GPU_batch_draw(batch);
}
}
diff --git a/source/blender/editors/space_node/node_add.cc b/source/blender/editors/space_node/node_add.cc
index c167744de01..9264c9d3572 100644
--- a/source/blender/editors/space_node/node_add.cc
+++ b/source/blender/editors/space_node/node_add.cc
@@ -260,7 +260,7 @@ static int add_reroute_exec(bContext *C, wmOperator *op)
BLI_listbase_clear(&input_links);
for (link = (bNodeLink *)ntree->links.first; link; link = link->next) {
- if (nodeLinkIsHidden(link)) {
+ if (node_link_is_hidden_or_dimmed(®ion->v2d, link)) {
continue;
}
if (add_reroute_intersect_check(link, mcoords, i, insert_point)) {
diff --git a/source/blender/editors/space_node/node_edit.cc b/source/blender/editors/space_node/node_edit.cc
index 5dd935bdd76..9ba445310be 100644
--- a/source/blender/editors/space_node/node_edit.cc
+++ b/source/blender/editors/space_node/node_edit.cc
@@ -21,6 +21,8 @@
* \ingroup spnode
*/
+#include <algorithm>
+
#include "MEM_guardedalloc.h"
#include "DNA_light_types.h"
@@ -1226,6 +1228,28 @@ int node_find_indicated_socket(
return 0;
}
+/* ****************** Link Dimming *********************** */
+
+float node_link_dim_factor(const View2D *v2d, const bNodeLink *link)
+{
+ const float min_endpoint_distance = std::min(
+ std::max(BLI_rctf_length_x(&v2d->cur, link->fromsock->locx),
+ BLI_rctf_length_y(&v2d->cur, link->fromsock->locy)),
+ std::max(BLI_rctf_length_x(&v2d->cur, link->tosock->locx),
+ BLI_rctf_length_y(&v2d->cur, link->tosock->locy)));
+
+ if (min_endpoint_distance == 0.0f) {
+ return 1.0f;
+ }
+ const float viewport_width = BLI_rctf_size_x(&v2d->cur);
+ return clamp_f(1.0f - min_endpoint_distance / viewport_width * 10.0f, 0.1f, 1.0f);
+}
+
+bool node_link_is_hidden_or_dimmed(const View2D *v2d, const bNodeLink *link)
+{
+ return nodeLinkIsHidden(link) || node_link_dim_factor(v2d, link) < 0.5f;
+}
+
/* ****************** Duplicate *********************** */
static void node_duplicate_reparent_recursive(bNode *node)
diff --git a/source/blender/editors/space_node/node_intern.h b/source/blender/editors/space_node/node_intern.h
index fe550242dbe..6ae49c954a5 100644
--- a/source/blender/editors/space_node/node_intern.h
+++ b/source/blender/editors/space_node/node_intern.h
@@ -268,6 +268,8 @@ int node_find_indicated_socket(struct SpaceNode *snode,
struct bNodeSocket **sockp,
const float cursor[2],
int in_out);
+float node_link_dim_factor(const struct View2D *v2d, const struct bNodeLink *link);
+bool node_link_is_hidden_or_dimmed(const struct View2D *v2d, const struct bNodeLink *link);
void NODE_OT_duplicate(struct wmOperatorType *ot);
void NODE_OT_delete(struct wmOperatorType *ot);
diff --git a/source/blender/editors/space_node/node_relationships.cc b/source/blender/editors/space_node/node_relationships.cc
index aadf93961e9..725c872e98f 100644
--- a/source/blender/editors/space_node/node_relationships.cc
+++ b/source/blender/editors/space_node/node_relationships.cc
@@ -36,6 +36,7 @@
#include "BKE_lib_id.h"
#include "BKE_main.h"
#include "BKE_node.h"
+#include "BKE_screen.h"
#include "ED_node.h" /* own include */
#include "ED_render.h"
@@ -1332,7 +1333,7 @@ static int cut_links_exec(bContext *C, wmOperator *op)
ED_preview_kill_jobs(CTX_wm_manager(C), bmain);
LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &snode->edittree->links) {
- if (nodeLinkIsHidden(link)) {
+ if (node_link_is_hidden_or_dimmed(®ion->v2d, link)) {
continue;
}
@@ -1429,7 +1430,7 @@ static int mute_links_exec(bContext *C, wmOperator *op)
/* Count intersected links and clear test flag. */
int tot = 0;
LISTBASE_FOREACH (bNodeLink *, link, &snode->edittree->links) {
- if (nodeLinkIsHidden(link)) {
+ if (node_link_is_hidden_or_dimmed(®ion->v2d, link)) {
continue;
}
link->flag &= ~NODE_LINK_TEST;
@@ -1443,7 +1444,7 @@ static int mute_links_exec(bContext *C, wmOperator *op)
/* Mute links. */
LISTBASE_FOREACH (bNodeLink *, link, &snode->edittree->links) {
- if (nodeLinkIsHidden(link) || (link->flag & NODE_LINK_TEST)) {
+ if (node_link_is_hidden_or_dimmed(®ion->v2d, link) || (link->flag & NODE_LINK_TEST)) {
continue;
}
@@ -1458,7 +1459,7 @@ static int mute_links_exec(bContext *C, wmOperator *op)
/* Clear remaining test flags. */
LISTBASE_FOREACH (bNodeLink *, link, &snode->edittree->links) {
- if (nodeLinkIsHidden(link)) {
+ if (node_link_is_hidden_or_dimmed(®ion->v2d, link)) {
continue;
}
link->flag &= ~NODE_LINK_TEST;
@@ -1894,9 +1895,11 @@ static bool ed_node_link_conditions(ScrArea *area,
return false;
}
+ ARegion *region = BKE_area_find_region_type(area, RGN_TYPE_WINDOW);
+
/* test node for links */
LISTBASE_FOREACH (bNodeLink *, link, &snode->edittree->links) {
- if (nodeLinkIsHidden(link)) {
+ if (node_link_is_hidden_or_dimmed(®ion->v2d, link)) {
continue;
}
@@ -1927,13 +1930,15 @@ void ED_node_link_intersect_test(ScrArea *area, int test)
return;
}
+ ARegion *region = BKE_area_find_region_type(area, RGN_TYPE_WINDOW);
+
/* find link to select/highlight */
bNodeLink *selink = nullptr;
float dist_best = FLT_MAX;
LISTBASE_FOREACH (bNodeLink *, link, &snode->edittree->links) {
float coord_array[NODE_LINK_RESOL + 1][2];
- if (nodeLinkIsHidden(link)) {
+ if (node_link_is_hidden_or_dimmed(®ion->v2d, link)) {
continue;
}
More information about the Bf-blender-cvs
mailing list