]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/region.h
Build fix for wxMSWUniv makefile driven builds. univ/setup0.h should be autoregenerat...
[wxWidgets.git] / include / wx / region.h
... / ...
CommitLineData
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/bitmap.h"
16#include "wx/gdiobj.h"
17#include "wx/gdicmn.h"
18
19class WXDLLEXPORT wxColour;
20class WXDLLEXPORT wxRegion;
21
22// ----------------------------------------------------------------------------
23// constants
24// ----------------------------------------------------------------------------
25
26// result of wxRegion::Contains() call
27enum 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
36enum 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
58class WXDLLEXPORT wxRegionBase : public wxGDIObject
59{
60public:
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 bool Ok() const { return m_refData != NULL; }
86
87 // Is region empty?
88 virtual bool IsEmpty() const = 0;
89 bool Empty() const { return IsEmpty(); }
90
91 // Is region equal (i.e. covers the same area as another one)?
92 bool IsEqual(const wxRegion& region) const;
93
94 // Get the bounding box
95 bool GetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const
96 { return DoGetBox(x, y, w, h); }
97 wxRect GetBox() const
98 {
99 wxCoord x, y, w, h;
100 return DoGetBox(x, y, w, h) ? wxRect(x, y, w, h) : wxRect();
101 }
102
103 // Test if the given point or rectangle is inside this region
104 wxRegionContain Contains(wxCoord x, wxCoord y) const
105 { return DoContainsPoint(x, y); }
106 wxRegionContain Contains(const wxPoint& pt) const
107 { return DoContainsPoint(pt.x, pt.y); }
108 wxRegionContain Contains(wxCoord x, wxCoord y, wxCoord w, wxCoord h) const
109 { return DoContainsRect(wxRect(x, y, w, h)); }
110 wxRegionContain Contains(const wxRect& rect) const
111 { return DoContainsRect(rect); }
112
113
114 // operations
115 // ----------
116
117 virtual void Clear() = 0;
118
119 // Move the region
120 bool Offset(wxCoord x, wxCoord y)
121 { return DoOffset(x, y); }
122 bool Offset(const wxPoint& pt)
123 { return DoOffset(pt.x, pt.y); }
124
125 // Union rectangle or region with this region.
126 bool Union(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
127 { return DoUnionWithRect(wxRect(x, y, w, h)); }
128 bool Union(const wxRect& rect)
129 { return DoUnionWithRect(rect); }
130 bool Union(const wxRegion& region)
131 { return DoUnionWithRegion(region); }
132
133#if wxUSE_IMAGE
134 // Use the non-transparent pixels of a wxBitmap for the region to combine
135 // with this region. First version takes transparency from bitmap's mask,
136 // second lets the user specify the colour to be treated as transparent
137 // along with an optional tolerance value.
138 // NOTE: implemented in common/rgncmn.cpp
139 bool Union(const wxBitmap& bmp);
140 bool Union(const wxBitmap& bmp, const wxColour& transp, int tolerance = 0);
141#endif // wxUSE_IMAGE
142
143 // Intersect rectangle or region with this one.
144 bool Intersect(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
145 { return Intersect(wxRect(x, y, w, h)); }
146 bool Intersect(const wxRect& rect);
147 bool Intersect(const wxRegion& region)
148 { return DoIntersect(region); }
149
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 { return Subtract(wxRect(x, y, w, h)); }
154 bool Subtract(const wxRect& rect);
155 bool Subtract(const wxRegion& region)
156 { return DoSubtract(region); }
157
158 // XOR: the union of two combined regions except for any overlapping areas.
159 bool Xor(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
160 { return Xor(wxRect(x, y, w, h)); }
161 bool Xor(const wxRect& rect);
162 bool Xor(const wxRegion& region)
163 { return DoXor(region); }
164
165
166 // Convert the region to a B&W bitmap with the white pixels being inside
167 // the region.
168 wxBitmap ConvertToBitmap() const;
169
170protected:
171 virtual bool DoIsEqual(const wxRegion& region) const = 0;
172 virtual bool DoGetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const = 0;
173 virtual wxRegionContain DoContainsPoint(wxCoord x, wxCoord y) const = 0;
174 virtual wxRegionContain DoContainsRect(const wxRect& rect) const = 0;
175
176 virtual bool DoOffset(wxCoord x, wxCoord y) = 0;
177
178 virtual bool DoUnionWithRect(const wxRect& rect) = 0;
179 virtual bool DoUnionWithRegion(const wxRegion& region) = 0;
180
181 virtual bool DoIntersect(const wxRegion& region) = 0;
182 virtual bool DoSubtract(const wxRegion& region) = 0;
183 virtual bool DoXor(const wxRegion& region) = 0;
184};
185
186// some ports implement a generic Combine() function while others only
187// implement individual wxRegion operations, factor out the common code for the
188// ports with Combine() in this class
189#if defined(__WXPALMOS__) || \
190 defined(__WXMSW__) || \
191 defined(__WXMAC__) || \
192 defined(__WXPM__)
193
194#define wxHAS_REGION_COMBINE
195
196class wxRegionWithCombine : public wxRegionBase
197{
198public:
199 // these methods are not part of public API as they're not implemented on
200 // all ports
201 bool Combine(wxCoord x, wxCoord y, wxCoord w, wxCoord h, wxRegionOp op);
202 bool Combine(const wxRect& rect, wxRegionOp op);
203 bool Combine(const wxRegion& region, wxRegionOp op)
204 { return DoCombine(region, op); }
205
206
207protected:
208 // the real Combine() method, to be defined in the derived class
209 virtual bool DoCombine(const wxRegion& region, wxRegionOp op) = 0;
210
211 // implement some wxRegionBase pure virtuals in terms of Combine()
212 virtual bool DoUnionWithRect(const wxRect& rect)
213 { return Combine(rect, wxRGN_OR); }
214 virtual bool DoUnionWithRegion(const wxRegion& region)
215 { return Combine(region, wxRGN_OR); }
216
217 virtual bool DoIntersect(const wxRegion& region)
218 { return Combine(region, wxRGN_AND); }
219 virtual bool DoSubtract(const wxRegion& region)
220 { return Combine(region, wxRGN_DIFF); }
221 virtual bool DoXor(const wxRegion& region)
222 { return Combine(region, wxRGN_XOR); }
223};
224
225#endif // ports with wxRegion::Combine()
226
227#if defined(__WXPALMOS__)
228 #include "wx/palmos/region.h"
229#elif defined(__WXMSW__)
230 #include "wx/msw/region.h"
231#elif defined(__WXGTK20__)
232 #include "wx/gtk/region.h"
233#elif defined(__WXGTK__)
234 #include "wx/gtk1/region.h"
235#elif defined(__WXMOTIF__) || defined(__WXX11__)
236 #include "wx/x11/region.h"
237#elif defined(__WXMGL__)
238 #include "wx/mgl/region.h"
239#elif defined(__WXDFB__)
240 #include "wx/dfb/region.h"
241#elif defined(__WXMAC__)
242 #include "wx/mac/region.h"
243#elif defined(__WXCOCOA__)
244 #include "wx/cocoa/region.h"
245#elif defined(__WXPM__)
246 #include "wx/os2/region.h"
247#endif
248
249// ----------------------------------------------------------------------------
250// inline functions implementation
251// ----------------------------------------------------------------------------
252
253// NB: these functions couldn't be defined in the class declaration as they use
254// wxRegion and so can be only defined after including the header declaring
255// the real class
256
257inline bool wxRegionBase::Intersect(const wxRect& rect)
258{
259 return DoIntersect(wxRegion(rect));
260}
261
262inline bool wxRegionBase::Subtract(const wxRect& rect)
263{
264 return DoSubtract(wxRegion(rect));
265}
266
267inline bool wxRegionBase::Xor(const wxRect& rect)
268{
269 return DoXor(wxRegion(rect));
270}
271
272#ifdef wxHAS_REGION_COMBINE
273
274inline bool wxRegionWithCombine::Combine(wxCoord x,
275 wxCoord y,
276 wxCoord w,
277 wxCoord h,
278 wxRegionOp op)
279{
280 return DoCombine(wxRegion(x, y, w, h), op);
281}
282
283inline bool wxRegionWithCombine::Combine(const wxRect& rect, wxRegionOp op)
284{
285 return DoCombine(wxRegion(rect), op);
286}
287
288#endif // wxHAS_REGION_COMBINE
289
290#endif // _WX_REGION_H_BASE_