]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/region.h
Remove wrong const from wxMenu::GetMenuItems() documentation.
[wxWidgets.git] / interface / wx / region.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: region.h
e54c96f1 3// Purpose: interface of wxRegionIterator
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
526954c5 6// Licence: wxWindows licence
23324ae1
FM
7/////////////////////////////////////////////////////////////////////////////
8
bbc5b7f8
BP
9/**
10 Types of results returned from a call to wxRegion::Contains().
11*/
12enum wxRegionContain
13{
14 /** The specified value is not contained within this region. */
15 wxOutRegion = 0,
16
17 /**
18 The specified value is partially contained within this region.
19
20 On Windows, this result is not supported. ::wxInRegion will be returned
21 instead.
22 */
23 wxPartRegion = 1,
24
25 /**
26 The specified value is fully contained within this region.
27
28 On Windows, this result will be returned even if only part of the specified
29 value is contained in this region.
30 */
31 wxInRegion = 2
32};
33
23324ae1
FM
34/**
35 @class wxRegionIterator
7c913512 36
23324ae1
FM
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.
7c913512 39
23324ae1
FM
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
42 loop.
7c913512 43
23324ae1 44 See wxPaintEvent for an example of use.
7c913512 45
23324ae1 46 @library{wxcore}
de022e4f
RR
47 @category{gdi}
48
49 @stdobjects
50 ::wxNullRegion
7c913512 51
e54c96f1 52 @see wxPaintEvent
23324ae1
FM
53*/
54class wxRegionIterator : public wxObject
55{
56public:
23324ae1 57 /**
bbc5b7f8 58 Default constructor.
23324ae1
FM
59 */
60 wxRegionIterator();
bbc5b7f8
BP
61 /**
62 Creates an iterator object given a region.
63 */
7c913512 64 wxRegionIterator(const wxRegion& region);
23324ae1
FM
65
66 /**
bbc5b7f8 67 An alias for GetHeight().
23324ae1 68 */
328f5751 69 wxCoord GetH() const;
23324ae1
FM
70
71 /**
72 Returns the height value for the current region.
73 */
328f5751 74 wxCoord GetHeight() const;
23324ae1
FM
75
76 /**
77 Returns the current rectangle.
78 */
328f5751 79 wxRect GetRect() const;
23324ae1
FM
80
81 /**
bbc5b7f8 82 An alias for GetWidth().
23324ae1 83 */
328f5751 84 wxCoord GetW() const;
23324ae1
FM
85
86 /**
87 Returns the width value for the current region.
88 */
328f5751 89 wxCoord GetWidth() const;
23324ae1
FM
90
91 /**
92 Returns the x value for the current region.
93 */
328f5751 94 wxCoord GetX() const;
23324ae1
FM
95
96 /**
97 Returns the y value for the current region.
98 */
328f5751 99 wxCoord GetY() const;
23324ae1
FM
100
101 /**
102 Returns @true if there are still some rectangles; otherwise returns @false.
103 */
328f5751 104 bool HaveRects() const;
23324ae1 105
23324ae1 106 /**
bbc5b7f8 107 Resets the iterator to the beginning of the rectangles.
23324ae1
FM
108 */
109 void Reset();
bbc5b7f8
BP
110
111 /**
112 Resets the iterator to the given region.
113 */
7c913512 114 void Reset(const wxRegion& region);
23324ae1
FM
115
116 /**
117 Increment operator. Increments the iterator to the next region.
bbc5b7f8
BP
118
119 @beginWxPythonOnly
120 A wxPython alias for this operator is called Next.
121 @endWxPythonOnly
23324ae1 122 */
11e3af6e 123 wxRegionIterator& operator ++();
23324ae1
FM
124
125 /**
126 Returns @true if there are still some rectangles; otherwise returns @false.
bbc5b7f8
BP
127
128 You can use this to test the iterator object as if it were of type @c bool.
23324ae1 129 */
328f5751 130 operator bool() const;
23324ae1
FM
131};
132
133
e54c96f1 134
23324ae1
FM
135/**
136 @class wxRegion
7c913512 137
23324ae1 138 A wxRegion represents a simple or complex region on a device context or window.
7c913512 139
bbc5b7f8 140 This class uses @ref overview_refcount "reference counting and copy-on-write"
23324ae1
FM
141 internally so that assignments between two instances of this class are very
142 cheap. You can therefore use actual objects instead of pointers without
143 efficiency problems. If an instance of this class is changed it will create
144 its own data internally so that other instances, which previously shared the
145 data using the reference counting, are not affected.
7c913512 146
bbc5b7f8
BP
147 @stdobjects
148 - ::wxNullRegion
149
23324ae1 150 @library{wxcore}
c0cc7004 151 @category{data,gdi}
7c913512 152
e54c96f1 153 @see wxRegionIterator
23324ae1
FM
154*/
155class wxRegion : public wxGDIObject
156{
157public:
23324ae1 158 /**
bbc5b7f8 159 Default constructor.
dd4eefcb
VZ
160
161 This constructor creates an invalid, or null, object, i.e. calling
6cdab3b4 162 IsOk() on it returns @false and IsEmpty() returns @true.
23324ae1
FM
163 */
164 wxRegion();
bbc5b7f8
BP
165 /**
166 Constructs a rectangular region with the given position and size.
167 */
7c913512 168 wxRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
bbc5b7f8
BP
169 /**
170 Constructs a rectangular region from the top left point and the bottom right
171 point.
172 */
7c913512 173 wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight);
bbc5b7f8
BP
174 /**
175 Constructs a rectangular region a wxRect object.
176 */
7c913512 177 wxRegion(const wxRect& rect);
bbc5b7f8
BP
178 /**
179 Copy constructor, uses @ref overview_refcount.
180 */
7c913512 181 wxRegion(const wxRegion& region);
bbc5b7f8
BP
182 /**
183 Constructs a region corresponding to the polygon made of @a n points
184 in the provided array.
185 @a fillStyle parameter may have values @c wxWINDING_RULE or @c wxODDEVEN_RULE.
186 */
ccf39540 187 wxRegion(size_t n, const wxPoint* points, wxPolygonFillMode fillStyle = wxODDEVEN_RULE);
bbc5b7f8
BP
188 /**
189 Constructs a region using a bitmap. See Union() for more details.
190 */
7c913512 191 wxRegion(const wxBitmap& bmp);
bbc5b7f8
BP
192 /**
193 Constructs a region using the non-transparent pixels of a bitmap. See
194 Union() for more details.
195 */
7c913512
FM
196 wxRegion(const wxBitmap& bmp, const wxColour& transColour,
197 int tolerance = 0);
23324ae1
FM
198
199 /**
200 Destructor.
bbc5b7f8 201 See @ref overview_refcount_destruct "reference-counted object destruction" for
23324ae1
FM
202 more info.
203 */
adaaa686 204 virtual ~wxRegion();
23324ae1
FM
205
206 /**
207 Clears the current region.
dd4eefcb
VZ
208
209 The object becomes invalid, or null, after being cleared.
23324ae1 210 */
adaaa686 211 virtual void Clear();
23324ae1 212
bbc5b7f8
BP
213 /**
214 Returns a value indicating whether the given point is contained within the region.
215
dd4eefcb
VZ
216 This method always returns @c wxOutRegion for an invalid region but
217 may, nevertheless, be safely called in this case.
218
bbc5b7f8
BP
219 @return The return value is one of @c wxOutRegion and @c wxInRegion.
220 */
11e3af6e 221 wxRegionContain Contains(wxCoord x, wxCoord y) const;
bbc5b7f8
BP
222 /**
223 Returns a value indicating whether the given point is contained within the region.
224
dd4eefcb
VZ
225 This method always returns @c wxOutRegion for an invalid region but
226 may, nevertheless, be safely called in this case.
227
bbc5b7f8
BP
228 @return The return value is one of @c wxOutRegion and @c wxInRegion.
229 */
230 wxRegionContain Contains(const wxPoint& pt) const;
23324ae1
FM
231 /**
232 Returns a value indicating whether the given rectangle is contained within the
233 region.
3c4f71cc 234
dd4eefcb
VZ
235 This method always returns @c wxOutRegion for an invalid region but
236 may, nevertheless, be safely called in this case.
237
bbc5b7f8
BP
238 @return One of ::wxOutRegion, ::wxPartRegion or ::wxInRegion.
239
240 @note On Windows, only ::wxOutRegion and ::wxInRegion are returned; a value
241 ::wxInRegion then indicates that all or some part of the region is
242 contained in this region.
23324ae1 243 */
11e3af6e 244 wxRegionContain Contains(wxCoord x, wxCoord y, wxCoord width, wxCoord height) const;
bbc5b7f8
BP
245 /**
246 Returns a value indicating whether the given rectangle is contained within the
247 region.
248
dd4eefcb
VZ
249 This method always returns @c wxOutRegion for an invalid region but
250 may, nevertheless, be safely called in this case.
251
bbc5b7f8
BP
252 @return One of ::wxOutRegion, ::wxPartRegion or ::wxInRegion.
253
254 @note On Windows, only ::wxOutRegion and ::wxInRegion are returned; a value
255 ::wxInRegion then indicates that all or some part of the region is
256 contained in this region.
257 */
258 wxRegionContain Contains(const wxRect& rect) const;
23324ae1
FM
259
260 /**
261 Convert the region to a black and white bitmap with the white pixels
262 being inside the region.
dd4eefcb
VZ
263
264 This method can't be used for invalid region.
23324ae1 265 */
328f5751 266 wxBitmap ConvertToBitmap() const;
23324ae1
FM
267
268 //@{
269 /**
270 Returns the outer bounds of the region.
dd4eefcb
VZ
271
272 This method returns 0-sized bounding box for invalid regions.
23324ae1
FM
273 */
274 void GetBox(wxCoord& x, wxCoord& y, wxCoord& width,
328f5751 275 wxCoord& height) const;
11e3af6e 276 wxRect GetBox() const;
23324ae1
FM
277 //@}
278
23324ae1 279 /**
bbc5b7f8
BP
280 Finds the intersection of this region and another, rectangular region,
281 specified using position and size.
3c4f71cc 282
dd4eefcb
VZ
283 This method always fails, i.e. returns @false, if this region is
284 invalid but may nevertheless be safely used even in this case.
285
d29a9a8a 286 @return @true if successful, @false otherwise.
3c4f71cc 287
23324ae1 288 @remarks Creates the intersection of the two regions, that is, the parts
4cc4bfaf
FM
289 which are in both regions. The result is stored in this
290 region.
23324ae1
FM
291 */
292 bool Intersect(wxCoord x, wxCoord y, wxCoord width,
293 wxCoord height);
bbc5b7f8
BP
294 /**
295 Finds the intersection of this region and another, rectangular region.
296
dd4eefcb
VZ
297 This method always fails, i.e. returns @false, if this region is
298 invalid but may nevertheless be safely used even in this case.
299
bbc5b7f8
BP
300 @return @true if successful, @false otherwise.
301
302 @remarks Creates the intersection of the two regions, that is, the parts
303 which are in both regions. The result is stored in this
304 region.
305 */
7c913512 306 bool Intersect(const wxRect& rect);
bbc5b7f8
BP
307 /**
308 Finds the intersection of this region and another region.
309
dd4eefcb
VZ
310 This method always fails, i.e. returns @false, if this region is
311 invalid but may nevertheless be safely used even in this case.
312
bbc5b7f8
BP
313 @return @true if successful, @false otherwise.
314
315 @remarks Creates the intersection of the two regions, that is, the parts
316 which are in both regions. The result is stored in this
317 region.
318 */
7c913512 319 bool Intersect(const wxRegion& region);
23324ae1
FM
320
321 /**
322 Returns @true if the region is empty, @false otherwise.
dd4eefcb
VZ
323
324 Always returns @true if the region is invalid.
23324ae1 325 */
adaaa686 326 virtual bool IsEmpty() const;
23324ae1
FM
327
328 /**
329 Returns @true if the region is equal to, i.e. covers the same area as,
bbc5b7f8
BP
330 another one.
331
dd4eefcb
VZ
332 If both this region and @a region are both invalid, they are considered
333 to be equal.
23324ae1 334 */
328f5751 335 bool IsEqual(const wxRegion& region) const;
23324ae1
FM
336
337 //@{
338 /**
339 Moves the region by the specified offsets in horizontal and vertical
340 directions.
3c4f71cc 341
dd4eefcb
VZ
342 This method can't be called if the region is invalid as it doesn't make
343 sense to offset it then. Attempts to do it will result in assert
344 failure.
345
d29a9a8a 346 @return @true if successful, @false otherwise (the region is unchanged
4cc4bfaf 347 then).
23324ae1
FM
348 */
349 bool Offset(wxCoord x, wxCoord y);
7c913512 350 bool Offset(const wxPoint& pt);
23324ae1
FM
351 //@}
352
23324ae1 353 /**
bbc5b7f8 354 Subtracts a rectangular region from this region.
3c4f71cc 355
dd4eefcb
VZ
356 This method always fails, i.e. returns @false, if this region is
357 invalid but may nevertheless be safely used even in this case.
358
d29a9a8a 359 @return @true if successful, @false otherwise.
3c4f71cc 360
23324ae1 361 @remarks This operation combines the parts of 'this' region that are not
4cc4bfaf
FM
362 part of the second region. The result is stored in this
363 region.
23324ae1
FM
364 */
365 bool Subtract(const wxRect& rect);
bbc5b7f8
BP
366 /**
367 Subtracts a region from this region.
368
dd4eefcb
VZ
369 This method always fails, i.e. returns @false, if this region is
370 invalid but may nevertheless be safely used even in this case.
371
bbc5b7f8
BP
372 @return @true if successful, @false otherwise.
373
374 @remarks This operation combines the parts of 'this' region that are not
375 part of the second region. The result is stored in this
376 region.
377 */
7c913512 378 bool Subtract(const wxRegion& region);
23324ae1 379
23324ae1 380 /**
bbc5b7f8
BP
381 Finds the union of this region and another, rectangular region, specified using
382 position and size.
3c4f71cc 383
dd4eefcb
VZ
384 This method can be used even if this region is invalid and has the
385 natural behaviour in this case, i.e. makes this region equal to the
386 given rectangle.
387
d29a9a8a 388 @return @true if successful, @false otherwise.
3c4f71cc 389
23324ae1 390 @remarks This operation creates a region that combines all of this region
4cc4bfaf
FM
391 and the second region. The result is stored in this
392 region.
23324ae1
FM
393 */
394 bool Union(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
bbc5b7f8
BP
395 /**
396 Finds the union of this region and another, rectangular region.
397
dd4eefcb
VZ
398 This method can be used even if this region is invalid and has the
399 natural behaviour in this case, i.e. makes this region equal to the
400 given rectangle.
401
bbc5b7f8
BP
402 @return @true if successful, @false otherwise.
403
404 @remarks This operation creates a region that combines all of this region
405 and the second region. The result is stored in this
406 region.
407 */
7c913512 408 bool Union(const wxRect& rect);
bbc5b7f8
BP
409 /**
410 Finds the union of this region and another region.
411
dd4eefcb
VZ
412 This method can be used even if this region is invalid and has the
413 natural behaviour in this case, i.e. makes this region equal to the
414 given @a region.
415
bbc5b7f8
BP
416 @return @true if successful, @false otherwise.
417
418 @remarks This operation creates a region that combines all of this region
419 and the second region. The result is stored in this
420 region.
421 */
7c913512 422 bool Union(const wxRegion& region);
bbc5b7f8
BP
423 /**
424 Finds the union of this region and the non-transparent pixels of a
425 bitmap. The bitmap's mask is used to determine transparency. If the
426 bitmap doesn't have a mask, the bitmap's full dimensions are used.
427
428 @return @true if successful, @false otherwise.
429
430 @remarks This operation creates a region that combines all of this region
431 and the second region. The result is stored in this
432 region.
433 */
7c913512 434 bool Union(const wxBitmap& bmp);
bbc5b7f8
BP
435 /**
436 Finds the union of this region and the non-transparent pixels of a
437 bitmap. Colour to be treated as transparent is specified in the
438 @a transColour argument, along with an optional colour tolerance value.
439
440 @return @true if successful, @false otherwise.
441
442 @remarks This operation creates a region that combines all of this region
443 and the second region. The result is stored in this
444 region.
445 */
7c913512
FM
446 bool Union(const wxBitmap& bmp, const wxColour& transColour,
447 int tolerance = 0);
23324ae1 448
23324ae1 449 /**
bbc5b7f8
BP
450 Finds the Xor of this region and another, rectangular region, specified using
451 position and size.
3c4f71cc 452
dd4eefcb
VZ
453 This method can be used even if this region is invalid and has the
454 natural behaviour in this case, i.e. makes this region equal to the
455 given rectangle.
456
d29a9a8a 457 @return @true if successful, @false otherwise.
3c4f71cc 458
23324ae1 459 @remarks This operation creates a region that combines all of this region
4cc4bfaf
FM
460 and the second region, except for any overlapping
461 areas. The result is stored in this region.
23324ae1
FM
462 */
463 bool Xor(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
bbc5b7f8
BP
464 /**
465 Finds the Xor of this region and another, rectangular region.
466
dd4eefcb
VZ
467 This method can be used even if this region is invalid and has the
468 natural behaviour in this case, i.e. makes this region equal to the
469 given rectangle.
470
bbc5b7f8
BP
471 @return @true if successful, @false otherwise.
472
473 @remarks This operation creates a region that combines all of this region
474 and the second region, except for any overlapping
475 areas. The result is stored in this region.
476 */
7c913512 477 bool Xor(const wxRect& rect);
bbc5b7f8
BP
478 /**
479 Finds the Xor of this region and another region.
480
dd4eefcb
VZ
481 This method can be used even if this region is invalid and has the
482 natural behaviour in this case, i.e. makes this region equal to the
483 given @a region.
484
bbc5b7f8
BP
485 @return @true if successful, @false otherwise.
486
487 @remarks This operation creates a region that combines all of this region
488 and the second region, except for any overlapping
489 areas. The result is stored in this region.
490 */
7c913512 491 bool Xor(const wxRegion& region);
23324ae1
FM
492
493 /**
bbc5b7f8 494 Assignment operator, using @ref overview_refcount.
23324ae1 495 */
43c48e1e 496 wxRegion& operator=(const wxRegion& region);
23324ae1 497};
e54c96f1 498
bbc5b7f8
BP
499/**
500 An empty region.
501*/
502wxRegion wxNullRegion;