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