]> git.saurik.com Git - wxWidgets.git/blame - include/wx/os2/region.h
oops, reverted clntdata.h change, it _is_ needed
[wxWidgets.git] / include / wx / os2 / region.h
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: region.h
3// Purpose: wxRegion class
409c9842 4// Author: David Webster
0e320a79 5// Modified by:
409c9842 6// Created: 10/15/99
0e320a79 7// RCS-ID: $Id$
409c9842 8// Copyright: (c) David Webster
65571936 9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_REGION_H_
13#define _WX_REGION_H_
14
0e320a79
DW
15#include "wx/list.h"
16#include "wx/gdiobj.h"
17#include "wx/gdicmn.h"
85f6b408 18#include "wx/bitmap.h"
51a7e6af 19#include "wx/os2/private.h"
0e320a79
DW
20
21class WXDLLEXPORT wxRect;
22class WXDLLEXPORT wxPoint;
23
24enum wxRegionContain {
409c9842 25 wxOutRegion = 0, wxPartRegion = 1, wxInRegion = 2
0e320a79
DW
26};
27
28// So far, for internal use only
5a56a532
DW
29enum 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
36class WXDLLEXPORT wxRegion : public wxGDIObject
37{
0e320a79 38public:
5a56a532
DW
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);
19193a2c 48 wxRegion(WXHRGN hRegion, WXHDC hPS); // Hangs on to this region
85f6b408
VS
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 }
409c9842
DW
58
59 wxRegion();
60 ~wxRegion();
61
5a56a532
DW
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); }
409c9842 69
5a56a532
DW
70 //
71 // Modify region
72 //
73
74 //
409c9842 75 // Clear current region
5a56a532
DW
76 //
77 void Clear(void);
409c9842 78
45e0dc94
DW
79 bool Offset( wxCoord x
80 ,wxCoord y
81 );
82
5a56a532 83 //
409c9842 84 // Union rectangle or region with this.
5a56a532
DW
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 //
409c9842 103 // Intersect rectangle or region with this.
5a56a532
DW
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 //
409c9842 122 // Subtract rectangle or region from this:
0e320a79 123 // Combines the parts of 'this' that are not part of the second region.
5a56a532
DW
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 //
409c9842 142 // XOR: the union of two combined regions except for any overlapping areas.
5a56a532
DW
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
409c9842 162 // Outer bounds of region
5a56a532
DW
163 //
164 void GetBox( wxCoord& rX
165 ,wxCoord& rY
166 ,wxCoord& rWidth
167 ,wxCoord& rHeight
168 ) const;
169 wxRect GetBox(void) const;
170
171 //
409c9842 172 // Is region empty?
5a56a532
DW
173 //
174 bool Empty(void) const;
0e320a79
DW
175 inline bool IsEmpty() const { return Empty(); }
176
5a56a532
DW
177 //
178 // Tests
409c9842 179 // Does the region contain the point (x,y)?
5a56a532
DW
180 //
181 wxRegionContain Contains( wxCoord lX
182 ,wxCoord lY
183 ) const;
4f5c180e
DW
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
85f6b408
VS
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
4f5c180e 194 // along with an optional tolerance value.
85f6b408
VS
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);
4f5c180e 199
5a56a532 200 //
409c9842 201 // Does the region contain the point pt?
5a56a532
DW
202 //
203 wxRegionContain Contains(const wxPoint& rPoint) const;
204
205 //
409c9842 206 // Does the region contain the rectangle (x, y, w, h)?
5a56a532
DW
207 //
208 wxRegionContain Contains( wxCoord x
209 ,wxCoord y
210 ,wxCoord lWidth
211 ,wxCoord lHeight
212 ) const;
213
214 //
409c9842 215 // Does the region contain the rectangle rect?
5a56a532
DW
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 //
409c9842 236 // Get internal region handle
5a56a532
DW
237 //
238 WXHRGN GetHRGN(void) const;
239 void SetPS(HPS hPS);
45e0dc94
DW
240
241protected:
242 virtual wxObjectRefData* CreateData(void) const;
107e4338
DW
243 virtual wxObjectRefData* CloneData(const wxObjectRefData* pData) const;
244
45e0dc94
DW
245 friend class WXDLLEXPORT wxRegionIterator;
246 DECLARE_DYNAMIC_CLASS(wxRegion);
247
5a56a532 248}; // end of CLASS wxRegion
0e320a79 249
5a56a532
DW
250class WXDLLEXPORT wxRegionIterator : public wxObject
251{
0e320a79
DW
252DECLARE_DYNAMIC_CLASS(wxRegionIterator);
253public:
409c9842 254 wxRegionIterator();
5a56a532 255 wxRegionIterator(const wxRegion& rRegion);
409c9842 256 ~wxRegionIterator();
0e320a79 257
5a56a532
DW
258 void Reset(void) { m_lCurrent = 0; }
259 void Reset(const wxRegion& rRegion);
0e320a79 260
5a56a532
DW
261 operator bool (void) const { return m_lCurrent < m_lNumRects; }
262 bool HaveRects(void) const { return m_lCurrent < m_lNumRects; }
0e320a79 263
5a56a532 264 void operator ++ (void);
409c9842 265 void operator ++ (int);
0e320a79 266
5a56a532
DW
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()); }
0e320a79
DW
274
275private:
5a56a532
DW
276 long m_lCurrent;
277 long m_lNumRects;
278 wxRegion m_vRegion;
279 wxRect* m_pRects;
280}; // end of wxRegionIterator
0e320a79
DW
281
282#endif
409c9842 283 // _WX_REGION_H_