using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Shapes; namespace PamhagenSysCtrl.Helpers.Pipeline { public class Trough : INode, ISource { public const double WIDTH = 100; public const double HEIGHT = 60; public double CenterX { get; set; } public double CenterY { get; set; } public double BottomY => CenterY + HEIGHT / 2; public string Label { get; set; } public bool IsFilled => CallbackIsFilled(); public ISet Inputs { get; init; } public ISet Outputs { get; init; } protected Func CallbackIsFilled; private Shape? _rect; private TextBlock? _text; public Trough(string label, double x, double y, Func cbFilled) { CenterX = x; CenterY = y; Label = label; CallbackIsFilled = cbFilled; Inputs = new HashSet(); Outputs = new HashSet(); } public void Draw(Canvas canvas) { _rect = new Rectangle() { Width = WIDTH, Height = HEIGHT, Stroke = Brushes.Black, StrokeThickness = 2, Fill = Brushes.WhiteSmoke, }; _text = new() { Text = Label, FontSize = 12, Width = WIDTH, TextAlignment = TextAlignment.Center, VerticalAlignment = VerticalAlignment.Center, }; _rect.SetValue(Canvas.LeftProperty, CenterX - WIDTH / 2); _rect.SetValue(Canvas.TopProperty, CenterY - HEIGHT / 2); _text.SetValue(Canvas.LeftProperty, CenterX - WIDTH / 2); _text.SetValue(Canvas.TopProperty, CenterY - 8); canvas.Children.Add(_rect); canvas.Children.Add(_text); } public bool Update(double x, double y, bool down) { var hover = Math.Abs(x - CenterX) <= WIDTH / 2 && Math.Abs(y - CenterY) <= HEIGHT / 2; _rect?.Fill = hover ? Brushes.LightGray : Brushes.WhiteSmoke; return hover; } } }