| 1 | ///////////////////////////////////////////////////////////////////////////// |
| 2 | // Name: region.h |
| 3 | // Purpose: wxRegion class |
| 4 | // Author: David Webster |
| 5 | // Modified by: |
| 6 | // Created: 10/15/99 |
| 7 | // RCS-ID: $Id$ |
| 8 | // Copyright: (c) David Webster |
| 9 | // Licence: wxWindows licence |
| 10 | ///////////////////////////////////////////////////////////////////////////// |
| 11 | |
| 12 | #ifndef _WX_REGION_H_ |
| 13 | #define _WX_REGION_H_ |
| 14 | |
| 15 | #include "wx/list.h" |
| 16 | #include "wx/gdiobj.h" |
| 17 | #include "wx/gdicmn.h" |
| 18 | #include "wx/os2/private.h" |
| 19 | |
| 20 | class WXDLLEXPORT wxRect; |
| 21 | class WXDLLEXPORT wxPoint; |
| 22 | |
| 23 | enum wxRegionContain { |
| 24 | wxOutRegion = 0, wxPartRegion = 1, wxInRegion = 2 |
| 25 | }; |
| 26 | |
| 27 | // So far, for internal use only |
| 28 | enum wxRegionOp { wxRGN_AND // Creates the intersection of the two combined regions. |
| 29 | ,wxRGN_COPY // Creates a copy of the region identified by hrgnSrc1. |
| 30 | ,wxRGN_DIFF // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2. |
| 31 | ,wxRGN_OR // Creates the union of two combined regions. |
| 32 | ,wxRGN_XOR // Creates the union of two combined regions except for any overlapping areas. |
| 33 | }; |
| 34 | |
| 35 | class WXDLLEXPORT wxRegion : public wxGDIObject |
| 36 | { |
| 37 | public: |
| 38 | wxRegion( wxCoord x |
| 39 | ,wxCoord y |
| 40 | ,wxCoord vWidth |
| 41 | ,wxCoord vHeight |
| 42 | ); |
| 43 | wxRegion( const wxPoint& rTopLeft |
| 44 | ,const wxPoint& rBottomRight |
| 45 | ); |
| 46 | wxRegion(const wxRect& rRect); |
| 47 | wxRegion(WXHRGN hRegion, WXHDC hPS); // Hangs on to this region |
| 48 | |
| 49 | wxRegion(); |
| 50 | ~wxRegion(); |
| 51 | |
| 52 | // |
| 53 | // Copying |
| 54 | // |
| 55 | inline wxRegion(const wxRegion& rSrc) |
| 56 | { Ref(rSrc); } |
| 57 | inline wxRegion& operator = (const wxRegion& rSrc) |
| 58 | { Ref(rSrc); return (*this); } |
| 59 | |
| 60 | // |
| 61 | // Modify region |
| 62 | // |
| 63 | |
| 64 | // |
| 65 | // Clear current region |
| 66 | // |
| 67 | void Clear(void); |
| 68 | |
| 69 | bool Offset( wxCoord x |
| 70 | ,wxCoord y |
| 71 | ); |
| 72 | |
| 73 | // |
| 74 | // Union rectangle or region with this. |
| 75 | // |
| 76 | inline bool Union( wxCoord x |
| 77 | ,wxCoord y |
| 78 | ,wxCoord vWidth |
| 79 | ,wxCoord vHeight |
| 80 | ) |
| 81 | { |
| 82 | return Combine( x |
| 83 | ,y |
| 84 | ,vWidth |
| 85 | ,vHeight |
| 86 | ,wxRGN_OR |
| 87 | ); |
| 88 | } |
| 89 | inline bool Union( const wxRect& rRect) { return Combine(rRect, wxRGN_OR); } |
| 90 | inline bool Union(const wxRegion& rRegion) { return Combine(rRegion, wxRGN_OR); } |
| 91 | |
| 92 | // |
| 93 | // Intersect rectangle or region with this. |
| 94 | // |
| 95 | inline bool Intersect( wxCoord x |
| 96 | ,wxCoord y |
| 97 | ,wxCoord vWidth |
| 98 | ,wxCoord vHeight |
| 99 | ) |
| 100 | { |
| 101 | return Combine( x |
| 102 | ,y |
| 103 | ,vWidth |
| 104 | ,vHeight |
| 105 | ,wxRGN_AND |
| 106 | ); |
| 107 | } |
| 108 | inline bool Intersect(const wxRect& rRect) { return Combine(rRect, wxRGN_AND); } |
| 109 | inline bool Intersect(const wxRegion& rRegion) { return Combine(rRegion, wxRGN_AND); } |
| 110 | |
| 111 | // |
| 112 | // Subtract rectangle or region from this: |
| 113 | // Combines the parts of 'this' that are not part of the second region. |
| 114 | // |
| 115 | inline bool Subtract( wxCoord x |
| 116 | ,wxCoord y |
| 117 | ,wxCoord vWidth |
| 118 | ,wxCoord vHeight |
| 119 | ) |
| 120 | { |
| 121 | return Combine( x |
| 122 | ,y |
| 123 | ,vWidth |
| 124 | ,vHeight |
| 125 | ,wxRGN_DIFF |
| 126 | ); |
| 127 | } |
| 128 | inline bool Subtract(const wxRect& rRect) { return Combine(rRect, wxRGN_DIFF); } |
| 129 | inline bool Subtract(const wxRegion& rRegion) { return Combine(rRegion, wxRGN_DIFF); } |
| 130 | |
| 131 | // |
| 132 | // XOR: the union of two combined regions except for any overlapping areas. |
| 133 | // |
| 134 | inline bool Xor( wxCoord x |
| 135 | ,wxCoord y |
| 136 | ,wxCoord vWidth |
| 137 | ,wxCoord vHeight |
| 138 | ) |
| 139 | { |
| 140 | return Combine( x |
| 141 | ,y |
| 142 | ,vWidth |
| 143 | ,vHeight |
| 144 | ,wxRGN_XOR |
| 145 | ); |
| 146 | } |
| 147 | inline bool Xor(const wxRect& rRect) { return Combine(rRect, wxRGN_XOR); } |
| 148 | inline bool Xor(const wxRegion& rRegion) { return Combine(rRegion, wxRGN_XOR); } |
| 149 | |
| 150 | // |
| 151 | // Information on region |
| 152 | // Outer bounds of region |
| 153 | // |
| 154 | void GetBox( wxCoord& rX |
| 155 | ,wxCoord& rY |
| 156 | ,wxCoord& rWidth |
| 157 | ,wxCoord& rHeight |
| 158 | ) const; |
| 159 | wxRect GetBox(void) const; |
| 160 | |
| 161 | // |
| 162 | // Is region empty? |
| 163 | // |
| 164 | bool Empty(void) const; |
| 165 | inline bool IsEmpty() const { return Empty(); } |
| 166 | |
| 167 | // |
| 168 | // Tests |
| 169 | // Does the region contain the point (x,y)? |
| 170 | // |
| 171 | wxRegionContain Contains( wxCoord lX |
| 172 | ,wxCoord lY |
| 173 | ) const; |
| 174 | |
| 175 | // |
| 176 | // Convert the region to a B&W bitmap with the black pixels being inside |
| 177 | // the region. |
| 178 | // |
| 179 | wxBitmap ConvertToBitmap(void) const; |
| 180 | |
| 181 | // Use the non-transparent pixels of a wxBitmap for the region to combine |
| 182 | // with this region. If the bitmap has a mask then it will be used, |
| 183 | // otherwise the colour to be treated as transparent may be specified, |
| 184 | // along with an optional tolerance value. |
| 185 | bool Union( const wxBitmap& rBmp |
| 186 | ,const wxColour& rTransColour = wxNullColour |
| 187 | ,int nTolerance = 0 |
| 188 | ); |
| 189 | |
| 190 | // |
| 191 | // Does the region contain the point pt? |
| 192 | // |
| 193 | wxRegionContain Contains(const wxPoint& rPoint) const; |
| 194 | |
| 195 | // |
| 196 | // Does the region contain the rectangle (x, y, w, h)? |
| 197 | // |
| 198 | wxRegionContain Contains( wxCoord x |
| 199 | ,wxCoord y |
| 200 | ,wxCoord lWidth |
| 201 | ,wxCoord lHeight |
| 202 | ) const; |
| 203 | |
| 204 | // |
| 205 | // Does the region contain the rectangle rect? |
| 206 | // |
| 207 | wxRegionContain Contains(const wxRect& rRect) const; |
| 208 | |
| 209 | // |
| 210 | // Internal |
| 211 | // |
| 212 | bool Combine( wxCoord x |
| 213 | ,wxCoord y |
| 214 | ,wxCoord vWidth |
| 215 | ,wxCoord vHeight |
| 216 | ,wxRegionOp eOp |
| 217 | ); |
| 218 | bool Combine( const wxRegion& rRegion |
| 219 | ,wxRegionOp eOp |
| 220 | ); |
| 221 | bool Combine( const wxRect& rRect |
| 222 | ,wxRegionOp eOp |
| 223 | ); |
| 224 | |
| 225 | // |
| 226 | // Get internal region handle |
| 227 | // |
| 228 | WXHRGN GetHRGN(void) const; |
| 229 | void SetPS(HPS hPS); |
| 230 | |
| 231 | protected: |
| 232 | virtual wxObjectRefData* CreateData(void) const; |
| 233 | virtual wxObjectRefData* CloneData(const wxObjectRefData* pData) const; |
| 234 | |
| 235 | friend class WXDLLEXPORT wxRegionIterator; |
| 236 | DECLARE_DYNAMIC_CLASS(wxRegion); |
| 237 | |
| 238 | }; // end of CLASS wxRegion |
| 239 | |
| 240 | class WXDLLEXPORT wxRegionIterator : public wxObject |
| 241 | { |
| 242 | DECLARE_DYNAMIC_CLASS(wxRegionIterator); |
| 243 | public: |
| 244 | wxRegionIterator(); |
| 245 | wxRegionIterator(const wxRegion& rRegion); |
| 246 | ~wxRegionIterator(); |
| 247 | |
| 248 | void Reset(void) { m_lCurrent = 0; } |
| 249 | void Reset(const wxRegion& rRegion); |
| 250 | |
| 251 | operator bool (void) const { return m_lCurrent < m_lNumRects; } |
| 252 | bool HaveRects(void) const { return m_lCurrent < m_lNumRects; } |
| 253 | |
| 254 | void operator ++ (void); |
| 255 | void operator ++ (int); |
| 256 | |
| 257 | wxCoord GetX(void) const; |
| 258 | wxCoord GetY(void) const; |
| 259 | wxCoord GetW(void) const; |
| 260 | wxCoord GetWidth(void) const { return GetW(); } |
| 261 | wxCoord GetH(void) const; |
| 262 | wxCoord GetHeight(void) const { return GetH(); } |
| 263 | wxRect GetRect(void) const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); } |
| 264 | |
| 265 | private: |
| 266 | long m_lCurrent; |
| 267 | long m_lNumRects; |
| 268 | wxRegion m_vRegion; |
| 269 | wxRect* m_pRects; |
| 270 | }; // end of wxRegionIterator |
| 271 | |
| 272 | #endif |
| 273 | // _WX_REGION_H_ |