| Version: 3.2.5

Public Member Functions | Public Attributes | List of all members
wxRect Class Reference
Class List by Category » Data Structures

`#include <wx/gdicmn.h>`

## Detailed Description

Represents a rectangle with integer coordinates.

`x` and `y` members specify the coordinates of the rectangle top-left corner and `width` and `height` specify its width and height respectively. The usual C++ semi-open interval convention is used: point `p` lies inside the rectangle if and only if both conditions below are satisfied:

x <= p.x < x + width
y <= p.y < y + height
wxRect::height
int height
Height member.
Definition: gdicmn.h:618
wxRect::y
int y
y coordinate of the top-left corner of the rectangle.
Definition: gdicmn.h:633
wxRect::x
int x
x coordinate of the top-left corner of the rectangle.
Definition: gdicmn.h:628
wxRect::width
int width
Width member.
Definition: gdicmn.h:623

In other words, the rectangle left and right boundaries are at `x` and `x+width-1` and its top and bottom boundaries are at `y` and `y+height-1` respectively.

Note that the x and y coordinates may be negative, but width and height are always strictly positive for non-empty rectangles.

##

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...
wxRect & | Intersect (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...
wxRect & | operator= (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...
wxRect & | Deflate (wxCoord dx, wxCoord dy)
| Decrease the rectangle size. More...
wxRect & | Deflate (const wxSize &diff)
| Decrease the rectangle size. More...
wxRect & | Deflate (wxCoord diff)
| Decrease the rectangle size. More...
wxRect | Deflate (wxCoord dx, wxCoord dy) const
| Decrease the rectangle size. More...
wxRect & | Inflate (wxCoord dx, wxCoord dy)
| Increases the size of the rectangle. More...
wxRect & | Inflate (const wxSize &diff)
| Increases the size of the rectangle. More...
wxRect & | Inflate (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...
wxRect & | Union (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...
wxRect & | operator+= (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...
wxRect & | operator*= (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-left corner of the rectangle. More...
int | y
| y coordinate of the top-left corner of the rectangle. More...

## Constructor & Destructor Documentation

## ◆ wxRect() [1/5]

wxRect::wxRect | ( |  | ) |

Default constructor.

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

## ◆ wxRect() [2/5]

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

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

## ◆ wxRect() [3/5]

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

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

The width of the rectangle will be `bottomRight.x-topLeft.x+1` and the height will be `bottomRight.y-topLeft.y+1`.

## ◆ wxRect() [4/5]

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

Creates a wxRect object from position pos and size values.

## ◆ wxRect() [5/5]

wxRect::wxRect | ( | const wxSize & | size | ) |

Creates a wxRect object from size values at the origin.

## Member Function Documentation

## ◆ CenterIn()

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.

## ◆ CentreIn()

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.

## ◆ Contains() [1/3]

bool wxRect::Contains | ( | const wxPoint & | pt | ) | const

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

## ◆ Contains() [2/3]

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.

## ◆ Contains() [3/3]

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.

## ◆ Deflate() [1/4]

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.

## ◆ Deflate() [2/4]

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.

## ◆ Deflate() [3/4]

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.

## ◆ Deflate() [4/4]

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.

## ◆ GetBottom()

int wxRect::GetBottom | ( |  | ) | const

Gets the bottom point of the rectangle.

## ◆ GetBottomLeft()

wxPoint wxRect::GetBottomLeft | ( |  | ) | const

Gets the position of the bottom left corner.

## ◆ GetBottomRight()

wxPoint wxRect::GetBottomRight | ( |  | ) | const

Gets the position of the bottom right corner.

## ◆ GetHeight()

int wxRect::GetHeight | ( |  | ) | const

Gets the height member.

## ◆ GetLeft()

int wxRect::GetLeft | ( |  | ) | const

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

## ◆ GetPosition()

wxPoint wxRect::GetPosition | ( |  | ) | const

Gets the position.

## ◆ GetRight()

int wxRect::GetRight | ( |  | ) | const

Gets the right point of the rectangle.

## ◆ GetSize()

wxSize wxRect::GetSize | ( |  | ) | const

Gets the size.

See also
  SetSize()

## ◆ GetTop()

int wxRect::GetTop | ( |  | ) | const

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

## ◆ GetTopLeft()

wxPoint wxRect::GetTopLeft | ( |  | ) | const

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

## ◆ GetTopRight()

wxPoint wxRect::GetTopRight | ( |  | ) | const

Gets the position of the top right corner.

## ◆ GetWidth()

int wxRect::GetWidth | ( |  | ) | const

Gets the width member.

## ◆ GetX()

int wxRect::GetX | ( |  | ) | const

Gets the x member.

## ◆ GetY()

int wxRect::GetY | ( |  | ) | const

Gets the y member.

## ◆ Inflate() [1/4]

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()

## ◆ Inflate() [2/4]

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()

## ◆ Inflate() [3/4]

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()

## ◆ Inflate() [4/4]

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()

## ◆ Intersect() [1/2]

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.

## ◆ Intersect() [2/2]

wxRect wxRect::Intersect | ( | const wxRect & | rect | ) | const

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

## ◆ Intersects()

bool wxRect::Intersects | ( | const wxRect & | rect | ) | const

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

## ◆ IsEmpty()

bool wxRect::IsEmpty | ( |  | ) | const

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

## ◆ Offset() [1/2]

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.

## ◆ Offset() [2/2]

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.

## ◆ operator!=()

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

Inequality operator.

## ◆ operator*()

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

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

## ◆ operator*=()

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

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

## ◆ operator+()

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

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

## ◆ operator+=()

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

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

## ◆ operator=()

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

Assignment operator.

## ◆ operator==()

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

Equality operator.

## ◆ SetBottom()

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.

## ◆ SetBottomLeft()

void wxRect::SetBottomLeft | ( | const wxPoint & | p | ) |

Set the bottom-left point of the rectangle.

## ◆ SetBottomRight()

void wxRect::SetBottomRight | ( | const wxPoint & | p | ) |

Set the bottom-right point of the rectangle.

## ◆ SetHeight()

void wxRect::SetHeight | ( | int | height | ) |

Sets the height.

## ◆ SetLeft()

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.

## ◆ SetPosition()

void wxRect::SetPosition | ( | const wxPoint & | pos | ) |

Sets the position.

## ◆ SetRight()

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.

## ◆ SetSize()

void wxRect::SetSize | ( | const wxSize & | s | ) |

Sets the size.

See also
  GetSize()

## ◆ SetTop()

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.

## ◆ SetTopLeft()

void wxRect::SetTopLeft | ( | const wxPoint & | p | ) |

Set the top-left point of the rectangle.

## ◆ SetTopRight()

void wxRect::SetTopRight | ( | const wxPoint & | p | ) |

Set the top-right point of the rectangle.

## ◆ SetWidth()

void wxRect::SetWidth | ( | int | width | ) |

Sets the width.

## ◆ SetX()

void wxRect::SetX | ( | int | x | ) |

Sets the x position.

## ◆ SetY()

void wxRect::SetY | ( | int | y | ) |

Sets the y position.

## ◆ Union() [1/2]

wxRect& wxRect::Union | ( | const wxRect & | rect | ) |

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

## ◆ Union() [2/2]

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.

## Member Data Documentation

## ◆ height

int wxRect::height

Height member.

## ◆ width

int wxRect::width

Width member.

## ◆ x

int wxRect::x

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

## ◆ y

int wxRect::y

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