Version: 3.1.0
wxRect Class Reference

#include <wx/gdicmn.h>

Detailed Description

A class for manipulating rectangles.

Note that the x, y coordinates and the width and height stored inside a wxRect object may be negative and that wxRect functions do not perform any check against negative values.

Library:  wxCore
Category:  Data Structures
See Also
wxPoint, wxSize

Public Member Functions

 wxRect ()
 Default constructor.
 
 wxRect (int x, int y, int width, int height)
 Creates a wxRect object from x, y, width and height values.
 
 wxRect (const wxPoint &topLeft, const wxPoint &bottomRight)
 Creates a wxRect object from top-left and bottom-right points.
 
 wxRect (const wxPoint &pos, const wxSize &size)
 Creates a wxRect object from position pos and size values.
 
 wxRect (const wxSize &size)
 Creates a wxRect object from size values at the origin.
 
bool Contains (int x, int y) const
 Returns true if the given point is inside the rectangle (or on its boundary) and false otherwise.
 
bool Contains (const wxPoint &pt) const
 Returns true if the given point is inside the rectangle (or on its boundary) and false otherwise.
 
bool Contains (const wxRect &rect) const
 Returns true if the given rectangle is completely inside this rectangle (or touches its boundary) and false otherwise.
 
int GetBottom () const
 Gets the bottom point of the rectangle.
 
wxPoint GetBottomLeft () const
 Gets the position of the bottom left corner.
 
wxPoint GetBottomRight () const
 Gets the position of the bottom right corner.
 
int GetHeight () const
 Gets the height member.
 
int GetLeft () const
 Gets the left point of the rectangle (the same as GetX()).
 
wxPoint GetPosition () const
 Gets the position.
 
int GetRight () const
 Gets the right point of the rectangle.
 
wxSize GetSize () const
 Gets the size.
 
int GetTop () const
 Gets the top point of the rectangle (the same as GetY()).
 
wxPoint GetTopLeft () const
 Gets the position of the top left corner of the rectangle, same as GetPosition().
 
wxPoint GetTopRight () const
 Gets the position of the top right corner.
 
int GetWidth () const
 Gets the width member.
 
int GetX () const
 Gets the x member.
 
int GetY () const
 Gets the y member.
 
wxRectIntersect (const wxRect &rect)
 Modifies this rectangle to contain the overlapping portion of this rectangle and the one passed in as parameter.
 
wxRect Intersect (const wxRect &rect) const
 Returns the overlapping portion of this rectangle and the one passed in as parameter.
 
bool Intersects (const wxRect &rect) const
 Returns true if this rectangle has a non-empty intersection with the rectangle rect and false otherwise.
 
bool IsEmpty () const
 Returns true if this rectangle has a width or height less than or equal to 0 and false otherwise.
 
void SetHeight (int height)
 Sets the height.
 
void SetPosition (const wxPoint &pos)
 Sets the position.
 
void SetSize (const wxSize &s)
 Sets the size.
 
void SetWidth (int width)
 Sets the width.
 
void SetX (int x)
 Sets the x position.
 
void SetY (int y)
 Sets the y position.
 
void SetLeft (int left)
 Set the left side of the rectangle.
 
void SetRight (int right)
 Set the right side of the rectangle.
 
void SetTop (int top)
 Set the top edge of the rectangle.
 
void SetBottom (int bottom)
 Set the bottom edge of the rectangle.
 
void SetTopLeft (const wxPoint &p)
 Set the top-left point of the rectangle.
 
void SetBottomRight (const wxPoint &p)
 Set the bottom-right point of the rectangle.
 
void SetTopRight (const wxPoint &p)
 Set the top-right point of the rectangle.
 
void SetBottomLeft (const wxPoint &p)
 Set the bottom-left point of the rectangle.
 
bool operator!= (const wxRect &r1, const wxRect &r2)
 Inequality operator.
 
wxRectoperator= (const wxRect &rect)
 Assignment operator.
 
bool operator== (const wxRect &r1, const wxRect &r2)
 Equality operator.
 
wxRect CentreIn (const wxRect &r, int dir=wxBOTH) const
 Returns the rectangle having the same size as this one but centered relatively to the given rectangle r.
 
wxRect CenterIn (const wxRect &r, int dir=wxBOTH) const
 Returns the rectangle having the same size as this one but centered relatively to the given rectangle r.
 
wxRectDeflate (wxCoord dx, wxCoord dy)
 Decrease the rectangle size.
 
wxRectDeflate (const wxSize &diff)
 Decrease the rectangle size.
 
wxRectDeflate (wxCoord diff)
 Decrease the rectangle size.
 
wxRect Deflate (wxCoord dx, wxCoord dy) const
 Decrease the rectangle size.
 
