]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: region.h | |
3 | // Purpose: wxRegion class | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 17/09/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart, Robert Roebling | |
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 | //----------------------------------------------------------------------------- | |
20 | // classes | |
21 | //----------------------------------------------------------------------------- | |
22 | ||
23 | class WXDLLIMPEXP_CORE wxRegion; | |
24 | ||
25 | //----------------------------------------------------------------------------- | |
26 | // constants | |
27 | //----------------------------------------------------------------------------- | |
28 | ||
29 | enum wxRegionContain | |
30 | { | |
31 | wxOutRegion = 0, | |
32 | wxPartRegion = 1, | |
33 | wxInRegion = 2 | |
34 | }; | |
35 | ||
36 | // So far, for internal use only | |
37 | enum wxRegionOp | |
38 | { | |
39 | wxRGN_AND, // Creates the intersection of the two combined regions. | |
40 | wxRGN_COPY, // Creates a copy of the region identified by hrgnSrc1. | |
41 | wxRGN_DIFF, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2. | |
42 | wxRGN_OR, // Creates the union of two combined regions. | |
43 | wxRGN_XOR // Creates the union of two combined regions except for any overlapping areas. | |
44 | }; | |
45 | ||
46 | // ---------------------------------------------------------------------------- | |
47 | // wxRegion | |
48 | // ---------------------------------------------------------------------------- | |
49 | ||
50 | class WXDLLIMPEXP_CORE wxRegion : public wxGDIObject | |
51 | { | |
52 | public: | |
53 | wxRegion() { } | |
54 | ||
55 | wxRegion( wxCoord x, wxCoord y, wxCoord w, wxCoord h ) | |
56 | { | |
57 | InitRect(x, y, w, h); | |
58 | } | |
59 | ||
60 | wxRegion( const wxPoint& topLeft, const wxPoint& bottomRight ) | |
61 | { | |
62 | InitRect(topLeft.x, topLeft.y, | |
63 | bottomRight.x - topLeft.x, bottomRight.y - topLeft.y); | |
64 | } | |
65 | ||
66 | wxRegion( const wxRect& rect ) | |
67 | { | |
68 | InitRect(rect.x, rect.y, rect.width, rect.height); | |
69 | } | |
70 | ||
71 | wxRegion( size_t n, const wxPoint *points, int fillStyle = wxODDEVEN_RULE ); | |
72 | ||
73 | wxRegion( const wxBitmap& bmp) | |
74 | { | |
75 | Union(bmp); | |
76 | } | |
77 | wxRegion( const wxBitmap& bmp, | |
78 | const wxColour& transColour, int tolerance = 0) | |
79 | { | |
80 | Union(bmp, transColour, tolerance); | |
81 | } | |
82 | ||
83 | ~wxRegion(); | |
84 | ||
85 | wxRegion( const wxRegion& region ) { Ref(region); } | |
86 | wxRegion& operator = ( const wxRegion& region ) { Ref(region); return *this; } | |
87 | ||
88 | bool Ok() const { return m_refData != NULL; } | |
89 | ||
90 | bool operator == ( const wxRegion& region ) const; | |
91 | bool operator != ( const wxRegion& region ) const { return !(*this == region); } | |
92 | ||
93 | void Clear(); | |
94 | ||
95 | bool Offset( wxCoord x, wxCoord y ); | |
96 | ||
97 | bool Union( wxCoord x, wxCoord y, wxCoord width, wxCoord height ); | |
98 | bool Union( const wxRect& rect ); | |
99 | bool Union( const wxRegion& region ); | |
100 | ||
101 | bool Intersect( wxCoord x, wxCoord y, wxCoord width, wxCoord height ); | |
102 | bool Intersect( const wxRect& rect ); | |
103 | bool Intersect( const wxRegion& region ); | |
104 | ||
105 | bool Subtract( wxCoord x, wxCoord y, wxCoord width, wxCoord height ); | |
106 | bool Subtract( const wxRect& rect ); | |
107 | bool Subtract( const wxRegion& region ); | |
108 | ||
109 | bool Xor( wxCoord x, wxCoord y, wxCoord width, wxCoord height ); | |
110 | bool Xor( const wxRect& rect ); | |
111 | bool Xor( const wxRegion& region ); | |
112 | ||
113 | void GetBox( wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h ) const; | |
114 | wxRect GetBox() const ; | |
115 | ||
116 | bool Empty() const; | |
117 | bool IsEmpty() const { return Empty(); } | |
118 | ||
119 | wxRegionContain Contains( wxCoord x, wxCoord y ) const; | |
120 | wxRegionContain Contains( wxCoord x, wxCoord y, wxCoord w, wxCoord h ) const; | |
121 | wxRegionContain Contains(const wxPoint& pt) const; | |
122 | wxRegionContain Contains(const wxRect& rect) const; | |
123 | ||
124 | // Convert the region to a B&W bitmap with the white pixels being inside | |
125 | // the region. | |
126 | wxBitmap ConvertToBitmap() const; | |
127 | ||
128 | // Use the non-transparent pixels of a wxBitmap for the region to combine | |
129 | // with this region. First version takes transparency from bitmap's mask, | |
130 | // second lets the user specify the colour to be treated as transparent | |
131 | // along with an optional tolerance value. | |
132 | // NOTE: implemented in common/rgncmn.cpp | |
133 | bool Union(const wxBitmap& bmp); | |
134 | bool Union(const wxBitmap& bmp, | |
135 | const wxColour& transColour, int tolerance = 0); | |
136 | ||
137 | ||
138 | public: | |
139 | WXRegion *GetX11Region() const; | |
140 | ||
141 | protected: | |
142 | // ref counting code | |
143 | virtual wxObjectRefData *CreateRefData() const; | |
144 | virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; | |
145 | ||
146 | // common part of ctors for a rectangle region | |
147 | void InitRect(wxCoord x, wxCoord y, wxCoord w, wxCoord h); | |
148 | ||
149 | private: | |
150 | DECLARE_DYNAMIC_CLASS(wxRegion) | |
151 | }; | |
152 | ||
153 | // ---------------------------------------------------------------------------- | |
154 | // wxRegionIterator: decomposes a region into rectangles | |
155 | // ---------------------------------------------------------------------------- | |
156 | ||
157 | class WXDLLIMPEXP_CORE wxRegionIterator: public wxObject | |
158 | { | |
159 | public: | |
160 | wxRegionIterator(); | |
161 | wxRegionIterator(const wxRegion& region); | |
162 | ||
163 | void Reset() { m_current = 0u; } | |
164 | void Reset(const wxRegion& region); | |
165 | ||
166 | operator bool () const; | |
167 | bool HaveRects() const; | |
168 | ||
169 | void operator ++ (); | |
170 | void operator ++ (int); | |
171 | ||
172 | wxCoord GetX() const; | |
173 | wxCoord GetY() const; | |
174 | wxCoord GetW() const; | |
175 | wxCoord GetWidth() const { return GetW(); } | |
176 | wxCoord GetH() const; | |
177 | wxCoord GetHeight() const { return GetH(); } | |
178 | wxRect GetRect() const; | |
179 | ||
180 | private: | |
181 | size_t m_current; | |
182 | wxRegion m_region; | |
183 | ||
184 | private: | |
185 | DECLARE_DYNAMIC_CLASS(wxRegionIterator) | |
186 | }; | |
187 | ||
188 | #endif | |
189 | // _WX_REGION_H_ |