using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; namespace PamhagenSysCtrl.Helpers.Pipeline { public class Auger { public double CenterX { get; set; } public double CenterY { get; set; } public double Width { get; set; } public double Height { get; set; } public double Angle { get; set; } public bool IsAnimationActive { get => !(_storyboard?.GetIsPaused() ?? true); set { 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; CenterY = y; Width = width; Height = height; Angle = angle; } public void Draw(Canvas canvas) { _polyline = new Polyline() { Fill = Brushes.Transparent, Stroke = Brushes.Black, }; _polyline.SetValue(Canvas.LeftProperty, 0.0); _leftSlide = new DoubleAnimation { From = 0, Duration = new Duration(TimeSpan.FromSeconds(1)), RepeatBehavior = RepeatBehavior.Forever, }; _storyboard = new Storyboard(); _storyboard.Children.Add(_leftSlide); Storyboard.SetTarget(_leftSlide, _polyline); Storyboard.SetTargetProperty(_leftSlide, new PropertyPath(Canvas.LeftProperty)); _clipCanvas = new Canvas() { ClipToBounds = true, }; _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() { 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); } } }