wxRectInflate (wxCoord dx, wxCoord dy)
 Increases the size of the rectangle.
 
wxRectInflate (const wxSize &diff)
 Increases the size of the rectangle.
 
wxRectInflate (wxCoord diff)
 Increases the size of the rectangle.
 
wxRect Inflate (wxCoord dx, wxCoord dy) const
 Increases the size of the rectangle.
 
void Offset (wxCoord dx, wxCoord dy)
 Moves the rectangle by the specified offset.
 
void Offset (const wxPoint &pt)
 Moves the rectangle by the specified offset.
 
wxRect Union (const wxRect &rect) const
 Modifies the rectangle to contain the bounding box of this rectangle and the one passed in as parameter.
 
wxRectUnion (const wxRect &rect)
 Modifies the rectangle to contain the bounding box of this rectangle and the one passed in as parameter.
 
wxRect operator+ (const wxRect &r1, const wxRect &r2)
 Like Union(), but doesn't treat empty rectangles specially.
 
wxRectoperator+= (const wxRect &r)
 Like Union(), but doesn't treat empty rectangles specially.
 
wxRect operator* (const wxRect &r1, const wxRect &r2)
 Returns the intersection of two rectangles (which may be empty).
 
wxRectoperator*= (const wxRect &r)
 Returns the intersection of two rectangles (which may be empty).
 

Public Attributes

int height
 Height member.
 
int width
 Width member.
 
int x
 x coordinate of the top-level corner of the rectangle.
 
int y
 y coordinate of the top-level corner of the rectangle.
 

Constructor & Destructor Documentation

wxRect::wxRect ( )

Default constructor.

Initializes to zero the internal x, y, width and height members.

wxRect::wxRect ( int  x,
int  y,
int  width,
int  height 
)

Creates a wxRect object from x, y, width and height values.

wxRect::wxRect ( const wxPoint topLeft,
const wxPoint bottomRight 
)

Creates a wxRect object from top-left and bottom-right points.

wxRect::wxRect ( const wxPoint pos,
const wxSize size 
)

Creates a wxRect object from position pos and size values.

wxRect::wxRect ( const wxSize size)

Creates a wxRect object from size values at the origin.

Member Function Documentation

wxRect wxRect::CenterIn ( const wxRect r,
int  dir = wxBOTH 
) const

Returns the rectangle having the same size as this one but centered relatively to the given rectangle r.

By default, rectangle is centred in both directions but if dir includes only wxVERTICAL or only wxHORIZONTAL, then it is only centered in this direction while the other component of its position remains unchanged.

wxRect wxRect::CentreIn ( const wxRect r,
int  dir = wxBOTH 
) const

Returns the rectangle having the same size as this one but centered relatively to the given rectangle r.

By default, rectangle is centred in both directions but if dir includes only wxVERTICAL or only wxHORIZONTAL, then it is only centered in this direction while the other component of its position remains unchanged.

bool wxRect::Contains ( int  x,
int  y 
) const

Returns true if the given point is inside the rectangle (or on its boundary) and false otherwise.

bool wxRect::Contains ( const wxPoint pt) const

Returns true if the given point is inside the rectangle (or on its boundary) and false otherwise.

bool wxRect::Contains ( const wxRect rect) const

Returns true if the given rectangle is completely inside this rectangle (or touches its boundary) and false otherwise.

wxRect& wxRect::Deflate ( wxCoord  dx,
wxCoord  dy 
)

Decrease the rectangle size.

This method is the opposite from Inflate(): Deflate(a, b) is equivalent to Inflate(-a, -b). Please refer to Inflate() for full description.

wxRect& wxRect::Deflate ( const wxSize diff)

Decrease the rectangle size.

This method is the opposite from Inflate(): Deflate(a, b) is equivalent to Inflate(-a, -b). Please refer to Inflate() for full description.

wxRect& wxRect::Deflate ( wxCoord  diff)

Decrease the rectangle size.

This method is the opposite from Inflate(): Deflate(a, b) is equivalent to Inflate(-a, -b). Please refer to Inflate() for full description.

wxRect wxRect::Deflate ( wxCoord  dx,
wxCoord  dy 
) const

Decrease the rectangle size.

This method is the opposite from Inflate(): Deflate(a, b) is equivalent to Inflate(-a, -b). Please refer to Inflate() for full description.

int wxRect::GetBottom ( ) const

Gets the bottom point of the rectangle.

wxPoint wxRect::GetBottomLeft ( ) const

Gets the position of the bottom left corner.

wxPoint wxRect::GetBottomRight ( ) const

Gets the position of the bottom right corner.

int wxRect::GetHeight ( ) const

Gets the height member.

int wxRect::GetLeft ( ) const

Gets the left point of the rectangle (the same as GetX()).

wxPoint wxRect::GetPosition ( ) const

