1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxRegionIterator
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
10 Types of results returned from a call to wxRegion::Contains().
14 /** The specified value is not contained within this region. */
18 The specified value is partially contained within this region.
20 On Windows, this result is not supported. ::wxInRegion will be returned
26 The specified value is fully contained within this region.
28 On Windows, this result will be returned even if only part of the specified
29 value is contained in this region.
35 @class wxRegionIterator
37 This class is used to iterate through the rectangles in a region,
38 typically when examining the damaged regions of a window within an OnPaint call.
40 To use it, construct an iterator object on the stack and loop through the
41 regions, testing the object and incrementing the iterator at the end of the
44 See wxPaintEvent for an example of use.
54 class wxRegionIterator
: public wxObject
62 Creates an iterator object given a region.
64 wxRegionIterator(const wxRegion
& region
);
67 An alias for GetHeight().
72 Returns the height value for the current region.
74 wxCoord
GetHeight() const;
77 Returns the current rectangle.
79 wxRect
GetRect() const;
82 An alias for GetWidth().
87 Returns the width value for the current region.
89 wxCoord
GetWidth() const;
92 Returns the x value for the current region.
97 Returns the y value for the current region.
102 Returns @true if there are still some rectangles; otherwise returns @false.
104 bool HaveRects() const;
107 Resets the iterator to the beginning of the rectangles.
112 Resets the iterator to the given region.
114 void Reset(const wxRegion
& region
);
117 Increment operator. Increments the iterator to the next region.
119 wxRegionIterator
& operator ++();
122 Returns @true if there are still some rectangles; otherwise returns @false.
124 You can use this to test the iterator object as if it were of type @c bool.
126 operator bool() const;
134 A wxRegion represents a simple or complex region on a device context or window.
136 This class uses @ref overview_refcount "reference counting and copy-on-write"
137 internally so that assignments between two instances of this class are very
138 cheap. You can therefore use actual objects instead of pointers without
139 efficiency problems. If an instance of this class is changed it will create
140 its own data internally so that other instances, which previously shared the
141 data using the reference counting, are not affected.
149 @see wxRegionIterator
151 class wxRegion
: public wxGDIObject
157 This constructor creates an invalid, or null, object, i.e. calling
158 IsOk() on it returns @false and IsEmpty() returns @true.
162 Constructs a rectangular region with the given position and size.
164 wxRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
166 Constructs a rectangular region from the top left point and the bottom right
169 wxRegion(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
171 Constructs a rectangular region a wxRect object.
173 wxRegion(const wxRect
& rect
);
175 Copy constructor, uses @ref overview_refcount.
177 wxRegion(const wxRegion
& region
);
179 Constructs a region corresponding to the polygon made of @a n points
180 in the provided array.
181 @a fillStyle parameter may have values @c wxWINDING_RULE or @c wxODDEVEN_RULE.
183 wxRegion(size_t n
, const wxPoint
* points
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
);
185 Constructs a region using a bitmap. See Union() for more details.
187 wxRegion(const wxBitmap
& bmp
);
189 Constructs a region using the non-transparent pixels of a bitmap. See
190 Union() for more details.
192 wxRegion(const wxBitmap
& bmp
, const wxColour
& transColour
,
197 See @ref overview_refcount_destruct "reference-counted object destruction" for
203 Clears the current region.
205 The object becomes invalid, or null, after being cleared.
207 virtual void Clear();
210 Returns a value indicating whether the given point is contained within the region.
212 This method always returns @c wxOutRegion for an invalid region but
213 may, nevertheless, be safely called in this case.
215 @return The return value is one of @c wxOutRegion and @c wxInRegion.
217 wxRegionContain
Contains(wxCoord x
, wxCoord y
) const;
219 Returns a value indicating whether the given point is contained within the region.
221 This method always returns @c wxOutRegion for an invalid region but
222 may, nevertheless, be safely called in this case.
224 @return The return value is one of @c wxOutRegion and @c wxInRegion.
226 wxRegionContain
Contains(const wxPoint
& pt
) const;
228 Returns a value indicating whether the given rectangle is contained within the
231 This method always returns @c wxOutRegion for an invalid region but
232 may, nevertheless, be safely called in this case.
234 @return One of ::wxOutRegion, ::wxPartRegion or ::wxInRegion.
236 @note On Windows, only ::wxOutRegion and ::wxInRegion are returned; a value
237 ::wxInRegion then indicates that all or some part of the region is
238 contained in this region.
240 wxRegionContain
Contains(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
) const;
242 Returns a value indicating whether the given rectangle is contained within the
245 This method always returns @c wxOutRegion for an invalid region but
246 may, nevertheless, be safely called in this case.
248 @return One of ::wxOutRegion, ::wxPartRegion or ::wxInRegion.
250 @note On Windows, only ::wxOutRegion and ::wxInRegion are returned; a value
251 ::wxInRegion then indicates that all or some part of the region is
252 contained in this region.
254 wxRegionContain
Contains(const wxRect
& rect
) const;
257 Convert the region to a black and white bitmap with the white pixels
258 being inside the region.
260 This method can't be used for invalid region.
262 wxBitmap
ConvertToBitmap() const;
266 Returns the outer bounds of the region.
268 This method returns 0-sized bounding box for invalid regions.
270 void GetBox(wxCoord
& x
, wxCoord
& y
, wxCoord
& width
,
271 wxCoord
& height
) const;
272 wxRect
GetBox() const;
276 Finds the intersection of this region and another, rectangular region,
277 specified using position and size.
279 This method always fails, i.e. returns @false, if this region is
280 invalid but may nevertheless be safely used even in this case.
282 @return @true if successful, @false otherwise.
284 @remarks Creates the intersection of the two regions, that is, the parts
285 which are in both regions. The result is stored in this
288 bool Intersect(wxCoord x
, wxCoord y
, wxCoord width
,
291 Finds the intersection of this region and another, rectangular region.
293 This method always fails, i.e. returns @false, if this region is
294 invalid but may nevertheless be safely used even in this case.
296 @return @true if successful, @false otherwise.
298 @remarks Creates the intersection of the two regions, that is, the parts
299 which are in both regions. The result is stored in this
302 bool Intersect(const wxRect
& rect
);
304 Finds the intersection of this region and another region.
306 This method always fails, i.e. returns @false, if this region is
307 invalid but may nevertheless be safely used even in this case.
309 @return @true if successful, @false otherwise.
311 @remarks Creates the intersection of the two regions, that is, the parts
312 which are in both regions. The result is stored in this
315 bool Intersect(const wxRegion
& region
);
318 Returns @true if the region is empty, @false otherwise.
320 Always returns @true if the region is invalid.
322 virtual bool IsEmpty() const;
325 Returns @true if the region is equal to, i.e.\ covers the same area as,
328 If both this region and @a region are both invalid, they are considered
331 bool IsEqual(const wxRegion
& region
) const;
335 Moves the region by the specified offsets in horizontal and vertical
338 This method can't be called if the region is invalid as it doesn't make
339 sense to offset it then. Attempts to do it will result in assert
342 @return @true if successful, @false otherwise (the region is unchanged
345 bool Offset(wxCoord x
, wxCoord y
);
346 bool Offset(const wxPoint
& pt
);
350 Subtracts a rectangular region from this region.
352 This method always fails, i.e. returns @false, if this region is
353 invalid but may nevertheless be safely used even in this case.
355 @return @true if successful, @false otherwise.
357 @remarks This operation combines the parts of 'this' region that are not
358 part of the second region. The result is stored in this
361 bool Subtract(const wxRect
& rect
);
363 Subtracts a region from this region.
365 This method always fails, i.e. returns @false, if this region is
366 invalid but may nevertheless be safely used even in this case.
368 @return @true if successful, @false otherwise.
370 @remarks This operation combines the parts of 'this' region that are not
371 part of the second region. The result is stored in this
374 bool Subtract(const wxRegion
& region
);
377 Finds the union of this region and another, rectangular region, specified using
380 This method can be used even if this region is invalid and has the
381 natural behaviour in this case, i.e. makes this region equal to the
384 @return @true if successful, @false otherwise.
386 @remarks This operation creates a region that combines all of this region
387 and the second region. The result is stored in this
390 bool Union(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
392 Finds the union of this region and another, rectangular region.
394 This method can be used even if this region is invalid and has the
395 natural behaviour in this case, i.e. makes this region equal to the
398 @return @true if successful, @false otherwise.
400 @remarks This operation creates a region that combines all of this region
401 and the second region. The result is stored in this
404 bool Union(const wxRect
& rect
);
406 Finds the union of this region and another region.
408 This method can be used even if this region is invalid and has the
409 natural behaviour in this case, i.e. makes this region equal to the
412 @return @true if successful, @false otherwise.
414 @remarks This operation creates a region that combines all of this region
415 and the second region. The result is stored in this
418 bool Union(const wxRegion
& region
);
420 Finds the union of this region and the non-transparent pixels of a
421 bitmap. The bitmap's mask is used to determine transparency. If the
422 bitmap doesn't have a mask, the bitmap's full dimensions are used.
424 @return @true if successful, @false otherwise.
426 @remarks This operation creates a region that combines all of this region
427 and the second region. The result is stored in this
430 bool Union(const wxBitmap
& bmp
);
432 Finds the union of this region and the non-transparent pixels of a
433 bitmap. Colour to be treated as transparent is specified in the
434 @a transColour argument, along with an optional colour tolerance value.
436 @return @true if successful, @false otherwise.
438 @remarks This operation creates a region that combines all of this region
439 and the second region. The result is stored in this
442 bool Union(const wxBitmap
& bmp
, const wxColour
& transColour
,
446 Finds the Xor of this region and another, rectangular region, specified using
449 This method can be used even if this region is invalid and has the
450 natural behaviour in this case, i.e. makes this region equal to the
453 @return @true if successful, @false otherwise.
455 @remarks This operation creates a region that combines all of this region
456 and the second region, except for any overlapping
457 areas. The result is stored in this region.
459 bool Xor(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
461 Finds the Xor of this region and another, rectangular region.
463 This method can be used even if this region is invalid and has the
464 natural behaviour in this case, i.e. makes this region equal to the
467 @return @true if successful, @false otherwise.
469 @remarks This operation creates a region that combines all of this region
470 and the second region, except for any overlapping
471 areas. The result is stored in this region.
473 bool Xor(const wxRect
& rect
);
475 Finds the Xor of this region and another region.
477 This method can be used even if this region is invalid and has the
478 natural behaviour in this case, i.e. makes this region equal to the
481 @return @true if successful, @false otherwise.
483 @remarks This operation creates a region that combines all of this region
484 and the second region, except for any overlapping
485 areas. The result is stored in this region.
487 bool Xor(const wxRegion
& region
);
490 Assignment operator, using @ref overview_refcount.
492 wxRegion
& operator=(const wxRegion
& region
);
498 wxRegion wxNullRegion
;