Vaca::Rect Class Reference

#include <Rect.h>

List of all members.


Detailed Description

A rectangle.

Public Member Functions

 Rect ()
 Creates a new empty rectangle with the origin in Point(0,0).
 Rect (int w, int h)
 Creates a new rectangle with the specified size with the origin in Point(0,0).
 Rect (const Size &size)
 Creates a new rectangle with the specified size with the origin in Point(0,0).
 Rect (const Rect &rect)
 Creates a copy of rect.
 Rect (const Point &point, const Size &size)
 Creates a new rectangle with the origin in point and the specified size.
 Rect (const Point &point1, const Point &point2)
 Creates a new rectangle with the origin in point1 and size equal to point2 - point1.
 Rect (int x, int y, int w, int h)
bool isEmpty () const
 Verifies if the width and/or height of the rectangle are less or equal than zero.
Point getCenter () const
 Returns the middle point of the rectangle (the centroid).
Point getOrigin () const
 Returns the point in the upper-left corner (that is inside the rectangle).
Point getPoint2 () const
 Returns point in the lower-right corner (that is outside the rectangle).
Size getSize () const
 Returns the size of the rectangle.
RectsetOrigin (const Point &pt)
 Changes the origin of the rectangle without modifying its size.
RectsetSize (const Size &sz)
 Changes the size of the rectangle without modifying its origin.
Rectoffset (int dx, int dy)
 Moves the rectangle origin in the specified delta.
Rectoffset (const Point &point)
 Moves the rectangle origin in the specified delta.
Rectinflate (int dw, int dh)
 Increases (or decreases if the delta is negative) the size of the rectangle.
Rectinflate (const Size &size)
 Increases (or decreases if the delta is negative) the size of the rectangle.
Rectenlarge (int unit)
Rectshrink (int unit)
bool contains (const Point &pt) const
 Returns true if this rectangle encloses the pt point.
bool contains (const Rect &rc) const
 Returns true if this rectangle entirely contains the rc rectangle.
bool intersects (const Rect &rc) const
 Returns true if the intersection between this rectangle with rc rectangle is not empty.
Rect createUnion (const Rect &rc) const
 Returns the union rectangle between this and rc rectangle.
Rect createIntersect (const Rect &rc) const
 Returns the intersection rectangle between this and rc rectangles.
bool operator== (const Rect &rc) const
bool operator!= (const Rect &rc) const
 Rect (LPCRECT rc)
 Converts a Win32's rectangle (RECT structure) to a Vaca's rectangle (Rect class).
 operator RECT () const
 Converts a Vaca's rectangle (Rect class) to a Win32's rectangle (RECT structure).

Public Attributes

int x
 Horizontal position of the rectangle's upper-left corner (increase from left to right).
int y
 Vertical position of the rectangle's upper-left corner (increase from top to bottom).
int w
 Width of the rectangle (increase from left to right).
int h
 Height of the rectangle (increase from left to right).

Constructor & Destructor Documentation

Rect::Rect (  ) 

Creates a new empty rectangle with the origin in Point(0,0).

The rectangle will be x=y=w=h=0

See also:
isEmpty

Rect::Rect ( int  w,
int  h 
)

Creates a new rectangle with the specified size with the origin in Point(0,0).

The rectangle will be x=y=0.

Rect::Rect ( const Size size  )  [explicit]

Creates a new rectangle with the specified size with the origin in Point(0,0).

The rectangle will be x=y=0.

Rect::Rect ( const Rect rect  ) 

Creates a copy of rect.

Rect::Rect ( const Point point,
const Size size 
)

Creates a new rectangle with the origin in point and the specified size.

Rect::Rect ( const Point point1,
const Point point2 
)

Creates a new rectangle with the origin in point1 and size equal to point2 - point1.

If a coordinate of point1 is greater than point2 (Point::x and/or Point::y), the coordinates are swapped. So the rectangle will be:

 #x = MIN(point1.x, point2.x)
 #y = MIN(point1.y, point2.y)
 #w = MAX(point1.x, point2.x) - #x
 #h = MAX(point1.x, point2.x) - #y
