1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Base header for wxRegion
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows Licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_REGION_H_BASE_
13 #define _WX_REGION_H_BASE_
15 #include "wx/bitmap.h"
16 #include "wx/gdiobj.h"
17 #include "wx/gdicmn.h"
19 class WXDLLEXPORT wxColour
;
20 class WXDLLEXPORT wxRegion
;
22 // ----------------------------------------------------------------------------
24 // ----------------------------------------------------------------------------
26 // result of wxRegion::Contains() call
34 // these constants are used with wxRegion::Combine() in the ports which have
38 // Creates the intersection of the two combined regions.
41 // Creates a copy of the region
44 // Combines the parts of first region that are not in the second one
47 // Creates the union of two combined regions.
50 // Creates the union of two regions except for any overlapping areas.
54 // ----------------------------------------------------------------------------
55 // wxRegionBase defines wxRegion API
56 // ----------------------------------------------------------------------------
58 class WXDLLEXPORT wxRegionBase
: public wxGDIObject
64 // none are defined here but the following should be available:
67 wxRegion(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
);
68 wxRegion(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
69 wxRegion(const wxRect
& rect
);
70 wxRegion(size_t n
, const wxPoint
*points
, int fillStyle
= wxODDEVEN_RULE
);
71 wxRegion(const wxBitmap
& bmp
);
72 wxRegion(const wxBitmap
& bmp
, const wxColour
& transp
, int tolerance
= 0);
78 bool operator==(const wxRegion
& region
) const { return IsEqual(region
); }
79 bool operator!=(const wxRegion
& region
) const { return !(*this == region
); }
85 bool Ok() const { return IsOk(); }
86 bool IsOk() const { return m_refData
!= NULL
; }
89 virtual bool IsEmpty() const = 0;
90 bool Empty() const { return IsEmpty(); }
92 // Is region equal (i.e. covers the same area as another one)?
93 bool IsEqual(const wxRegion
& region
) const;
95 // Get the bounding box
96 bool GetBox(wxCoord
& x
, wxCoord
& y
, wxCoord
& w
, wxCoord
& h
) const
97 { return DoGetBox(x
, y
, w
, h
); }
101 return DoGetBox(x
, y
, w
, h
) ? wxRect(x
, y
, w
, h
) : wxRect();
104 // Test if the given point or rectangle is inside this region
105 wxRegionContain
Contains(wxCoord x
, wxCoord y
) const
106 { return DoContainsPoint(x
, y
); }
107 wxRegionContain
Contains(const wxPoint
& pt
) const
108 { return DoContainsPoint(pt
.x
, pt
.y
); }
109 wxRegionContain
Contains(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
) const
110 { return DoContainsRect(wxRect(x
, y
, w
, h
)); }
111 wxRegionContain
Contains(const wxRect
& rect
) const
112 { return DoContainsRect(rect
); }
118 virtual void Clear() = 0;
121 bool Offset(wxCoord x
, wxCoord y
)
122 { return DoOffset(x
, y
); }
123 bool Offset(const wxPoint
& pt
)
124 { return DoOffset(pt
.x
, pt
.y
); }
126 // Union rectangle or region with this region.
127 bool Union(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
128 { return DoUnionWithRect(wxRect(x
, y
, w
, h
)); }
129 bool Union(const wxRect
& rect
)
130 { return DoUnionWithRect(rect
); }
131 bool Union(const wxRegion
& region
)
132 { return DoUnionWithRegion(region
); }
135 // Use the non-transparent pixels of a wxBitmap for the region to combine
136 // with this region. First version takes transparency from bitmap's mask,
137 // second lets the user specify the colour to be treated as transparent
138 // along with an optional tolerance value.
139 // NOTE: implemented in common/rgncmn.cpp
140 bool Union(const wxBitmap
& bmp
);
141 bool Union(const wxBitmap
& bmp
, const wxColour
& transp
, int tolerance
= 0);
142 #endif // wxUSE_IMAGE
144 // Intersect rectangle or region with this one.
145 bool Intersect(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
);
146 bool Intersect(const wxRect
& rect
);
147 bool Intersect(const wxRegion
& region
)
148 { return DoIntersect(region
); }
150 // Subtract rectangle or region from this:
151 // Combines the parts of 'this' that are not part of the second region.
152 bool Subtract(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
);
153 bool Subtract(const wxRect
& rect
);
154 bool Subtract(const wxRegion
& region
)
155 { return DoSubtract(region
); }
157 // XOR: the union of two combined regions except for any overlapping areas.
158 bool Xor(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
);
159 bool Xor(const wxRect
& rect
);
160 bool Xor(const wxRegion
& region
)
161 { return DoXor(region
); }
164 // Convert the region to a B&W bitmap with the white pixels being inside
166 wxBitmap
ConvertToBitmap() const;
169 virtual bool DoIsEqual(const wxRegion
& region
) const = 0;
170 virtual bool DoGetBox(wxCoord
& x
, wxCoord
& y
, wxCoord
& w
, wxCoord
& h
) const = 0;
171 virtual wxRegionContain
DoContainsPoint(wxCoord x
, wxCoord y
) const = 0;
172 virtual wxRegionContain
DoContainsRect(const wxRect
& rect
) const = 0;
174 virtual bool DoOffset(wxCoord x
, wxCoord y
) = 0;
176 virtual bool DoUnionWithRect(const wxRect
& rect
) = 0;
177 virtual bool DoUnionWithRegion(const wxRegion
& region
) = 0;
179 virtual bool DoIntersect(const wxRegion
& region
) = 0;
180 virtual bool DoSubtract(const wxRegion
& region
) = 0;
181 virtual bool DoXor(const wxRegion
& region
) = 0;
184 // some ports implement a generic Combine() function while others only
185 // implement individual wxRegion operations, factor out the common code for the
186 // ports with Combine() in this class
187 #if defined(__WXPALMOS__) || \
188 defined(__WXMSW__) || \
189 defined(__WXMAC__) || \
192 #define wxHAS_REGION_COMBINE
194 class WXDLLEXPORT wxRegionWithCombine
: public wxRegionBase
197 // these methods are not part of public API as they're not implemented on
199 bool Combine(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
, wxRegionOp op
);
200 bool Combine(const wxRect
& rect
, wxRegionOp op
);
201 bool Combine(const wxRegion
& region
, wxRegionOp op
)
202 { return DoCombine(region
, op
); }
206 // the real Combine() method, to be defined in the derived class
207 virtual bool DoCombine(const wxRegion
& region
, wxRegionOp op
) = 0;
209 // implement some wxRegionBase pure virtuals in terms of Combine()
210 virtual bool DoUnionWithRect(const wxRect
& rect
)
211 { return Combine(rect
, wxRGN_OR
); }
212 virtual bool DoUnionWithRegion(const wxRegion
& region
)
213 { return Combine(region
, wxRGN_OR
); }
215 virtual bool DoIntersect(const wxRegion
& region
)
216 { return Combine(region
, wxRGN_AND
); }
217 virtual bool DoSubtract(const wxRegion
& region
)
218 { return Combine(region
, wxRGN_DIFF
); }
219 virtual bool DoXor(const wxRegion
& region
)
220 { return Combine(region
, wxRGN_XOR
); }
223 #endif // ports with wxRegion::Combine()
225 #if defined(__WXPALMOS__)
226 #include "wx/palmos/region.h"
227 #elif defined(__WXMSW__)
228 #include "wx/msw/region.h"
229 #elif defined(__WXGTK20__)
230 #include "wx/gtk/region.h"
231 #elif defined(__WXGTK__)
232 #include "wx/gtk1/region.h"
233 #elif defined(__WXMOTIF__) || defined(__WXX11__)
234 #include "wx/x11/region.h"
235 #elif defined(__WXMGL__)
236 #include "wx/mgl/region.h"
237 #elif defined(__WXDFB__)
238 #include "wx/dfb/region.h"
239 #elif defined(__WXMAC__)
240 #include "wx/mac/region.h"
241 #elif defined(__WXCOCOA__)
242 #include "wx/cocoa/region.h"
243 #elif defined(__WXPM__)
244 #include "wx/os2/region.h"
247 // ----------------------------------------------------------------------------
248 // inline functions implementation
249 // ----------------------------------------------------------------------------
251 // NB: these functions couldn't be defined in the class declaration as they use
252 // wxRegion and so can be only defined after including the header declaring
255 inline bool wxRegionBase::Intersect(const wxRect
& rect
)
257 return DoIntersect(wxRegion(rect
));
260 inline bool wxRegionBase::Subtract(const wxRect
& rect
)
262 return DoSubtract(wxRegion(rect
));
265 inline bool wxRegionBase::Xor(const wxRect
& rect
)
267 return DoXor(wxRegion(rect
));
270 // ...and these functions are here because they call the ones above, and its
271 // not really proper to call an inline function before its defined inline.
273 inline bool wxRegionBase::Intersect(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
275 return Intersect(wxRect(x
, y
, w
, h
));
278 inline bool wxRegionBase::Subtract(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
280 return Subtract(wxRect(x
, y
, w
, h
));
283 inline bool wxRegionBase::Xor(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
285 return Xor(wxRect(x
, y
, w
, h
));
288 #ifdef wxHAS_REGION_COMBINE
290 inline bool wxRegionWithCombine::Combine(wxCoord x
,
296 return DoCombine(wxRegion(x
, y
, w
, h
), op
);
299 inline bool wxRegionWithCombine::Combine(const wxRect
& rect
, wxRegionOp op
)
301 return DoCombine(wxRegion(rect
), op
);
304 #endif // wxHAS_REGION_COMBINE
306 #endif // _WX_REGION_H_BASE_