]>
Commit | Line | Data |
---|---|---|
0dbd6262 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: region.h | |
3 | // Purpose: wxRegion class | |
a31a5f85 | 4 | // Author: Stefan Csomor |
0dbd6262 | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
0dbd6262 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
e40298d5 | 9 | // Licence: wxWindows licence |
0dbd6262 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_REGION_H_ | |
13 | #define _WX_REGION_H_ | |
14 | ||
af49c4b8 | 15 | #if defined(__GNUG__) && !defined(__APPLE__) |
0dbd6262 SC |
16 | #pragma interface "region.h" |
17 | #endif | |
18 | ||
19 | #include "wx/list.h" | |
20 | #include "wx/gdiobj.h" | |
21 | #include "wx/gdicmn.h" | |
22 | ||
23 | class WXDLLEXPORT wxRect; | |
24 | class WXDLLEXPORT wxPoint; | |
25 | ||
26 | enum wxRegionContain { | |
e40298d5 | 27 | wxOutRegion = 0, wxPartRegion = 1, wxInRegion = 2 |
0dbd6262 SC |
28 | }; |
29 | ||
30 | // So far, for internal use only | |
31 | enum wxRegionOp { | |
32 | wxRGN_AND, // Creates the intersection of the two combined regions. | |
33 | wxRGN_COPY, // Creates a copy of the region identified by hrgnSrc1. | |
34 | wxRGN_DIFF, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2. | |
35 | wxRGN_OR, // Creates the union of two combined regions. | |
36 | wxRGN_XOR // Creates the union of two combined regions except for any overlapping areas. | |
37 | }; | |
38 | ||
39 | class WXDLLEXPORT wxRegion : public wxGDIObject { | |
40 | DECLARE_DYNAMIC_CLASS(wxRegion); | |
e40298d5 | 41 | friend class WXDLLEXPORT wxRegionIterator; |
0dbd6262 SC |
42 | public: |
43 | wxRegion(long x, long y, long w, long h); | |
44 | wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight); | |
45 | wxRegion(const wxRect& rect); | |
e7600a2c GD |
46 | wxRegion( WXHRGN hRegion ); |
47 | wxRegion(); | |
1542ea39 RD |
48 | wxRegion( const wxBitmap& bmp, |
49 | const wxColour& transColour = wxNullColour, | |
50 | int tolerance = 0) | |
51 | { | |
52 | Union(bmp, transColour, tolerance); | |
53 | } | |
54 | ||
e7600a2c | 55 | ~wxRegion(); |
1542ea39 | 56 | |
e7600a2c GD |
57 | //# Copying |
58 | wxRegion(const wxRegion& r) | |
59 | : wxGDIObject() | |
60 | { Ref(r); } | |
61 | wxRegion& operator = (const wxRegion& r) | |
62 | { Ref(r); return (*this); } | |
1542ea39 | 63 | |
e7600a2c GD |
64 | //# Modify region |
65 | // Clear current region | |
66 | void Clear(); | |
1542ea39 | 67 | |
e7600a2c GD |
68 | // Union rectangle or region with this. |
69 | bool Union(long x, long y, long width, long height) | |
70 | { return Combine(x, y, width, height, wxRGN_OR); } | |
71 | bool Union(const wxRect& rect) | |
72 | { return Combine(rect, wxRGN_OR); } | |
73 | bool Union(const wxRegion& region) | |
74 | { return Combine(region, wxRGN_OR); } | |
1542ea39 | 75 | |
e7600a2c GD |
76 | // Intersect rectangle or region with this. |
77 | bool Intersect(long x, long y, long width, long height) | |
78 | { return Combine(x, y, width, height, wxRGN_AND); } | |
79 | bool Intersect(const wxRect& rect) | |
80 | { return Combine(rect, wxRGN_AND); } | |
81 | bool Intersect(const wxRegion& region) | |
82 | { return Combine(region, wxRGN_AND); } | |
1542ea39 | 83 | |
e7600a2c | 84 | // Subtract rectangle or region from this: |
0dbd6262 | 85 | // Combines the parts of 'this' that are not part of the second region. |
e7600a2c GD |
86 | bool Subtract(long x, long y, long width, long height) |
87 | { return Combine(x, y, width, height, wxRGN_DIFF); } | |
88 | bool Subtract(const wxRect& rect) | |
89 | { return Combine(rect, wxRGN_DIFF); } | |
90 | bool Subtract(const wxRegion& region) | |
91 | { return Combine(region, wxRGN_DIFF); } | |
1542ea39 | 92 | |
e7600a2c GD |
93 | // XOR: the union of two combined regions except for any overlapping areas. |
94 | bool Xor(long x, long y, long width, long height) | |
95 | { return Combine(x, y, width, height, wxRGN_XOR); } | |
96 | bool Xor(const wxRect& rect) | |
97 | { return Combine(rect, wxRGN_XOR); } | |
98 | bool Xor(const wxRegion& region) | |
99 | { return Combine(region, wxRGN_XOR); } | |
1542ea39 | 100 | |
e7600a2c GD |
101 | //# Information on region |
102 | // Outer bounds of region | |
103 | void GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const; | |
104 | wxRect GetBox() const ; | |
1542ea39 | 105 | |
e7600a2c GD |
106 | // Is region empty? |
107 | bool Empty() const; | |
0dbd6262 | 108 | inline bool IsEmpty() const { return Empty(); } |
1542ea39 | 109 | |
e7600a2c GD |
110 | //# Tests |
111 | // Does the region contain the point (x,y)? | |
112 | wxRegionContain Contains(long x, long 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(long x, long y, long w, long h) const; | |
117 | // Does the region contain the rectangle rect? | |
118 | wxRegionContain Contains(const wxRect& rect) const; | |
1542ea39 | 119 | |
819451b6 | 120 | // Convert the region to a B&W bitmap with the white pixels being inside |
1542ea39 RD |
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. If the bitmap has a mask then it will be used, | |
126 | // otherwise the colour to be treated as transparent may be specified, | |
127 | // along with an optional tolerance value. | |
128 | bool Union(const wxBitmap& bmp, | |
129 | const wxColour& transColour = wxNullColour, | |
130 | int tolerance = 0); | |
131 | ||
e7600a2c GD |
132 | // Internal |
133 | bool Combine(long x, long y, long width, long height, wxRegionOp op); | |
134 | bool Combine(const wxRegion& region, wxRegionOp op); | |
135 | bool Combine(const wxRect& rect, wxRegionOp op); | |
136 | const WXHRGN GetWXHRGN() const ; | |
0dbd6262 SC |
137 | }; |
138 | ||
e7600a2c GD |
139 | class WXDLLEXPORT wxRegionIterator : public wxObject |
140 | { | |
141 | DECLARE_DYNAMIC_CLASS(wxRegionIterator) | |
1542ea39 | 142 | |
0dbd6262 | 143 | public: |
e7600a2c GD |
144 | wxRegionIterator(); |
145 | wxRegionIterator(const wxRegion& region); | |
146 | wxRegionIterator(const wxRegionIterator& iterator); | |
147 | ~wxRegionIterator(); | |
148 | ||
149 | wxRegionIterator& operator=(const wxRegionIterator& iterator); | |
6dcbb6d0 | 150 | |
e7600a2c GD |
151 | void Reset() { m_current = 0; } |
152 | void Reset(const wxRegion& region); | |
1542ea39 | 153 | |
e7600a2c GD |
154 | operator bool () const { return m_current < m_numRects; } |
155 | bool HaveRects() const { return m_current < m_numRects; } | |
6dcbb6d0 | 156 | |
e7600a2c GD |
157 | wxRegionIterator& operator++(); |
158 | wxRegionIterator operator++(int); | |
1542ea39 | 159 | |
e7600a2c GD |
160 | long GetX() const; |
161 | long GetY() const; | |
162 | long GetW() const; | |
163 | long GetWidth() const { return GetW(); } | |
164 | long GetH() const; | |
165 | long GetHeight() const { return GetH(); } | |
0dbd6262 | 166 | wxRect GetRect() const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); } |
0dbd6262 | 167 | private: |
6dcbb6d0 GD |
168 | void SetRects(long numRects, wxRect *rects); |
169 | ||
e7600a2c GD |
170 | long m_current; |
171 | long m_numRects; | |
172 | wxRegion m_region; | |
0dbd6262 SC |
173 | wxRect* m_rects; |
174 | }; | |
175 | ||
176 | #endif | |
e40298d5 | 177 | // _WX_REGION_H_ |