52 lines
1.6 KiB
C#
52 lines
1.6 KiB
C#
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
using System.Windows.Shapes;
|
|
|
|
namespace PamhagenSysCtrl.Helpers.Pipeline {
|
|
public class Valve : INode {
|
|
|
|
public double CenterX { get; set; }
|
|
public double CenterY { get; set; }
|
|
public string Label { get; set; }
|
|
|
|
public bool IsOpen => CallbackIsOpen();
|
|
public bool WantOpen => CallbackWantOpen();
|
|
public ISet<IEdge> Inputs { get; init; }
|
|
public ISet<IEdge> Outputs { get; init; }
|
|
|
|
protected Func<bool> CallbackIsOpen;
|
|
protected Func<bool> CallbackWantOpen;
|
|
|
|
private Ellipse Me;
|
|
|
|
public Valve(string label, double x, double y, Func<bool> cbOpen, Func<bool> cbWant) {
|
|
CenterX = x;
|
|
CenterY = y;
|
|
Label = label;
|
|
CallbackIsOpen = cbOpen;
|
|
CallbackWantOpen = cbWant;
|
|
Inputs = new HashSet<IEdge>();
|
|
Outputs = new HashSet<IEdge>();
|
|
}
|
|
|
|
public void Draw(Canvas canvas) {
|
|
Me = new Ellipse() {
|
|
Height = 20,
|
|
Width = 20,
|
|
Fill = Brushes.Gray,
|
|
Stroke = Brushes.Black,
|
|
StrokeThickness = 2,
|
|
};
|
|
Me.SetValue(Canvas.LeftProperty, CenterX - 10);
|
|
Me.SetValue(Canvas.TopProperty, CenterY - 10);
|
|
canvas.Children.Add(Me);
|
|
}
|
|
|
|
public bool Update(double x, double y) {
|
|
var hover = Math.Sqrt(Math.Pow(CenterX - x, 2) + Math.Pow(CenterY - y, 2)) <= 10;
|
|
Me.Fill = hover ? Brushes.LightGray : Brushes.Gray;
|
|
return hover;
|
|
}
|
|
}
|
|
}
|