4 #include <lib/base/esize.h>
5 #include <lib/base/epoint.h>
8 // x2 = x1 + width (AND NOT, NEVER, NEVER EVER +1 or -1 !!!!)
10 class eRect
// rectangle class
13 eRect() { x1
= y1
= x2
= y2
= 0; }
14 eRect( const ePoint
&topleft
, const ePoint
&bottomright
);
16 // we use this contructor very often... do it inline...
17 eRect( const ePoint
&topleft
, const eSize
&size
)
21 x2
= (x1
+size
.width());
22 y2
= (y1
+size
.height());
25 eRect( int left
, int top
, int width
, int height
);
30 eRect
normalize() const;
43 void setLeft( int pos
);
44 void setTop( int pos
);
45 void setRight( int pos
);
46 void setBottom( int pos
);
50 ePoint
topLeft() const;
51 ePoint
bottomRight() const;
52 ePoint
topRight() const;
53 ePoint
bottomLeft() const;
54 ePoint
center() const;
56 void rect( int *x
, int *y
, int *w
, int *h
) const;
57 void coords( int *x1
, int *y1
, int *x2
, int *y2
) const;
59 void moveTopLeft( const ePoint
&p
);
60 void moveBottomRight( const ePoint
&p
);
61 void moveTopRight( const ePoint
&p
);
62 void moveBottomLeft( const ePoint
&p
);
63 void moveCenter( const ePoint
&p
);
65 void moveBy( int dx
, int dy
)
73 void setRect( int x
, int y
, int w
, int h
);
74 void setCoords( int x1
, int y1
, int x2
, int y2
);
79 void setWidth( int w
);
80 void setHeight( int h
);
81 void setSize( const eSize
&s
);
83 eRect
operator|(const eRect
&r
) const;
84 eRect
operator&(const eRect
&r
) const;
85 eRect
& operator|=(const eRect
&r
);
86 eRect
& operator&=(const eRect
&r
);
88 bool contains( const ePoint
&p
) const;
89 bool contains( int x
, int y
) const;
90 bool contains( const eRect
&r
) const;
91 eRect
unite( const eRect
&r
) const;
92 eRect
intersect( const eRect
&r
) const;
93 bool intersects( const eRect
&r
) const;
95 friend bool operator==( const eRect
&, const eRect
& );
96 friend bool operator!=( const eRect
&, const eRect
& );
105 bool operator==( const eRect
&, const eRect
& );
106 bool operator!=( const eRect
&, const eRect
& );
109 /*****************************************************************************
110 eRect stream functions
111 *****************************************************************************/
114 inline ostream
&operator<<( ostream
& s
, const eRect
& r
)
116 s
<< r
.left() << r
.top()
117 << r
.right() << r
.bottom();
122 inline istream
&operator>>( istream
& s
, eRect
& r
)
125 s
>> x1
>> y1
>> x2
>> y2
;
126 r
.setCoords( x1
, y1
, x2
, y2
);
131 /*****************************************************************************
132 eRect inline member functions
133 *****************************************************************************/
135 inline eRect::eRect( int left
, int top
, int width
, int height
)
143 inline bool eRect::isNull() const
144 { return x2
== x1
&& y2
== y1
; }
146 inline bool eRect::isEmpty() const
147 { return x1
>= x2
|| y1
>= y2
; }
149 inline bool eRect::isValid() const
150 { return x1
<= x2
&& y1
<= y2
; }
152 inline int eRect::left() const
155 inline int eRect::top() const
158 inline int eRect::right() const
161 inline int eRect::bottom() const
164 inline int &eRect::rLeft()
167 inline int & eRect::rTop()
170 inline int & eRect::rRight()
173 inline int & eRect::rBottom()
176 inline int eRect::x() const
179 inline int eRect::y() const
182 inline void eRect::setLeft( int pos
)
185 inline void eRect::setTop( int pos
)
188 inline void eRect::setRight( int pos
)
191 inline void eRect::setBottom( int pos
)
194 inline void eRect::setX( int x
)
197 inline void eRect::setY( int y
)
200 inline ePoint
eRect::topLeft() const
201 { return ePoint(x1
, y1
); }
203 inline ePoint
eRect::bottomRight() const
204 { return ePoint(x2
, y2
); }
206 inline ePoint
eRect::topRight() const
207 { return ePoint(x2
, y1
); }
209 inline ePoint
eRect::bottomLeft() const
210 { return ePoint(x1
, y2
); }
212 inline ePoint
eRect::center() const
213 { return ePoint((x1
+x2
)/2, (y1
+y2
)/2); }
215 inline int eRect::width() const
218 inline int eRect::height() const
221 inline eSize
eRect::size() const
222 { return eSize(x2
-x1
, y2
-y1
); }
224 inline bool eRect::contains( int x
, int y
) const
226 return x
>= x1
&& x
< x2
&& y
>= y1
&& y
< y2
;