| Version: 3.2.5

Public Member Functions | List of all members
wxRegion Class Reference
Class List by Category » Data Structures | Class List by Category » Graphics Device Interface (GDI)

`#include <wx/region.h>`

Inheritance diagram for wxRegion:
[legend]

## Detailed Description

A wxRegion represents a simple or complex region on a device context or window.

This class uses reference counting and copy-on-write internally so that assignments between two instances of this class are very cheap. You can therefore use actual objects instead of pointers without efficiency problems. If an instance of this class is changed it will create its own data internally so that other instances, which previously shared the data using the reference counting, are not affected.

Predefined objects/pointers:

- wxNullRegion

##

Library: wxCore
Category: Data Structures, Graphics Device Interface (GDI)

See also
  wxRegionIterator

## Public Member Functions

| wxRegion ()
| Default constructor. More...
| wxRegion (wxCoord x, wxCoord y, wxCoord width, wxCoord height)
| Constructs a rectangular region with the given position and size. More...
| wxRegion (const wxPoint &topLeft, const wxPoint &bottomRight)
| Constructs a rectangular region from the top left point and the bottom right point. More...
| wxRegion (const wxRect &rect)
| Constructs a rectangular region a wxRect object. More...
| wxRegion (const wxRegion &region)
| Copy constructor, uses Reference Counting. More...
| wxRegion (size_t n, const wxPoint *points, wxPolygonFillMode fillStyle=wxODDEVEN_RULE)
| Constructs a region corresponding to the polygon made of n points in the provided array. More...
| wxRegion (const wxBitmap &bmp)
| Constructs a region using a bitmap. More...
| wxRegion (const wxBitmap &bmp, const wxColour &transColour, int tolerance=0)
| Constructs a region using the non-transparent pixels of a bitmap. More...
virtual | ~wxRegion ()
| Destructor. More...
virtual void | Clear ()
| Clears the current region. More...
wxRegionContain | Contains (wxCoord x, wxCoord y) const
| Returns a value indicating whether the given point is contained within the region. More...
wxRegionContain | Contains (const wxPoint &pt) const
| Returns a value indicating whether the given point is contained within the region. More...
wxRegionContain | Contains (wxCoord x, wxCoord y, wxCoord width, wxCoord height) const
| Returns a value indicating whether the given rectangle is contained within the region. More...
wxRegionContain | Contains (const wxRect &rect) const
| Returns a value indicating whether the given rectangle is contained within the region. More...
wxBitmap | ConvertToBitmap () const
| Convert the region to a black and white bitmap with the white pixels being inside the region. More...
bool | Intersect (wxCoord x, wxCoord y, wxCoord width, wxCoord height)
| Finds the intersection of this region and another, rectangular region, specified using position and size. More...
bool | Intersect (const wxRect &rect)
| Finds the intersection of this region and another, rectangular region. More...
bool | Intersect (const wxRegion &region)
| Finds the intersection of this region and another region. More...
virtual bool | IsEmpty () const
| Returns true if the region is empty, false otherwise. More...
bool | IsEqual (const wxRegion &region) const
| Returns true if the region is equal to, i.e. covers the same area as, another one. More...
bool | Subtract (const wxRect &rect)
| Subtracts a rectangular region from this region. More...
bool | Subtract (const wxRegion &region)
| Subtracts a region from this region. More...
bool | Union (wxCoord x, wxCoord y, wxCoord width, wxCoord height)
| Finds the union of this region and another, rectangular region, specified using position and size. More...
bool | Union (const wxRect &rect)
| Finds the union of this region and another, rectangular region. More...
bool | Union (const wxRegion &region)
| Finds the union of this region and another region. More...
bool | Union (const wxBitmap &bmp)
| Finds the union of this region and the non-transparent pixels of a bitmap. More...
bool | Union (const wxBitmap &bmp, const wxColour &transColour, int tolerance=0)
| Finds the union of this region and the non-transparent pixels of a bitmap. More...
bool | Xor (wxCoord x, wxCoord y, wxCoord width, wxCoord height)
| Finds the Xor of this region and another, rectangular region, specified using position and size. More...
bool | Xor (const wxRect &rect)
| Finds the Xor of this region and another, rectangular region. More...
bool | Xor (const wxRegion &region)
| Finds the Xor of this region and another region. More...
wxRegion & | operator= (const wxRegion &region)
| Assignment operator, using Reference Counting. More...
void | GetBox (wxCoord &x, wxCoord &y, wxCoord &width, wxCoord &height) const
| Returns the outer bounds of the region. More...
wxRect | GetBox () const
| Returns the outer bounds of the region. More...
bool | Offset (wxCoord x, wxCoord y)
| Moves the region by the specified offsets in horizontal and vertical directions. More...
bool | Offset (const wxPoint &pt)
| Moves the region by the specified offsets in horizontal and vertical directions. More...
Public Member Functions inherited from wxGDIObject
| wxGDIObject ()
| Default constructor. More...
Public Member Functions inherited from wxObject
| wxObject ()
| Default ctor; initializes to NULL the internal reference data. More...
| wxObject (const wxObject &other)
| Copy ctor. More...
virtual | ~wxObject ()
| Destructor. More...
virtual wxClassInfo * | GetClassInfo () const
| This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). More...
wxObjectRefData * | GetRefData () const
| Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. More...
bool | IsKindOf (const wxClassInfo *info) const
| Determines whether this class is a subclass of (or the same class as) the given class. More...
bool | IsSameAs (const wxObject &obj) const
| Returns true if this object has the same data pointer as obj. More...
void | Ref (const wxObject &clone)
| Makes this object refer to the data in clone. More...
void | SetRefData (wxObjectRefData *data)
| Sets the wxObject::m_refData pointer. More...
void | UnRef ()
| Decrements the reference count in the associated data, and if it is zero, deletes the data. More...
void | UnShare ()
| This is the same of AllocExclusive() but this method is public. More...
void | operator delete (void *buf)
| The delete operator is defined for debugging versions of the library only, when the identifier `__WXDEBUG__` is defined. More...
void * | operator new (size_t size, const wxString &filename=NULL, int lineNum=0)
| The new operator is defined for debugging versions of the library only, when the identifier `__WXDEBUG__` is defined. More...

