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 FillState FillState => CallbackFillState(); public bool IsFilled => FillState != FillState.Empty; public ISet Inputs { get; init; } public ISet Outputs { get; init; } protected Func CallbackFillState; private Shape? _inner; private Shape? _outer; private TextBlock? _text; public Trough(string label, double x, double y, Func cbFillState) { CenterX = x; CenterY = y; Label = label; CallbackFillState = cbFillState; Inputs = new HashSet(); Outputs = new HashSet(); } public void Draw(Canvas canvas) { _outer = new Rectangle() { Width = WIDTH, Height = HEIGHT, Fill = Brushes.Black, }; _inner = new Rectangle() { Width = WIDTH - 4, Height = HEIGHT - 2, Fill = Brushes.WhiteSmoke, }; _text = new() { Text = Label, FontSize = 14, Width = WIDTH, TextAlignment = TextAlignment.Center, VerticalAlignment = VerticalAlignment.Center, }; _outer.SetValue(Canvas.LeftProperty, CenterX - WIDTH / 2); _outer.SetValue(Canvas.TopProperty, CenterY - HEIGHT / 2); _inner.SetValue(Canvas.LeftProperty, CenterX - WIDTH / 2 + 2); _inner.SetValue(Canvas.TopProperty, CenterY - HEIGHT / 2); _text.SetValue(Canvas.LeftProperty, CenterX - WIDTH / 2); _text.SetValue(Canvas.TopProperty, CenterY - 10); canvas.Children.Add(_outer); canvas.Children.Add(_inner); canvas.Children.Add(_text); } public bool IsInside(double x, double y) { return Math.Abs(x - CenterX) <= WIDTH / 2 && Math.Abs(y - CenterY) <= HEIGHT / 2; } public void Update(bool isHovering, bool isPressed) { _inner?.Fill = PamhagenBrushes.ForFillState(FillState, isHovering && isPressed ? Brushes.DarkGray : isHovering ? Brushes.LightGray : Brushes.WhiteSmoke ); } } }