]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/classic/region.h
wxPalette unified. Source cleaning.
[wxWidgets.git] / include / wx / mac / classic / region.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: region.h
3 // Purpose: wxRegion class
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
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 class WXDLLEXPORT wxRect;
20 class WXDLLEXPORT wxPoint;
21
22 enum wxRegionContain {
23 wxOutRegion = 0, wxPartRegion = 1, wxInRegion = 2
24 };
25
26 // So far, for internal use only
27 enum wxRegionOp {
28 wxRGN_AND, // Creates the intersection of the two combined regions.
29 wxRGN_COPY, // Creates a copy of the region identified by hrgnSrc1.
30 wxRGN_DIFF, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
31 wxRGN_OR, // Creates the union of two combined regions.
32 wxRGN_XOR // Creates the union of two combined regions except for any overlapping areas.
33 };
34
35 class WXDLLEXPORT wxRegion : public wxGDIObject {
36 DECLARE_DYNAMIC_CLASS(wxRegion);
37 friend class WXDLLEXPORT wxRegionIterator;
38 public:
39 wxRegion(long x, long y, long w, long h);
40 wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight);
41 wxRegion(const wxRect& rect);
42 wxRegion( WXHRGN hRegion );
43 wxRegion();
44 wxRegion( const wxBitmap& bmp)
45 {
46 Union(bmp);
47 }
48 wxRegion( const wxBitmap& bmp,
49 const wxColour& transColour, int tolerance = 0)
50 {
51 Union(bmp, transColour, tolerance);
52 }
53
54 ~wxRegion();
55
56 //# Copying
57 wxRegion(const wxRegion& r)
58 : wxGDIObject()
59 { Ref(r); }
60 wxRegion& operator = (const wxRegion& r)
61 { Ref(r); return (*this); }
62
63 //# Modify region
64 // Clear current region
65 void Clear();
66
67 // Union rectangle or region with this.
68 bool Union(long x, long y, long width, long height)
69 { return Combine(x, y, width, height, wxRGN_OR); }
70 bool Union(const wxRect& rect)
71 { return Combine(rect, wxRGN_OR); }
72 bool Union(const wxRegion& region)
73 { return Combine(region, wxRGN_OR); }
74
75 // Intersect rectangle or region with this.
76 bool Intersect(long x, long y, long width, long height)
77 { return Combine(x, y, width, height, wxRGN_AND); }
78 bool Intersect(const wxRect& rect)
79 { return Combine(rect, wxRGN_AND); }
80 bool Intersect(const wxRegion& region)
81 { return Combine(region, wxRGN_AND); }
82
83 // Subtract rectangle or region from this:
84 // Combines the parts of 'this' that are not part of the second region.
85 bool Subtract(long x, long y, long width, long height)
86 { return Combine(x, y, width, height, wxRGN_DIFF); }
87 bool Subtract(const wxRect& rect)
88 { return Combine(rect, wxRGN_DIFF); }
89 bool Subtract(const wxRegion& region)
90 { return Combine(region, wxRGN_DIFF); }
91
92 // XOR: the union of two combined regions except for any overlapping areas.
93 bool Xor(long x, long y, long width, long height)
94 { return Combine(x, y, width, height, wxRGN_XOR); }
95 bool Xor(const wxRect& rect)
96 { return Combine(rect, wxRGN_XOR); }
97 bool Xor(const wxRegion& region)
98 { return Combine(region, wxRGN_XOR); }
99
100 //# Information on region
101 // Outer bounds of region
102 void GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const;
103 wxRect GetBox() const ;
104
105 // Is region empty?
106 bool Empty() const;
107 inline bool IsEmpty() const { return Empty(); }
108
109 //# Tests
110 // Does the region contain the point (x,y)?
111 wxRegionContain Contains(long x, long y) const;
112 // Does the region contain the point pt?
113 wxRegionContain Contains(const wxPoint& pt) const;
114 // Does the region contain the rectangle (x, y, w, h)?
115 wxRegionContain Contains(long x, long y, long w, long h) const;
116 // Does the region contain the rectangle rect?
117 wxRegionContain Contains(const wxRect& rect) const;
118
119 // Convert the region to a B&W bitmap with the white pixels being inside
120 // the region.
121 wxBitmap ConvertToBitmap() const;
122
123 // Use the non-transparent pixels of a wxBitmap for the region to combine
124 // with this region. First version takes transparency from bitmap's mask,
125 // second lets the user specify the colour to be treated as transparent
126 // along with an optional tolerance value.
127 // NOTE: implemented in common/rgncmn.cpp
128 bool Union(const wxBitmap& bmp);
129 bool Union(const wxBitmap& bmp,
130 const wxColour& transColour, int tolerance = 0);
131
132 // Internal
133 bool Combine(long x, long y, long width, long height, wxRegionOp op);
134 bool Combine(const wxRegion& region, wxRegionOp op);
135 bool Combine(const wxRect& rect, wxRegionOp op);
136 const WXHRGN GetWXHRGN() const ;
137 };
138
139 class WXDLLEXPORT wxRegionIterator : public wxObject
140 {
141 DECLARE_DYNAMIC_CLASS(wxRegionIterator)
142
143 public:
144 wxRegionIterator();
145 wxRegionIterator(const wxRegion& region);
146 wxRegionIterator(const wxRegionIterator& iterator);
147 ~wxRegionIterator();
148
149 wxRegionIterator& operator=(const wxRegionIterator& iterator);
150
151 void Reset() { m_current = 0; }
152 void Reset(const wxRegion& region);
153
154 operator bool () const { return m_current < m_numRects; }
155 bool HaveRects() const { return m_current < m_numRects; }
156
157 wxRegionIterator& operator++();
158 wxRegionIterator operator++(int);
159
160 long GetX() const;
161 long GetY() const;
162 long GetW() const;
163 long GetWidth() const { return GetW(); }
164 long GetH() const;
165 long GetHeight() const { return GetH(); }
166 wxRect GetRect() const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }
167 private:
168 void SetRects(long numRects, wxRect *rects);
169
170 long m_current;
171 long m_numRects;
172 wxRegion m_region;
173 wxRect* m_rects;
174 };
175
176 #endif
177 // _WX_REGION_H_