]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mgl/region.h
added wxMirrorDC
[wxWidgets.git] / include / wx / mgl / region.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: region.h
3 // Purpose: wxRegion class
4 // Author: Vaclav Slavik
5 // Created: 2001/03/12
6 // RCS-ID: $Id$
7 // Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_REGION_H_
12 #define _WX_REGION_H_
13
14 #ifdef __GNUG__
15 #pragma interface "region.h"
16 #endif
17
18 #include "wx/list.h"
19 #include "wx/gdiobj.h"
20 #include "wx/gdicmn.h"
21 #include "wx/list.h"
22
23 class WXDLLEXPORT wxRect;
24 class WXDLLEXPORT wxPoint;
25 class MGLRegion;
26
27 enum wxRegionContain
28 {
29 wxOutRegion = 0,
30 wxPartRegion = 1,
31 wxInRegion = 2
32 };
33
34 class WXDLLEXPORT wxRegion : public wxGDIObject
35 {
36 DECLARE_DYNAMIC_CLASS(wxRegion);
37 friend class WXDLLEXPORT wxRegionIterator;
38
39 public:
40 wxRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
41 wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight);
42 wxRegion(const wxRect& rect);
43 wxRegion(const MGLRegion& region);
44 wxRegion( const wxBitmap& bmp,
45 const wxColour& transColour = wxNullColour,
46 int tolerance = 0)
47 {
48 Union(bmp, transColour, tolerance);
49 }
50
51 wxRegion();
52 ~wxRegion();
53
54 //# Copying
55 inline wxRegion(const wxRegion& r)
56 { Ref(r); }
57 inline wxRegion& operator = (const wxRegion& r)
58 { Ref(r); return (*this); }
59
60 //# Modify region
61 // Clear current region
62 void Clear(void);
63
64 bool Offset(wxCoord x, wxCoord y);
65
66 // Union rectangle or region with this.
67 bool Union(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
68 bool Union(const wxRect& rect) { return Union(rect.x, rect.y, rect.width, rect.height); }
69 bool Union(const wxRegion& region);
70
71 // Intersect rectangle or region with this.
72 bool Intersect(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
73 bool Intersect(const wxRect& rect) { return Intersect(rect.x, rect.y, rect.width, rect.height); }
74 bool Intersect(const wxRegion& region);
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(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
79 bool Subtract(const wxRect& rect) { return Subtract(rect.x, rect.y, rect.width, rect.height); }
80 bool Subtract(const wxRegion& region);
81
82 // XOR: the union of two combined regions except for any overlapping areas.
83 bool Xor(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
84 bool Xor(const wxRect& rect) { return Xor(rect.x, rect.y, rect.width, rect.height); }
85 bool Xor(const wxRegion& region);
86
87 //# Information on region
88 // Outer bounds of region
89 void GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const;
90 wxRect GetBox(void) const ;
91
92 // Is region empty?
93 bool Empty(void) const;
94 inline bool IsEmpty(void) const { return Empty(); }
95
96 //# Tests
97 // Does the region contain the point (x,y)?
98 wxRegionContain Contains(wxCoord x, wxCoord y) const;
99 // Does the region contain the point pt?
100 wxRegionContain Contains(const wxPoint& pt) const;
101 // Does the region contain the rectangle (x, y, w, h)?
102 wxRegionContain Contains(wxCoord x, wxCoord y, wxCoord w, wxCoord h) const;
103 // Does the region contain the rectangle rect?
104 wxRegionContain Contains(const wxRect& rect) const;
105
106 // Convert the region to a B&W bitmap with the white pixels being inside
107 // the region.
108 wxBitmap ConvertToBitmap() const;
109
110 // Use the non-transparent pixels of a wxBitmap for the region to combine
111 // with this region. If the bitmap has a mask then it will be used,
112 // otherwise the colour to be treated as transparent may be specified,
113 // along with an optional tolerance value.
114 bool Union(const wxBitmap& bmp,
115 const wxColour& transColour = wxNullColour,
116 int tolerance = 0);
117
118
119 // implementation from now on:
120 const MGLRegion& GetMGLRegion() const;
121
122 protected:
123 // ref counting code
124 virtual wxObjectRefData *CreateRefData() const;
125 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
126 };
127
128
129 WX_DECLARE_EXPORTED_LIST(wxRect, wxRegionRectList);
130
131 class WXDLLEXPORT wxRegionIterator : public wxObject
132 {
133 DECLARE_DYNAMIC_CLASS(wxRegionIterator);
134 public:
135 wxRegionIterator(void);
136 wxRegionIterator(const wxRegion& region);
137 ~wxRegionIterator(void);
138
139 void Reset(void) { m_currentNode = NULL; }
140 void Reset(const wxRegion& region);
141
142 #ifndef __SALFORDC__
143 operator bool (void) const { return (m_currentNode != NULL); }
144 #endif
145
146 bool HaveRects(void) const { return (m_currentNode != NULL); }
147
148 void operator ++ (void);
149 void operator ++ (int);
150
151 wxCoord GetX(void) const;
152 wxCoord GetY(void) const;
153 wxCoord GetW(void) const;
154 wxCoord GetWidth(void) const { return GetW(); }
155 wxCoord GetH(void) const;
156 wxCoord GetHeight(void) const { return GetH(); }
157 wxRect GetRect() const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }
158
159 private:
160 wxRegionRectList m_rects;
161 wxRegionRectList::Node *m_currentNode;
162 };
163
164 #endif
165 // _WX_REGION_H_