]> git.saurik.com Git - wxWidgets.git/blob - include/wx/os2/region.h
Small change
[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 DECLARE_DYNAMIC_CLASS(wxRegion);
37 friend class WXDLLEXPORT wxRegionIterator;
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
50 wxRegion();
51 ~wxRegion();
52
53 //
54 // Copying
55 //
56 inline wxRegion(const wxRegion& rSrc)
57 { Ref(rSrc); }
58 inline wxRegion& operator = (const wxRegion& rSrc)
59 { Ref(rSrc); return (*this); }
60
61 //
62 // Modify region
63 //
64
65 //
66 // Clear current region
67 //
68 void Clear(void);
69
70 //
71 // Union rectangle or region with this.
72 //
73 inline bool Union( wxCoord x
74 ,wxCoord y
75 ,wxCoord vWidth
76 ,wxCoord vHeight
77 )
78 {
79 return Combine( x
80 ,y
81 ,vWidth
82 ,vHeight
83 ,wxRGN_OR
84 );
85 }
86 inline bool Union( const wxRect& rRect) { return Combine(rRect, wxRGN_OR); }
87 inline bool Union(const wxRegion& rRegion) { return Combine(rRegion, wxRGN_OR); }
88
89 //
90 // Intersect rectangle or region with this.
91 //
92 inline bool Intersect( wxCoord x
93 ,wxCoord y
94 ,wxCoord vWidth
95 ,wxCoord vHeight
96 )
97 {
98 return Combine( x
99 ,y
100 ,vWidth
101 ,vHeight
102 ,wxRGN_AND
103 );
104 }
105 inline bool Intersect(const wxRect& rRect) { return Combine(rRect, wxRGN_AND); }
106 inline bool Intersect(const wxRegion& rRegion) { return Combine(rRegion, wxRGN_AND); }
107
108 //
109 // Subtract rectangle or region from this:
110 // Combines the parts of 'this' that are not part of the second region.
111 //
112 inline bool Subtract( wxCoord x
113 ,wxCoord y
114 ,wxCoord vWidth
115 ,wxCoord vHeight
116 )
117 {
118 return Combine( x
119 ,y
120 ,vWidth
121 ,vHeight
122 ,wxRGN_DIFF
123 );
124 }
125 inline bool Subtract(const wxRect& rRect) { return Combine(rRect, wxRGN_DIFF); }
126 inline bool Subtract(const wxRegion& rRegion) { return Combine(rRegion, wxRGN_DIFF); }
127
128 //
129 // XOR: the union of two combined regions except for any overlapping areas.
130 //
131 inline bool Xor( wxCoord x
132 ,wxCoord y
133 ,wxCoord vWidth
134 ,wxCoord vHeight
135 )
136 {
137 return Combine( x
138 ,y
139 ,vWidth
140 ,vHeight
141 ,wxRGN_XOR
142 );
143 }
144 inline bool Xor(const wxRect& rRect) { return Combine(rRect, wxRGN_XOR); }
145 inline bool Xor(const wxRegion& rRegion) { return Combine(rRegion, wxRGN_XOR); }
146
147 //
148 // Information on region
149 // Outer bounds of region
150 //
151 void GetBox( wxCoord& rX
152 ,wxCoord& rY
153 ,wxCoord& rWidth
154 ,wxCoord& rHeight
155 ) const;
156 wxRect GetBox(void) const;
157
158 //
159 // Is region empty?
160 //
161 bool Empty(void) const;
162 inline bool IsEmpty() const { return Empty(); }
163
164 //
165 // Tests
166 // Does the region contain the point (x,y)?
167 //
168 wxRegionContain Contains( wxCoord lX
169 ,wxCoord lY
170 ) const;
171 //
172 // Does the region contain the point pt?
173 //
174 wxRegionContain Contains(const wxPoint& rPoint) const;
175
176 //
177 // Does the region contain the rectangle (x, y, w, h)?
178 //
179 wxRegionContain Contains( wxCoord x
180 ,wxCoord y
181 ,wxCoord lWidth
182 ,wxCoord lHeight
183 ) const;
184
185 //
186 // Does the region contain the rectangle rect?
187 //
188 wxRegionContain Contains(const wxRect& rRect) const;
189
190 //
191 // Internal
192 //
193 bool Combine( wxCoord x
194 ,wxCoord y
195 ,wxCoord vWidth
196 ,wxCoord vHeight
197 ,wxRegionOp eOp
198 );
199 bool Combine( const wxRegion& rRegion
200 ,wxRegionOp eOp
201 );
202 bool Combine( const wxRect& rRect
203 ,wxRegionOp eOp
204 );
205
206 //
207 // Get internal region handle
208 //
209 WXHRGN GetHRGN(void) const;
210 void SetPS(HPS hPS);
211 }; // end of CLASS wxRegion
212
213 class WXDLLEXPORT wxRegionIterator : public wxObject
214 {
215 DECLARE_DYNAMIC_CLASS(wxRegionIterator);
216 public:
217 wxRegionIterator();
218 wxRegionIterator(const wxRegion& rRegion);
219 ~wxRegionIterator();
220
221 void Reset(void) { m_lCurrent = 0; }
222 void Reset(const wxRegion& rRegion);
223
224 operator bool (void) const { return m_lCurrent < m_lNumRects; }
225 bool HaveRects(void) const { return m_lCurrent < m_lNumRects; }
226
227 void operator ++ (void);
228 void operator ++ (int);
229
230 wxCoord GetX(void) const;
231 wxCoord GetY(void) const;
232 wxCoord GetW(void) const;
233 wxCoord GetWidth(void) const { return GetW(); }
234 wxCoord GetH(void) const;
235 wxCoord GetHeight(void) const { return GetH(); }
236 wxRect GetRect(void) const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }
237
238 private:
239 long m_lCurrent;
240 long m_lNumRects;
241 wxRegion m_vRegion;
242 wxRect* m_pRects;
243 }; // end of wxRegionIterator
244
245 #endif
246 // _WX_REGION_H_