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