]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/carbon/region.h
wxTinderbox build fix (!PCH support).
[wxWidgets.git] / include / wx / mac / carbon / 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(size_t n, const wxPoint *points, int fillStyle = wxODDEVEN_RULE );
44 wxRegion();
45 wxRegion(const wxBitmap& bmp)
46 {
47 Union(bmp);
48 }
49 wxRegion(const wxBitmap& bmp,
50 const wxColour& transColour, int tolerance = 0)
51 {
52 Union(bmp, transColour, tolerance);
53 }
54
55 ~wxRegion();
56
57 //# Modify region
58 // Clear current region
59 void Clear();
60
61 // Move the region
62 bool Offset(wxCoord x, wxCoord y);
63
64 // Union rectangle or region with this.
65 bool Union(long x, long y, long width, long height)
66 { return Combine(x, y, width, height, wxRGN_OR); }
67 bool Union(const wxRect& rect)
68 { return Combine(rect, wxRGN_OR); }
69 bool Union(const wxRegion& region)
70 { return Combine(region, wxRGN_OR); }
71
72 // Intersect rectangle or region with this.
73 bool Intersect(long x, long y, long width, long height)
74 { return Combine(x, y, width, height, wxRGN_AND); }
75 bool Intersect(const wxRect& rect)
76 { return Combine(rect, wxRGN_AND); }
77 bool Intersect(const wxRegion& region)
78 { return Combine(region, wxRGN_AND); }
79
80 // Subtract rectangle or region from this:
81 // Combines the parts of 'this' that are not part of the second region.
82 bool Subtract(long x, long y, long width, long height)
83 { return Combine(x, y, width, height, wxRGN_DIFF); }
84 bool Subtract(const wxRect& rect)
85 { return Combine(rect, wxRGN_DIFF); }
86 bool Subtract(const wxRegion& region)
87 { return Combine(region, wxRGN_DIFF); }
88
89 // XOR: the union of two combined regions except for any overlapping areas.
90 bool Xor(long x, long y, long width, long height)
91 { return Combine(x, y, width, height, wxRGN_XOR); }
92 bool Xor(const wxRect& rect)
93 { return Combine(rect, wxRGN_XOR); }
94 bool Xor(const wxRegion& region)
95 { return Combine(region, wxRGN_XOR); }
96
97 //# Information on region
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(long x, long 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(long x, long y, long w, long 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(long x, long y, long width, long height, wxRegionOp op);
131 bool Combine(const wxRegion& region, wxRegionOp op);
132 bool Combine(const wxRect& rect, wxRegionOp op);
133 const WXHRGN GetWXHRGN() const ;
134 };
135
136 class WXDLLEXPORT wxRegionIterator : public wxObject
137 {
138 DECLARE_DYNAMIC_CLASS(wxRegionIterator)
139
140 public:
141 wxRegionIterator();
142 wxRegionIterator(const wxRegion& region);
143 wxRegionIterator(const wxRegionIterator& iterator);
144 ~wxRegionIterator();
145
146 wxRegionIterator& operator=(const wxRegionIterator& iterator);
147
148 void Reset() { m_current = 0; }
149 void Reset(const wxRegion& region);
150
151 operator bool () const { return m_current < m_numRects; }
152 bool HaveRects() const { return m_current < m_numRects; }
153
154 wxRegionIterator& operator++();
155 wxRegionIterator operator++(int);
156
157 long GetX() const;
158 long GetY() const;
159 long GetW() const;
160 long GetWidth() const { return GetW(); }
161 long GetH() const;
162 long GetHeight() const { return GetH(); }
163 wxRect GetRect() const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }
164 private:
165 void SetRects(long numRects, wxRect *rects);
166
167 long m_current;
168 long m_numRects;
169 wxRegion m_region;
170 wxRect* m_rects;
171 };
172
173 #endif
174 // _WX_REGION_H_