Add press 1 and 2
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
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; }
|
||||
|
||||
protected Func<bool> CallbackIsFull;
|
||||
|
||||
public double TopY => CenterY - DIAMETER / 2;
|
||||
public bool IsFull => CallbackIsFull();
|
||||
|
||||
public int? CapacityLiters { get; set; }
|
||||
|
||||
private Shape? _circle;
|
||||
private TextBlock? _text;
|
||||
|
||||
|
||||
public Press(string label, double x, double y, int capacityLiters, Func<bool> cbFull) {
|
||||
CenterX = x;
|
||||
CenterY = y;
|
||||
Label = label;
|
||||
CapacityLiters = capacityLiters;
|
||||
CallbackIsFull = cbFull;
|
||||
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 Update(double x, double y) {
|
||||
var hover = Math.Sqrt(Math.Pow(CenterX - x, 2) + Math.Pow(CenterY - y, 2)) <= DIAMETER / 2;
|
||||
_circle?.Fill = hover ? Brushes.LightGray : Brushes.WhiteSmoke;
|
||||
return hover;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user