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 Stirrer { public double CenterX { get; set; } public double CenterY { get; set; } public double Radius { get; set; } public bool IsRotatingClockwise { 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 RotateTransform? _transform; private DoubleAnimation? _rotate; public Stirrer(double x, double y, double radius, bool clockwise = true) { CenterX = x; CenterY = y; Radius = radius; IsRotatingClockwise = clockwise; } public void Draw(Canvas canvas) { _transform = new RotateTransform(0); _polyline = new Polyline() { Stroke = Brushes.Black, RenderTransform = _transform, StrokeLineJoin = PenLineJoin.Round, }; _rotate = new DoubleAnimation { From = 0, To = IsRotatingClockwise ? 360 : -360, Duration = new Duration(TimeSpan.FromSeconds(4.5)), RepeatBehavior = RepeatBehavior.Forever, }; Storyboard.SetTarget(_rotate, _polyline); _storyboard = new Storyboard(); _storyboard.Children.Add(_rotate); Storyboard.SetTargetProperty(_rotate, new PropertyPath("RenderTransform.Angle")); canvas.Children.Add(_polyline); _storyboard.Begin(); _storyboard.Pause(); } public void Scale(double scale) { var border = Graph.ToBorder(scale); var dx = Radius * Math.Cos(double.DegreesToRadians(30)); var dy = Radius * Math.Sin(double.DegreesToRadians(30)); _polyline?.Points = [ Graph.ToPx(CenterX, CenterY, scale, round: false), Graph.ToPx(CenterX, CenterY - Radius, scale, round: false), Graph.ToPx(CenterX, CenterY, scale, round: false), Graph.ToPx(CenterX + dx, CenterY + dy, scale, round: false), Graph.ToPx(CenterX, CenterY, scale, round: false), Graph.ToPx(CenterX - dx, CenterY + dy, scale, round: false), Graph.ToPx(CenterX, CenterY, scale, round: false)]; _polyline?.StrokeThickness = border * 1.5; _transform?.CenterX = Graph.ToPx(CenterX, scale); _transform?.CenterY = Graph.ToPx(CenterY, scale); } } }