]>
Commit | Line | Data |
---|---|---|
83df96d6 JS |
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$ | |
1934d291 | 8 | // Copyright: (c) Julian Smart, Robert Roebling |
65571936 | 9 | // Licence: wxWindows licence |
83df96d6 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_REGION_H_ | |
13 | #define _WX_REGION_H_ | |
14 | ||
83df96d6 JS |
15 | #include "wx/list.h" |
16 | #include "wx/gdiobj.h" | |
17 | #include "wx/gdicmn.h" | |
18 | ||
1934d291 RR |
19 | //----------------------------------------------------------------------------- |
20 | // classes | |
21 | //----------------------------------------------------------------------------- | |
83df96d6 | 22 | |
968eb2ef | 23 | class WXDLLIMPEXP_CORE wxRegion; |
83df96d6 | 24 | |
1934d291 RR |
25 | //----------------------------------------------------------------------------- |
26 | // constants | |
27 | //----------------------------------------------------------------------------- | |
83df96d6 | 28 | |
83df96d6 | 29 | // So far, for internal use only |
1934d291 RR |
30 | enum wxRegionOp |
31 | { | |
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. | |
83df96d6 JS |
37 | }; |
38 | ||
1934d291 RR |
39 | // ---------------------------------------------------------------------------- |
40 | // wxRegion | |
41 | // ---------------------------------------------------------------------------- | |
42 | ||
968eb2ef | 43 | class WXDLLIMPEXP_CORE wxRegion : public wxGDIObject |
1934d291 | 44 | { |
83df96d6 | 45 | public: |
1934d291 RR |
46 | wxRegion() { } |
47 | ||
48 | wxRegion( wxCoord x, wxCoord y, wxCoord w, wxCoord h ) | |
49 | { | |
50 | InitRect(x, y, w, h); | |
51 | } | |
52 | ||
53 | wxRegion( const wxPoint& topLeft, const wxPoint& bottomRight ) | |
54 | { | |
55 | InitRect(topLeft.x, topLeft.y, | |
56 | bottomRight.x - topLeft.x, bottomRight.y - topLeft.y); | |
57 | } | |
58 | ||
59 | wxRegion( const wxRect& rect ) | |
60 | { | |
61 | InitRect(rect.x, rect.y, rect.width, rect.height); | |
62 | } | |
63 | ||
64 | wxRegion( size_t n, const wxPoint *points, int fillStyle = wxODDEVEN_RULE ); | |
1542ea39 | 65 | |
85f6b408 VS |
66 | wxRegion( const wxBitmap& bmp) |
67 | { | |
68 | Union(bmp); | |
69 | } | |
1542ea39 | 70 | wxRegion( const wxBitmap& bmp, |
85f6b408 | 71 | const wxColour& transColour, int tolerance = 0) |
1542ea39 RD |
72 | { |
73 | Union(bmp, transColour, tolerance); | |
74 | } | |
75 | ||
83df96d6 | 76 | ~wxRegion(); |
1934d291 | 77 | |
1934d291 RR |
78 | bool Ok() const { return m_refData != NULL; } |
79 | ||
fbfb8bcc VZ |
80 | bool operator == ( const wxRegion& region ) const; |
81 | bool operator != ( const wxRegion& region ) const { return !(*this == region); } | |
1934d291 | 82 | |
83df96d6 | 83 | void Clear(); |
1934d291 RR |
84 | |
85 | bool Offset( wxCoord x, wxCoord y ); | |
86 | ||
87 | bool Union( wxCoord x, wxCoord y, wxCoord width, wxCoord height ); | |
88 | bool Union( const wxRect& rect ); | |
89 | bool Union( const wxRegion& region ); | |
90 | ||
91 | bool Intersect( wxCoord x, wxCoord y, wxCoord width, wxCoord height ); | |
92 | bool Intersect( const wxRect& rect ); | |
93 | bool Intersect( const wxRegion& region ); | |
94 | ||
95 | bool Subtract( wxCoord x, wxCoord y, wxCoord width, wxCoord height ); | |
96 | bool Subtract( const wxRect& rect ); | |
97 | bool Subtract( const wxRegion& region ); | |
98 | ||
99 | bool Xor( wxCoord x, wxCoord y, wxCoord width, wxCoord height ); | |
100 | bool Xor( const wxRect& rect ); | |
101 | bool Xor( const wxRegion& region ); | |
102 | ||
103 | void GetBox( wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h ) const; | |
83df96d6 | 104 | wxRect GetBox() const ; |
1934d291 | 105 | |
83df96d6 | 106 | bool Empty() const; |
1934d291 RR |
107 | bool IsEmpty() const { return Empty(); } |
108 | ||
109 | wxRegionContain Contains( wxCoord x, wxCoord y ) const; | |
110 | wxRegionContain Contains( wxCoord x, wxCoord y, wxCoord w, wxCoord h ) const; | |
83df96d6 | 111 | wxRegionContain Contains(const wxPoint& pt) const; |
83df96d6 | 112 | wxRegionContain Contains(const wxRect& rect) const; |
1934d291 | 113 | |
819451b6 | 114 | // Convert the region to a B&W bitmap with the white pixels being inside |
1542ea39 RD |
115 | // the region. |
116 | wxBitmap ConvertToBitmap() const; | |
117 | ||
118 | // Use the non-transparent pixels of a wxBitmap for the region to combine | |
85f6b408 VS |
119 | // with this region. First version takes transparency from bitmap's mask, |
120 | // second lets the user specify the colour to be treated as transparent | |
1542ea39 | 121 | // along with an optional tolerance value. |
85f6b408 VS |
122 | // NOTE: implemented in common/rgncmn.cpp |
123 | bool Union(const wxBitmap& bmp); | |
1542ea39 | 124 | bool Union(const wxBitmap& bmp, |
85f6b408 | 125 | const wxColour& transColour, int tolerance = 0); |
1542ea39 RD |
126 | |
127 | ||
1934d291 RR |
128 | public: |
129 | WXRegion *GetX11Region() const; | |
130 | ||
131 | protected: | |
132 | // ref counting code | |
133 | virtual wxObjectRefData *CreateRefData() const; | |
134 | virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; | |
1542ea39 | 135 | |
1934d291 RR |
136 | // common part of ctors for a rectangle region |
137 | void InitRect(wxCoord x, wxCoord y, wxCoord w, wxCoord h); | |
138 | ||
139 | private: | |
777105f2 | 140 | DECLARE_DYNAMIC_CLASS(wxRegion) |
83df96d6 JS |
141 | }; |
142 | ||
1934d291 RR |
143 | // ---------------------------------------------------------------------------- |
144 | // wxRegionIterator: decomposes a region into rectangles | |
145 | // ---------------------------------------------------------------------------- | |
146 | ||
968eb2ef | 147 | class WXDLLIMPEXP_CORE wxRegionIterator: public wxObject |
1934d291 | 148 | { |
83df96d6 JS |
149 | public: |
150 | wxRegionIterator(); | |
151 | wxRegionIterator(const wxRegion& region); | |
1934d291 RR |
152 | |
153 | void Reset() { m_current = 0u; } | |
83df96d6 | 154 | void Reset(const wxRegion& region); |
1934d291 RR |
155 | |
156 | operator bool () const; | |
157 | bool HaveRects() const; | |
158 | ||
83df96d6 JS |
159 | void operator ++ (); |
160 | void operator ++ (int); | |
1934d291 | 161 | |
83df96d6 JS |
162 | wxCoord GetX() const; |
163 | wxCoord GetY() const; | |
164 | wxCoord GetW() const; | |
165 | wxCoord GetWidth() const { return GetW(); } | |
166 | wxCoord GetH() const; | |
167 | wxCoord GetHeight() const { return GetH(); } | |
1934d291 RR |
168 | wxRect GetRect() const; |
169 | ||
83df96d6 | 170 | private: |
1934d291 | 171 | size_t m_current; |
83df96d6 | 172 | wxRegion m_region; |
1934d291 RR |
173 | |
174 | private: | |
777105f2 | 175 | DECLARE_DYNAMIC_CLASS(wxRegionIterator) |
83df96d6 JS |
176 | }; |
177 | ||
178 | #endif | |
179 | // _WX_REGION_H_ |