region.h 16 KB

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