Gets the position.

int wxRect::GetRight ( ) const

Gets the right point of the rectangle.

wxSize wxRect::GetSize ( ) const

Gets the size.

See Also
SetSize()
int wxRect::GetTop ( ) const

Gets the top point of the rectangle (the same as GetY()).

wxPoint wxRect::GetTopLeft ( ) const

Gets the position of the top left corner of the rectangle, same as GetPosition().

wxPoint wxRect::GetTopRight ( ) const

Gets the position of the top right corner.

int wxRect::GetWidth ( ) const

Gets the width member.

int wxRect::GetX ( ) const

Gets the x member.

int wxRect::GetY ( ) const

Gets the y member.

wxRect& wxRect::Inflate ( wxCoord  dx,
wxCoord  dy 
)

Increases the size of the rectangle.

The left border is moved farther left and the right border is moved farther right by dx. The upper border is moved farther up and the bottom border is moved farther down by dy. (Note that the width and height of the rectangle thus change by 2*dx and 2*dy, respectively.) If one or both of dx and dy are negative, the opposite happens: the rectangle size decreases in the respective direction.

Inflating and deflating behaves "naturally". Defined more precisely, that means:

  1. "Real" inflates (that is, dx and/or dy = 0) are not constrained. Thus inflating a rectangle can cause its upper left corner to move into the negative numbers. (2.5.4 and older forced the top left coordinate to not fall below (0, 0), which implied a forced move of the rectangle.)
  2. Deflates are clamped to not reduce the width or height of the rectangle below zero. In such cases, the top-left corner is nonetheless handled properly. For example, a rectangle at (10, 10) with size (20, 40) that is inflated by (-15, -15) will become located at (20, 25) at size (0, 10). Finally, observe that the width and height are treated independently. In the above example, the width is reduced by 20, whereas the height is reduced by the full 30 (rather than also stopping at 20, when the width reached zero).
See Also
Deflate()
wxRect& wxRect::Inflate ( const wxSize diff)

Increases the size of the rectangle.

The left border is moved farther left and the right border is moved farther right by dx. The upper border is moved farther up and the bottom border is moved farther down by dy. (Note that the width and height of the rectangle thus change by 2*dx and 2*dy, respectively.) If one or both of dx and dy are negative, the opposite happens: the rectangle size decreases in the respective direction.

Inflating and deflating behaves "naturally". Defined more precisely, that means:

  1. "Real" inflates (that is, dx and/or dy = 0) are not constrained. Thus inflating a rectangle can cause its upper left corner to move into the negative numbers. (2.5.4 and older forced the top left coordinate to not fall below (0, 0), which implied a forced move of the rectangle.)
  2. Deflates are clamped to not reduce the width or height of the rectangle below zero. In such cases, the top-left corner is nonetheless handled properly. For example, a rectangle at (10, 10) with size (20, 40) that is inflated by (-15, -15) will become located at (20, 25) at size (0, 10). Finally, observe that the width and height are treated independently. In the above example, the width is reduced by 20, whereas the height is reduced by the full 30 (rather than also stopping at 20, when the width reached zero).
See Also
Deflate()
wxRect& wxRect::Inflate ( wxCoord  diff)

Increases the size of the rectangle.

The left border is moved farther left and the right border is moved farther right by dx. The upper border is moved farther up and the bottom border is moved farther down by dy. (Note that the width and height of the rectangle thus change by 2*dx and 2*dy, respectively.) If one or both of dx and dy are negative, the opposite happens: the rectangle size decreases in the respective direction.

Inflating and deflating behaves "naturally". Defined more precisely, that means:

  1. "Real" inflates (that is, dx and/or dy = 0) are not constrained. Thus inflating a rectangle can cause its upper left corner to move into the negative numbers. (2.5.4 and older forced the top left coordinate to not fall below (0, 0), which implied a forced move of the rectangle.)
  2. Deflates are clamped to not reduce the width or height of the rectangle below zero. In such cases, the top-left corner is nonetheless handled properly. For example, a rectangle at (10, 10) with size (20, 40) that is inflated by (-15, -15) will become located at (20, 25) at size (0, 10). Finally, observe that the width and height are treated independently. In the above example, the width is reduced by 20, whereas the height is reduced by the full 30 (rather than also stopping at 20, when the width reached zero).
See Also
Deflate()
wxRect wxRect::Inflate ( wxCoord  dx,
wxCoord  dy 
) const

Increases the size of the rectangle.

The left border is moved farther left and the right border is moved farther right by dx. The upper border is moved farther up and the bottom border is moved farther down by dy. (Note that the width and height of the rectangle thus change by 2*dx and 2*dy, respectively.) If one or both of dx and dy are negative, the opposite happens: the rectangle size decreases in the respective direction.

