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