mirror of
https://github.com/Relintai/material-maker.git
synced 2024-11-13 06:27:18 +01:00
Added clipping when drawing links
This commit is contained in:
parent
1a5ddae226
commit
d6527848d3
@ -1,9 +1,20 @@
|
|||||||
extends Node2D
|
extends Control
|
||||||
|
|
||||||
|
var clip_pos = Vector2(0, 0)
|
||||||
|
var clip_size = Vector2(0, 0)
|
||||||
var end
|
var end
|
||||||
var source = null
|
var source = null
|
||||||
var target = 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):
|
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)))
|
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:
|
if target != null:
|
||||||
color = Color(0.5, 1, 0.5, 0.5)
|
color = Color(0.5, 1, 0.5, 0.5)
|
||||||
rect = Rect2(target.rect_global_position, target.rect_size*target.get_global_transform().get_scale())
|
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)
|
end = closest(rect, start)
|
||||||
rect = Rect2(source.rect_global_position, source.rect_size*source.get_global_transform().get_scale())
|
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)
|
start = closest(rect, end)
|
||||||
draw_line(start, end, color, 1, true)
|
draw_line(start-clip_pos, end-clip_pos, color, 1, true)
|
||||||
|
@ -52,10 +52,14 @@ func delete():
|
|||||||
|
|
||||||
func _on_mouse_entered():
|
func _on_mouse_entered():
|
||||||
_on_mouse_exited()
|
_on_mouse_exited()
|
||||||
|
get_graph_edit()
|
||||||
|
if graph_edit == null:
|
||||||
|
return
|
||||||
links = []
|
links = []
|
||||||
var viewport = get_viewport()
|
var viewport = get_viewport()
|
||||||
for w in linked_widgets:
|
for w in linked_widgets:
|
||||||
var link = Link.new()
|
var link = Link.new()
|
||||||
|
link.clip(graph_edit.rect_global_position, graph_edit.rect_size)
|
||||||
link.source = self
|
link.source = self
|
||||||
link.target = w.widget
|
link.target = w.widget
|
||||||
viewport.add_child(link)
|
viewport.add_child(link)
|
||||||
@ -73,7 +77,10 @@ var link = null
|
|||||||
var graph_edit = null
|
var graph_edit = null
|
||||||
var pointed_control = 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):
|
func find_control(gp):
|
||||||
for c in graph_edit.get_children():
|
for c in graph_edit.get_children():
|
||||||
@ -108,14 +115,13 @@ func _input(event):
|
|||||||
|
|
||||||
func pick_linked():
|
func pick_linked():
|
||||||
# Verify we are in a graph edit
|
# Verify we are in a graph edit
|
||||||
graph_edit = get_parent()
|
get_graph_edit()
|
||||||
while graph_edit != null && !(graph_edit is GraphEdit):
|
|
||||||
graph_edit = graph_edit.get_parent()
|
|
||||||
if graph_edit == null:
|
if graph_edit == null:
|
||||||
return
|
return
|
||||||
# Create line that will be shown when looking for a target
|
# Create line that will be shown when looking for a target
|
||||||
var viewport = get_viewport()
|
var viewport = get_viewport()
|
||||||
link = Link.new()
|
link = Link.new()
|
||||||
|
link.clip(graph_edit.rect_global_position, graph_edit.rect_size)
|
||||||
link.source = self
|
link.source = self
|
||||||
link.end = rect_global_position+0.5*rect_size*get_global_transform().get_scale()
|
link.end = rect_global_position+0.5*rect_size*get_global_transform().get_scale()
|
||||||
viewport.add_child(link)
|
viewport.add_child(link)
|
||||||
|
Loading…
Reference in New Issue
Block a user