]> git.saurik.com Git - wxWidgets.git/blob - include/wx/os2/region.h
region from polygon added
[wxWidgets.git] / include / wx / os2 / region.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: region.h
3 // Purpose: wxRegion class
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/15/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_REGION_H_
13 #define _WX_REGION_H_
14
15 #include "wx/list.h"
16 #include "wx/gdiobj.h"
17 #include "wx/gdicmn.h"
18 #include "wx/bitmap.h"
19 #include "wx/os2/private.h"
20
21 class WXDLLEXPORT wxRect;
22 class WXDLLEXPORT wxPoint;
23
24 enum wxRegionContain {
25 wxOutRegion = 0, wxPartRegion = 1, wxInRegion = 2
26 };
27
28 // So far, for internal use only
29 enum wxRegionOp { wxRGN_AND // Creates the intersection of the two combined regions.
30 ,wxRGN_COPY // Creates a copy of the region identified by hrgnSrc1.
31 ,wxRGN_DIFF // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
32 ,wxRGN_OR // Creates the union of two combined regions.
33 ,wxRGN_XOR // Creates the union of two combined regions except for any overlapping areas.
34 };
35
36 class WXDLLEXPORT wxRegion : public wxGDIObject
37 {
38 public:
39 wxRegion( wxCoord x
40 ,wxCoord y
41 ,wxCoord vWidth
42 ,wxCoord vHeight
43 );
44 wxRegion( const wxPoint& rTopLeft
45 ,const wxPoint& rBottomRight
46 );
47 wxRegion(const wxRect& rRect);
48 wxRegion(WXHRGN hRegion, WXHDC hPS); // Hangs on to this region
49 wxRegion( const wxBitmap& bmp)
50 {
51 Union(bmp);
52 }
53 wxRegion( const wxBitmap& bmp,
54 const wxColour& transColour, int tolerance = 0)
55 {
56 Union(bmp, transColour, tolerance);
57 }
58
59 wxRegion();
60 ~wxRegion();
61
62 //
63 // Copying
64 //
65 inline wxRegion(const wxRegion& rSrc)
66 { Ref(rSrc); }
67 inline wxRegion& operator = (const wxRegion& rSrc)
68 { Ref(rSrc); return (*this); }
69
70 //
71 // Modify region
72 //
73
74 //
75 // Clear current region
76 //
77 void Clear(void);
78
79 bool Offset( wxCoord x
80 ,wxCoord y
81 );
82
83 //
84 // Union rectangle or region with this.
85 //
86 inline bool Union( wxCoord x
87 ,wxCoord y
88 ,wxCoord vWidth
89 ,wxCoord vHeight
90 )
91 {
92 return Combine( x
93 ,y
94 ,vWidth
95 ,vHeight
96 ,wxRGN_OR
97 );
98 }
99 inline bool Union( const wxRect& rRect) { return Combine(rRect, wxRGN_OR); }
100 inline bool Union(const wxRegion& rRegion) { return Combine(rRegion, wxRGN_OR); }
101
102 //
103 // Intersect rectangle or region with this.
104 //
105 inline bool Intersect( wxCoord x
106 ,wxCoord y
107 ,wxCoord vWidth
108 ,wxCoord vHeight
109 )
110 {
111 return Combine( x
112 ,y
113 ,vWidth
114 ,vHeight
115 ,wxRGN_AND
116 );
117 }
118 inline bool Intersect(const wxRect& rRect) { return Combine(rRect, wxRGN_AND); }
119 inline bool Intersect(const wxRegion& rRegion) { return Combine(rRegion, wxRGN_AND); }
120
121 //
122 // Subtract rectangle or region from this:
123 // Combines the parts of 'this' that are not part of the second region.
124 //
125 inline bool Subtract( wxCoord x
126 ,wxCoord y
127 ,wxCoord vWidth
128 ,wxCoord vHeight
129 )
130 {
131 return Combine( x
132 ,y
133 ,vWidth
134 ,vHeight
135 ,wxRGN_DIFF
136 );
137 }
138 inline bool Subtract(const wxRect& rRect) { return Combine(rRect, wxRGN_DIFF); }
139 inline bool Subtract(const wxRegion& rRegion) { return Combine(rRegion, wxRGN_DIFF); }
140
141 //
142 // XOR: the union of two combined regions except for any overlapping areas.
143 //
144 inline bool Xor( wxCoord x
145 ,wxCoord y
146 ,wxCoord vWidth
147 ,wxCoord vHeight
148 )
149 {
150 return Combine( x
151 ,y
152 ,vWidth
153 ,vHeight
154 ,wxRGN_XOR
155 );
156 }
157 inline bool Xor(const wxRect& rRect) { return Combine(rRect, wxRGN_XOR); }
158 inline bool Xor(const wxRegion& rRegion) { return Combine(rRegion, wxRGN_XOR); }
159
160 //
161 // Information on region
162 // Outer bounds of region
163 //
164 void GetBox( wxCoord& rX
165 ,wxCoord& rY
166 ,wxCoord& rWidth
167 ,wxCoord& rHeight
168 ) const;
169 wxRect GetBox(void) const;
170
171 //
172 // Is region empty?
173 //
174 bool Empty(void) const;
175 inline bool IsEmpty() const { return Empty(); }
176
177 //
178 // Tests
179 // Does the region contain the point (x,y)?
180 //
181 wxRegionContain Contains( wxCoord lX
182 ,wxCoord lY
183 ) const;
184
185 //
186 // Convert the region to a B&W bitmap with the black pixels being inside
187 // the region.
188 //
189 wxBitmap ConvertToBitmap(void) const;
190
191 // Use the non-transparent pixels of a wxBitmap for the region to combine
192 // with this region. First version takes transparency from bitmap's mask,
193 // second lets the user specify the colour to be treated as transparent
194 // along with an optional tolerance value.
195 // NOTE: implemented in common/rgncmn.cpp
196 bool Union(const wxBitmap& bmp);
197 bool Union(const wxBitmap& bmp,
198 const wxColour& transColour, int tolerance = 0);
199
200 //
201 // Does the region contain the point pt?
202 //
203 wxRegionContain Contains(const wxPoint& rPoint) const;
204
205 //
206 // Does the region contain the rectangle (x, y, w, h)?
207 //
208 wxRegionContain Contains( wxCoord x
209 ,wxCoord y
210 ,wxCoord lWidth
211 ,wxCoord lHeight
212 ) const;
213
214 //
215 // Does the region contain the rectangle rect?
216 //
217 wxRegionContain Contains(const wxRect& rRect) const;
218
219 //
220 // Internal
221 //
222 bool Combine( wxCoord x
223 ,wxCoord y
224 ,wxCoord vWidth
225 ,wxCoord vHeight
226 ,wxRegionOp eOp
227 );
228 bool Combine( const wxRegion& rRegion
229 ,wxRegionOp eOp
230 );
231 bool Combine( const wxRect& rRect
232 ,wxRegionOp eOp
233 );
234
235 //
236 // Get internal region handle
237 //
238 WXHRGN GetHRGN(void) const;
239 void SetPS(HPS hPS);
240
241 protected:
242 virtual wxObjectRefData* CreateData(void) const;
243 virtual wxObjectRefData* CloneData(const wxObjectRefData* pData) const;
244
245 friend class WXDLLEXPORT wxRegionIterator;
246 DECLARE_DYNAMIC_CLASS(wxRegion);
247
248 }; // end of CLASS wxRegion
249
250 class WXDLLEXPORT wxRegionIterator : public wxObject
251 {
252 DECLARE_DYNAMIC_CLASS(wxRegionIterator);
253 public:
254 wxRegionIterator();
255 wxRegionIterator(const wxRegion& rRegion);
256 ~wxRegionIterator();
257
258 void Reset(void) { m_lCurrent = 0; }
259 void Reset(const wxRegion& rRegion);
260
261 operator bool (void) const { return m_lCurrent < m_lNumRects; }
262 bool HaveRects(void) const { return m_lCurrent < m_lNumRects; }
263
264 void operator ++ (void);
265 void operator ++ (int);
266
267 wxCoord GetX(void) const;
268 wxCoord GetY(void) const;
269 wxCoord GetW(void) const;
270 wxCoord GetWidth(void) const { return GetW(); }
271 wxCoord GetH(void) const;
272 wxCoord GetHeight(void) const { return GetH(); }
273 wxRect GetRect(void) const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }
274
275 private:
276 long m_lCurrent;
277 long m_lNumRects;
278 wxRegion m_vRegion;
279 wxRect* m_pRects;
280 }; // end of wxRegionIterator
281
282 #endif
283 // _WX_REGION_H_