Files
pamhagen-sysctrl/PamhagenSysCtrl/Helpers/Pipeline/EncasedAuger.cs
T
lorenz.stechauner 36c1ced254
Test / Run tests (push) Successful in 16s
[WIP] Scaling
2026-08-13 18:15:58 +02:00

110 lines
3.9 KiB
C#

using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
namespace PamhagenSysCtrl.Helpers.Pipeline {
public class EncasedAuger : INode {
public const double WIDTH = 16;
public const double HEIGHT = 4;
public double CenterX { get; set; }
public double CenterY { get; set; }
public double Angle { get; set; }
public string Label { get; set; }
public ISet<IEdge> Inputs { get; init; }
public ISet<IEdge> Outputs { get; init; }
public bool IsClickable { get; private set; }
public bool IsActive => CallbackActive();
public bool IsAnimationActive {
get => _animationActive;
set {
_animationActive = value;
_auger?.IsAnimationActive = value;
}
}
protected Func<bool> CallbackActive;
private bool _animationActive;
private Canvas? _canvas;
private Rectangle? _inner;
private Rectangle? _outer;
private Auger? _auger;
private TextBlock? _text;
public EncasedAuger(string label, double x, double y, Func<bool> cbActive, double angle = 0, bool clickable = true) {
CenterX = x;
CenterY = y;
Label = label;
Angle = angle;
CallbackActive = cbActive;
IsClickable = clickable;
Inputs = new HashSet<IEdge>();
Outputs = new HashSet<IEdge>();
}
public void Draw(Canvas canvas) {
_canvas = new Canvas() {
RenderTransform = new RotateTransform(Angle),
};
_outer = new Rectangle() {
Fill = Brushes.Black,
};
_inner = new Rectangle() {
Fill = Brushes.WhiteSmoke,
};
_canvas.Children.Add(_outer);
_canvas.Children.Add(_inner);
canvas.Children.Add(_canvas);
_text = new() {
Text = Label,
TextAlignment = TextAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
};
canvas.Children.Add(_text);
_auger = new Auger(CenterX, CenterY, WIDTH, 2.4, Angle);
_auger.Draw(canvas);
}
public void Scale(double scale) {
var border = Graph.ToBorder(scale);
_canvas?.SetValue(Canvas.LeftProperty, (CenterX - WIDTH / 2) * scale);
_canvas?.SetValue(Canvas.TopProperty, (CenterY - HEIGHT / 2) * scale);
_canvas?.RenderTransform = new RotateTransform(Angle, WIDTH / 2 * scale, HEIGHT / 2 * scale);
_outer?.Width = WIDTH * scale;
_outer?.Height = HEIGHT * scale;
_inner?.Width = WIDTH * scale;
_inner?.Height = HEIGHT * scale - border * 2;
_inner?.SetValue(Canvas.TopProperty, border);
_text?.FontSize = 12;
_text?.Width = WIDTH * scale;
_text?.SetValue(Canvas.LeftProperty, (CenterX - WIDTH / 2) * scale);
_text?.SetValue(Canvas.TopProperty, (CenterY + HEIGHT / 2) * scale);
_auger?.Scale(scale);
}
public bool IsInside(double x, double y) {
return Math.Sqrt(Math.Pow(CenterX - x, 2) + Math.Pow(CenterY - y, 2)) <= WIDTH / 2;
}
public void Update(bool isHovering, bool isPressed) {
isHovering = isHovering && IsClickable;
IsAnimationActive = IsActive;
_inner?.Fill =
IsAnimationActive && isHovering && isPressed ? PamhagenBrushes.Red :
IsAnimationActive && isHovering ? PamhagenBrushes.Red :
!IsAnimationActive && isHovering && isPressed ? PamhagenBrushes.Green :
!IsAnimationActive && isHovering ? PamhagenBrushes.Green :
IsAnimationActive ? PamhagenBrushes.Green :
Brushes.WhiteSmoke;
}
}
}