]> git.saurik.com Git - wxWidgets.git/blob - include/wx/os2/region.h
added NormalizeValue() which can be used to ensure that the control value is in range
[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 // Modify region
64 //
65
66 //
67 // Clear current region
68 //
69 void Clear(void);
70
71 bool Offset( wxCoord x
72 ,wxCoord y
73 );
74
75 //
76 // Union rectangle or region with this.
77 //
78 inline bool Union( wxCoord x
79 ,wxCoord y
80 ,wxCoord vWidth
81 ,wxCoord vHeight
82 )
83 {
84 return Combine( x
85 ,y
86 ,vWidth
87 ,vHeight
88 ,wxRGN_OR
89 );
90 }
91 inline bool Union( const wxRect& rRect) { return Combine(rRect, wxRGN_OR); }
92 inline bool Union(const wxRegion& rRegion) { return Combine(rRegion, wxRGN_OR); }
93
94 //
95 // Intersect rectangle or region with this.
96 //
97 inline bool Intersect( wxCoord x
98 ,wxCoord y
99 ,wxCoord vWidth
100 ,wxCoord vHeight
101 )
102 {
103 return Combine( x
104 ,y
105 ,vWidth
106 ,vHeight
107 ,wxRGN_AND
108 );
109 }
110 inline bool Intersect(const wxRect& rRect) { return Combine(rRect, wxRGN_AND); }
111 inline bool Intersect(const wxRegion& rRegion) { return Combine(rRegion, wxRGN_AND); }
112
113 //
114 // Subtract rectangle or region from this:
115 // Combines the parts of 'this' that are not part of the second region.
116 //
117 inline bool Subtract( wxCoord x
118 ,wxCoord y
119 ,wxCoord vWidth
120 ,wxCoord vHeight
121 )
122 {
123 return Combine( x
124 ,y
125 ,vWidth
126 ,vHeight
127 ,wxRGN_DIFF
128 );
129 }
130 inline bool Subtract(const wxRect& rRect) { return Combine(rRect, wxRGN_DIFF); }
131 inline bool Subtract(const wxRegion& rRegion) { return Combine(rRegion, wxRGN_DIFF); }
132
133 //
134 // XOR: the union of two combined regions except for any overlapping areas.
135 //
136 inline bool Xor( wxCoord x
137 ,wxCoord y
138 ,wxCoord vWidth
139 ,wxCoord vHeight
140 )
141 {
142 return Combine( x
143 ,y
144 ,vWidth
145 ,vHeight
146 ,wxRGN_XOR
147 );
148 }
149 inline bool Xor(const wxRect& rRect) { return Combine(rRect, wxRGN_XOR); }
150 inline bool Xor(const wxRegion& rRegion) { return Combine(rRegion, wxRGN_XOR); }
151
152 //
153 // Information on region
154 // Outer bounds of region
155 //
156 void GetBox( wxCoord& rX
157 ,wxCoord& rY
158 ,wxCoord& rWidth
159 ,wxCoord& rHeight
160 ) const;
161 wxRect GetBox(void) const;
162
163 //
164 // Is region empty?
165 //
166 bool Empty(void) const;
167 inline bool IsEmpty() const { return Empty(); }
168
169 //
170 // Tests
171 // Does the region contain the point (x,y)?
172 //
173 inline wxRegionContain Contains( wxCoord lX, wxCoord lY ) const{
174 return Contains( wxPoint( lX, lY ) );
175 }
176 //
177 // Convert the region to a B&W bitmap with the black pixels being inside
178 // the region.
179 //
180 wxBitmap ConvertToBitmap(void) const;
181
182 // Use the non-transparent pixels of a wxBitmap for the region to combine
183 // with this region. First version takes transparency from bitmap's mask,
184 // second lets the user specify the colour to be treated as transparent
185 // along with an optional tolerance value.
186 // NOTE: implemented in common/rgncmn.cpp
187 bool Union(const wxBitmap& bmp);
188 bool Union(const wxBitmap& bmp,
189 const wxColour& transColour, int tolerance = 0);
190
191 //
192 // Does the region contain the point pt?
193 //
194 wxRegionContain Contains(const wxPoint& rPoint) const;
195
196 //
197 // Does the region contain the rectangle (x, y, w, h)?
198 //
199 wxRegionContain Contains( wxCoord x
200 ,wxCoord y
201 ,wxCoord lWidth
202 ,wxCoord lHeight
203 ) const;
204
205 //
206 // Does the region contain the rectangle rect?
207 //
208 inline wxRegionContain Contains(const wxRect& rRect) const{
209 return Contains( rRect.x, rRect.y,
210 rRect.GetWidth(), rRect.GetHeight());
211 }
212
213 //
214 // Internal
215 //
216 bool Combine( wxCoord x
217 ,wxCoord y
218 ,wxCoord vWidth
219 ,wxCoord vHeight
220 ,wxRegionOp eOp
221 );
222 bool Combine( const wxRegion& rRegion
223 ,wxRegionOp eOp
224 );
225 bool Combine( const wxRect& rRect
226 ,wxRegionOp eOp
227 );
228
229 //
230 // Get internal region handle
231 //
232 WXHRGN GetHRGN(void) const;
233 void SetPS(HPS hPS);
234
235 protected:
236 virtual wxObjectRefData* CreateData(void) const;
237 virtual wxObjectRefData* CloneData(const wxObjectRefData* pData) const;
238
239 friend class WXDLLEXPORT wxRegionIterator;
240 DECLARE_DYNAMIC_CLASS(wxRegion);
241
242 }; // end of CLASS wxRegion
243
244 class WXDLLEXPORT wxRegionIterator : public wxObject
245 {
246 DECLARE_DYNAMIC_CLASS(wxRegionIterator);
247 public:
248 wxRegionIterator();
249 wxRegionIterator(const wxRegion& rRegion);
250 ~wxRegionIterator();
251
252 void Reset(void) { m_lCurrent = 0; }
253 void Reset(const wxRegion& rRegion);
254
255 operator bool (void) const { return m_lCurrent < m_lNumRects; }
256 bool HaveRects(void) const { return m_lCurrent < m_lNumRects; }
257
258 void operator ++ (void);
259 void operator ++ (int);
260
261 wxCoord GetX(void) const;
262 wxCoord GetY(void) const;
263 wxCoord GetW(void) const;
264 wxCoord GetWidth(void) const { return GetW(); }
265 wxCoord GetH(void) const;
266 wxCoord GetHeight(void) const { return GetH(); }
267 wxRect GetRect(void) const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }
268
269 private:
270 long m_lCurrent;
271 long m_lNumRects;
272 wxRegion m_vRegion;
273 wxRect* m_pRects;
274 }; // end of wxRegionIterator
275
276 #endif
277 // _WX_REGION_H_