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/os2/private.h"
20 class WXDLLEXPORT wxRect
;
21 class WXDLLEXPORT wxPoint
;
23 enum wxRegionContain
{
24 wxOutRegion
= 0, wxPartRegion
= 1, wxInRegion
= 2
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.
35 class WXDLLEXPORT wxRegion
: public wxGDIObject
43 wxRegion( const wxPoint
& rTopLeft
44 ,const wxPoint
& rBottomRight
46 wxRegion(const wxRect
& rRect
);
47 wxRegion(WXHRGN hRegion
, WXHDC hPS
); // Hangs on to this region
55 inline wxRegion(const wxRegion
& rSrc
)
57 inline wxRegion
& operator = (const wxRegion
& rSrc
)
58 { Ref(rSrc
); return (*this); }
65 // Clear current region
69 bool Offset( wxCoord x
74 // Union rectangle or region with this.
76 inline bool Union( wxCoord x
89 inline bool Union( const wxRect
& rRect
) { return Combine(rRect
, wxRGN_OR
); }
90 inline bool Union(const wxRegion
& rRegion
) { return Combine(rRegion
, wxRGN_OR
); }
93 // Intersect rectangle or region with this.
95 inline bool Intersect( wxCoord x
108 inline bool Intersect(const wxRect
& rRect
) { return Combine(rRect
, wxRGN_AND
); }
109 inline bool Intersect(const wxRegion
& rRegion
) { return Combine(rRegion
, wxRGN_AND
); }
112 // Subtract rectangle or region from this:
113 // Combines the parts of 'this' that are not part of the second region.
115 inline bool Subtract( wxCoord x
128 inline bool Subtract(const wxRect
& rRect
) { return Combine(rRect
, wxRGN_DIFF
); }
129 inline bool Subtract(const wxRegion
& rRegion
) { return Combine(rRegion
, wxRGN_DIFF
); }
132 // XOR: the union of two combined regions except for any overlapping areas.
134 inline bool Xor( wxCoord x
147 inline bool Xor(const wxRect
& rRect
) { return Combine(rRect
, wxRGN_XOR
); }
148 inline bool Xor(const wxRegion
& rRegion
) { return Combine(rRegion
, wxRGN_XOR
); }
151 // Information on region
152 // Outer bounds of region
154 void GetBox( wxCoord
& rX
159 wxRect
GetBox(void) const;
164 bool Empty(void) const;
165 inline bool IsEmpty() const { return Empty(); }
169 // Does the region contain the point (x,y)?
171 wxRegionContain
Contains( wxCoord lX
176 // Convert the region to a B&W bitmap with the black pixels being inside
179 wxBitmap
ConvertToBitmap(void) const;
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
191 // Does the region contain the point pt?
193 wxRegionContain
Contains(const wxPoint
& rPoint
) const;
196 // Does the region contain the rectangle (x, y, w, h)?
198 wxRegionContain
Contains( wxCoord x
205 // Does the region contain the rectangle rect?
207 wxRegionContain
Contains(const wxRect
& rRect
) const;
212 bool Combine( wxCoord x
218 bool Combine( const wxRegion
& rRegion
221 bool Combine( const wxRect
& rRect
226 // Get internal region handle
228 WXHRGN
GetHRGN(void) const;
232 virtual wxObjectRefData
* CreateData(void) const;
233 virtual wxObjectRefData
* CloneData(const wxObjectRefData
* pData
) const;
235 friend class WXDLLEXPORT wxRegionIterator
;
236 DECLARE_DYNAMIC_CLASS(wxRegion
);
238 }; // end of CLASS wxRegion
240 class WXDLLEXPORT wxRegionIterator
: public wxObject
242 DECLARE_DYNAMIC_CLASS(wxRegionIterator
);
245 wxRegionIterator(const wxRegion
& rRegion
);
248 void Reset(void) { m_lCurrent
= 0; }
249 void Reset(const wxRegion
& rRegion
);
251 operator bool (void) const { return m_lCurrent
< m_lNumRects
; }
252 bool HaveRects(void) const { return m_lCurrent
< m_lNumRects
; }
254 void operator ++ (void);
255 void operator ++ (int);
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()); }
270 }; // end of wxRegionIterator