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
238
239
240
241
242
|
#ifndef ERECT_H
#define ERECT_H
#include <lib/gdi/esize.h>
#include <lib/gdi/epoint.h>
// x2 = x1 + width (AND NOT, NEVER, NEVER EVER +1 or -1 !!!!)
class eRect // rectangle class
{
friend class gRegion;
public:
/* eRect() constructs an INVALID rectangle. */
eRect() { x1 = y1 = 0; x2 = y2 = -1; }
eRect( const ePoint &topleft, const ePoint &bottomright );
// we use this contructor very often... do it inline...
eRect( const ePoint &topleft, const eSize &size )
{
x1 = topleft.x();
y1 = topleft.y();
x2 = (x1+size.width());
y2 = (y1+size.height());
}
eRect( int left, int top, int width, int height );
bool empty() const;
bool valid() const;
eRect normalize() const;
int left() const;
int top() const;
int right() const;
int bottom() const;
int &rLeft();
int &rTop();
int &rRight();
int &rBottom();
int x() const;
int y() const;
void setLeft( int pos );
void setTop( int pos );
void setRight( int pos );
void setBottom( int pos );
void setX( int x );
void setY( int y );
ePoint topLeft() const;
ePoint bottomRight() const;
ePoint topRight() const;
ePoint bottomLeft() const;
/* the sole intention of these functions
is to allow painting frames without
messing around with the coordinates.
they point to the last pixel included
in the rectangle (which means that 1 is
subtracted from the right and bottom
coordinates */
ePoint topLeft1() const;
ePoint bottomRight1() const;
ePoint topRight1() const;
ePoint bottomLeft1() const;
ePoint center() const;
void rect( int *x, int *y, int *w, int *h ) const;
void coords( int *x1, int *y1, int *x2, int *y2 ) const;
void moveTopLeft( const ePoint &p );
void moveBottomRight( const ePoint &p );
void moveTopRight( const ePoint &p );
void moveBottomLeft( const ePoint &p );
void moveCenter( const ePoint &p );
void moveBy( int dx, int dy )
{
x1 += dx;
y1 += dy;
x2 += dx;
y2 += dy;
}
void moveBy(ePoint r)
{
x1 += r.x();
y1 += r.y();
x2 += r.x();
y2 += r.y();
}
void setRect( int x, int y, int w, int h );
void setCoords( int x1, int y1, int x2, int y2 );
eSize size() const;
int width() const;
int height() const;
void setWidth( int w );
void setHeight( int h );
void setSize( const eSize &s );
eRect operator|(const eRect &r) const;
eRect operator&(const eRect &r) const;
eRect& operator|=(const eRect &r);
eRect& operator&=(const eRect &r);
bool contains( const ePoint &p) const;
bool contains( int x, int y) const;
bool contains( const eRect &r) const;
eRect unite( const eRect &r ) const;
eRect intersect( const eRect &r ) const;
bool intersects( const eRect &r ) const;
friend bool operator==( const eRect &, const eRect & );
friend bool operator!=( const eRect &, const eRect & );
static eRect emptyRect() { return eRect(0, 0, 0, 0); }
static eRect invalidRect() { return eRect(); }
void scale(int x_n, int x_d, int y_n, int y_d);
private:
int x1;
int y1;
int x2;
int y2;
};
bool operator==( const eRect &, const eRect & );
bool operator!=( const eRect &, const eRect & );
/*****************************************************************************
eRect inline member functions
*****************************************************************************/
inline eRect::eRect( int left, int top, int width, int height )
{
x1 = left;
y1 = top;
x2 = left+width;
y2 = top+height;
}
inline bool eRect::empty() const
{ return x1 >= x2 || y1 >= y2; }
inline bool eRect::valid() const
{ return x1 <= x2 && y1 <= y2; }
inline int eRect::left() const
{ return x1; }
inline int eRect::top() const
{ return y1; }
inline int eRect::right() const
{ return x2; }
inline int eRect::bottom() const
{ return y2; }
inline int &eRect::rLeft()
{ return x1; }
inline int & eRect::rTop()
{ return y1; }
inline int & eRect::rRight()
{ return x2; }
inline int & eRect::rBottom()
{ return y2; }
inline int eRect::x() const
{ return x1; }
inline int eRect::y() const
{ return y1; }
inline void eRect::setLeft( int pos )
{ x1 = pos; }
inline void eRect::setTop( int pos )
{ y1 = pos; }
inline void eRect::setRight( int pos )
{ x2 = pos; }
inline void eRect::setBottom( int pos )
{ y2 = pos; }
inline void eRect::setX( int x )
{ x1 = x; }
inline void eRect::setY( int y )
{ y1 = y; }
inline ePoint eRect::topLeft() const
{ return ePoint(x1, y1); }
inline ePoint eRect::bottomRight() const
{ return ePoint(x2, y2); }
inline ePoint eRect::topRight() const
{ return ePoint(x2, y1); }
inline ePoint eRect::bottomLeft() const
{ return ePoint(x1, y2); }
inline ePoint eRect::topLeft1() const
{ return ePoint(x1, y1); }
inline ePoint eRect::bottomRight1() const
{ return ePoint(x2-1, y2-1); }
inline ePoint eRect::topRight1() const
{ return ePoint(x2-1, y1); }
inline ePoint eRect::bottomLeft1() const
{ return ePoint(x1, y2-1); }
inline ePoint eRect::center() const
{ return ePoint((x1+x2)/2, (y1+y2)/2); }
inline int eRect::width() const
{ return x2 - x1; }
inline int eRect::height() const
{ return y2 - y1; }
inline eSize eRect::size() const
{ return eSize(x2-x1, y2-y1); }
inline bool eRect::contains( int x, int y) const
{
return (x >= x1) && (x < x2) && (y >= y1) && (y < y2);
}
#endif // eRect_H
|