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
);
67 // Clear current region
71 bool Offset( wxCoord x
76 // Union rectangle or region with this.
78 inline bool Union( wxCoord x
91 inline bool Union( const wxRect
& rRect
) { return Combine(rRect
, wxRGN_OR
); }
92 inline bool Union(const wxRegion
& rRegion
) { return Combine(rRegion
, wxRGN_OR
); }
95 // Intersect rectangle or region with this.
97 inline bool Intersect( wxCoord x
110 inline bool Intersect(const wxRect
& rRect
) { return Combine(rRect
, wxRGN_AND
); }
111 inline bool Intersect(const wxRegion
& rRegion
) { return Combine(rRegion
, wxRGN_AND
); }
114 // Subtract rectangle or region from this:
115 // Combines the parts of 'this' that are not part of the second region.
117 inline bool Subtract( wxCoord x
130 inline bool Subtract(const wxRect
& rRect
) { return Combine(rRect
, wxRGN_DIFF
); }
131 inline bool Subtract(const wxRegion
& rRegion
) { return Combine(rRegion
, wxRGN_DIFF
); }
134 // XOR: the union of two combined regions except for any overlapping areas.
136 inline bool Xor( wxCoord x
149 inline bool Xor(const wxRect
& rRect
) { return Combine(rRect
, wxRGN_XOR
); }
150 inline bool Xor(const wxRegion
& rRegion
) { return Combine(rRegion
, wxRGN_XOR
); }
153 // Information on region
154 // Outer bounds of region
156 void GetBox( wxCoord
& rX
161 wxRect
GetBox(void) const;
166 bool Empty(void) const;
167 inline bool IsEmpty() const { return Empty(); }
171 // Does the region contain the point (x,y)?
173 wxRegionContain
Contains( wxCoord lX
178 // Convert the region to a B&W bitmap with the black pixels being inside
181 wxBitmap
ConvertToBitmap(void) const;
183 // Use the non-transparent pixels of a wxBitmap for the region to combine
184 // with this region. First version takes transparency from bitmap's mask,
185 // second lets the user specify the colour to be treated as transparent
186 // along with an optional tolerance value.
187 // NOTE: implemented in common/rgncmn.cpp
188 bool Union(const wxBitmap
& bmp
);
189 bool Union(const wxBitmap
& bmp
,
190 const wxColour
& transColour
, int tolerance
= 0);
193 // Does the region contain the point pt?
195 wxRegionContain
Contains(const wxPoint
& rPoint
) const;
198 // Does the region contain the rectangle (x, y, w, h)?
200 wxRegionContain
Contains( wxCoord x
207 // Does the region contain the rectangle rect?
209 wxRegionContain
Contains(const wxRect
& rRect
) const;
214 bool Combine( wxCoord x
220 bool Combine( const wxRegion
& rRegion
223 bool Combine( const wxRect
& rRect
228 // Get internal region handle
230 WXHRGN
GetHRGN(void) const;
234 virtual wxObjectRefData
* CreateData(void) const;
235 virtual wxObjectRefData
* CloneData(const wxObjectRefData
* pData
) const;
237 friend class WXDLLEXPORT wxRegionIterator
;
238 DECLARE_DYNAMIC_CLASS(wxRegion
);
240 }; // end of CLASS wxRegion
242 class WXDLLEXPORT wxRegionIterator
: public wxObject
244 DECLARE_DYNAMIC_CLASS(wxRegionIterator
);
247 wxRegionIterator(const wxRegion
& rRegion
);
250 void Reset(void) { m_lCurrent
= 0; }
251 void Reset(const wxRegion
& rRegion
);
253 operator bool (void) const { return m_lCurrent
< m_lNumRects
; }
254 bool HaveRects(void) const { return m_lCurrent
< m_lNumRects
; }
256 void operator ++ (void);
257 void operator ++ (int);
259 wxCoord
GetX(void) const;
260 wxCoord
GetY(void) const;
261 wxCoord
GetW(void) const;
262 wxCoord
GetWidth(void) const { return GetW(); }
263 wxCoord
GetH(void) const;
264 wxCoord
GetHeight(void) const { return GetH(); }
265 wxRect
GetRect(void) const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }
272 }; // end of wxRegionIterator