101 lines
3.5 KiB
C#
101 lines
3.5 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 = 80;
|
|
public const double HEIGHT = 20;
|
|
|
|
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 Shape? _inner;
|
|
private Shape? _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) {
|
|
var c = new Canvas() {
|
|
RenderTransform = new RotateTransform(Angle, WIDTH / 2, HEIGHT / 2),
|
|
};
|
|
_outer = new Rectangle() {
|
|
Width = WIDTH,
|
|
Height = HEIGHT,
|
|
Fill = Brushes.Black,
|
|
};
|
|
_inner = new Rectangle() {
|
|
Width = WIDTH,
|
|
Height = HEIGHT - 4,
|
|
Fill = Brushes.WhiteSmoke,
|
|
};
|
|
c.SetValue(Canvas.LeftProperty, CenterX - WIDTH / 2);
|
|
c.SetValue(Canvas.TopProperty, CenterY - HEIGHT / 2);
|
|
_inner.SetValue(Canvas.TopProperty, 2.0);
|
|
c.Children.Add(_outer);
|
|
c.Children.Add(_inner);
|
|
canvas.Children.Add(c);
|
|
|
|
_text = new() {
|
|
Text = Label,
|
|
Width = WIDTH,
|
|
FontSize = 12,
|
|
TextAlignment = TextAlignment.Center,
|
|
VerticalAlignment = VerticalAlignment.Center,
|
|
};
|
|
_text.SetValue(Canvas.LeftProperty, CenterX - WIDTH / 2);
|
|
_text.SetValue(Canvas.TopProperty, CenterY + HEIGHT / 2);
|
|
canvas.Children.Add(_text);
|
|
|
|
_auger = new Auger(CenterX, CenterY, WIDTH, 12, Angle);
|
|
_auger.Draw(canvas);
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|