]>
Commit | Line | Data |
---|---|---|
99d80019 JS |
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 | ||
34138703 JS |
12 | #ifndef _WX_REGION_H_BASE_ |
13 | #define _WX_REGION_H_BASE_ | |
c801d85f | 14 | |
8a16d737 VZ |
15 | #include "wx/bitmap.h" |
16 | #include "wx/gdiobj.h" | |
17 | #include "wx/gdicmn.h" | |
c87beb79 | 18 | |
8a16d737 VZ |
19 | class WXDLLEXPORT wxColour; |
20 | class WXDLLEXPORT wxRegion; | |
21 | ||
22 | // ---------------------------------------------------------------------------- | |
23 | // constants | |
24 | // ---------------------------------------------------------------------------- | |
25 | ||
26 | // result of wxRegion::Contains() call | |
be2001fe VS |
27 | enum wxRegionContain |
28 | { | |
29 | wxOutRegion = 0, | |
30 | wxPartRegion = 1, | |
31 | wxInRegion = 2 | |
32 | }; | |
33 | ||
8a16d737 VZ |
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 | ||
b7cacb43 VZ |
85 | bool Ok() const { return IsOk(); } |
86 | bool IsOk() const { return m_refData != NULL; } | |
8a16d737 VZ |
87 | |
88 | // Is region empty? | |
89 | virtual bool IsEmpty() const = 0; | |
90 | bool Empty() const { return IsEmpty(); } | |
91 | ||
92 | // Is region equal (i.e. covers the same area as another one)? | |
93 | bool IsEqual(const wxRegion& region) const; | |
94 | ||
95 | // Get the bounding box | |
96 | bool GetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const | |
97 | { return DoGetBox(x, y, w, h); } | |
98 | wxRect GetBox() const | |
99 | { | |
100 | wxCoord x, y, w, h; | |
101 | return DoGetBox(x, y, w, h) ? wxRect(x, y, w, h) : wxRect(); | |
102 | } | |
103 | ||
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); } | |
113 | ||
114 | ||
115 | // operations | |
116 | // ---------- | |
117 | ||
118 | virtual void Clear() = 0; | |
119 | ||
120 | // Move the region | |
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); } | |
125 | ||
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); } | |
133 | ||
134 | #if wxUSE_IMAGE | |
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 | |
143 | ||
144 | // Intersect rectangle or region with this one. | |
145 | bool Intersect(wxCoord x, wxCoord y, wxCoord w, wxCoord h) | |
146 | { return Intersect(wxRect(x, y, w, h)); } | |
147 | bool Intersect(const wxRect& rect); | |
148 | bool Intersect(const wxRegion& region) | |
149 | { return DoIntersect(region); } | |
150 | ||
151 | // Subtract rectangle or region from this: | |
152 | // Combines the parts of 'this' that are not part of the second region. | |
153 | bool Subtract(wxCoord x, wxCoord y, wxCoord w, wxCoord h) | |
154 | { return Subtract(wxRect(x, y, w, h)); } | |
155 | bool Subtract(const wxRect& rect); | |
156 | bool Subtract(const wxRegion& region) | |
157 | { return DoSubtract(region); } | |
158 | ||
159 | // XOR: the union of two combined regions except for any overlapping areas. | |
160 | bool Xor(wxCoord x, wxCoord y, wxCoord w, wxCoord h) | |
161 | { return Xor(wxRect(x, y, w, h)); } | |
162 | bool Xor(const wxRect& rect); | |
163 | bool Xor(const wxRegion& region) | |
164 | { return DoXor(region); } | |
165 | ||
166 | ||
167 | // Convert the region to a B&W bitmap with the white pixels being inside | |
168 | // the region. | |
169 | wxBitmap ConvertToBitmap() const; | |
170 | ||
171 | protected: | |
172 | virtual bool DoIsEqual(const wxRegion& region) const = 0; | |
173 | virtual bool DoGetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const = 0; | |
174 | virtual wxRegionContain DoContainsPoint(wxCoord x, wxCoord y) const = 0; | |
175 | virtual wxRegionContain DoContainsRect(const wxRect& rect) const = 0; | |
176 | ||
177 | virtual bool DoOffset(wxCoord x, wxCoord y) = 0; | |
178 | ||
179 | virtual bool DoUnionWithRect(const wxRect& rect) = 0; | |
180 | virtual bool DoUnionWithRegion(const wxRegion& region) = 0; | |
181 | ||
182 | virtual bool DoIntersect(const wxRegion& region) = 0; | |
183 | virtual bool DoSubtract(const wxRegion& region) = 0; | |
184 | virtual bool DoXor(const wxRegion& region) = 0; | |
185 | }; | |
186 | ||
187 | // some ports implement a generic Combine() function while others only | |
188 | // implement individual wxRegion operations, factor out the common code for the | |
189 | // ports with Combine() in this class | |
190 | #if defined(__WXPALMOS__) || \ | |
191 | defined(__WXMSW__) || \ | |
192 | defined(__WXMAC__) || \ | |
193 | defined(__WXPM__) | |
194 | ||
195 | #define wxHAS_REGION_COMBINE | |
196 | ||
f600738e | 197 | class WXDLLEXPORT wxRegionWithCombine : public wxRegionBase |
8a16d737 VZ |
198 | { |
199 | public: | |
200 | // these methods are not part of public API as they're not implemented on | |
201 | // all ports | |
202 | bool Combine(wxCoord x, wxCoord y, wxCoord w, wxCoord h, wxRegionOp op); | |
203 | bool Combine(const wxRect& rect, wxRegionOp op); | |
204 | bool Combine(const wxRegion& region, wxRegionOp op) | |
205 | { return DoCombine(region, op); } | |
206 | ||
207 | ||
208 | protected: | |
209 | // the real Combine() method, to be defined in the derived class | |
210 | virtual bool DoCombine(const wxRegion& region, wxRegionOp op) = 0; | |
211 | ||
212 | // implement some wxRegionBase pure virtuals in terms of Combine() | |
213 | virtual bool DoUnionWithRect(const wxRect& rect) | |
214 | { return Combine(rect, wxRGN_OR); } | |
215 | virtual bool DoUnionWithRegion(const wxRegion& region) | |
216 | { return Combine(region, wxRGN_OR); } | |
217 | ||
218 | virtual bool DoIntersect(const wxRegion& region) | |
219 | { return Combine(region, wxRGN_AND); } | |
220 | virtual bool DoSubtract(const wxRegion& region) | |
221 | { return Combine(region, wxRGN_DIFF); } | |
222 | virtual bool DoXor(const wxRegion& region) | |
223 | { return Combine(region, wxRGN_XOR); } | |
224 | }; | |
225 | ||
226 | #endif // ports with wxRegion::Combine() | |
227 | ||
4055ed82 | 228 | #if defined(__WXPALMOS__) |
c87beb79 | 229 | #include "wx/palmos/region.h" |
ffecfa5a | 230 | #elif defined(__WXMSW__) |
c87beb79 | 231 | #include "wx/msw/region.h" |
1be7a35c | 232 | #elif defined(__WXGTK20__) |
c87beb79 | 233 | #include "wx/gtk/region.h" |
1be7a35c MR |
234 | #elif defined(__WXGTK__) |
235 | #include "wx/gtk1/region.h" | |
c87beb79 VZ |
236 | #elif defined(__WXMOTIF__) || defined(__WXX11__) |
237 | #include "wx/x11/region.h" | |
d32cad2c | 238 | #elif defined(__WXMGL__) |
c87beb79 | 239 | #include "wx/mgl/region.h" |
b3c86150 VS |
240 | #elif defined(__WXDFB__) |
241 | #include "wx/dfb/region.h" | |
34138703 | 242 | #elif defined(__WXMAC__) |
c87beb79 | 243 | #include "wx/mac/region.h" |
e64df9bc | 244 | #elif defined(__WXCOCOA__) |
c87beb79 | 245 | #include "wx/cocoa/region.h" |
1777b9bb | 246 | #elif defined(__WXPM__) |
c87beb79 | 247 | #include "wx/os2/region.h" |
c801d85f KB |
248 | #endif |
249 | ||
8a16d737 VZ |
250 | // ---------------------------------------------------------------------------- |
251 | // inline functions implementation | |
252 | // ---------------------------------------------------------------------------- | |
253 | ||
254 | // NB: these functions couldn't be defined in the class declaration as they use | |
255 | // wxRegion and so can be only defined after including the header declaring | |
256 | // the real class | |
257 | ||
258 | inline bool wxRegionBase::Intersect(const wxRect& rect) | |
259 | { | |
260 | return DoIntersect(wxRegion(rect)); | |
261 | } | |
262 | ||
263 | inline bool wxRegionBase::Subtract(const wxRect& rect) | |
264 | { | |
265 | return DoSubtract(wxRegion(rect)); | |
266 | } | |
267 | ||
268 | inline bool wxRegionBase::Xor(const wxRect& rect) | |
269 | { | |
270 | return DoXor(wxRegion(rect)); | |
271 | } | |
272 | ||
273 | #ifdef wxHAS_REGION_COMBINE | |
274 | ||
275 | inline bool wxRegionWithCombine::Combine(wxCoord x, | |
276 | wxCoord y, | |
277 | wxCoord w, | |
278 | wxCoord h, | |
279 | wxRegionOp op) | |
280 | { | |
281 | return DoCombine(wxRegion(x, y, w, h), op); | |
282 | } | |
283 | ||
284 | inline bool wxRegionWithCombine::Combine(const wxRect& rect, wxRegionOp op) | |
285 | { | |
286 | return DoCombine(wxRegion(rect), op); | |
287 | } | |
288 | ||
289 | #endif // wxHAS_REGION_COMBINE | |
290 | ||
291 | #endif // _WX_REGION_H_BASE_ |