4 #include <lib/gdi/esize.h>
5 #include <lib/gdi/epoint.h>
8 // x2 = x1 + width (AND NOT, NEVER, NEVER EVER +1 or -1 !!!!)
10 class eRect // rectangle class
14 /* eRect() constructs an INVALID rectangle. */
15 eRect() { x1 = y1 = 0; x2 = y2 = -1; }
16 eRect( const ePoint &topleft, const ePoint &bottomright );
18 // we use this contructor very often... do it inline...
19 eRect( const ePoint &topleft, const eSize &size )
23 x2 = (x1+size.width());
24 y2 = (y1+size.height());
27 eRect( int left, int top, int width, int height );
31 eRect normalize() const;
44 void setLeft( int pos );
45 void setTop( int pos );
46 void setRight( int pos );
47 void setBottom( int pos );
51 ePoint topLeft() const;
52 ePoint bottomRight() const;
53 ePoint topRight() const;
54 ePoint bottomLeft() const;
56 /* the sole intention of these functions
57 is to allow painting frames without
58 messing around with the coordinates.
59 they point to the last pixel included
60 in the rectangle (which means that 1 is
61 subtracted from the right and bottom
63 ePoint topLeft1() const;
64 ePoint bottomRight1() const;
65 ePoint topRight1() const;
66 ePoint bottomLeft1() const;
67 ePoint center() const;
69 void rect( int *x, int *y, int *w, int *h ) const;
70 void coords( int *x1, int *y1, int *x2, int *y2 ) const;
72 void moveTopLeft( const ePoint &p );
73 void moveBottomRight( const ePoint &p );
74 void moveTopRight( const ePoint &p );
75 void moveBottomLeft( const ePoint &p );
76 void moveCenter( const ePoint &p );
78 void moveBy( int dx, int dy )
94 void setRect( int x, int y, int w, int h );
95 void setCoords( int x1, int y1, int x2, int y2 );
100 void setWidth( int w );
101 void setHeight( int h );
102 void setSize( const eSize &s );
104 eRect operator|(const eRect &r) const;
105 eRect operator&(const eRect &r) const;
106 eRect& operator|=(const eRect &r);
107 eRect& operator&=(const eRect &r);
109 bool contains( const ePoint &p) const;
110 bool contains( int x, int y) const;
111 bool contains( const eRect &r) const;
112 eRect unite( const eRect &r ) const;
113 eRect intersect( const eRect &r ) const;
114 bool intersects( const eRect &r ) const;
116 friend bool operator==( const eRect &, const eRect & );
117 friend bool operator!=( const eRect &, const eRect & );
119 static eRect emptyRect() { return eRect(0, 0, 0, 0); }
120 static eRect invalidRect() { return eRect(); }
129 bool operator==( const eRect &, const eRect & );
130 bool operator!=( const eRect &, const eRect & );
133 /*****************************************************************************
134 eRect inline member functions
135 *****************************************************************************/
137 inline eRect::eRect( int left, int top, int width, int height )
145 inline bool eRect::empty() const
146 { return x1 == x2 || y1 == y2; }
148 inline bool eRect::valid() const
149 { return x1 <= x2 && y1 <= y2; }
151 inline int eRect::left() const
154 inline int eRect::top() const
157 inline int eRect::right() const
160 inline int eRect::bottom() const
163 inline int &eRect::rLeft()
166 inline int & eRect::rTop()
169 inline int & eRect::rRight()
172 inline int & eRect::rBottom()
175 inline int eRect::x() const
178 inline int eRect::y() const
181 inline void eRect::setLeft( int pos )
184 inline void eRect::setTop( int pos )
187 inline void eRect::setRight( int pos )
190 inline void eRect::setBottom( int pos )
193 inline void eRect::setX( int x )
196 inline void eRect::setY( int y )
199 inline ePoint eRect::topLeft() const
200 { return ePoint(x1, y1); }
202 inline ePoint eRect::bottomRight() const
203 { return ePoint(x2, y2); }
205 inline ePoint eRect::topRight() const
206 { return ePoint(x2, y1); }
208 inline ePoint eRect::bottomLeft() const
209 { return ePoint(x1, y2); }
211 inline ePoint eRect::topLeft1() const
212 { return ePoint(x1, y1); }
214 inline ePoint eRect::bottomRight1() const
215 { return ePoint(x2-1, y2-1); }
217 inline ePoint eRect::topRight1() const
218 { return ePoint(x2-1, y1); }
220 inline ePoint eRect::bottomLeft1() const
221 { return ePoint(x1, y2-1); }
223 inline ePoint eRect::center() const
224 { return ePoint((x1+x2)/2, (y1+y2)/2); }
226 inline int eRect::width() const
229 inline int eRect::height() const
232 inline eSize eRect::size() const
233 { return eSize(x2-x1, y2-y1); }
235 inline bool eRect::contains( int x, int y) const
237 return (x >= x1) && (x < x2) && (y >= y1) && (y < y2);