From d6527848d3471aa8a520988fa70978e4ff0ddce0 Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Mon, 10 Sep 2018 22:43:17 +0200 Subject: [PATCH] Added clipping when drawing links --- .../widgets/linked_widgets/link.gd | 19 +++++++++++++++---- .../linked_widgets/linked_control_base.gd | 14 ++++++++++---- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/addons/material_maker/widgets/linked_widgets/link.gd b/addons/material_maker/widgets/linked_widgets/link.gd index 18e5a3e..0f19d84 100644 --- a/addons/material_maker/widgets/linked_widgets/link.gd +++ b/addons/material_maker/widgets/linked_widgets/link.gd @@ -1,9 +1,20 @@ -extends Node2D +extends Control +var clip_pos = Vector2(0, 0) +var clip_size = Vector2(0, 0) var end var source = null var target = null +func _ready(): + mouse_filter = Control.MOUSE_FILTER_IGNORE + +func clip(p, s): + clip_pos = p + rect_global_position = p + rect_size = s + rect_clip_content = true + func closest(rect, point): return Vector2(max(rect.position.x, min(rect.end.x, point.x)), max(rect.position.y, min(rect.end.y, point.y))) @@ -14,9 +25,9 @@ func _draw(): if target != null: color = Color(0.5, 1, 0.5, 0.5) rect = Rect2(target.rect_global_position, target.rect_size*target.get_global_transform().get_scale()) - draw_rect(rect, color, false) + draw_rect(Rect2(rect.position-clip_pos, rect.size), color, false) end = closest(rect, start) rect = Rect2(source.rect_global_position, source.rect_size*source.get_global_transform().get_scale()) - draw_rect(rect, color, false) + draw_rect(Rect2(rect.position-clip_pos, rect.size), color, false) start = closest(rect, end) - draw_line(start, end, color, 1, true) + draw_line(start-clip_pos, end-clip_pos, color, 1, true) diff --git a/addons/material_maker/widgets/linked_widgets/linked_control_base.gd b/addons/material_maker/widgets/linked_widgets/linked_control_base.gd index d10854a..e7d1a8c 100644 --- a/addons/material_maker/widgets/linked_widgets/linked_control_base.gd +++ b/addons/material_maker/widgets/linked_widgets/linked_control_base.gd @@ -52,10 +52,14 @@ func delete(): func _on_mouse_entered(): _on_mouse_exited() + get_graph_edit() + if graph_edit == null: + return links = [] var viewport = get_viewport() for w in linked_widgets: var link = Link.new() + link.clip(graph_edit.rect_global_position, graph_edit.rect_size) link.source = self link.target = w.widget viewport.add_child(link) @@ -73,7 +77,10 @@ var link = null var graph_edit = null var pointed_control = null -const Link = preload("res://addons/material_maker/widgets/linked_widgets/link.gd") +func get_graph_edit(): + graph_edit = get_parent() + while graph_edit != null && !(graph_edit is GraphEdit): + graph_edit = graph_edit.get_parent() func find_control(gp): for c in graph_edit.get_children(): @@ -108,14 +115,13 @@ func _input(event): func pick_linked(): # Verify we are in a graph edit - graph_edit = get_parent() - while graph_edit != null && !(graph_edit is GraphEdit): - graph_edit = graph_edit.get_parent() + get_graph_edit() if graph_edit == null: return # Create line that will be shown when looking for a target var viewport = get_viewport() link = Link.new() + link.clip(graph_edit.rect_global_position, graph_edit.rect_size) link.source = self link.end = rect_global_position+0.5*rect_size*get_global_transform().get_scale() viewport.add_child(link)