82 lines
3.0 KiB
C#
82 lines
3.0 KiB
C#
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 = 20;
|
|
public const double HEIGHT = 12;
|
|
|
|
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<IEdge> Inputs { get; init; }
|
|
public ISet<IEdge> Outputs { get; init; }
|
|
|
|
protected Func<FillState> CallbackFillState;
|
|
|
|
private Shape? _inner;
|
|
private Shape? _outer;
|
|
private TextBlock? _text;
|
|
|
|
public Trough(string label, double x, double y, Func<FillState> cbFillState) {
|
|
CenterX = x;
|
|
CenterY = y;
|
|
Label = label;
|
|
CallbackFillState = cbFillState;
|
|
Inputs = new HashSet<IEdge>();
|
|
Outputs = new HashSet<IEdge>();
|
|
}
|
|
|
|
public void Draw(Canvas canvas) {
|
|
_outer = new Rectangle() {
|
|
Fill = Brushes.Black,
|
|
};
|
|
_inner = new Rectangle() {
|
|
Fill = Brushes.WhiteSmoke,
|
|
};
|
|
_text = new() {
|
|
Text = Label,
|
|
TextAlignment = TextAlignment.Center,
|
|
VerticalAlignment = VerticalAlignment.Center,
|
|
};
|
|
canvas.Children.Add(_outer);
|
|
canvas.Children.Add(_inner);
|
|
canvas.Children.Add(_text);
|
|
}
|
|
|
|
public void Scale(double scale) {
|
|
var border = Graph.ToBorder(scale);
|
|
_outer?.Width = WIDTH * scale;
|
|
_outer?.Height = HEIGHT * scale;
|
|
_inner?.Width = WIDTH * scale - border * 2;
|
|
_inner?.Height = HEIGHT * scale - border;
|
|
_text?.Width = WIDTH * scale;
|
|
_text?.FontSize = 14;
|
|
_outer?.SetValue(Canvas.LeftProperty, (CenterX - WIDTH / 2) * scale);
|
|
_outer?.SetValue(Canvas.TopProperty, (CenterY - HEIGHT / 2) * scale);
|
|
_inner?.SetValue(Canvas.LeftProperty, (CenterX - WIDTH / 2) * scale + border);
|
|
_inner?.SetValue(Canvas.TopProperty, (CenterY - HEIGHT / 2) * scale);
|
|
_text?.SetValue(Canvas.LeftProperty, (CenterX - WIDTH / 2) * scale);
|
|
_text?.SetValue(Canvas.TopProperty, (CenterY * scale) - 10);
|
|
}
|
|
|
|
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
|
|
);
|
|
}
|
|
}
|
|
}
|