76 lines
2.6 KiB
C#
76 lines
2.6 KiB
C#
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
using System.Windows.Shapes;
|
|
|
|
namespace PamhagenSysCtrl.Helpers.Pipeline {
|
|
public class Press : INode, ISink {
|
|
|
|
public const double DIAMETER = 120;
|
|
|
|
public double CenterX { get; set; }
|
|
public double CenterY { get; set; }
|
|
public string Label { get; set; }
|
|
|
|
public ISet<IEdge> Inputs { get; set; }
|
|
public ISet<IEdge> Outputs { get; set; }
|
|
|
|
public double TopY => CenterY - DIAMETER / 2;
|
|
public FillState FillState => CallbackFillState();
|
|
public bool IsFull => FillState == FillState.Full;
|
|
|
|
public int? CapacityLiters { get; set; }
|
|
|
|
protected Func<FillState> CallbackFillState;
|
|
|
|
private Shape? _circle;
|
|
private TextBlock? _text;
|
|
|
|
|
|
public Press(string label, double x, double y, int capacityLiters, Func<FillState> cbFillState) {
|
|
CenterX = x;
|
|
CenterY = y;
|
|
Label = label;
|
|
CapacityLiters = capacityLiters;
|
|
CallbackFillState = cbFillState;
|
|
Inputs = new HashSet<IEdge>();
|
|
Outputs = new HashSet<IEdge>();
|
|
}
|
|
|
|
public void Draw(Canvas canvas) {
|
|
_circle = new Ellipse() {
|
|
Width = DIAMETER,
|
|
Height = DIAMETER,
|
|
Stroke = Brushes.Black,
|
|
StrokeThickness = 2,
|
|
Fill = Brushes.WhiteSmoke,
|
|
};
|
|
_text = new() {
|
|
Text = CapacityLiters.HasValue ? $"{Label}\n{CapacityLiters:N0}" : Label,
|
|
FontSize = 14,
|
|
Width = DIAMETER,
|
|
TextAlignment = TextAlignment.Center,
|
|
VerticalAlignment = VerticalAlignment.Center,
|
|
};
|
|
_circle.SetValue(Canvas.LeftProperty, CenterX - DIAMETER / 2);
|
|
_circle.SetValue(Canvas.TopProperty, CenterY - DIAMETER / 2);
|
|
_text.SetValue(Canvas.LeftProperty, CenterX - DIAMETER / 2);
|
|
_text.SetValue(Canvas.TopProperty, CenterY - (CapacityLiters.HasValue ? 20 : 10));
|
|
canvas.Children.Add(_circle);
|
|
canvas.Children.Add(_text);
|
|
}
|
|
|
|
public bool IsInside(double x, double y) {
|
|
return Math.Sqrt(Math.Pow(CenterX - x, 2) + Math.Pow(CenterY - y, 2)) <= DIAMETER / 2;
|
|
}
|
|
|
|
public void Update(bool isHovering, bool isPressed) {
|
|
_circle?.Fill = PamhagenBrushes.ForFillState(FillState,
|
|
isHovering && isPressed ? Brushes.DarkGray :
|
|
isHovering ? Brushes.LightGray :
|
|
Brushes.WhiteSmoke
|
|
);
|
|
}
|
|
}
|
|
}
|