Add path finding
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
using System.Windows.Controls;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
public class Valve : INode {
|
||||
|
||||
public const double RADIUS = 24;
|
||||
|
||||
public double CenterX { get; set; }
|
||||
public double CenterY { get; set; }
|
||||
public string Label { get; set; }
|
||||
@@ -17,7 +20,8 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
protected Func<bool> CallbackIsOpen;
|
||||
protected Func<bool> CallbackWantOpen;
|
||||
|
||||
private Ellipse Me;
|
||||
private Ellipse? _circle;
|
||||
private TextBlock? _text;
|
||||
|
||||
public Valve(string label, double x, double y, Func<bool> cbOpen, Func<bool> cbWant) {
|
||||
CenterX = x;
|
||||
@@ -30,21 +34,32 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
}
|
||||
|
||||
public void Draw(Canvas canvas) {
|
||||
Me = new Ellipse() {
|
||||
Height = 20,
|
||||
Width = 20,
|
||||
Fill = Brushes.Gray,
|
||||
_circle = new() {
|
||||
Height = RADIUS,
|
||||
Width = RADIUS,
|
||||
Fill = Brushes.DarkGray,
|
||||
Stroke = Brushes.Black,
|
||||
StrokeThickness = 2,
|
||||
};
|
||||
Me.SetValue(Canvas.LeftProperty, CenterX - 10);
|
||||
Me.SetValue(Canvas.TopProperty, CenterY - 10);
|
||||
canvas.Children.Add(Me);
|
||||
_circle.SetValue(Canvas.LeftProperty, CenterX - RADIUS / 2);
|
||||
_circle.SetValue(Canvas.TopProperty, CenterY - RADIUS / 2);
|
||||
_text = new() {
|
||||
Text = Label,
|
||||
FontSize = 10,
|
||||
Width = RADIUS,
|
||||
Height = RADIUS,
|
||||
TextAlignment = TextAlignment.Center,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
};
|
||||
_text.SetValue(Canvas.LeftProperty, CenterX - RADIUS / 2);
|
||||
_text.SetValue(Canvas.TopProperty, CenterY - RADIUS / 2 + 5);
|
||||
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)) <= 10;
|
||||
Me.Fill = hover ? Brushes.LightGray : Brushes.Gray;
|
||||
var hover = Math.Sqrt(Math.Pow(CenterX - x, 2) + Math.Pow(CenterY - y, 2)) <= RADIUS / 2;
|
||||
_circle?.Fill = hover ? Brushes.LightGray : Brushes.DarkGray;
|
||||
return hover;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user