Add Rebler
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
using System.Reflection;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
public class Rebler : INode {
|
||||
|
||||
public const double WIDTH = 120;
|
||||
public const double HEIGHT = 60;
|
||||
|
||||
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 TextBlock? _text;
|
||||
private Shape? _rect;
|
||||
private Shape? _hopperOuter;
|
||||
private Shape? _hopperInner;
|
||||
private Shape? _bottomInner;
|
||||
private Shape? _bottomOuter;
|
||||
|
||||
public Rebler(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,
|
||||
Fill = Brushes.WhiteSmoke,
|
||||
Stroke = Brushes.Black,
|
||||
StrokeThickness = 2,
|
||||
};
|
||||
var hx = CenterX + WIDTH / 2 - 10;
|
||||
var top = CenterY - HEIGHT / 2;
|
||||
var h = 15;
|
||||
var w = 25;
|
||||
_hopperOuter = new Polygon() {
|
||||
Points = [new(hx - w, top - h), new(hx, top + 30), new(hx + w, top - h)],
|
||||
Fill = Brushes.Black,
|
||||
};
|
||||
_hopperInner = new Polygon() {
|
||||
Points = [new(hx - w + 2, top - h), new(hx, top + 26), new(hx + w - 2, top - h)],
|
||||
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(_hopperOuter);
|
||||
canvas.Children.Add(_rect);
|
||||
canvas.Children.Add(_hopperInner);
|
||||
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 ? Brushes.LightGray : Brushes.WhiteSmoke;
|
||||
_hopperInner?.Fill = isHovering ? Brushes.LightGray : Brushes.WhiteSmoke;
|
||||
_bottomInner?.Fill = isHovering ? Brushes.LightGray : Brushes.WhiteSmoke;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user