53 lines
1.7 KiB
C#
53 lines
1.7 KiB
C#
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
using System.Windows.Shapes;
|
|
|
|
namespace PamhagenSysCtrl.Helpers.Pipeline {
|
|
class Tank : INode, ISink, ISource {
|
|
|
|
public const double WIDTH = 60;
|
|
public const double HEIGHT = 100;
|
|
|
|
public double CenterX { get; set; }
|
|
public double CenterY { get; set; }
|
|
public double TopY => CenterY - HEIGHT / 2;
|
|
public string Label { get; set; }
|
|
public bool IsFull => CallbackIsFull();
|
|
public bool IsFilled => CallbackIsFilled();
|
|
|
|
public ISet<IEdge> Inputs { get; init; }
|
|
public ISet<IEdge> Outputs { get; init; }
|
|
|
|
protected Func<bool> CallbackIsFilled;
|
|
protected Func<bool> CallbackIsFull;
|
|
|
|
public Tank(string label, double x, double y, Func<bool> cbFilled, Func<bool> cbFull) {
|
|
CenterX = x;
|
|
CenterY = y;
|
|
Label = label;
|
|
CallbackIsFilled = cbFilled;
|
|
CallbackIsFull = cbFull;
|
|
Inputs = new HashSet<IEdge>();
|
|
Outputs = new HashSet<IEdge>();
|
|
}
|
|
|
|
public void Draw(Canvas canvas) {
|
|
var rect = new Rectangle() {
|
|
Width = WIDTH,
|
|
Height = HEIGHT,
|
|
Stroke = Brushes.Black,
|
|
StrokeThickness = 2,
|
|
Fill = Brushes.White,
|
|
};
|
|
rect.SetValue(Canvas.LeftProperty, CenterX - WIDTH / 2);
|
|
rect.SetValue(Canvas.TopProperty, CenterY - HEIGHT / 2);
|
|
canvas.Children.Add(rect);
|
|
}
|
|
|
|
public bool Update(double x, double y) {
|
|
var hover = Math.Abs(x - CenterX) <= WIDTH / 2 && Math.Abs(y - CenterY) <= HEIGHT / 2;
|
|
return hover;
|
|
}
|
|
}
|
|
}
|