-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFigure.h
237 lines (213 loc) · 4.27 KB
/
Figure.h
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
229
230
231
232
233
234
235
236
237
#ifndef FIGURE_H
#define FIGURE_H
#include <QWidget>
#include <vector>
#include <iostream>
using namespace std;
//多边形边类,用于扫描转换
class LineNode
{
public:
bool operator<( const LineNode& b) const
{
return x < b.x;
}
void print()
{
cout << "x=" << x << ", dx=" << dx << ", ymin=" << ymin << ", ymax=" << ymax << endl;
}
double x; //ymin对应的x坐标
double upx; //每条线ymax的顶点对应的x坐标
double dx; //y增加1时,对应的x增量
double ymin; //边端点y坐标最小值
double ymax; //边端点y坐标最大值
};
//画图的颜色、线宽
class paintstyle
{
public:
paintstyle(int r=0,int g=0,int b=0,int width=1)
:m_red(r),m_green(g),m_blue(b),m_width(width){}
paintstyle(const paintstyle& style)
{
m_red = style.m_red;
m_green = style.m_green;
m_blue = style.m_blue;
m_width = style.m_width;
}
int r() { return m_red; }
int g() { return m_green; }
int b() { return m_blue; }
int w() { return m_width; }
private:
int m_red, m_green, m_blue;
int m_width;
};
//图形类
class CFigure
{
public:
virtual void Draw(QPixmap &pixmap) {}
void setPaintStyle(paintstyle m_style)
{
style = m_style;
}
//是否开启反走样
void setAntialiasing(bool TrueorFalse)
{
antialiasing = TrueorFalse;
}
paintstyle style;
bool antialiasing = true;
};
//线类(继承CFigure)
class CLine:public CFigure
{
public:
virtual void Draw(QPixmap &pixmap);
//构造函数初始化列表
CLine(int x1,int y1,int x2,int y2):
m_x1(x1),m_y1(y1),m_x2(x2),m_y2(y2){}
//拷贝构造函数
CLine(const CLine& line)
{
this->m_x1 = line.m_x1;
this->m_x2 = line.m_x2;
this->m_y1 = line.m_y1;
this->m_y2 = line.m_y2;
}
//赋值构造函数
CLine& CLine::operator=(const CLine& line)
{
this->m_x1 = line.m_x1;
this->m_x2 = line.m_x2;
this->m_y1 = line.m_y1;
this->m_y2 = line.m_y2;
return *this;
}
private:
int m_x1;
int m_x2;
int m_y1;
int m_y2;
};
//矩形类(继承CFigure)
class CRect :public CFigure
{
public:
virtual void Draw(QPixmap &pixmap);
//构造函数初始化列表
CRect(int left, int up, int right, int down) :
m_left(left), m_up(up), m_right(right), m_down(down) {}
//拷贝构造函数
CRect(const CRect& Rect)
{
this->m_left = Rect.m_left;
this->m_up = Rect.m_up;
this->m_right = Rect.m_right;
this->m_down = Rect.m_down;
}
//赋值构造函数
CRect& CRect::operator=(const CRect& Rect)
{
this->m_left = Rect.m_left;
this->m_up = Rect.m_up;
this->m_right = Rect.m_right;
this->m_down = Rect.m_down;
return *this;
}
private:
int m_left;
int m_up;
int m_right;
int m_down;
};
//椭圆类(继承CFigure)
class CEllipse :public CFigure
{
public:
virtual void Draw(QPixmap &pixmap);
//构造函数初始化列表
CEllipse(int left, int up, int right, int down) :
m_left(left), m_up(up), m_right(right), m_down(down) {}
//拷贝构造函数
CEllipse(const CEllipse& Ellipse)
{
this->m_left = Ellipse.m_left;
this->m_up = Ellipse.m_up;
this->m_right = Ellipse.m_right;
this->m_down = Ellipse.m_down;
}
//赋值构造函数
CEllipse& CEllipse::operator=(const CEllipse& Ellipse)
{
this->m_left = Ellipse.m_left;
this->m_up = Ellipse.m_up;
this->m_right = Ellipse.m_right;
this->m_down = Ellipse.m_down;
return *this;
}
private:
int m_left;
int m_up;
int m_right;
int m_down;
};
class CPolygon :public CFigure
{
public:
CPolygon() {}
bool isclosed = false;
CPolygon(vector<QPoint> vertex) :m_vertex(vertex){}
virtual void Draw(QPixmap &pixmap);
CPolygon(const CPolygon& polygon)
{
m_vertex = polygon.m_vertex;
}
CPolygon& operator=(const CPolygon& polygon)
{
m_vertex = polygon.m_vertex;
return *this;
}
void addVertex(const QPoint& vertex)
{
m_vertex.push_back(vertex);
}
void addVertex(int x,int y)
{
QPoint vertex(x, y);
m_vertex.push_back(vertex);
}
private:
vector<QPoint> m_vertex;
};
//class CFreehand:public CFigure
//{
//public:
// virtual void Draw(QPixmap &pixmap);
// CFreehand(vector<QPoint> vertex) :m_vertex(vertex) {}
// CFreehand(const CFreehand& freehand)
// {
// m_vertex = freehand.m_vertex;
// }
// CFreehand& operator=(const CFreehand& freehand)
// {
// m_vertex = freehand.m_vertex;
// return *this;
// }
//
// void addVertex(const QPoint& vertex)
// {
// m_vertex.push_back(vertex);
// }
// void addVertex(int x, int y)
// {
// QPoint vertex(x, y);
// m_vertex.push_back(vertex);
// }
//
//private:
// vector<QPoint> m_vertex;
//
//};
#endif // ! FIGURE_H