| Name | Message | Date |
|---|---|---|
| 📄 GraphConnection.cs | 5 days ago | |
| 📄 MainWindow.axaml | 5 days ago | |
| 📄 MainWindow.axaml.cs | 5 days ago |
📄
ui/src/Views/GraphConnection.cs
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
using Avalonia; using Avalonia.Controls; using Avalonia.Media; using Cfa.Ui.Graph; namespace Cfa.Ui.Views; public sealed class GraphConnection : Control { public static readonly StyledProperty<GraphEdge?> EdgeProperty = AvaloniaProperty.Register< GraphConnection, GraphEdge? >(nameof(Edge)); static GraphConnection() => AffectsRender<GraphConnection>(EdgeProperty); public GraphEdge? Edge { get => GetValue(EdgeProperty); set => SetValue(EdgeProperty, value); } public override void Render(DrawingContext context) { base.Render(context); if (Edge is not { } edge) { return; } var start = edge.Start; var end = edge.End; var control1 = edge.Control1; var control2 = edge.Control2; var geometry = new StreamGeometry(); using (var drawing = geometry.Open()) { drawing.BeginFigure(start, false); drawing.CubicBezierTo(control1, control2, end); drawing.EndFigure(false); } var brush = Brushes.SkyBlue; context.DrawGeometry(null, new Pen(brush, edge.Thickness), geometry); var direction = new Vector(end.X - control2.X, end.Y - control2.Y); if (direction.Length > 0) { direction /= direction.Length; var normal = new Vector(-direction.Y, direction.X); var arrow = new StreamGeometry(); using (var drawing = arrow.Open()) { drawing.BeginFigure(end, true); drawing.LineTo(end - direction * 13 + normal * 6); drawing.LineTo(end - direction * 13 - normal * 6); drawing.EndFigure(true); } context.DrawGeometry(brush, null, arrow); } } }