## Additional Inherited Members

Protected Member Functions inherited from wxObject
void | AllocExclusive ()
| Ensure that this object's data is not shared with any other object. More...
virtual wxObjectRefData * | CreateRefData () const
| Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More...
virtual wxObjectRefData * | CloneRefData (const wxObjectRefData *data) const
| Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. More...
Protected Attributes inherited from wxObject
wxObjectRefData * | m_refData
| Pointer to an object which is the object's reference-counted data. More...

## Constructor & Destructor Documentation

## ◆ wxRegion() [1/8]

wxRegion::wxRegion | ( |  | ) |

Default constructor.

This constructor creates an invalid, or null, object, i.e. calling IsOk() on it returns false and IsEmpty() returns true.

## ◆ wxRegion() [2/8]

wxRegion::wxRegion | ( | wxCoord | x,
|  | wxCoord | y,
|  | wxCoord | width,
|  | wxCoord | height
| ) |  |

Constructs a rectangular region with the given position and size.

## ◆ wxRegion() [3/8]

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

Constructs a rectangular region from the top left point and the bottom right point.

## ◆ wxRegion() [4/8]

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

Constructs a rectangular region a wxRect object.

## ◆ wxRegion() [5/8]

wxRegion::wxRegion | ( | const wxRegion & | region | ) |

Copy constructor, uses Reference Counting.

## ◆ wxRegion() [6/8]

wxRegion::wxRegion | ( | size_t | n,
|  | const wxPoint * | points,
|  | wxPolygonFillMode | fillStyle = `wxODDEVEN_RULE`
| ) |  |

Constructs a region corresponding to the polygon made of n points in the provided array.

fillStyle parameter may have values `wxWINDING_RULE` or `wxODDEVEN_RULE`.

## ◆ wxRegion() [7/8]

wxRegion::wxRegion | ( | const wxBitmap & | bmp | ) |

Constructs a region using a bitmap.

See Union() for more details.

## ◆ wxRegion() [8/8]

wxRegion::wxRegion | ( | const wxBitmap & | bmp,
|  | const wxColour & | transColour,
|  | int | tolerance = `0`
| ) |  |

Constructs a region using the non-transparent pixels of a bitmap.

See Union() for more details.

## ◆ ~wxRegion()

virtual wxRegion::~wxRegion | ( |  | ) |

virtual

Destructor.

See reference-counted object destruction for more info.

## Member Function Documentation

## ◆ Clear()

virtual void wxRegion::Clear | ( |  | ) |

virtual

Clears the current region.

The object becomes invalid, or null, after being cleared.

## ◆ Contains() [1/4]

wxRegionContain wxRegion::Contains | ( | const wxPoint & | pt | ) | const

Returns a value indicating whether the given point is contained within the region.

This method always returns `wxOutRegion` for an invalid region but may, nevertheless, be safely called in this case.

