-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathpm_rect.h
231 lines (192 loc) · 3.67 KB
/
pm_rect.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
/*
* File : pm_rect.h
* COPYRIGHT (C) 2012-2017, Shanghai Real-Thread Technology Co., Ltd
*
* Change Logs:
* Date Author Notes
* 2017-11-05 realthread the first version
*/
#pragma once
#include <rtgui/rtgui.h>
#include <rtgui/region.h>
namespace Persimmon
{
class Rect;
class Point
{
public:
Point()
{
xp = 0;
yp = 0;
}
Point(int xpos, int ypos);
void move(int x, int y);
inline bool isNull() const
{
return (xp == 0 && yp == 0);
}
inline int x() const
{
return xp;
}
inline int y() const
{
return yp;
}
inline void set(int x, int y)
{
xp = x;
yp = y;
}
inline void setX(int x)
{
xp = x;
}
inline void setY(int y)
{
yp = y;
}
inline Point &operator+=(const Point &p);
inline Point &operator-=(const Point &p);
friend inline const Point operator+(const Point &, const Point &);
friend inline const Point operator-(const Point &, const Point &);
struct rtgui_point getPoint(void)
{
struct rtgui_point p;
p.x = xp;
p.y = yp;
return p;
}
private:
int xp;
int yp;
};
inline Point &Point::operator+=(const Point &p)
{
xp+=p.xp;
yp+=p.yp;
return *this;
}
inline Point &Point::operator-=(const Point &p)
{
xp-=p.xp;
yp-=p.yp;
return *this;
}
inline const Point operator+(const Point &p1, const Point &p2)
{
return Point(p1.xp+p2.xp, p1.yp+p2.yp);
}
inline const Point operator-(const Point &p1, const Point &p2)
{
return Point(p1.xp-p2.xp, p1.yp-p2.yp);
}
class Size
{
public:
Size(int width, int height);
Size(const Rect &rect);
int getWidth() const
{
return width;
}
int getHeight() const
{
return height;
}
private:
rt_uint16_t width;
rt_uint16_t height;
};
class Rect
{
public:
Rect()
{
rect.x1 = rect.x2 = 0;
rect.y1 = rect.y2 = 0;
}
Rect(const struct rtgui_rect *r);
Rect(int x, int y, int width, int height);
Rect(const Point &point, const Size &size);
bool isNull () const
{
return (rtgui_rect_is_empty(&rect) == RT_TRUE);
}
void set(int x, int y, int width, int height);
int getWidth() const;
Rect* setWidth(int width);
int getHeight() const;
Rect* setHeight(int height);
Size getSize() const;
void setSize(const Size& size);
void move(int x, int y);
void move(const Point &point);
void moveto(int deltaX, int deltaY);
void moveto(const Point &deltaPoint);
int left() const;
int top() const;
int right() const;
int bottom() const;
int x() const
{
return rect.x1;
}
Rect* setX(int x)
{
rect.x1 = x;
return this;
}
int y() const
{
return rect.y1;
}
Rect* setY(int y)
{
rect.y1 = y;
return this;
}
bool contain(int x, int y);
struct rtgui_rect* getRect(void)
{
return ▭
}
void getRect(struct rtgui_rect* r)
{
if (r) *r = rect;
}
private:
struct rtgui_rect rect;
};
inline const Rect operator+(const Rect& rect,
const Point& pt)
{
Rect rt(rect);
rt.moveto(pt);
return rt;
}
inline const Rect operator-(const Rect& rect,
const Point& pt)
{
Rect rt(rect);
rt.moveto(-pt.x(), -pt.y());
return rt;
}
inline int Rect::left() const
{
return rect.x1;
}
inline int Rect::top() const
{
return rect.y1;
}
inline int Rect::right() const
{
return rect.x2;
}
inline int Rect::bottom() const
{
return rect.y2;
}
}