@@ -7,42 +7,40 @@ using System.Windows.Shapes;
|
||||
namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
internal sealed class FlowArrows {
|
||||
|
||||
public const double SPEED = 20;
|
||||
public const double SPACING = 15;
|
||||
public const double LENGTH = 7;
|
||||
public const double WIDTH = 7;
|
||||
public const double SPEED = 4;
|
||||
public const double SPACING = 3;
|
||||
public const double LENGTH = 1.4;
|
||||
public const double WIDTH = 1.4;
|
||||
|
||||
private static readonly Stopwatch Clock = Stopwatch.StartNew();
|
||||
|
||||
private double _scale = 5;
|
||||
private readonly Canvas _layer;
|
||||
private readonly Point[] _path;
|
||||
private Point[] _points = [];
|
||||
private double _length;
|
||||
private double _pathOffset;
|
||||
private bool _isActive;
|
||||
|
||||
public double Length => GetLength(_path[0], _path[1]) + GetLength(_path[1], _path[2]);
|
||||
public double Length { get; init; }
|
||||
|
||||
private FlowArrows(Canvas canvas, Point[] path) {
|
||||
private FlowArrows(Point[] path) {
|
||||
_path = path;
|
||||
Length = _path.Length <= 1 ? 0 : Enumerable.Range(0, _path.Length - 1).Sum(i => GetLength(_path[i], _path[i + 1]));
|
||||
_layer = new Canvas() {
|
||||
IsHitTestVisible = false,
|
||||
Visibility = Visibility.Collapsed,
|
||||
};
|
||||
_layer.Unloaded += (_, _) => Stop();
|
||||
canvas.Children.Add(_layer);
|
||||
}
|
||||
|
||||
public static FlowArrows Create(Canvas canvas, Line first, Line second) {
|
||||
return new FlowArrows(canvas, [
|
||||
new Point(first.X1, first.Y1),
|
||||
new Point(first.X2, first.Y2),
|
||||
new Point(second.X2, second.Y2),
|
||||
]);
|
||||
public static FlowArrows Create(Canvas canvas, IEnumerable<Point> points) {
|
||||
var arrows = new FlowArrows([.. points]);
|
||||
canvas.Children.Add(arrows._layer);
|
||||
return arrows;
|
||||
}
|
||||
|
||||
public static FlowArrows Create(Canvas canvas, Polyline path) {
|
||||
return new FlowArrows(canvas, [.. path.Points]);
|
||||
public void Scale(double scale) {
|
||||
_scale = scale;
|
||||
}
|
||||
|
||||
public void Update((bool TowardEnd, double PathOffset)? flow) {
|
||||
@@ -52,7 +50,6 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
}
|
||||
|
||||
_points = flow.Value.TowardEnd ? _path : [.. _path.Reverse()];
|
||||
_length = GetLength(_points[0], _points[1]) + GetLength(_points[1], _points[2]);
|
||||
_pathOffset = flow.Value.PathOffset;
|
||||
if (!_isActive) {
|
||||
CompositionTarget.Rendering += OnRendering;
|
||||
@@ -69,7 +66,7 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
private void Render() {
|
||||
var distance = ((Clock.Elapsed.TotalSeconds * SPEED - _pathOffset) % SPACING + SPACING) % SPACING;
|
||||
var arrowIndex = 0;
|
||||
while (distance <= _length) {
|
||||
while (distance <= Length) {
|
||||
var arrow = GetArrow(arrowIndex++);
|
||||
SetPosition(arrow, distance);
|
||||
arrow.Visibility = Visibility.Visible;
|
||||
@@ -145,9 +142,9 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
direction = v2;
|
||||
}
|
||||
|
||||
double ux = direction.X;
|
||||
double uy = direction.Y;
|
||||
(arrow.RenderTransform as MatrixTransform)?.Matrix = new Matrix(ux, uy, -uy, ux, position.X, position.Y);
|
||||
double ux = direction.X * _scale;
|
||||
double uy = direction.Y * _scale;
|
||||
(arrow.RenderTransform as MatrixTransform)?.Matrix = new Matrix(ux, uy, -uy, ux, position.X * _scale, position.Y * _scale);
|
||||
}
|
||||
|
||||
private void Stop() {
|
||||
|
||||
Reference in New Issue
Block a user