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

Public Attributes

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

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.