class eRect // rectangle class
{
+ friend class gRegion;
public:
- eRect() { x1 = y1 = x2 = y2 = 0; }
+ /* 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( int left, int top, int width, int height );
- bool isNull() const;
- bool isEmpty() const;
- bool isValid() const;
+ bool empty() const;
+ bool valid() const;
eRect normalize() const;
int left() 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;
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 );
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(); }
+
private:
int x1;
int y1;
bool operator!=( const eRect &, const eRect & );
-/*****************************************************************************
- eRect stream functions
- *****************************************************************************/
-namespace std
-{
- inline ostream &operator<<( ostream & s, const eRect & r )
- {
- s << r.left() << r.top()
- << r.right() << r.bottom();
-
- return s;
- }
-
- inline istream &operator>>( istream & s, eRect & r )
- {
- int x1, y1, x2, y2;
- s >> x1 >> y1 >> x2 >> y2;
- r.setCoords( x1, y1, x2, y2 );
- return s;
- }
-}
-
/*****************************************************************************
eRect inline member functions
*****************************************************************************/
y2 = top+height;
}
-inline bool eRect::isNull() const
-{ return x2 == x1 && y2 == y1; }
-
-inline bool eRect::isEmpty() const
-{ return x1 >= x2 || y1 >= y2; }
+inline bool eRect::empty() const
+{ return x1 == x2 || y1 == y2; }
-inline bool eRect::isValid() const
+inline bool eRect::valid() const
{ return x1 <= x2 && y1 <= y2; }
inline int eRect::left() const
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 bool eRect::contains( int x, int y) const
{
- return x >= x1 && x < x2 && y >= y1 && y < y2;
+ return (x >= x1) && (x < x2) && (y >= y1) && (y < y2);
}
#endif // eRect_H