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