1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxRegion class
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "region.h"
20 #include "wx/gdiobj.h"
21 #include "wx/gdicmn.h"
23 class WXDLLEXPORT wxRect
;
24 class WXDLLEXPORT wxPoint
;
26 enum wxRegionContain
{
27 wxOutRegion
= 0, wxPartRegion
= 1, wxInRegion
= 2
30 // So far, for internal use only
32 wxRGN_AND
, // Creates the intersection of the two combined regions.
33 wxRGN_COPY
, // Creates a copy of the region identified by hrgnSrc1.
34 wxRGN_DIFF
, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
35 wxRGN_OR
, // Creates the union of two combined regions.
36 wxRGN_XOR
// Creates the union of two combined regions except for any overlapping areas.
39 class WXDLLEXPORT wxRegion
: public wxGDIObject
{
40 DECLARE_DYNAMIC_CLASS(wxRegion
);
41 friend class WXDLLEXPORT wxRegionIterator
;
43 wxRegion(long x
, long y
, long w
, long h
);
44 wxRegion(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
45 wxRegion(const wxRect
& rect
);
47 wxRegion( const wxBitmap
& bmp
,
48 const wxColour
& transColour
= wxNullColour
,
51 Union(bmp
, transColour
, tolerance
);
57 wxRegion(const wxRegion
& r
)
60 wxRegion
& operator = (const wxRegion
& r
)
61 { Ref(r
); return (*this); }
64 // Clear current region
67 // Union rectangle or region with this.
68 bool Union(long x
, long y
, long width
, long height
)
69 { return Combine(x
, y
, width
, height
, wxRGN_OR
); }
70 bool Union(const wxRect
& rect
)
71 { return Combine(rect
, wxRGN_OR
); }
72 bool Union(const wxRegion
& region
)
73 { return Combine(region
, wxRGN_OR
); }
75 // Intersect rectangle or region with this.
76 bool Intersect(long x
, long y
, long width
, long height
)
77 { return Combine(x
, y
, width
, height
, wxRGN_AND
); }
78 bool Intersect(const wxRect
& rect
)
79 { return Combine(rect
, wxRGN_AND
); }
80 bool Intersect(const wxRegion
& region
)
81 { return Combine(region
, wxRGN_AND
); }
83 // Subtract rectangle or region from this:
84 // Combines the parts of 'this' that are not part of the second region.
85 bool Subtract(long x
, long y
, long width
, long height
)
86 { return Combine(x
, y
, width
, height
, wxRGN_DIFF
); }
87 bool Subtract(const wxRect
& rect
)
88 { return Combine(rect
, wxRGN_DIFF
); }
89 bool Subtract(const wxRegion
& region
)
90 { return Combine(region
, wxRGN_DIFF
); }
92 // XOR: the union of two combined regions except for any overlapping areas.
93 bool Xor(long x
, long y
, long width
, long height
)
94 { return Combine(x
, y
, width
, height
, wxRGN_XOR
); }
95 bool Xor(const wxRect
& rect
)
96 { return Combine(rect
, wxRGN_XOR
); }
97 bool Xor(const wxRegion
& region
)
98 { return Combine(region
, wxRGN_XOR
); }
100 //# Information on region
101 // Outer bounds of region
102 void GetBox(wxCoord
& x
, wxCoord
& y
, wxCoord
&w
, wxCoord
&h
) const;
103 wxRect
GetBox() const ;
107 inline bool IsEmpty() const { return Empty(); }
110 // Does the region contain the point (x,y)?
111 wxRegionContain
Contains(long x
, long y
) const;
112 // Does the region contain the point pt?
113 wxRegionContain
Contains(const wxPoint
& pt
) const;
114 // Does the region contain the rectangle (x, y, w, h)?
115 wxRegionContain
Contains(long x
, long y
, long w
, long h
) const;
116 // Does the region contain the rectangle rect?
117 wxRegionContain
Contains(const wxRect
& rect
) const;
119 // Convert the region to a B&W bitmap with the black pixels being inside
121 wxBitmap
ConvertToBitmap() const;
123 // Use the non-transparent pixels of a wxBitmap for the region to combine
124 // with this region. If the bitmap has a mask then it will be used,
125 // otherwise the colour to be treated as transparent may be specified,
126 // along with an optional tolerance value.
127 bool Union(const wxBitmap
& bmp
,
128 const wxColour
& transColour
= wxNullColour
,
133 bool Combine(long x
, long y
, long width
, long height
, wxRegionOp op
);
134 bool Combine(const wxRegion
& region
, wxRegionOp op
);
135 bool Combine(const wxRect
& rect
, wxRegionOp op
);
138 class WXDLLEXPORT wxRegionIterator
: public wxObject
140 DECLARE_DYNAMIC_CLASS(wxRegionIterator
)
144 wxRegionIterator(const wxRegion
& region
);
145 wxRegionIterator(const wxRegionIterator
& iterator
);
148 wxRegionIterator
& operator=(const wxRegionIterator
& iterator
);
150 void Reset() { m_current
= 0; }
151 void Reset(const wxRegion
& region
);
153 operator bool () const { return m_current
< m_numRects
; }
154 bool HaveRects() const { return m_current
< m_numRects
; }
156 wxRegionIterator
& operator++();
157 wxRegionIterator
operator++(int);
162 long GetWidth() const { return GetW(); }
164 long GetHeight() const { return GetH(); }
165 wxRect
GetRect() const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }
167 void SetRects(long numRects
, wxRect
*rects
);