[WIP] Scaling
Test / Run tests (push) Successful in 13s

This commit is contained in:
2026-08-13 23:47:43 +02:00
parent 2dee3a9ae9
commit c7f90889d8
24 changed files with 764 additions and 564 deletions
@@ -7,8 +7,8 @@ using System.Windows.Shapes;
namespace PamhagenSysCtrl.Helpers.Pipeline {
public class ConveyorBelt : INode {
public const double WIDTH = 30;
public const double HEIGHT = 120;
public const double WIDTH = 6;
public const double HEIGHT = 24;
public double CenterX { get; set; }
public double CenterY { get; set; }
@@ -18,22 +18,23 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
public bool IsActive => CallbackActive();
public bool IsAnimationActive {
get => _animationActive;
get => !(_storyboard?.GetIsPaused() ?? true);
set {
_animationActive = value;
if (value) {
_storyboard?.Resume();
} else {
_storyboard?.Pause();
if (_storyboard == null) return;
if (value && _storyboard.GetIsPaused()) {
_storyboard.Resume();
} else if (!value && !_storyboard.GetIsPaused()) {
_storyboard.Pause();
}
}
}
protected Func<bool> CallbackActive;
private bool _animationActive;
private Shape? _rect;
private Rectangle? _rect;
private Polyline? _polyline;
private DoubleAnimation? _slideUp;
private Canvas? _clipCanvas;
private Storyboard? _storyboard;
public ConveyorBelt(string label, double x, double y, Func<bool> cbActive) {
@@ -47,52 +48,63 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
public void Draw(Canvas canvas) {
_rect = new Rectangle() {
Width = WIDTH,
Height = HEIGHT,
Stroke = Brushes.Black,
StrokeThickness = 2,
Fill = Brushes.WhiteSmoke,
StrokeLineJoin = PenLineJoin.Round,
};
_rect.SetValue(Canvas.LeftProperty, CenterX - WIDTH / 2);
_rect.SetValue(Canvas.TopProperty, CenterY - HEIGHT / 2);
var d = 15;
int n = (int)(HEIGHT / d) + 2;
_polyline = new Polyline() {
Points = [.. Enumerable.Range(0, n).SelectMany(i => new List<Point>() {
new(-WIDTH, i * d), new(WIDTH, i * d), new(-WIDTH, i * d)
})],
Fill = Brushes.Transparent,
Stroke = Brushes.Black,
StrokeThickness = 2,
};
_polyline.SetValue(Canvas.TopProperty, 0.0);
var slideUp = new DoubleAnimation {
_slideUp = new DoubleAnimation {
From = 0,
To = -d,
Duration = new Duration(TimeSpan.FromSeconds(1)),
RepeatBehavior = RepeatBehavior.Forever,
};
Storyboard.SetTargetProperty(_slideUp, new PropertyPath(Canvas.TopProperty));
_storyboard = new Storyboard();
_storyboard.Children.Add(slideUp);
Storyboard.SetTarget(slideUp, _polyline);
Storyboard.SetTargetProperty(slideUp, new PropertyPath(Canvas.TopProperty));
var clipCanvas = new Canvas() {
Width = WIDTH - 15,
Height = HEIGHT - 8,
_storyboard.Children.Add(_slideUp);
Storyboard.SetTarget(_slideUp, _polyline);
_clipCanvas = new Canvas() {
ClipToBounds = true,
};
clipCanvas.SetValue(Canvas.TopProperty, CenterY - HEIGHT / 2 + 4);
clipCanvas.SetValue(Canvas.LeftProperty, CenterX - WIDTH / 2 + 7.5);
clipCanvas.Children.Add(_polyline);
_clipCanvas.Children.Add(_polyline);
canvas.Children.Add(_rect);
canvas.Children.Add(clipCanvas);
canvas.Children.Add(_clipCanvas);
_storyboard.Begin();
_storyboard.Pause();
}
public void Scale(double scale) {
var border = Graph.ToBorder(scale);
_rect?.Width = WIDTH * scale;
_rect?.Height = HEIGHT * scale;
_rect?.StrokeThickness = border;
_rect?.SetValue(Canvas.LeftProperty, (CenterX - WIDTH / 2) * scale);
_rect?.SetValue(Canvas.TopProperty, (CenterY - HEIGHT / 2) * scale);
var d = Math.Round(3 * scale);
int n = (int)(HEIGHT * scale / d) + 2;
_polyline?.Points = [.. Enumerable.Range(0, n).SelectMany(i => new List<Point>() {
new(-WIDTH * scale, i * d), new(WIDTH * scale, i * d), new(-WIDTH * scale, i * d)
})];
_polyline?.StrokeThickness = border;
var active = IsAnimationActive;
_slideUp?.To = -d;
_storyboard?.Stop();
_storyboard?.Begin();
if (!active) _storyboard?.Pause();
_clipCanvas?.Width = (WIDTH - 2.2) * scale - border * 2;
_clipCanvas?.Height = (HEIGHT - 0.8) * scale - border * 2;
_clipCanvas?.SetValue(Canvas.LeftProperty, (CenterX - WIDTH / 2 + 1.1) * scale + border);
_clipCanvas?.SetValue(Canvas.TopProperty, (CenterY - HEIGHT / 2 + 0.4) * scale + border);
}
public bool IsInside(double x, double y) {
@@ -102,11 +114,11 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
public void Update(bool isHovering, bool isPressed) {
IsAnimationActive = IsActive;
_rect?.Fill =
IsAnimationActive && isHovering && isPressed ? PamhagenBrushes.Red :
IsAnimationActive && isHovering ? PamhagenBrushes.Red :
!IsAnimationActive && isHovering && isPressed ? PamhagenBrushes.Green :
!IsAnimationActive && isHovering ? PamhagenBrushes.Green :
IsAnimationActive ? PamhagenBrushes.Green :
IsActive && isHovering && isPressed ? PamhagenBrushes.Red :
IsActive && isHovering ? PamhagenBrushes.Red :
!IsActive && isHovering && isPressed ? PamhagenBrushes.Green :
!IsActive && isHovering ? PamhagenBrushes.Green :
IsActive ? PamhagenBrushes.Green :
Brushes.WhiteSmoke;
}
}