93 lines
3.1 KiB
C#
93 lines
3.1 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 IsActive {
|
|
get => _active;
|
|
set {
|
|
_active = value;
|
|
_auger?.IsActive = value;
|
|
}
|
|
}
|
|
|
|
private bool _active;
|
|
private Shape? _inner;
|
|
private Shape? _outer;
|
|
private Auger? _auger;
|
|
private TextBlock? _text;
|
|
|
|
public EncasedAuger(string label, double x, double y, double angle = 0) {
|
|
CenterX = x;
|
|
CenterY = y;
|
|
Label = label;
|
|
Angle = angle;
|
|
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) {
|
|
_inner?.Fill =
|
|
IsActive && isHovering && isPressed ? PamhagenBrushes.Red :
|
|
IsActive && isHovering ? PamhagenBrushes.Red :
|
|
!IsActive && isHovering && isPressed ? PamhagenBrushes.Green :
|
|
!IsActive && isHovering ? PamhagenBrushes.Green :
|
|
IsActive ? PamhagenBrushes.Green :
|
|
Brushes.WhiteSmoke;
|
|
}
|
|
}
|
|
}
|