PlanarChart.cs
5.8 KB
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace zhouchen.chart.chart
{
// 平面图类
public class PlanarChart : ChartBase
{
#region 外接矩形参数
protected int _x;
public int x
{
get { return _x; }
set
{
_x = value;
NotifyPropertyChanged(nameof(x));
}
}
private int _y;
public int y
{
get { return _y; }
set
{
_y = value;
NotifyPropertyChanged(nameof(y));
}
}
private int _width;
public int width
{
get { return _width; }
set
{
_width = value;
NotifyPropertyChanged(nameof(width));
}
}
private int _height;
public int height
{
get { return _height; }
set
{
_height = value;
NotifyPropertyChanged(nameof(height));
}
}
public int left => _x;
public int top => _y;
public int right => _x + _width;
public int bottom => _y + _height;
// 外接矩形
public Rectangle rcCircumscribed => new Rectangle(_x, _y, _width, _height);
public enum CORR_PT
{
PT_UNKNOW = -1,
PT_BEGIN = 0,
PT_LT = PT_BEGIN, PT_MT, PT_RT,
PT_LM, PT_MM, PT_RM,
PT_LB, PT_MB, PT_RB,
PT_END, PT_CNT = PT_END
}
public Point[] ptCorrs = new Point[(int)CORR_PT.PT_CNT];
#endregion
// 是否填充颜色
protected bool _IsFillColor = false;
public bool IsFillColor
{
get { return _IsFillColor; }
set
{
_IsFillColor = value;
NotifyPropertyChanged("IsFillColor");
}
}
// 填充颜色
protected Color _FillColor = Color.FromArgb(255, 255, 0, 255);
public Color FillColor
{
get { return _FillColor; }
set
{
_FillColor = value;
NotifyPropertyChanged("FillColor");
}
}
public PlanarChart()
{
_x = 0;
_y = 0;
_width = 0;
_height = 0;
this.ReCountPt();
}
public PlanarChart(Point ptStart, Point ptEnd)
{
_x = Math.Min(ptStart.X, ptEnd.X);
_y = Math.Min(ptStart.Y, ptEnd.Y);
_width = Math.Abs(ptStart.X - ptEnd.X);
_height = Math.Abs(ptStart.Y - ptEnd.Y);
this.ReCountPt();
}
public PlanarChart(Point ptlocation, Size size)
{
_x = ptlocation.X;
_y = ptlocation.Y;
_width = size.Width;
_height = size.Height;
this.ReCountPt();
}
public PlanarChart(int x, int y, int width, int height)
{
_x = x;
_y = y;
_width = width;
_height = height;
this.ReCountPt();
}
// 计算每个点的坐标
public void ReCountPt()
{
// 左上
ptCorrs[(int)CORR_PT.PT_LT].X = left;
ptCorrs[(int)CORR_PT.PT_LT].Y = top;
// 右下
ptCorrs[(int)CORR_PT.PT_RB].X = right;
ptCorrs[(int)CORR_PT.PT_RB].Y = bottom;
// 右上
ptCorrs[(int)CORR_PT.PT_RT].X = right;
ptCorrs[(int)CORR_PT.PT_RT].Y = top;
// 左下
ptCorrs[(int)CORR_PT.PT_LB].X = left;
ptCorrs[(int)CORR_PT.PT_LB].Y = bottom;
// 中上
ptCorrs[(int)CORR_PT.PT_MT].X = left + _width / 2;
ptCorrs[(int)CORR_PT.PT_MT].Y = top;
// 左中
ptCorrs[(int)CORR_PT.PT_LM].X = left;
ptCorrs[(int)CORR_PT.PT_LM].Y = top + _height / 2;
// 中中
ptCorrs[(int)CORR_PT.PT_MM].X = left + _width / 2;
ptCorrs[(int)CORR_PT.PT_MM].Y = top + _height / 2;
// 右中
ptCorrs[(int)CORR_PT.PT_RM].X = right;
ptCorrs[(int)CORR_PT.PT_RM].Y = top + _height / 2;
// 中下
ptCorrs[(int)CORR_PT.PT_MB].X = left + _width / 2;
ptCorrs[(int)CORR_PT.PT_MB].Y = bottom;
}
public override void DrawChart(Graphics graph, Matrix matrix)
{
if(!IsSelect)
{
return;
}
Point[] pts = (Point[])ptCorrs.Clone();
matrix.TransformPoints(pts);
Pen pen_select_line = new Pen(COLOR_SELECT_LINE, 1);
Brush brush_select_fill = new SolidBrush(COLOR_SELECT_FILL);
graph.DrawPolygon(pen_select_line, new Point[]
{
pts[(int)CORR_PT.PT_LT],
pts[(int)CORR_PT.PT_RT],
pts[(int)CORR_PT.PT_RB],
pts[(int)CORR_PT.PT_LB]
});
Rectangle[] rcpt = new Rectangle[pts.Length];
int nIndex = 0;
foreach (Point pt in pts)
{
rcpt[nIndex++] = new Rectangle(pt.X - SPACE_HALF, pt.Y - SPACE_HALF, SPACE_FULL, SPACE_FULL);
}
nIndex = -1;
foreach (Rectangle rc in rcpt)
{
nIndex++;
if (4 == nIndex)
{
continue;
}
graph.FillEllipse(brush_select_fill, rc);
graph.DrawEllipse(pen_select_line, rc);
}
}
}
}