-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathNodeInput.cs
More file actions
91 lines (74 loc) · 3.2 KB
/
Copy pathNodeInput.cs
File metadata and controls
91 lines (74 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using NodeGraph.NET6.Utilities;
using System.Windows;
using System.Windows.Controls;
namespace NodeGraph.NET6.Controls
{
public class NodeInputContent : NodeConnectorContent
{
public bool AllowToConnectMultiple
{
get => (bool)GetValue(AllowToConnectMultipleProperty);
set => SetValue(AllowToConnectMultipleProperty, value);
}
public static readonly DependencyProperty AllowToConnectMultipleProperty = DependencyProperty.Register(
nameof(AllowToConnectMultiple),
typeof(bool),
typeof(NodeInputContent),
new PropertyMetadata(false));
public static bool AllowToOverrideConnection { get; set; } = false;
protected override FrameworkElement ConnectorControl => _ConnectorControl;
FrameworkElement _ConnectorControl = null;
static NodeInputContent()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(NodeInputContent), new FrameworkPropertyMetadata(typeof(NodeInputContent)));
}
public override void OnApplyTemplate()
{
_ConnectorControl = GetTemplateChild("__InputConnector__") as FrameworkElement;
base.OnApplyTemplate();
}
public override void UpdateLinkPosition(Canvas canvas)
{
var transformer = _ConnectorControl.TransformToVisual(canvas);
var posOnCanvas = transformer.Transform(new Point(0, _ConnectorControl.ActualHeight * 0.5));
foreach (var nodeLink in NodeLinks)
{
nodeLink.UpdateInputEdge(posOnCanvas.X, posOnCanvas.Y);
}
}
public override bool CanConnectTo(NodeConnectorContent connector)
{
if (AllowToOverrideConnection == false && ConnectedCount > 0 && AllowToConnectMultiple == false)
{
// already connected to other node link.
return false;
}
if ((CanConnect && connector is NodeOutputContent && Node != connector.Node) == false)
{
return false;
}
// check for circulation connecting.
var nodeLinks = connector.Node.EnumrateConnectedNodeLinks();
foreach (var nodeLink in nodeLinks)
{
if (nodeLink.Output?.Node == Node)
{
return false;
}
}
return true;
}
}
public class NodeInput : NodeConnector<NodeInputContent>
{
protected override string ConnectorCanvasName => "__NodeInputCanvas__";
protected override ControlTemplate NodeConnectorContentTemplate => _NodeInputTemplate.Get("__NodeInputContentTemplate__");
ResourceInstance<ControlTemplate> _NodeInputTemplate = new ResourceInstance<ControlTemplate>();
protected override Style NodeConnectorContentBaseStyle => _NodeConnectorContentBaseStyle.Get("__NodeInputBaseStyle__");
ResourceInstance<Style> _NodeConnectorContentBaseStyle = new ResourceInstance<Style>();
static NodeInput()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(NodeInput), new FrameworkPropertyMetadata(typeof(NodeInput)));
}
}
}