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