Inflating and deflating behaves "naturally". Defined more precisely, that means:

  1. "Real" inflates (that is, dx and/or dy = 0) are not constrained. Thus inflating a rectangle can cause its upper left corner to move into the negative numbers. (2.5.4 and older forced the top left coordinate to not fall below (0, 0), which implied a forced move of the rectangle.)
  2. Deflates are clamped to not reduce the width or height of the rectangle below zero. In such cases, the top-left corner is nonetheless handled properly. For example, a rectangle at (10, 10) with size (20, 40) that is inflated by (-15, -15) will become located at (20, 25) at size (0, 10). Finally, observe that the width and height are treated independently. In the above example, the width is reduced by 20, whereas the height is reduced by the full 30 (rather than also stopping at 20, when the width reached zero).
See Also
Deflate()
wxRect& wxRect::Intersect ( const wxRect rect)

Modifies this rectangle to contain the overlapping portion of this rectangle and the one passed in as parameter.

Returns
This rectangle, modified.
wxRect wxRect::Intersect ( const wxRect rect) const

Returns the overlapping portion of this rectangle and the one passed in as parameter.

bool wxRect::Intersects ( const wxRect rect) const

Returns true if this rectangle has a non-empty intersection with the rectangle rect and false otherwise.

bool wxRect::IsEmpty ( ) const

Returns true if this rectangle has a width or height less than or equal to 0 and false otherwise.

void wxRect::Offset ( wxCoord  dx,
wxCoord  dy 
)

Moves the rectangle by the specified offset.

If dx is positive, the rectangle is moved to the right, if dy is positive, it is moved to the bottom, otherwise it is moved to the left or top respectively.

void wxRect::Offset ( const wxPoint pt)

Moves the rectangle by the specified offset.

If dx is positive, the rectangle is moved to the right, if dy is positive, it is moved to the bottom, otherwise it is moved to the left or top respectively.

bool wxRect::operator!= ( const wxRect r1,
const wxRect r2 
)

Inequality operator.

wxRect wxRect::operator* ( const wxRect r1,
const wxRect r2 
)

Returns the intersection of two rectangles (which may be empty).

wxRect& wxRect::operator*= ( const wxRect r)

Returns the intersection of two rectangles (which may be empty).

wxRect wxRect::operator+ ( const wxRect r1,
const wxRect r2 
)

Like Union(), but doesn't treat empty rectangles specially.

wxRect& wxRect::operator+= ( const wxRect r)

Like Union(), but doesn't treat empty rectangles specially.

wxRect& wxRect::operator= ( const wxRect rect)

Assignment operator.

bool wxRect::operator== ( const wxRect r1,
const wxRect r2 
)

Equality operator.

void wxRect::SetBottom ( int  bottom)

Set the bottom edge of the rectangle.

Notice that this doesn't affect GetTop() return value but changes the rectangle height to set its bottom side to the given position.

void wxRect::SetBottomLeft ( const wxPoint p)

Set the bottom-left point of the rectangle.

void wxRect::SetBottomRight ( const wxPoint p)

Set the bottom-right point of the rectangle.

void wxRect::SetHeight ( int  height)

Sets the height.

void wxRect::SetLeft ( int  left)

Set the left side of the rectangle.

Notice that because the rectangle stores its left side and width, calling SetLeft() changes the right side position too – but does preserve the width.

void wxRect::SetPosition ( const wxPoint pos)

Sets the position.

void wxRect::SetRight ( int  right)

Set the right side of the rectangle.

Notice that this doesn't affect GetLeft() return value but changes the rectangle width to set its right side to the given position.

void wxRect::SetSize ( const wxSize s)

Sets the size.

See Also
GetSize()
void wxRect::SetTop ( int  top)

Set the top edge of the rectangle.

Notice that because the rectangle stores its top side and height, calling SetTop() changes the bottom side position too – but does preserve the height.

void wxRect::SetTopLeft ( const wxPoint p)

Set the top-left point of the rectangle.

void wxRect::SetTopRight ( const wxPoint p)

Set the top-right point of the rectangle.

void wxRect::SetWidth ( int  width)

Sets the width.

void wxRect::SetX ( int  x)

Sets the x position.

void wxRect::SetY ( int  y)

Sets the y position.

wxRect wxRect::Union ( const wxRect rect) const

Modifies the rectangle to contain the bounding box of this rectangle and the one passed in as parameter.

wxRect& wxRect::Union ( const wxRect rect)

Modifies the rectangle to contain the bounding box of this rectangle and the one passed in as parameter.

Member Data Documentation

int wxRect::height

Height member.

int wxRect::width

Width member.

int wxRect::x

x coordinate of the top-level corner of the rectangle.

int wxRect::y

y coordinate of the top-level corner of the rectangle.