Returns
  The return value is one of `wxOutRegion` and `wxInRegion`.

## ◆ Contains() [2/4]

wxRegionContain wxRegion::Contains | ( | const wxRect & | rect | ) | const

Returns a value indicating whether the given rectangle is contained within the region.

This method always returns `wxOutRegion` for an invalid region but may, nevertheless, be safely called in this case.

Returns
  One of wxOutRegion, wxPartRegion or wxInRegion.

Note
  On Windows, only wxOutRegion and wxInRegion are returned; a value wxInRegion then indicates that all or some part of the region is contained in this region.

## ◆ Contains() [3/4]

wxRegionContain wxRegion::Contains | ( | wxCoord | x,
|  | wxCoord | y
| ) |  | const

Returns a value indicating whether the given point is contained within the region.

This method always returns `wxOutRegion` for an invalid region but may, nevertheless, be safely called in this case.

Returns
  The return value is one of `wxOutRegion` and `wxInRegion`.

## ◆ Contains() [4/4]

wxRegionContain wxRegion::Contains | ( | wxCoord | x,
|  | wxCoord | y,
|  | wxCoord | width,
|  | wxCoord | height
| ) |  | const

Returns a value indicating whether the given rectangle is contained within the region.

This method always returns `wxOutRegion` for an invalid region but may, nevertheless, be safely called in this case.

Returns
  One of wxOutRegion, wxPartRegion or wxInRegion.

Note
  On Windows, only wxOutRegion and wxInRegion are returned; a value wxInRegion then indicates that all or some part of the region is contained in this region.

## ◆ ConvertToBitmap()

wxBitmap wxRegion::ConvertToBitmap | ( |  | ) | const

Convert the region to a black and white bitmap with the white pixels being inside the region.

This method can't be used for invalid region.

## ◆ GetBox() [1/2]

wxRect wxRegion::GetBox | ( |  | ) | const

Returns the outer bounds of the region.

This method returns 0-sized bounding box for invalid regions.

## ◆ GetBox() [2/2]

void wxRegion::GetBox | ( | wxCoord & | x,
|  | wxCoord & | y,
|  | wxCoord & | width,
|  | wxCoord & | height
| ) |  | const

Returns the outer bounds of the region.

This method returns 0-sized bounding box for invalid regions.

## ◆ Intersect() [1/3]

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

Finds the intersection of this region and another, rectangular region.

This method always fails, i.e. returns false, if this region is invalid but may nevertheless be safely used even in this case.

Returns
  true if successful, false otherwise.

Remarks
  Creates the intersection of the two regions, that is, the parts which are in both regions. The result is stored in this region.

## ◆ Intersect() [2/3]

bool wxRegion::Intersect | ( | const wxRegion & | region | ) |

Finds the intersection of this region and another region.

This method always fails, i.e. returns false, if this region is invalid but may nevertheless be safely used even in this case.

Returns
  true if successful, false otherwise.

Remarks
  Creates the intersection of the two regions, that is, the parts which are in both regions. The result is stored in this region.

## ◆ Intersect() [3/3]

bool wxRegion::Intersect | ( | wxCoord | x,
|  | wxCoord | y,
|  | wxCoord | width,
|  | wxCoord | height
| ) |  |

Finds the intersection of this region and another, rectangular region, specified using position and size.

This method always fails, i.e. returns false, if this region is invalid but may nevertheless be safely used even in this case.

Returns
  true if successful, false otherwise.

Remarks
  Creates the intersection of the two regions, that is, the parts which are in both regions. The result is stored in this region.

## ◆ IsEmpty()

virtual bool wxRegion::IsEmpty | ( |  | ) | const

virtual

Returns true if the region is empty, false otherwise.

Always returns true if the region is invalid.

## ◆ IsEqual()

bool wxRegion::IsEqual | ( | const wxRegion & | region | ) | const

Returns true if the region is equal to, i.e. covers the same area as, another one.

If both this region and region are both invalid, they are considered to be equal.

## ◆ Offset() [1/2]

bool wxRegion::Offset | ( | const wxPoint & | pt | ) |

Moves the region by the specified offsets in horizontal and vertical directions.

This method can't be called if the region is invalid as it doesn't make sense to offset it then. Attempts to do it will result in assert failure.

Returns
  true if successful, false otherwise (the region is unchanged then).

## ◆ Offset() [2/2]

bool wxRegion::Offset | ( | wxCoord | x,
|  | wxCoord | y
| ) |  |

Moves the region by the specified offsets in horizontal and vertical directions.