See that point2 isn't included in the rectangle, it's like the point returned by getPoint2 method.

See also:
getPoint2

Rect::Rect ( int  x,
int  y,
int  w,
int  h 
)

Rect::Rect ( LPCRECT  rc  )  [explicit]

Converts a Win32's rectangle (RECT structure) to a Vaca's rectangle (Rect class).

For internal use only.


Member Function Documentation

bool Rect::isEmpty (  )  const

Verifies if the width and/or height of the rectangle are less or equal than zero.

Point Rect::getCenter (  )  const

Returns the middle point of the rectangle (the centroid).

Returns:
Point(x+w/2, y+h/2)

Point Rect::getOrigin (  )  const

Returns the point in the upper-left corner (that is inside the rectangle).

Returns:
Point(x, y)

Point Rect::getPoint2 (  )  const

Returns point in the lower-right corner (that is outside the rectangle).

Returns:
Point(x+w, y+h)

Size Rect::getSize (  )  const

Returns the size of the rectangle.

Returns:
Size(w, h)

Rect & Rect::setOrigin ( const Point pt  ) 

Changes the origin of the rectangle without modifying its size.

Rect & Rect::setSize ( const Size sz  ) 

Changes the size of the rectangle without modifying its origin.

Rect & Rect::offset ( int  dx,
int  dy 
)

Moves the rectangle origin in the specified delta.

Parameters:
dx How many pixels displace the x coordinate (x+=dx).
dy How many pixels displace the y coordinate (y+=dy).
Returns:
A reference to this.

Rect & Rect::offset ( const Point point  ) 

Moves the rectangle origin in the specified delta.

Parameters:
point How many pixels displace the origin (x+=point.x, y+=point.y).
Returns:
A reference to this.

Rect & Rect::inflate ( int  dw,
int  dh 
)

Increases (or decreases if the delta is negative) the size of the rectangle.

Parameters:
dw How many pixels to increase the width of the rectangle w.
dh How many pixels to increase the height of the rectangle h.
Returns:
A reference to this.

Rect & Rect::inflate ( const Size size  ) 

Increases (or decreases if the delta is negative) the size of the rectangle.

Parameters:
size How many pixels to increase the size of the rectangle (w+=size.w, h+=size.h).
Returns:
A reference to this.

Rect & Rect::enlarge ( int  unit  ) 

Todo:
docme
Returns:
A reference to this.

Rect & Rect::shrink ( int  unit  ) 

Todo:
docme
Returns:
A reference to this.

bool Rect::contains ( const Point pt  )  const

Returns true if this rectangle encloses the pt point.

bool Rect::contains ( const Rect rc  )  const

Returns true if this rectangle entirely contains the rc rectangle.

Warning:
If some rectangle is empty, this method returns false.

bool Rect::intersects ( const Rect rc  )  const

Returns true if the intersection between this rectangle with rc rectangle is not empty.

Warning:
If some rectangle is empty, this method returns false.

Rect Rect::createUnion ( const Rect rc  )  const

Returns the union rectangle between this and rc rectangle.

Warning:
If some rectangle is empty, this method will return the other rectangle.

Rect Rect::createIntersect ( const Rect rc  )  const

Returns the intersection rectangle between this and rc rectangles.

bool Rect::operator== ( const Rect rc  )  const

bool Rect::operator!= ( const Rect rc  )  const

Rect::operator RECT (  )  const

Converts a Vaca's rectangle (Rect class) to a Win32's rectangle (RECT structure).

For internal use only.


Member Data Documentation

Horizontal position of the rectangle's upper-left corner (increase from left to right).

x=0 means the beginning of the left side in the screen or Widget's client area.

Vertical position of the rectangle's upper-left corner (increase from top to bottom).

y=0 means the beginning of the top side in the screen or Widget's client area.

Width of the rectangle (increase from left to right).

w<1 means an empty rectangle.

Height of the rectangle (increase from left to right).

h<1 means an empty rectangle.