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