Changeset View
Changeset View
Standalone View
Standalone View
node_wrangler.py
| Show First 20 Lines • Show All 727 Lines • ▼ Show 20 Lines | for outp in available_outputs: | ||||
| link_made = True | link_made = True | ||||
| links.new(outp, inp) | links.new(outp, inp) | ||||
| return True | return True | ||||
| print("Could not make a link from " + node1.name + " to " + node2.name) | print("Could not make a link from " + node1.name + " to " + node2.name) | ||||
| return link_made | return link_made | ||||
| def node_global_location(node): | |||||
| n = node.parent | |||||
| if not n: | |||||
| return node.location | |||||
| loc = node.location | |||||
| x, y = loc[0], loc[1] | |||||
| while True: | |||||
| loc = n.location | |||||
| x += loc[0] | |||||
| y += loc[1] | |||||
| if not n.parent: | |||||
| break | |||||
| n = n.parent | |||||
| return [x, y] | |||||
| def node_at_pos(nodes, context, event): | def node_at_pos(nodes, context, event): | ||||
| nodes_under_mouse = [] | nodes_under_mouse = [] | ||||
| target_node = None | target_node = None | ||||
| dpi_factor = dpifac() | |||||
| store_mouse_cursor(context, event) | store_mouse_cursor(context, event) | ||||
| x, y = context.space_data.cursor_location | x, y = context.space_data.cursor_location | ||||
| # Make a list of each corner (and middle of border) for each node. | # Make a list of each corner (and middle of border) for each node. | ||||
| # Will be sorted to find nearest point and thus nearest node | # Will be sorted to find nearest point and thus nearest node | ||||
| node_points_with_dist = [] | node_points_with_dist = [] | ||||
| for node in nodes: | for node in nodes: | ||||
| skipnode = False | |||||
| if node.type != 'FRAME': # no point trying to link to a frame node | if node.type != 'FRAME': # no point trying to link to a frame node | ||||
| locx = node.location.x | |||||
| locy = node.location.y | locx, locy = node_global_location(node) | ||||
| dimx = node.dimensions.x/dpifac() | dimx = node.dimensions.x/dpi_factor | ||||
| dimy = node.dimensions.y/dpifac() | dimy = node.dimensions.y/dpi_factor | ||||
| 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 | |||||
| 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, y - locy)]) # Top Left | ||||
| node_points_with_dist.append([node, hypot(x - (locx + dimx), y - locy)]) # Top Right | node_points_with_dist.append([node, hypot(x - (locx + dimx), y - locy)]) # Top Right | ||||
| node_points_with_dist.append([node, hypot(x - locx, y - (locy - dimy))]) # Bottom Left | node_points_with_dist.append([node, hypot(x - locx, y - (locy - dimy))]) # Bottom Left | ||||
| node_points_with_dist.append([node, hypot(x - (locx + dimx), y - (locy - dimy))]) # Bottom Right | node_points_with_dist.append([node, hypot(x - (locx + dimx), y - (locy - dimy))]) # Bottom Right | ||||
| node_points_with_dist.append([node, hypot(x - (locx + (dimx / 2)), y - locy)]) # Mid Top | node_points_with_dist.append([node, hypot(x - (locx + (dimx / 2)), y - locy)]) # Mid Top | ||||
| node_points_with_dist.append([node, hypot(x - (locx + (dimx / 2)), y - (locy - dimy))]) # Mid Bottom | node_points_with_dist.append([node, hypot(x - (locx + (dimx / 2)), y - (locy - dimy))]) # Mid Bottom | ||||
| node_points_with_dist.append([node, hypot(x - locx, y - (locy - (dimy / 2)))]) # Mid Left | node_points_with_dist.append([node, hypot(x - locx, y - (locy - (dimy / 2)))]) # Mid Left | ||||
| node_points_with_dist.append([node, hypot(x - (locx + dimx), y - (locy - (dimy / 2)))]) # Mid Right | node_points_with_dist.append([node, hypot(x - (locx + dimx), y - (locy - (dimy / 2)))]) # Mid Right | ||||
| nearest_node = sorted(node_points_with_dist, key=lambda k: k[1])[0][0] | nearest_node = sorted(node_points_with_dist, key=lambda k: k[1])[0][0] | ||||
| for node in nodes: | for node in nodes: | ||||
| if node.type != 'FRAME' and skipnode == False: | if node.type != 'FRAME': | ||||
| locx = node.location.x | locx, locy = node.location | ||||
| locy = node.location.y | dimx = node.dimensions.x/dpi_factor | ||||
| dimx = node.dimensions.x/dpifac() | dimy = node.dimensions.y/dpi_factor | ||||
| dimy = node.dimensions.y/dpifac() | |||||
| if node.parent: | if node.parent: | ||||
| locx += node.parent.location.x | locx += node.parent.location.x | ||||
| locy += node.parent.location.y | locy += node.parent.location.y | ||||
| if (locx <= x <= locx + dimx) and \ | if (locx <= x <= locx + dimx) and \ | ||||
| (locy - dimy <= y <= locy): | (locy - dimy <= y <= locy): | ||||
| nodes_under_mouse.append(node) | nodes_under_mouse.append(node) | ||||
| if len(nodes_under_mouse) == 1: | if len(nodes_under_mouse) == 1: | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | vertices = [(radius * cos(i * 2 * pi / sides) + mx, | ||||
| for i in range(sides + 1)] | for i in range(sides + 1)] | ||||
| batch = batch_for_shader(shader, 'TRI_FAN', {"pos": vertices}) | batch = batch_for_shader(shader, 'TRI_FAN', {"pos": vertices}) | ||||
| shader.bind() | shader.bind() | ||||
| shader.uniform_float("color", colour) | shader.uniform_float("color", colour) | ||||
| batch.draw(shader) | batch.draw(shader) | ||||
| def draw_rounded_node_border(shader, node, radius=8, colour=(1.0, 1.0, 1.0, 0.7)): | 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 | dpi_factor = dpifac() | ||||
| bottom_bar = (16*dpifac()) + 1 | |||||
| area_width = bpy.context.area.width - (16*dpi_factor) - 1 | |||||
| bottom_bar = (16*dpi_factor) + 1 | |||||
| sides = 16 | sides = 16 | ||||
| radius = radius*dpifac() | radius = radius*dpi_factor | ||||
| nlocx = (node.location.x+1)*dpifac() | nloc = node_global_location(node) | ||||
| nlocy = (node.location.y+1)*dpifac() | nlocx, nlocy = (nloc[0]+1)*dpi_factor, (nloc[1]+1)*dpi_factor | ||||
| ndimx = node.dimensions.x | ndimx = node.dimensions.x | ||||
| ndimy = node.dimensions.y | 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: | if node.hide: | ||||
| nlocx += -1 | nlocx += -1 | ||||
| nlocy += 5 | nlocy += 5 | ||||
| if node.type == 'REROUTE': | if node.type == 'REROUTE': | ||||
| #nlocx += 1 | #nlocx += 1 | ||||
| nlocy -= 1 | nlocy -= 1 | ||||
| ndimx = 0 | ndimx = 0 | ||||
| ▲ Show 20 Lines • Show All 4,559 Lines • Show Last 20 Lines | |||||