]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/region.h
added and documented SplitVolume() and GetPathTerminators(); corrected SetPath()...
[wxWidgets.git] / include / wx / msw / region.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/region.h
3 // Purpose: wxRegion class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) 1997-2002 wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_REGION_H_
13 #define _WX_REGION_H_
14
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "region.h"
17 #endif
18
19 #include "wx/gdiobj.h"
20 #include "wx/gdicmn.h"
21
22 class WXDLLEXPORT wxRect;
23 class WXDLLEXPORT wxPoint;
24
25 enum wxRegionContain
26 {
27 wxOutRegion = 0,
28 wxPartRegion = 1,
29 wxInRegion = 2
30 };
31
32 // So far, for internal use only
33 enum wxRegionOp
34 {
35 wxRGN_AND, // Creates the intersection of the two combined regions.
36 wxRGN_COPY, // Creates a copy of the region identified by hrgnSrc1.
37 wxRGN_DIFF, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
38 wxRGN_OR, // Creates the union of two combined regions.
39 wxRGN_XOR // Creates the union of two combined regions except for any overlapping areas.
40 };
41
42 class WXDLLEXPORT wxRegion : public wxGDIObject
43 {
44 public:
45 wxRegion();
46 wxRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
47 wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight);
48 wxRegion(const wxRect& rect);
49 wxRegion(WXHRGN hRegion); // Hangs on to this region
50 wxRegion(size_t n, const wxPoint *points, int fillStyle = wxODDEVEN_RULE );
51 wxRegion( const wxBitmap& bmp)
52 {
53 Union(bmp);
54 }
55 wxRegion( const wxBitmap& bmp,
56 const wxColour& transColour, int tolerance = 0)
57 {
58 Union(bmp, transColour, tolerance);
59 }
60
61 virtual ~wxRegion();
62
63 // Copying
64 wxRegion(const wxRegion& r)
65 { Ref(r); }
66 wxRegion& operator = (const wxRegion& r)
67 { Ref(r); return (*this); }
68
69 // Modify region
70 // -------------
71
72 // Clear current region
73 void Clear();
74
75 // Move the region
76 bool Offset(wxCoord x, wxCoord y);
77
78 // Union rectangle or region with this.
79 bool Union(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_OR); }
80 bool Union(const wxRect& rect) { return Combine(rect, wxRGN_OR); }
81 bool Union(const wxRegion& region) { return Combine(region, wxRGN_OR); }
82
83 // Intersect rectangle or region with this.
84 bool Intersect(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_AND); }
85 bool Intersect(const wxRect& rect) { return Combine(rect, wxRGN_AND); }
86 bool Intersect(const wxRegion& region) { return Combine(region, wxRGN_AND); }
87
88 // Subtract rectangle or region from this:
89 // Combines the parts of 'this' that are not part of the second region.
90 bool Subtract(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_DIFF); }
91 bool Subtract(const wxRect& rect) { return Combine(rect, wxRGN_DIFF); }
92 bool Subtract(const wxRegion& region) { return Combine(region, wxRGN_DIFF); }
93
94 // XOR: the union of two combined regions except for any overlapping areas.
95 bool Xor(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_XOR); }
96 bool Xor(const wxRect& rect) { return Combine(rect, wxRGN_XOR); }
97 bool Xor(const wxRegion& region) { return Combine(region, wxRGN_XOR); }
98
99 // Information on region
100 // ---------------------
101
102 // Outer bounds of region
103 void GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const;
104 wxRect GetBox() const ;
105
106 // Is region empty?
107 bool Empty() const;
108 inline bool IsEmpty() const { return Empty(); }
109
110 // Tests
111 // Does the region contain the point (x,y)?
112 wxRegionContain Contains(wxCoord x, wxCoord y) const;
113 // Does the region contain the point pt?
114 wxRegionContain Contains(const wxPoint& pt) const;
115 // Does the region contain the rectangle (x, y, w, h)?
116 wxRegionContain Contains(wxCoord x, wxCoord y, wxCoord w, wxCoord h) const;
117 // Does the region contain the rectangle rect?
118 wxRegionContain Contains(const wxRect& rect) const;
119
120 // Convert the region to a B&W bitmap with the white pixels being inside
121 // the region.
122 wxBitmap ConvertToBitmap() const;
123
124 // Use the non-transparent pixels of a wxBitmap for the region to combine
125 // with this region. First version takes transparency from bitmap's mask,
126 // second lets the user specify the colour to be treated as transparent
127 // along with an optional tolerance value.
128 // NOTE: implemented in common/rgncmn.cpp
129 bool Union(const wxBitmap& bmp);
130 bool Union(const wxBitmap& bmp,
131 const wxColour& transColour, int tolerance = 0);
132
133 // Internal
134 bool Combine(wxCoord x, wxCoord y, wxCoord width, wxCoord height, wxRegionOp op);
135 bool Combine(const wxRegion& region, wxRegionOp op);
136 bool Combine(const wxRect& rect, wxRegionOp op);
137
138 // Get internal region handle
139 WXHRGN GetHRGN() const;
140
141 protected:
142 virtual wxObjectRefData *CreateRefData() const;
143 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
144
145 friend class WXDLLEXPORT wxRegionIterator;
146
147 DECLARE_DYNAMIC_CLASS(wxRegion)
148 };
149
150 class WXDLLEXPORT wxRegionIterator : public wxObject
151 {
152 public:
153 wxRegionIterator() { Init(); }
154 wxRegionIterator(const wxRegion& region);
155 wxRegionIterator(const wxRegionIterator& ri) { Init(); *this = ri; }
156
157 wxRegionIterator& operator=(const wxRegionIterator& ri);
158
159 virtual ~wxRegionIterator();
160
161 void Reset() { m_current = 0; }
162 void Reset(const wxRegion& region);
163
164 bool HaveRects() const { return (m_current < m_numRects); }
165
166 #ifndef __SALFORDC__
167 operator bool () const { return HaveRects(); }
168 #endif
169
170 wxRegionIterator& operator++();
171 wxRegionIterator operator++(int);
172
173 wxCoord GetX() const;
174 wxCoord GetY() const;
175 wxCoord GetW() const;
176 wxCoord GetWidth() const { return GetW(); }
177 wxCoord GetH() const;
178 wxCoord GetHeight() const { return GetH(); }
179
180 wxRect GetRect() const { return wxRect(GetX(), GetY(), GetW(), GetH()); }
181
182 private:
183 // common part of all ctors
184 void Init();
185
186 long m_current;
187 long m_numRects;
188 wxRegion m_region;
189 wxRect* m_rects;
190
191 DECLARE_DYNAMIC_CLASS(wxRegionIterator)
192 };
193
194 #endif
195 // _WX_REGION_H_