namespace Yw.WinFrmUI.HydroL2d { /// /// 连接节点 /// public class Junction : Node { /// /// 宽度 /// public float? Width { get; set; } /// /// 高度 /// public float? Height { get; set; } /// /// 填充颜色 /// public Color? FillColor { get; set; } /// /// 悬停宽度 /// public float? HoveredWidth { get; set; } /// /// 悬停高度 /// public float? HoveredHeight { get; set; } /// /// 悬停填充颜色 /// public Color? HoveredFillColor { get; set; } /// /// 选择宽度 /// public float? SelectedWidth { get; set; } /// /// 选择高度 /// public float? SelectedHeight { get; set; } /// /// 选择填充颜色 /// public Color? SelectedFillColor { get; set; } private Coordinate _coordinate { get; set; }//坐标信息 //获取坐标位置 private Coordinate GetCoordinate(Graphics g) { var ps = this.Position;//原始点 var ws = this.Width.HasValue ? this.Width.Value : CacheHelper.HydroL2d.Junction.Size.Width;//原始宽度 var hs = this.Height.HasValue ? this.Height.Value : CacheHelper.HydroL2d.Junction.Size.Height;//原始高度 var wz = ws / g.PageScale; //缩放宽度 var hz = hs / g.PageScale;//缩放高度 return Coordinate.GetCoordinate(ps, 0, new SizeF(wz, hz), StringAlignment.Center, StringAlignment.Center); } /// /// 绘制 /// public override void Draw(Graphics g) { _coordinate = GetCoordinate(g); if (this.Hovered) { var fromCacheBrush = true; var brush = CacheHelper.JunctionHoveredFillBrush; if (this.HoveredFillColor.HasValue) { brush = new SolidBrush(this.HoveredFillColor.Value); fromCacheBrush = false; } var width = this.HoveredWidth.HasValue ? this.HoveredWidth.Value : CacheHelper.HydroL2d.Junction.HoveredSize.Width; var height = this.HoveredHeight.HasValue ? this.HoveredHeight.Value : CacheHelper.HydroL2d.Junction.HoveredSize.Height; var x = this.Position.X - width / g.PageScale / 2f; var y = this.Position.Y - height / g.PageScale / 2f; var rect = new RectangleF(x, y, width / g.PageScale, height / g.PageScale); g.FillEllipse(brush, rect); if (!fromCacheBrush) { brush.Dispose(); } } else if (this.Selected) { var fromCacheBrush = true; var brush = CacheHelper.JunctionSelectedFillBrush; if (this.SelectedFillColor.HasValue) { brush = new SolidBrush(this.SelectedFillColor.Value); fromCacheBrush = false; } var width = this.SelectedWidth.HasValue ? this.SelectedWidth.Value : CacheHelper.HydroL2d.Junction.SelectedSize.Width; var height = this.SelectedHeight.HasValue ? this.SelectedHeight.Value : CacheHelper.HydroL2d.Junction.SelectedSize.Height; var x = this.Position.X - width / g.PageScale / 2f; var y = this.Position.Y - height / g.PageScale / 2f; var rect = new RectangleF(x, y, width / g.PageScale, height / g.PageScale); g.FillEllipse(brush, rect); if (!fromCacheBrush) { brush.Dispose(); } } else { var fromCacheBrush = true; var brush = CacheHelper.JunctionFillBrush; if (this.FillColor.HasValue) { brush = new SolidBrush(this.FillColor.Value); fromCacheBrush = false; } var width = this.Width.HasValue ? this.Width.Value : CacheHelper.HydroL2d.Junction.Size.Width; var height = this.Height.HasValue ? this.Height.Value : CacheHelper.HydroL2d.Junction.Size.Height; var x = this.Position.X - width / g.PageScale / 2f; var y = this.Position.Y - height / g.PageScale / 2f; var rect = new RectangleF(x, y, width / g.PageScale, height / g.PageScale); g.FillEllipse(brush, rect); if (!fromCacheBrush) { brush.Dispose(); } } } /// /// 包含 /// public override bool Contains(PointF pt) { if (_coordinate == null) { return false; } return _coordinate.BeforeRectf.Contains(pt); } /// /// 相交 /// public override bool Intersect(RectangleF rectf) { if (rectf.Contains(this.Position)) { return true; } return false; } } }