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 inline wxRegionContain
Contains( wxCoord lX
, wxCoord lY
) const{
174 return Contains( wxPoint( lX
, lY
) );
177 // Convert the region to a B&W bitmap with the black pixels being inside
180 wxBitmap
ConvertToBitmap(void) const;
182 // Use the non-transparent pixels of a wxBitmap for the region to combine
183 // with this region. First version takes transparency from bitmap's mask,
184 // second lets the user specify the colour to be treated as transparent
185 // along with an optional tolerance value.
186 // NOTE: implemented in common/rgncmn.cpp
187 bool Union(const wxBitmap
& bmp
);
188 bool Union(const wxBitmap
& bmp
,
189 const wxColour
& transColour
, int tolerance
= 0);
192 // Does the region contain the point pt?
194 wxRegionContain
Contains(const wxPoint
& rPoint
) const;
197 // Does the region contain the rectangle (x, y, w, h)?
199 wxRegionContain
Contains( wxCoord x
206 // Does the region contain the rectangle rect?
208 inline wxRegionContain
Contains(const wxRect
& rRect
) const{
209 return Contains( rRect
.x
, rRect
.y
,
210 rRect
.GetWidth(), rRect
.GetHeight());
216 bool Combine( wxCoord x
222 bool Combine( const wxRegion
& rRegion
225 bool Combine( const wxRect
& rRect
230 // Get internal region handle
232 WXHRGN
GetHRGN(void) const;
236 virtual wxObjectRefData
* CreateData(void) const;
237 virtual wxObjectRefData
* CloneData(const wxObjectRefData
* pData
) const;
239 friend class WXDLLEXPORT wxRegionIterator
;
240 DECLARE_DYNAMIC_CLASS(wxRegion
);
242 }; // end of CLASS wxRegion
244 class WXDLLEXPORT wxRegionIterator
: public wxObject
246 DECLARE_DYNAMIC_CLASS(wxRegionIterator
);
249 wxRegionIterator(const wxRegion
& rRegion
);
252 void Reset(void) { m_lCurrent
= 0; }
253 void Reset(const wxRegion
& rRegion
);
255 operator bool (void) const { return m_lCurrent
< m_lNumRects
; }
256 bool HaveRects(void) const { return m_lCurrent
< m_lNumRects
; }
258 void operator ++ (void);
259 void operator ++ (int);
261 wxCoord
GetX(void) const;
262 wxCoord
GetY(void) const;
263 wxCoord
GetW(void) const;
264 wxCoord
GetWidth(void) const { return GetW(); }
265 wxCoord
GetH(void) const;
266 wxCoord
GetHeight(void) const { return GetH(); }
267 wxRect
GetRect(void) const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }
274 }; // end of wxRegionIterator