1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxRegion class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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
);
46 wxRegion( WXHRGN hRegion
);
47 wxRegion(size_t n
, const wxPoint
*points
, int fillStyle
= wxODDEVEN_RULE
);
49 wxRegion(const wxBitmap
& bmp
)
53 wxRegion(const wxBitmap
& bmp
,
54 const wxColour
& transColour
, int tolerance
= 0)
56 Union(bmp
, transColour
, tolerance
);
62 wxRegion(const wxRegion
& r
)
65 wxRegion
& operator = (const wxRegion
& r
)
66 { Ref(r
); return (*this); }
69 // Clear current region
72 // Union rectangle or region with this.
73 bool Union(long x
, long y
, long width
, long height
)
74 { return Combine(x
, y
, width
, height
, wxRGN_OR
); }
75 bool Union(const wxRect
& rect
)
76 { return Combine(rect
, wxRGN_OR
); }
77 bool Union(const wxRegion
& region
)
78 { return Combine(region
, wxRGN_OR
); }
80 // Intersect rectangle or region with this.
81 bool Intersect(long x
, long y
, long width
, long height
)
82 { return Combine(x
, y
, width
, height
, wxRGN_AND
); }
83 bool Intersect(const wxRect
& rect
)
84 { return Combine(rect
, wxRGN_AND
); }
85 bool Intersect(const wxRegion
& region
)
86 { return Combine(region
, wxRGN_AND
); }
88 // Subtract rectangle or region from this:
89 // Combines the parts of 'this' that are not part of the second region.
90 bool Subtract(long x
, long y
, long width
, long height
)
91 { return Combine(x
, y
, width
, height
, wxRGN_DIFF
); }
92 bool Subtract(const wxRect
& rect
)
93 { return Combine(rect
, wxRGN_DIFF
); }
94 bool Subtract(const wxRegion
& region
)
95 { return Combine(region
, wxRGN_DIFF
); }
97 // XOR: the union of two combined regions except for any overlapping areas.
98 bool Xor(long x
, long y
, long width
, long height
)
99 { return Combine(x
, y
, width
, height
, wxRGN_XOR
); }
100 bool Xor(const wxRect
& rect
)
101 { return Combine(rect
, wxRGN_XOR
); }
102 bool Xor(const wxRegion
& region
)
103 { return Combine(region
, wxRGN_XOR
); }
105 //# Information on region
106 // Outer bounds of region
107 void GetBox(wxCoord
& x
, wxCoord
& y
, wxCoord
&w
, wxCoord
&h
) const;
108 wxRect
GetBox() const ;
112 inline bool IsEmpty() const { return Empty(); }
115 // Does the region contain the point (x,y)?
116 wxRegionContain
Contains(long x
, long y
) const;
117 // Does the region contain the point pt?
118 wxRegionContain
Contains(const wxPoint
& pt
) const;
119 // Does the region contain the rectangle (x, y, w, h)?
120 wxRegionContain
Contains(long x
, long y
, long w
, long h
) const;
121 // Does the region contain the rectangle rect?
122 wxRegionContain
Contains(const wxRect
& rect
) const;
124 // Convert the region to a B&W bitmap with the white pixels being inside
126 wxBitmap
ConvertToBitmap() const;
128 // Use the non-transparent pixels of a wxBitmap for the region to combine
129 // with this region. First version takes transparency from bitmap's mask,
130 // second lets the user specify the colour to be treated as transparent
131 // along with an optional tolerance value.
132 // NOTE: implemented in common/rgncmn.cpp
133 bool Union(const wxBitmap
& bmp
);
134 bool Union(const wxBitmap
& bmp
,
135 const wxColour
& transColour
, int tolerance
= 0);
138 bool Combine(long x
, long y
, long width
, long height
, wxRegionOp op
);
139 bool Combine(const wxRegion
& region
, wxRegionOp op
);
140 bool Combine(const wxRect
& rect
, wxRegionOp op
);
141 const WXHRGN
GetWXHRGN() const ;
144 class WXDLLEXPORT wxRegionIterator
: public wxObject
146 DECLARE_DYNAMIC_CLASS(wxRegionIterator
)
150 wxRegionIterator(const wxRegion
& region
);
151 wxRegionIterator(const wxRegionIterator
& iterator
);
154 wxRegionIterator
& operator=(const wxRegionIterator
& iterator
);
156 void Reset() { m_current
= 0; }
157 void Reset(const wxRegion
& region
);
159 operator bool () const { return m_current
< m_numRects
; }
160 bool HaveRects() const { return m_current
< m_numRects
; }
162 wxRegionIterator
& operator++();
163 wxRegionIterator
operator++(int);
168 long GetWidth() const { return GetW(); }
170 long GetHeight() const { return GetH(); }
171 wxRect
GetRect() const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }
173 void SetRects(long numRects
, wxRect
*rects
);