[Bf-extensions-cvs] [c34f0b90] master: Node Wrangler: fix node outline position with ui scaling

Iyad Ahmed noreply at git.blender.org
Thu Mar 10 11:51:03 CET 2022


Commit: c34f0b90d49938eccf9c1a9ae59b055155e00f9b
Author: Iyad Ahmed
Date:   Thu Mar 10 11:49:29 2022 +0100
Branches: master
https://developer.blender.org/rBAc34f0b90d49938eccf9c1a9ae59b055155e00f9b

Node Wrangler: fix node outline position with ui scaling

Differential Revision: https://developer.blender.org/D14285

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

M	node_wrangler.py

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

diff --git a/node_wrangler.py b/node_wrangler.py
index ddc7ad50..19ccf0c5 100644
--- a/node_wrangler.py
+++ b/node_wrangler.py
@@ -716,6 +716,11 @@ def autolink(node1, node2, links):
     print("Could not make a link from " + node1.name + " to " + node2.name)
     return link_made
 
+def abs_node_location(node):
+    abs_location = node.location
+    if node.parent is None:
+        return abs_location
+    return abs_location + abs_node_location(node.parent)
 
 def node_at_pos(nodes, context, event):
     nodes_under_mouse = []
@@ -730,23 +735,10 @@ def node_at_pos(nodes, context, event):
     for node in nodes:
         skipnode = False
         if node.type != 'FRAME':  # no point trying to link to a frame node
-            locx = node.location.x
-            locy = node.location.y
             dimx = node.dimensions.x/dpifac()
             dimy = node.dimensions.y/dpifac()
-            if node.parent:
-                locx += node.parent.location.x
-                locy += node.parent.location.y
-                if node.parent.parent:
-                    locx += node.parent.parent.location.x
-                    locy += node.parent.parent.location.y
-                    if node.parent.parent.parent:
-                        locx += node.parent.parent.parent.location.x
-                        locy += node.parent.parent.parent.location.y
-                        if node.parent.parent.parent.parent:
-                            # Support three levels or parenting
-                            # There's got to be a better way to do this...
-                            skipnode = True
+            locx, locy = abs_node_location(node)
+
             if not skipnode:
                 node_points_with_dist.append([node, hypot(x - locx, y - locy)])  # Top Left
                 node_points_with_dist.append([node, hypot(x - (locx + dimx), y - locy)])  # Top Right
@@ -762,13 +754,9 @@ def node_at_pos(nodes, context, event):
 
     for node in nodes:
         if node.type != 'FRAME' and skipnode == False:
-            locx = node.location.x
-            locy = node.location.y
+            locx, locy = abs_node_location(node)
             dimx = node.dimensions.x/dpifac()
             dimy = node.dimensions.y/dpifac()
-            if node.parent:
-                locx += node.parent.location.x
-                locy += node.parent.location.y
             if (locx <= x <= locx + dimx) and \
                (locy - dimy <= y <= locy):
                 nodes_under_mouse.append(node)
@@ -823,26 +811,19 @@ def draw_circle_2d_filled(shader, mx, my, radius, colour=(1.0, 1.0, 1.0, 0.7)):
     shader.uniform_float("color", colour)
     batch.draw(shader)
 
+
 def draw_rounded_node_border(shader, node, radius=8, colour=(1.0, 1.0, 1.0, 0.7)):
     area_width = bpy.context.area.width - (16*dpifac()) - 1
     bottom_bar = (16*dpifac()) + 1
     sides = 16
     radius = radius*dpifac()
 
-    nlocx = (node.location.x+1)*dpifac()
-    nlocy = (node.location.y+1)*dpifac()
+    nlocx, nlocy = abs_node_location(node)
+
+    nlocx = (nlocx+1)*dpifac()
+    nlocy = (nlocy+1)*dpifac()
     ndimx = node.dimensions.x
     ndimy = node.dimensions.y
-    # This is a stupid way to do this... TODO use while loop
-    if node.parent:
-        nlocx += node.parent.location.x
-        nlocy += node.parent.location.y
-        if node.parent.parent:
-            nlocx += node.parent.parent.location.x
-            nlocy += node.parent.parent.location.y
-            if node.parent.parent.parent:
-                nlocx += node.parent.parent.parent.location.x
-                nlocy += node.parent.parent.parent.location.y
 
     if node.hide:
         nlocx += -1



More information about the Bf-extensions-cvs mailing list