]>
Commit | Line | Data |
---|---|---|
32b8ec41 VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: region.h | |
3 | // Purpose: wxRegion class | |
4 | // Author: Vaclav Slavik | |
5 | // Created: 2001/03/12 | |
6 | // RCS-ID: $Id$ | |
52750c2e | 7 | // Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com) |
65571936 | 8 | // Licence: wxWindows licence |
32b8ec41 VZ |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
11 | #ifndef _WX_REGION_H_ | |
12 | #define _WX_REGION_H_ | |
13 | ||
12028905 | 14 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
32b8ec41 VZ |
15 | #pragma interface "region.h" |
16 | #endif | |
17 | ||
18 | #include "wx/list.h" | |
19 | #include "wx/gdiobj.h" | |
20 | #include "wx/gdicmn.h" | |
21 | #include "wx/list.h" | |
22 | ||
23 | class WXDLLEXPORT wxRect; | |
24 | class WXDLLEXPORT wxPoint; | |
25 | class MGLRegion; | |
26 | ||
1542ea39 | 27 | enum wxRegionContain |
32b8ec41 | 28 | { |
1542ea39 RD |
29 | wxOutRegion = 0, |
30 | wxPartRegion = 1, | |
32b8ec41 VZ |
31 | wxInRegion = 2 |
32 | }; | |
33 | ||
1542ea39 | 34 | class WXDLLEXPORT wxRegion : public wxGDIObject |
32b8ec41 VZ |
35 | { |
36 | DECLARE_DYNAMIC_CLASS(wxRegion); | |
37 | friend class WXDLLEXPORT wxRegionIterator; | |
38 | ||
39 | public: | |
40 | wxRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h); | |
41 | wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight); | |
42 | wxRegion(const wxRect& rect); | |
43 | wxRegion(const MGLRegion& region); | |
85f6b408 VS |
44 | wxRegion( const wxBitmap& bmp) |
45 | { | |
46 | Union(bmp); | |
47 | } | |
1542ea39 | 48 | wxRegion( const wxBitmap& bmp, |
85f6b408 | 49 | const wxColour& transColour, int tolerance = 0) |
1542ea39 RD |
50 | { |
51 | Union(bmp, transColour, tolerance); | |
52 | } | |
32b8ec41 VZ |
53 | |
54 | wxRegion(); | |
55 | ~wxRegion(); | |
56 | ||
57 | //# Copying | |
58 | inline wxRegion(const wxRegion& r) | |
59 | { Ref(r); } | |
60 | inline wxRegion& operator = (const wxRegion& r) | |
61 | { Ref(r); return (*this); } | |
62 | ||
63 | //# Modify region | |
64 | // Clear current region | |
65 | void Clear(void); | |
66 | ||
6d7ee9e8 VS |
67 | bool Offset(wxCoord x, wxCoord y); |
68 | ||
32b8ec41 VZ |
69 | // Union rectangle or region with this. |
70 | bool Union(wxCoord x, wxCoord y, wxCoord width, wxCoord height); | |
71 | bool Union(const wxRect& rect) { return Union(rect.x, rect.y, rect.width, rect.height); } | |
72 | bool Union(const wxRegion& region); | |
73 | ||
74 | // Intersect rectangle or region with this. | |
75 | bool Intersect(wxCoord x, wxCoord y, wxCoord width, wxCoord height); | |
76 | bool Intersect(const wxRect& rect) { return Intersect(rect.x, rect.y, rect.width, rect.height); } | |
77 | bool Intersect(const wxRegion& region); | |
78 | ||
79 | // Subtract rectangle or region from this: | |
80 | // Combines the parts of 'this' that are not part of the second region. | |
81 | bool Subtract(wxCoord x, wxCoord y, wxCoord width, wxCoord height); | |
82 | bool Subtract(const wxRect& rect) { return Subtract(rect.x, rect.y, rect.width, rect.height); } | |
83 | bool Subtract(const wxRegion& region); | |
84 | ||
85 | // XOR: the union of two combined regions except for any overlapping areas. | |
86 | bool Xor(wxCoord x, wxCoord y, wxCoord width, wxCoord height); | |
87 | bool Xor(const wxRect& rect) { return Xor(rect.x, rect.y, rect.width, rect.height); } | |
88 | bool Xor(const wxRegion& region); | |
89 | ||
90 | //# Information on region | |
91 | // Outer bounds of region | |
92 | void GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const; | |
93 | wxRect GetBox(void) const ; | |
94 | ||
95 | // Is region empty? | |
96 | bool Empty(void) const; | |
97 | inline bool IsEmpty(void) const { return Empty(); } | |
98 | ||
99 | //# Tests | |
100 | // Does the region contain the point (x,y)? | |
101 | wxRegionContain Contains(wxCoord x, wxCoord y) const; | |
102 | // Does the region contain the point pt? | |
103 | wxRegionContain Contains(const wxPoint& pt) const; | |
104 | // Does the region contain the rectangle (x, y, w, h)? | |
105 | wxRegionContain Contains(wxCoord x, wxCoord y, wxCoord w, wxCoord h) const; | |
106 | // Does the region contain the rectangle rect? | |
107 | wxRegionContain Contains(const wxRect& rect) const; | |
1542ea39 | 108 | |
819451b6 | 109 | // Convert the region to a B&W bitmap with the white pixels being inside |
1542ea39 RD |
110 | // the region. |
111 | wxBitmap ConvertToBitmap() const; | |
112 | ||
113 | // Use the non-transparent pixels of a wxBitmap for the region to combine | |
85f6b408 VS |
114 | // with this region. First version takes transparency from bitmap's mask, |
115 | // second lets the user specify the colour to be treated as transparent | |
1542ea39 | 116 | // along with an optional tolerance value. |
85f6b408 VS |
117 | // NOTE: implemented in common/rgncmn.cpp |
118 | bool Union(const wxBitmap& bmp); | |
1542ea39 | 119 | bool Union(const wxBitmap& bmp, |
85f6b408 | 120 | const wxColour& transColour, int tolerance = 0); |
1542ea39 RD |
121 | |
122 | ||
32b8ec41 VZ |
123 | // implementation from now on: |
124 | const MGLRegion& GetMGLRegion() const; | |
6d7ee9e8 VS |
125 | |
126 | protected: | |
127 | // ref counting code | |
128 | virtual wxObjectRefData *CreateRefData() const; | |
129 | virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; | |
32b8ec41 VZ |
130 | }; |
131 | ||
132 | ||
133 | WX_DECLARE_EXPORTED_LIST(wxRect, wxRegionRectList); | |
134 | ||
1542ea39 | 135 | class WXDLLEXPORT wxRegionIterator : public wxObject |
32b8ec41 VZ |
136 | { |
137 | DECLARE_DYNAMIC_CLASS(wxRegionIterator); | |
138 | public: | |
139 | wxRegionIterator(void); | |
140 | wxRegionIterator(const wxRegion& region); | |
141 | ~wxRegionIterator(void); | |
142 | ||
143 | void Reset(void) { m_currentNode = NULL; } | |
144 | void Reset(const wxRegion& region); | |
145 | ||
146 | #ifndef __SALFORDC__ | |
147 | operator bool (void) const { return (m_currentNode != NULL); } | |
148 | #endif | |
149 | ||
150 | bool HaveRects(void) const { return (m_currentNode != NULL); } | |
151 | ||
152 | void operator ++ (void); | |
153 | void operator ++ (int); | |
154 | ||
155 | wxCoord GetX(void) const; | |
156 | wxCoord GetY(void) const; | |
157 | wxCoord GetW(void) const; | |
158 | wxCoord GetWidth(void) const { return GetW(); } | |
159 | wxCoord GetH(void) const; | |
160 | wxCoord GetHeight(void) const { return GetH(); } | |
161 | wxRect GetRect() const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); } | |
162 | ||
163 | private: | |
164 | wxRegionRectList m_rects; | |
165 | wxRegionRectList::Node *m_currentNode; | |
166 | }; | |
167 | ||
168 | #endif | |
169 | // _WX_REGION_H_ |