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
36 DECLARE_DYNAMIC_CLASS(wxRegion
);
37 friend class WXDLLEXPORT wxRegionIterator
;
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
56 inline wxRegion(const wxRegion
& rSrc
)
58 inline wxRegion
& operator = (const wxRegion
& rSrc
)
59 { Ref(rSrc
); return (*this); }
66 // Clear current region
71 // Union rectangle or region with this.
73 inline bool Union( wxCoord x
86 inline bool Union( const wxRect
& rRect
) { return Combine(rRect
, wxRGN_OR
); }
87 inline bool Union(const wxRegion
& rRegion
) { return Combine(rRegion
, wxRGN_OR
); }
90 // Intersect rectangle or region with this.
92 inline bool Intersect( wxCoord x
105 inline bool Intersect(const wxRect
& rRect
) { return Combine(rRect
, wxRGN_AND
); }
106 inline bool Intersect(const wxRegion
& rRegion
) { return Combine(rRegion
, wxRGN_AND
); }
109 // Subtract rectangle or region from this:
110 // Combines the parts of 'this' that are not part of the second region.
112 inline bool Subtract( wxCoord x
125 inline bool Subtract(const wxRect
& rRect
) { return Combine(rRect
, wxRGN_DIFF
); }
126 inline bool Subtract(const wxRegion
& rRegion
) { return Combine(rRegion
, wxRGN_DIFF
); }
129 // XOR: the union of two combined regions except for any overlapping areas.
131 inline bool Xor( wxCoord x
144 inline bool Xor(const wxRect
& rRect
) { return Combine(rRect
, wxRGN_XOR
); }
145 inline bool Xor(const wxRegion
& rRegion
) { return Combine(rRegion
, wxRGN_XOR
); }
148 // Information on region
149 // Outer bounds of region
151 void GetBox( wxCoord
& rX
156 wxRect
GetBox(void) const;
161 bool Empty(void) const;
162 inline bool IsEmpty() const { return Empty(); }
166 // Does the region contain the point (x,y)?
168 wxRegionContain
Contains( wxCoord lX
172 // Does the region contain the point pt?
174 wxRegionContain
Contains(const wxPoint
& rPoint
) const;
177 // Does the region contain the rectangle (x, y, w, h)?
179 wxRegionContain
Contains( wxCoord x
186 // Does the region contain the rectangle rect?
188 wxRegionContain
Contains(const wxRect
& rRect
) const;
193 bool Combine( wxCoord x
199 bool Combine( const wxRegion
& rRegion
202 bool Combine( const wxRect
& rRect
207 // Get internal region handle
209 WXHRGN
GetHRGN(void) const;
211 }; // end of CLASS wxRegion
213 class WXDLLEXPORT wxRegionIterator
: public wxObject
215 DECLARE_DYNAMIC_CLASS(wxRegionIterator
);
218 wxRegionIterator(const wxRegion
& rRegion
);
221 void Reset(void) { m_lCurrent
= 0; }
222 void Reset(const wxRegion
& rRegion
);
224 operator bool (void) const { return m_lCurrent
< m_lNumRects
; }
225 bool HaveRects(void) const { return m_lCurrent
< m_lNumRects
; }
227 void operator ++ (void);
228 void operator ++ (int);
230 wxCoord
GetX(void) const;
231 wxCoord
GetY(void) const;
232 wxCoord
GetW(void) const;
233 wxCoord
GetWidth(void) const { return GetW(); }
234 wxCoord
GetH(void) const;
235 wxCoord
GetHeight(void) const { return GetH(); }
236 wxRect
GetRect(void) const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }
243 }; // end of wxRegionIterator