This method can't be called if the region is invalid as it doesn't make sense to offset it then. Attempts to do it will result in assert failure.

Returns
  true if successful, false otherwise (the region is unchanged then).

## ◆ operator=()

wxRegion& wxRegion::operator= | ( | const wxRegion & | region | ) |

Assignment operator, using Reference Counting.

## ◆ Subtract() [1/2]

bool wxRegion::Subtract | ( | const wxRect & | rect | ) |

Subtracts a rectangular region from this region.

This method always fails, i.e. returns false, if this region is invalid but may nevertheless be safely used even in this case.

Returns
  true if successful, false otherwise.

Remarks
  This operation combines the parts of 'this' region that are not part of the second region. The result is stored in this region.

## ◆ Subtract() [2/2]

bool wxRegion::Subtract | ( | const wxRegion & | region | ) |

Subtracts a region from this region.

This method always fails, i.e. returns false, if this region is invalid but may nevertheless be safely used even in this case.

Returns
  true if successful, false otherwise.

Remarks
  This operation combines the parts of 'this' region that are not part of the second region. The result is stored in this region.

## ◆ Union() [1/5]

bool wxRegion::Union | ( | const wxBitmap & | bmp | ) |

Finds the union of this region and the non-transparent pixels of a bitmap.

The bitmap's mask is used to determine transparency. If the bitmap doesn't have a mask, the bitmap's full dimensions are used.

Returns
  true if successful, false otherwise.

Remarks
  This operation creates a region that combines all of this region and the second region. The result is stored in this region.

## ◆ Union() [2/5]

bool wxRegion::Union | ( | const wxBitmap & | bmp,
|  | const wxColour & | transColour,
|  | int | tolerance = `0`
| ) |  |

Finds the union of this region and the non-transparent pixels of a bitmap.

Colour to be treated as transparent is specified in the transColour argument, along with an optional colour tolerance value.

Returns
  true if successful, false otherwise.

Remarks
  This operation creates a region that combines all of this region and the second region. The result is stored in this region.

## ◆ Union() [3/5]

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

Finds the union of this region and another, rectangular region.

This method can be used even if this region is invalid and has the natural behaviour in this case, i.e. makes this region equal to the given rectangle.

Returns
  true if successful, false otherwise.

Remarks
  This operation creates a region that combines all of this region and the second region. The result is stored in this region.

## ◆ Union() [4/5]

bool wxRegion::Union | ( | const wxRegion & | region | ) |

Finds the union of this region and another region.

This method can be used even if this region is invalid and has the natural behaviour in this case, i.e. makes this region equal to the given region.

Returns
  true if successful, false otherwise.

Remarks
  This operation creates a region that combines all of this region and the second region. The result is stored in this region.

## ◆ Union() [5/5]

bool wxRegion::Union | ( | wxCoord | x,
|  | wxCoord | y,
|  | wxCoord | width,
|  | wxCoord | height
| ) |  |

Finds the union of this region and another, rectangular region, specified using position and size.

This method can be used even if this region is invalid and has the natural behaviour in this case, i.e. makes this region equal to the given rectangle.

Returns
  true if successful, false otherwise.

Remarks
  This operation creates a region that combines all of this region and the second region. The result is stored in this region.

## ◆ Xor() [1/3]

bool wxRegion::Xor | ( | const wxRect & | rect | ) |

Finds the Xor of this region and another, rectangular region.

This method can be used even if this region is invalid and has the natural behaviour in this case, i.e. makes this region equal to the given rectangle.

Returns
  true if successful, false otherwise.

Remarks
  This operation creates a region that combines all of this region and the second region, except for any overlapping areas. The result is stored in this region.

## ◆ Xor() [2/3]

bool wxRegion::Xor | ( | const wxRegion & | region | ) |

Finds the Xor of this region and another region.

This method can be used even if this region is invalid and has the natural behaviour in this case, i.e. makes this region equal to the given region.

Returns
  true if successful, false otherwise.

Remarks
  This operation creates a region that combines all of this region and the second region, except for any overlapping areas. The result is stored in this region.

## ◆ Xor() [3/3]

bool wxRegion::Xor | ( | wxCoord | x,
|  | wxCoord | y,
|  | wxCoord | width,
|  | wxCoord | height
| ) |  |

Finds the Xor of this region and another, rectangular region, specified using position and size.

This method can be used even if this region is invalid and has the natural behaviour in this case, i.e. makes this region equal to the given rectangle.

Returns
  true if successful, false otherwise.

Remarks
  This operation creates a region that combines all of this region and the second region, except for any overlapping areas. The result is stored in this region.