@@ -14,17 +14,21 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
public double Angle { get; set; }
|
||||
|
||||
public bool IsAnimationActive {
|
||||
get => !(_storyboard?.GetIsPaused() ?? true);
|
||||
set {
|
||||
if (value) {
|
||||
_storyboard?.Resume();
|
||||
} else {
|
||||
_storyboard?.Pause();
|
||||
if (_storyboard == null) return;
|
||||
if (value && _storyboard.GetIsPaused()) {
|
||||
_storyboard.Resume();
|
||||
} else if (!value && !_storyboard.GetIsPaused()) {
|
||||
_storyboard.Pause();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Polyline? _polyline;
|
||||
private Storyboard? _storyboard;
|
||||
private DoubleAnimation? _leftSlide;
|
||||
private Canvas? _clipCanvas;
|
||||
|
||||
public Auger(double x, double y, double width, double height, double angle = 0) {
|
||||
CenterX = x;
|
||||
@@ -35,41 +39,45 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
}
|
||||
|
||||
public void Draw(Canvas canvas) {
|
||||
var d = Height / 4;
|
||||
int n = (int)(Width / d / 4) + 2;
|
||||
_polyline = new Polyline() {
|
||||
Points = [.. Enumerable.Range(0, n).SelectMany(i => new List<Point>() {
|
||||
new(i * 4 * d, Height / 2), new((i * 4 + 1) * d, 0),
|
||||
new((i * 4 + 2) * d, Height / 2), new((i * 4 + 3) * d, Height)
|
||||
}), new(n * 4 * d, Height / 2), new(0, Height / 2)],
|
||||
Fill = Brushes.Transparent,
|
||||
Stroke = Brushes.Black,
|
||||
StrokeThickness = 2,
|
||||
};
|
||||
_polyline.SetValue(Canvas.LeftProperty, 0.0);
|
||||
|
||||
var slideLeft = new DoubleAnimation {
|
||||
_leftSlide = new DoubleAnimation {
|
||||
From = 0,
|
||||
To = -d * 4,
|
||||
Duration = new Duration(TimeSpan.FromSeconds(1)),
|
||||
RepeatBehavior = RepeatBehavior.Forever,
|
||||
};
|
||||
_storyboard = new Storyboard();
|
||||
_storyboard.Children.Add(slideLeft);
|
||||
Storyboard.SetTarget(slideLeft, _polyline);
|
||||
Storyboard.SetTargetProperty(slideLeft, new PropertyPath(Canvas.LeftProperty));
|
||||
var clipCanvas = new Canvas() {
|
||||
Width = Width,
|
||||
Height = Height,
|
||||
_storyboard.Children.Add(_leftSlide);
|
||||
Storyboard.SetTarget(_leftSlide, _polyline);
|
||||
Storyboard.SetTargetProperty(_leftSlide, new PropertyPath(Canvas.LeftProperty));
|
||||
_clipCanvas = new Canvas() {
|
||||
ClipToBounds = true,
|
||||
RenderTransform = new RotateTransform(Angle, Width / 2, Height / 2),
|
||||
};
|
||||
clipCanvas.SetValue(Canvas.TopProperty, CenterY - Height / 2);
|
||||
clipCanvas.SetValue(Canvas.LeftProperty, CenterX - Width / 2);
|
||||
clipCanvas.Children.Add(_polyline);
|
||||
canvas.Children.Add(clipCanvas);
|
||||
_clipCanvas.Children.Add(_polyline);
|
||||
canvas.Children.Add(_clipCanvas);
|
||||
_storyboard.Begin();
|
||||
_storyboard.Pause();
|
||||
}
|
||||
|
||||
public void Scale(double scale) {
|
||||
var border = Graph.ToBorder(scale);
|
||||
var d = Height / 4 * scale;
|
||||
int n = (int)(Width * scale / d / 4) + 2;
|
||||
_polyline?.Points = [.. Enumerable.Range(0, n).SelectMany(i => new List<Point>() {
|
||||
new(i * 4 * d, Height / 2 * scale), new((i * 4 + 1) * d, 0),
|
||||
new((i * 4 + 2) * d, Height / 2 * scale), new((i * 4 + 3) * d, Height * scale)
|
||||
}), new(n * 4 * d, Height / 2 * scale), new(0, Height / 2 * scale)];
|
||||
_polyline?.StrokeThickness = border;
|
||||
_leftSlide?.To = -d / 4;
|
||||
_clipCanvas?.Width = Width * scale;
|
||||
_clipCanvas?.Height = Height * scale;
|
||||
_clipCanvas?.RenderTransform = new RotateTransform(Angle, Width / 2 * scale, Height / 2 * scale);
|
||||
_clipCanvas?.SetValue(Canvas.TopProperty, (CenterY - Height / 2) * scale);
|
||||
_clipCanvas?.SetValue(Canvas.LeftProperty,( CenterX - Width / 2) * scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user