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"
19 class WXDLLEXPORT wxRect
;
20 class WXDLLEXPORT wxPoint
;
22 enum wxRegionContain
{
23 wxOutRegion
= 0, wxPartRegion
= 1, wxInRegion
= 2
26 // So far, for internal use only
27 enum wxRegionOp
{ wxRGN_AND
// Creates the intersection of the two combined regions.
28 ,wxRGN_COPY
// Creates a copy of the region identified by hrgnSrc1.
29 ,wxRGN_DIFF
// Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
30 ,wxRGN_OR
// Creates the union of two combined regions.
31 ,wxRGN_XOR
// Creates the union of two combined regions except for any overlapping areas.
34 class WXDLLEXPORT wxRegion
: public wxGDIObject
42 wxRegion( const wxPoint
& rTopLeft
43 ,const wxPoint
& rBottomRight
45 wxRegion(const wxRect
& rRect
);
46 wxRegion(WXHRGN hRegion
, WXHDC hPS
); // Hangs on to this region
54 inline wxRegion(const wxRegion
& rSrc
)
56 inline wxRegion
& operator = (const wxRegion
& rSrc
)
57 { Ref(rSrc
); return (*this); }
64 // Clear current region
68 bool Offset( wxCoord x
73 // Union rectangle or region with this.
75 inline bool Union( wxCoord x
88 inline bool Union( const wxRect
& rRect
) { return Combine(rRect
, wxRGN_OR
); }
89 inline bool Union(const wxRegion
& rRegion
) { return Combine(rRegion
, wxRGN_OR
); }
92 // Intersect rectangle or region with this.
94 inline bool Intersect( wxCoord x
107 inline bool Intersect(const wxRect
& rRect
) { return Combine(rRect
, wxRGN_AND
); }
108 inline bool Intersect(const wxRegion
& rRegion
) { return Combine(rRegion
, wxRGN_AND
); }
111 // Subtract rectangle or region from this:
112 // Combines the parts of 'this' that are not part of the second region.
114 inline bool Subtract( wxCoord x
127 inline bool Subtract(const wxRect
& rRect
) { return Combine(rRect
, wxRGN_DIFF
); }
128 inline bool Subtract(const wxRegion
& rRegion
) { return Combine(rRegion
, wxRGN_DIFF
); }
131 // XOR: the union of two combined regions except for any overlapping areas.
133 inline bool Xor( wxCoord x
146 inline bool Xor(const wxRect
& rRect
) { return Combine(rRect
, wxRGN_XOR
); }
147 inline bool Xor(const wxRegion
& rRegion
) { return Combine(rRegion
, wxRGN_XOR
); }
150 // Information on region
151 // Outer bounds of region
153 void GetBox( wxCoord
& rX
158 wxRect
GetBox(void) const;
163 bool Empty(void) const;
164 inline bool IsEmpty() const { return Empty(); }
168 // Does the region contain the point (x,y)?
170 wxRegionContain
Contains( wxCoord lX
174 // Does the region contain the point pt?
176 wxRegionContain
Contains(const wxPoint
& rPoint
) const;
179 // Does the region contain the rectangle (x, y, w, h)?
181 wxRegionContain
Contains( wxCoord x
188 // Does the region contain the rectangle rect?
190 wxRegionContain
Contains(const wxRect
& rRect
) const;
195 bool Combine( wxCoord x
201 bool Combine( const wxRegion
& rRegion
204 bool Combine( const wxRect
& rRect
209 // Get internal region handle
211 WXHRGN
GetHRGN(void) const;
215 virtual wxObjectRefData
* CreateData(void) const;
216 virtual wxObjectRefData
* CloneData(const wxObjectRefData
* pData
) const;
218 friend class WXDLLEXPORT wxRegionIterator
;
219 DECLARE_DYNAMIC_CLASS(wxRegion
);
221 }; // end of CLASS wxRegion
223 class WXDLLEXPORT wxRegionIterator
: public wxObject
225 DECLARE_DYNAMIC_CLASS(wxRegionIterator
);
228 wxRegionIterator(const wxRegion
& rRegion
);
231 void Reset(void) { m_lCurrent
= 0; }
232 void Reset(const wxRegion
& rRegion
);
234 operator bool (void) const { return m_lCurrent
< m_lNumRects
; }
235 bool HaveRects(void) const { return m_lCurrent
< m_lNumRects
; }
237 void operator ++ (void);
238 void operator ++ (int);
240 wxCoord
GetX(void) const;
241 wxCoord
GetY(void) const;
242 wxCoord
GetW(void) const;
243 wxCoord
GetWidth(void) const { return GetW(); }
244 wxCoord
GetH(void) const;
245 wxCoord
GetHeight(void) const { return GetH(); }
246 wxRect
GetRect(void) const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }
253 }; // end of wxRegionIterator