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() { x1 = y1 = x2 = y2 = 0; }
15 eRect( const ePoint &topleft, const ePoint &bottomright );
17 // we use this contructor very often... do it inline...
18 eRect( const ePoint &topleft, const eSize &size )
22 x2 = (x1+size.width());
23 y2 = (y1+size.height());
26 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;
55 ePoint center() const;
57 void rect( int *x, int *y, int *w, int *h ) const;
58 void coords( int *x1, int *y1, int *x2, int *y2 ) const;
60 void moveTopLeft( const ePoint &p );
61 void moveBottomRight( const ePoint &p );
62 void moveTopRight( const ePoint &p );
63 void moveBottomLeft( const ePoint &p );
64 void moveCenter( const ePoint &p );
66 void moveBy( int dx, int dy )
82 void setRect( int x, int y, int w, int h );
83 void setCoords( int x1, int y1, int x2, int y2 );
88 void setWidth( int w );
89 void setHeight( int h );
90 void setSize( const eSize &s );
92 eRect operator|(const eRect &r) const;
93 eRect operator&(const eRect &r) const;
94 eRect& operator|=(const eRect &r);
95 eRect& operator&=(const eRect &r);
97 bool contains( const ePoint &p) const;
98 bool contains( int x, int y) const;
99 bool contains( const eRect &r) const;
100 eRect unite( const eRect &r ) const;
101 eRect intersect( const eRect &r ) const;
102 bool intersects( const eRect &r ) const;
104 friend bool operator==( const eRect &, const eRect & );
105 friend bool operator!=( const eRect &, const eRect & );
114 bool operator==( const eRect &, const eRect & );
115 bool operator!=( const eRect &, const eRect & );
118 /*****************************************************************************
119 eRect stream functions
120 *****************************************************************************/
123 inline ostream &operator<<( ostream & s, const eRect & r )
125 s << r.left() << r.top()
126 << r.right() << r.bottom();
131 inline istream &operator>>( istream & s, eRect & r )
134 s >> x1 >> y1 >> x2 >> y2;
135 r.setCoords( x1, y1, x2, y2 );
140 /*****************************************************************************
141 eRect inline member functions
142 *****************************************************************************/
144 inline eRect::eRect( int left, int top, int width, int height )
152 inline bool eRect::isNull() const
153 { return x2 == x1 && y2 == y1; }
155 inline bool eRect::isEmpty() const
156 { return x1 >= x2 || y1 >= y2; }
158 inline bool eRect::isValid() const
159 { return x1 <= x2 && y1 <= y2; }
161 inline int eRect::left() const
164 inline int eRect::top() const
167 inline int eRect::right() const
170 inline int eRect::bottom() const
173 inline int &eRect::rLeft()
176 inline int & eRect::rTop()
179 inline int & eRect::rRight()
182 inline int & eRect::rBottom()
185 inline int eRect::x() const
188 inline int eRect::y() const
191 inline void eRect::setLeft( int pos )
194 inline void eRect::setTop( int pos )
197 inline void eRect::setRight( int pos )
200 inline void eRect::setBottom( int pos )
203 inline void eRect::setX( int x )
206 inline void eRect::setY( int y )
209 inline ePoint eRect::topLeft() const
210 { return ePoint(x1, y1); }
212 inline ePoint eRect::bottomRight() const
213 { return ePoint(x2, y2); }
215 inline ePoint eRect::topRight() const
216 { return ePoint(x2, y1); }
218 inline ePoint eRect::bottomLeft() const
219 { return ePoint(x1, y2); }
221 inline ePoint eRect::center() const
222 { return ePoint((x1+x2)/2, (y1+y2)/2); }
224 inline int eRect::width() const
227 inline int eRect::height() const
230 inline eSize eRect::size() const
231 { return eSize(x2-x1, y2-y1); }
233 inline bool eRect::contains( int x, int y) const
235 return (x >= x1) && (x < x2) && (y >= y1) && (y < y2);