65 lines
2.1 KiB
C#
65 lines
2.1 KiB
C#
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
using System.Windows.Shapes;
|
|
|
|
namespace PamhagenSysCtrl.Helpers.Pipeline {
|
|
public class HeatExchanger : INode {
|
|
|
|
public const double WIDTH = 30;
|
|
public const double HEIGHT = 120;
|
|
|
|
public double CenterX { get; set; }
|
|
public double CenterY { get; set; }
|
|
public string Label { get; set; }
|
|
public ISet<IEdge> Inputs { get; init; }
|
|
public ISet<IEdge> Outputs { get; init; }
|
|
|
|
private Shape? _rect;
|
|
private TextBlock? _text;
|
|
|
|
public HeatExchanger(string label, double x, double y) {
|
|
CenterX = x;
|
|
CenterY = y;
|
|
Label = label;
|
|
Inputs = new HashSet<IEdge>();
|
|
Outputs = new HashSet<IEdge>();
|
|
}
|
|
|
|
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 = HEIGHT,
|
|
TextAlignment = TextAlignment.Center,
|
|
VerticalAlignment = VerticalAlignment.Center,
|
|
RenderTransform = new RotateTransform(270),
|
|
};
|
|
_rect.SetValue(Canvas.LeftProperty, CenterX - WIDTH / 2);
|
|
_rect.SetValue(Canvas.TopProperty, CenterY - HEIGHT / 2);
|
|
_text.SetValue(Canvas.LeftProperty, CenterX - 9);
|
|
_text.SetValue(Canvas.TopProperty, CenterY + HEIGHT / 2);
|
|
canvas.Children.Add(_rect);
|
|
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) {
|
|
_rect?.Fill =
|
|
isHovering && isPressed ? Brushes.DarkGray :
|
|
isHovering ? Brushes.LightGray :
|
|
Brushes.WhiteSmoke;
|
|
}
|
|
}
|
|
}
|