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