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 // So far, for internal use only
25 enum wxRegionOp
{ wxRGN_AND
// Creates the intersection of the two combined regions.
26 ,wxRGN_COPY
// Creates a copy of the region identified by hrgnSrc1.
27 ,wxRGN_DIFF
// Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
28 ,wxRGN_OR
// Creates the union of two combined regions.
29 ,wxRGN_XOR
// Creates the union of two combined regions except for any overlapping areas.
32 class WXDLLEXPORT wxRegion
: public wxGDIObject
40 wxRegion( const wxPoint
& rTopLeft
41 ,const wxPoint
& rBottomRight
43 wxRegion(const wxRect
& rRect
);
44 wxRegion(WXHRGN hRegion
, WXHDC hPS
); // Hangs on to this region
45 wxRegion( const wxBitmap
& bmp
)
49 wxRegion( const wxBitmap
& bmp
,
50 const wxColour
& transColour
, int tolerance
= 0)
52 Union(bmp
, transColour
, tolerance
);
63 // Clear current region
67 bool Offset( wxCoord x
72 // Union rectangle or region with this.
74 inline bool Union( wxCoord x
87 inline bool Union( const wxRect
& rRect
) { return Combine(rRect
, wxRGN_OR
); }
88 inline bool Union(const wxRegion
& rRegion
) { return Combine(rRegion
, wxRGN_OR
); }
91 // Intersect rectangle or region with this.
93 inline bool Intersect( wxCoord x
106 inline bool Intersect(const wxRect
& rRect
) { return Combine(rRect
, wxRGN_AND
); }
107 inline bool Intersect(const wxRegion
& rRegion
) { return Combine(rRegion
, wxRGN_AND
); }
110 // Subtract rectangle or region from this:
111 // Combines the parts of 'this' that are not part of the second region.
113 inline bool Subtract( wxCoord x
126 inline bool Subtract(const wxRect
& rRect
) { return Combine(rRect
, wxRGN_DIFF
); }
127 inline bool Subtract(const wxRegion
& rRegion
) { return Combine(rRegion
, wxRGN_DIFF
); }
130 // XOR: the union of two combined regions except for any overlapping areas.
132 inline bool Xor( wxCoord x
145 inline bool Xor(const wxRect
& rRect
) { return Combine(rRect
, wxRGN_XOR
); }
146 inline bool Xor(const wxRegion
& rRegion
) { return Combine(rRegion
, wxRGN_XOR
); }
149 // Information on region
150 // Outer bounds of region
152 void GetBox( wxCoord
& rX
157 wxRect
GetBox(void) const;
162 bool Empty(void) const;
163 inline bool IsEmpty() const { return Empty(); }
167 // Does the region contain the point (x,y)?
169 inline wxRegionContain
Contains( wxCoord lX
, wxCoord lY
) const{
170 return Contains( wxPoint( lX
, lY
) );
173 // Convert the region to a B&W bitmap with the black pixels being inside
176 wxBitmap
ConvertToBitmap(void) const;
178 // Use the non-transparent pixels of a wxBitmap for the region to combine
179 // with this region. First version takes transparency from bitmap's mask,
180 // second lets the user specify the colour to be treated as transparent
181 // along with an optional tolerance value.
182 // NOTE: implemented in common/rgncmn.cpp
183 bool Union(const wxBitmap
& bmp
);
184 bool Union(const wxBitmap
& bmp
,
185 const wxColour
& transColour
, int tolerance
= 0);
188 // Does the region contain the point pt?
190 wxRegionContain
Contains(const wxPoint
& rPoint
) const;
193 // Does the region contain the rectangle (x, y, w, h)?
195 wxRegionContain
Contains( wxCoord x
202 // Does the region contain the rectangle rect?
204 inline wxRegionContain
Contains(const wxRect
& rRect
) const{
205 return Contains( rRect
.x
, rRect
.y
,
206 rRect
.GetWidth(), rRect
.GetHeight());
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
);
246 virtual ~wxRegionIterator();
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