]> git.saurik.com Git - wxWidgets.git/blob - include/wx/region.h
fixed IO redirection to work in wxExecute() in console applications (including the...
[wxWidgets.git] / include / wx / region.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/region.h
3 // Purpose: Base header for wxRegion
4 // Author: Julian Smart
5 // Modified by:
6 // Created:
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows Licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_REGION_H_BASE_
13 #define _WX_REGION_H_BASE_
14
15 #include "wx/gdiobj.h"
16 #include "wx/gdicmn.h"
17
18 class WXDLLIMPEXP_FWD_CORE wxBitmap;
19 class WXDLLIMPEXP_FWD_CORE wxColour;
20 class WXDLLIMPEXP_FWD_CORE wxRegion;
21
22 // ----------------------------------------------------------------------------
23 // constants
24 // ----------------------------------------------------------------------------
25
26 // result of wxRegion::Contains() call
27 enum wxRegionContain
28 {
29 wxOutRegion = 0,
30 wxPartRegion = 1,
31 wxInRegion = 2
32 };
33
34 // these constants are used with wxRegion::Combine() in the ports which have
35 // this method
36 enum wxRegionOp
37 {
38 // Creates the intersection of the two combined regions.
39 wxRGN_AND,
40
41 // Creates a copy of the region
42 wxRGN_COPY,
43
44 // Combines the parts of first region that are not in the second one
45 wxRGN_DIFF,
46
47 // Creates the union of two combined regions.
48 wxRGN_OR,
49
50 // Creates the union of two regions except for any overlapping areas.
51 wxRGN_XOR
52 };
53
54 // ----------------------------------------------------------------------------
55 // wxRegionBase defines wxRegion API
56 // ----------------------------------------------------------------------------
57
58 class WXDLLEXPORT wxRegionBase : public wxGDIObject
59 {
60 public:
61 // ctors
62 // -----
63
64 // none are defined here but the following should be available:
65 #if 0
66 wxRegion();
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);
73 #endif // 0
74
75 // operators
76 // ---------
77
78 bool operator==(const wxRegion& region) const { return IsEqual(region); }
79 bool operator!=(const wxRegion& region) const { return !(*this == region); }
80
81
82 // accessors
83 // ---------
84
85 // Is region empty?
86 virtual bool IsEmpty() const = 0;
87 bool Empty() const { return IsEmpty(); }
88
89 // Is region equal (i.e. covers the same area as another one)?
90 bool IsEqual(const wxRegion& region) const;
91
92 // Get the bounding box
93 bool GetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const
94 { return DoGetBox(x, y, w, h); }
95 wxRect GetBox() const
96 {
97 wxCoord x, y, w, h;
98 return DoGetBox(x, y, w, h) ? wxRect(x, y, w, h) : wxRect();
99 }
100
101 // Test if the given point or rectangle is inside this region
102 wxRegionContain Contains(wxCoord x, wxCoord y) const
103 { return DoContainsPoint(x, y); }
104 wxRegionContain Contains(const wxPoint& pt) const
105 { return DoContainsPoint(pt.x, pt.y); }
106 wxRegionContain Contains(wxCoord x, wxCoord y, wxCoord w, wxCoord h) const
107 { return DoContainsRect(wxRect(x, y, w, h)); }
108 wxRegionContain Contains(const wxRect& rect) const
109 { return DoContainsRect(rect); }
110
111
112 // operations
113 // ----------
114
115 virtual void Clear() = 0;
116
117 // Move the region
118 bool Offset(wxCoord x, wxCoord y)
119 { return DoOffset(x, y); }
120 bool Offset(const wxPoint& pt)
121 { return DoOffset(pt.x, pt.y); }
122
123 // Union rectangle or region with this region.
124 bool Union(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
125 { return DoUnionWithRect(wxRect(x, y, w, h)); }
126 bool Union(const wxRect& rect)
127 { return DoUnionWithRect(rect); }
128 bool Union(const wxRegion& region)
129 { return DoUnionWithRegion(region); }
130
131 #if wxUSE_IMAGE
132 // Use the non-transparent pixels of a wxBitmap for the region to combine
133 // with this region. First version takes transparency from bitmap's mask,
134 // second lets the user specify the colour to be treated as transparent
135 // along with an optional tolerance value.
136 // NOTE: implemented in common/rgncmn.cpp
137 bool Union(const wxBitmap& bmp);
138 bool Union(const wxBitmap& bmp, const wxColour& transp, int tolerance = 0);
139 #endif // wxUSE_IMAGE
140
141 // Intersect rectangle or region with this one.
142 bool Intersect(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
143 bool Intersect(const wxRect& rect);
144 bool Intersect(const wxRegion& region)
145 { return DoIntersect(region); }
146
147 // Subtract rectangle or region from this:
148 // Combines the parts of 'this' that are not part of the second region.
149 bool Subtract(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
150 bool Subtract(const wxRect& rect);
151 bool Subtract(const wxRegion& region)
152 { return DoSubtract(region); }
153
154 // XOR: the union of two combined regions except for any overlapping areas.
155 bool Xor(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
156 bool Xor(const wxRect& rect);
157 bool Xor(const wxRegion& region)
158 { return DoXor(region); }
159
160
161 // Convert the region to a B&W bitmap with the white pixels being inside
162 // the region.
163 wxBitmap ConvertToBitmap() const;
164
165 protected:
166 virtual bool DoIsEqual(const wxRegion& region) const = 0;
167 virtual bool DoGetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const = 0;
168 virtual wxRegionContain DoContainsPoint(wxCoord x, wxCoord y) const = 0;
169 virtual wxRegionContain DoContainsRect(const wxRect& rect) const = 0;
170
171 virtual bool DoOffset(wxCoord x, wxCoord y) = 0;
172
173 virtual bool DoUnionWithRect(const wxRect& rect) = 0;
174 virtual bool DoUnionWithRegion(const wxRegion& region) = 0;
175
176 virtual bool DoIntersect(const wxRegion& region) = 0;
177 virtual bool DoSubtract(const wxRegion& region) = 0;
178 virtual bool DoXor(const wxRegion& region) = 0;
179 };
180
181 // some ports implement a generic Combine() function while others only
182 // implement individual wxRegion operations, factor out the common code for the
183 // ports with Combine() in this class
184 #if defined(__WXPALMOS__) || \
185 defined(__WXMSW__) || \
186 defined(__WXMAC__) || \
187 defined(__WXPM__)
188
189 #define wxHAS_REGION_COMBINE
190
191 class WXDLLEXPORT wxRegionWithCombine : public wxRegionBase
192 {
193 public:
194 // these methods are not part of public API as they're not implemented on
195 // all ports
196 bool Combine(wxCoord x, wxCoord y, wxCoord w, wxCoord h, wxRegionOp op);
197 bool Combine(const wxRect& rect, wxRegionOp op);
198 bool Combine(const wxRegion& region, wxRegionOp op)
199 { return DoCombine(region, op); }
200
201
202 protected:
203 // the real Combine() method, to be defined in the derived class
204 virtual bool DoCombine(const wxRegion& region, wxRegionOp op) = 0;
205
206 // implement some wxRegionBase pure virtuals in terms of Combine()
207 virtual bool DoUnionWithRect(const wxRect& rect);
208 virtual bool DoUnionWithRegion(const wxRegion& region);
209 virtual bool DoIntersect(const wxRegion& region);
210 virtual bool DoSubtract(const wxRegion& region);
211 virtual bool DoXor(const wxRegion& region);
212 };
213
214 #endif // ports with wxRegion::Combine()
215
216 #if defined(__WXPALMOS__)
217 #include "wx/palmos/region.h"
218 #elif defined(__WXMSW__)
219 #include "wx/msw/region.h"
220 #elif defined(__WXGTK20__)
221 #include "wx/gtk/region.h"
222 #elif defined(__WXGTK__)
223 #include "wx/gtk1/region.h"
224 #elif defined(__WXMOTIF__) || defined(__WXX11__)
225 #include "wx/x11/region.h"
226 #elif defined(__WXMGL__)
227 #include "wx/mgl/region.h"
228 #elif defined(__WXDFB__)
229 #include "wx/dfb/region.h"
230 #elif defined(__WXMAC__)
231 #include "wx/mac/region.h"
232 #elif defined(__WXCOCOA__)
233 #include "wx/cocoa/region.h"
234 #elif defined(__WXPM__)
235 #include "wx/os2/region.h"
236 #endif
237
238 // ----------------------------------------------------------------------------
239 // inline functions implementation
240 // ----------------------------------------------------------------------------
241
242 // NB: these functions couldn't be defined in the class declaration as they use
243 // wxRegion and so can be only defined after including the header declaring
244 // the real class
245
246 inline bool wxRegionBase::Intersect(const wxRect& rect)
247 {
248 return DoIntersect(wxRegion(rect));
249 }
250
251 inline bool wxRegionBase::Subtract(const wxRect& rect)
252 {
253 return DoSubtract(wxRegion(rect));
254 }
255
256 inline bool wxRegionBase::Xor(const wxRect& rect)
257 {
258 return DoXor(wxRegion(rect));
259 }
260
261 // ...and these functions are here because they call the ones above, and its
262 // not really proper to call an inline function before its defined inline.
263
264 inline bool wxRegionBase::Intersect(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
265 {
266 return Intersect(wxRect(x, y, w, h));
267 }
268
269 inline bool wxRegionBase::Subtract(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
270 {
271 return Subtract(wxRect(x, y, w, h));
272 }
273
274 inline bool wxRegionBase::Xor(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
275 {
276 return Xor(wxRect(x, y, w, h));
277 }
278
279 #ifdef wxHAS_REGION_COMBINE
280
281 inline bool wxRegionWithCombine::Combine(wxCoord x,
282 wxCoord y,
283 wxCoord w,
284 wxCoord h,
285 wxRegionOp op)
286 {
287 return DoCombine(wxRegion(x, y, w, h), op);
288 }
289
290 inline bool wxRegionWithCombine::Combine(const wxRect& rect, wxRegionOp op)
291 {
292 return DoCombine(wxRegion(rect), op);
293 }
294
295 #endif // wxHAS_REGION_COMBINE
296
297 #endif // _WX_REGION_H_BASE_