1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxRegion class
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #include "wx/gdiobj.h"
17 #include "wx/gdicmn.h"
18 #include "wx/bitmap.h"
19 #include "wx/os2/private.h"
21 class WXDLLEXPORT wxRect
;
22 class WXDLLEXPORT wxPoint
;
24 enum wxRegionContain
{
25 wxOutRegion
= 0, wxPartRegion
= 1, wxInRegion
= 2
28 // So far, for internal use only
29 enum wxRegionOp
{ wxRGN_AND
// Creates the intersection of the two combined regions.
30 ,wxRGN_COPY
// Creates a copy of the region identified by hrgnSrc1.
31 ,wxRGN_DIFF
// Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
32 ,wxRGN_OR
// Creates the union of two combined regions.
33 ,wxRGN_XOR
// Creates the union of two combined regions except for any overlapping areas.
36 class WXDLLEXPORT wxRegion
: public wxGDIObject
44 wxRegion( const wxPoint
& rTopLeft
45 ,const wxPoint
& rBottomRight
47 wxRegion(const wxRect
& rRect
);
48 wxRegion(WXHRGN hRegion
, WXHDC hPS
); // Hangs on to this region
49 wxRegion( const wxBitmap
& bmp
)
53 wxRegion( const wxBitmap
& bmp
,
54 const wxColour
& transColour
, int tolerance
= 0)
56 Union(bmp
, transColour
, tolerance
);
65 inline wxRegion(const wxRegion
& rSrc
)
67 inline wxRegion
& operator = (const wxRegion
& rSrc
)
68 { Ref(rSrc
); return (*this); }
75 // Clear current region
79 bool Offset( wxCoord x
84 // Union rectangle or region with this.
86 inline bool Union( wxCoord x
99 inline bool Union( const wxRect
& rRect
) { return Combine(rRect
, wxRGN_OR
); }
100 inline bool Union(const wxRegion
& rRegion
) { return Combine(rRegion
, wxRGN_OR
); }
103 // Intersect rectangle or region with this.
105 inline bool Intersect( wxCoord x
118 inline bool Intersect(const wxRect
& rRect
) { return Combine(rRect
, wxRGN_AND
); }
119 inline bool Intersect(const wxRegion
& rRegion
) { return Combine(rRegion
, wxRGN_AND
); }
122 // Subtract rectangle or region from this:
123 // Combines the parts of 'this' that are not part of the second region.
125 inline bool Subtract( wxCoord x
138 inline bool Subtract(const wxRect
& rRect
) { return Combine(rRect
, wxRGN_DIFF
); }
139 inline bool Subtract(const wxRegion
& rRegion
) { return Combine(rRegion
, wxRGN_DIFF
); }
142 // XOR: the union of two combined regions except for any overlapping areas.
144 inline bool Xor( wxCoord x
157 inline bool Xor(const wxRect
& rRect
) { return Combine(rRect
, wxRGN_XOR
); }
158 inline bool Xor(const wxRegion
& rRegion
) { return Combine(rRegion
, wxRGN_XOR
); }
161 // Information on region
162 // Outer bounds of region
164 void GetBox( wxCoord
& rX
169 wxRect
GetBox(void) const;
174 bool Empty(void) const;
175 inline bool IsEmpty() const { return Empty(); }
179 // Does the region contain the point (x,y)?
181 wxRegionContain
Contains( wxCoord lX
186 // Convert the region to a B&W bitmap with the black pixels being inside
189 wxBitmap
ConvertToBitmap(void) const;
191 // Use the non-transparent pixels of a wxBitmap for the region to combine
192 // with this region. First version takes transparency from bitmap's mask,
193 // second lets the user specify the colour to be treated as transparent
194 // along with an optional tolerance value.
195 // NOTE: implemented in common/rgncmn.cpp
196 bool Union(const wxBitmap
& bmp
);
197 bool Union(const wxBitmap
& bmp
,
198 const wxColour
& transColour
, int tolerance
= 0);
201 // Does the region contain the point pt?
203 wxRegionContain
Contains(const wxPoint
& rPoint
) const;
206 // Does the region contain the rectangle (x, y, w, h)?
208 wxRegionContain
Contains( wxCoord x
215 // Does the region contain the rectangle rect?
217 wxRegionContain
Contains(const wxRect
& rRect
) const;
222 bool Combine( wxCoord x
228 bool Combine( const wxRegion
& rRegion
231 bool Combine( const wxRect
& rRect
236 // Get internal region handle
238 WXHRGN
GetHRGN(void) const;
242 virtual wxObjectRefData
* CreateData(void) const;
243 virtual wxObjectRefData
* CloneData(const wxObjectRefData
* pData
) const;
245 friend class WXDLLEXPORT wxRegionIterator
;
246 DECLARE_DYNAMIC_CLASS(wxRegion
);
248 }; // end of CLASS wxRegion
250 class WXDLLEXPORT wxRegionIterator
: public wxObject
252 DECLARE_DYNAMIC_CLASS(wxRegionIterator
);
255 wxRegionIterator(const wxRegion
& rRegion
);
258 void Reset(void) { m_lCurrent
= 0; }
259 void Reset(const wxRegion
& rRegion
);
261 operator bool (void) const { return m_lCurrent
< m_lNumRects
; }
262 bool HaveRects(void) const { return m_lCurrent
< m_lNumRects
; }
264 void operator ++ (void);
265 void operator ++ (int);
267 wxCoord
GetX(void) const;
268 wxCoord
GetY(void) const;
269 wxCoord
GetW(void) const;
270 wxCoord
GetWidth(void) const { return GetW(); }
271 wxCoord
GetH(void) const;
272 wxCoord
GetHeight(void) const { return GetH(); }
273 wxRect
GetRect(void) const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }
280 }; // end of wxRegionIterator