duheng
2024-11-14 60908c00556f4f53d82f5588ae3013f80c443590
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
namespace Yw.WinFrmUI.HydroL2d
{
    /// <summary>
    /// 连接节点
    /// </summary>
    public class Junction : Node
    {
 
        /// <summary>
        /// 宽度
        /// </summary>
        public float? Width { get; set; }
 
        /// <summary>
        /// 高度
        /// </summary>
        public float? Height { get; set; }
 
        /// <summary>
        /// 填充颜色
        /// </summary>
        public Color? FillColor { get; set; }
 
        /// <summary>
        /// 悬停宽度
        /// </summary>
        public float? HoveredWidth { get; set; }
 
        /// <summary>
        /// 悬停高度
        /// </summary>
        public float? HoveredHeight { get; set; }
 
        /// <summary>
        /// 悬停填充颜色
        /// </summary>
        public Color? HoveredFillColor { get; set; }
 
        /// <summary>
        /// 选择宽度
        /// </summary>
        public float? SelectedWidth { get; set; }
 
        /// <summary>
        /// 选择高度
        /// </summary>
        public float? SelectedHeight { get; set; }
 
        /// <summary>
        /// 选择填充颜色
        /// </summary>
        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);
        }
 
        /// <summary>
        /// 绘制
        /// </summary>
        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();
                }
            }
        }
 
        /// <summary>
        /// 包含
        /// </summary>
        public override bool Contains(PointF pt)
        {
            if (_coordinate == null)
            {
                return false;
            }
            return _coordinate.BeforeRectf.Contains(pt);
        }
 
        /// <summary>
        /// 相交
        /// </summary>
        public override bool Intersect(RectangleF rectf)
        {
            if (rectf.Contains(this.Position))
            {
                return true;
            }
            return false;
 
        }
 
 
 
    }
}