]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mgl/region.h
added wxString ctor from std::string (inside #ifdef wxUSE_STD_STRING); removed pragma...
[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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
15 #pragma interface "region.h"
16 #endif
17
18 #include "wx/list.h"
19 #include "wx/gdiobj.h"
20 #include "wx/gdicmn.h"
21
22 class WXDLLEXPORT wxRect;
23 class WXDLLEXPORT wxPoint;
24 class MGLRegion;
25
26 enum wxRegionContain
27 {
28 wxOutRegion = 0,
29 wxPartRegion = 1,
30 wxInRegion = 2
31 };
32
33 class WXDLLEXPORT wxRegion : public wxGDIObject
34 {
35 DECLARE_DYNAMIC_CLASS(wxRegion);
36 friend class WXDLLEXPORT wxRegionIterator;
37
38 public:
39 wxRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
40 wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight);
41 wxRegion(const wxRect& rect);
42 wxRegion(const MGLRegion& region);
43 wxRegion( const wxBitmap& bmp)
44 {
45 Union(bmp);
46 }
47 wxRegion( const wxBitmap& bmp,
48 const wxColour& transColour, int tolerance = 0)
49 {
50 Union(bmp, transColour, tolerance);
51 }
52
53 wxRegion();
54 ~wxRegion();
55
56 //# Copying
57 inline wxRegion(const wxRegion& r)
58 { Ref(r); }
59 inline wxRegion& operator = (const wxRegion& r)
60 { Ref(r); return (*this); }
61
62 //# Modify region
63 // Clear current region
64 void Clear(void);
65
66 bool Offset(wxCoord x, wxCoord y);
67
68 // Union rectangle or region with this.
69 bool Union(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
70 bool Union(const wxRect& rect) { return Union(rect.x, rect.y, rect.width, rect.height); }
71 bool Union(const wxRegion& region);
72
73 // Intersect rectangle or region with this.
74 bool Intersect(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
75 bool Intersect(const wxRect& rect) { return Intersect(rect.x, rect.y, rect.width, rect.height); }
76 bool Intersect(const wxRegion& region);
77
78 // Subtract rectangle or region from this:
79 // Combines the parts of 'this' that are not part of the second region.
80 bool Subtract(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
81 bool Subtract(const wxRect& rect) { return Subtract(rect.x, rect.y, rect.width, rect.height); }
82 bool Subtract(const wxRegion& region);
83
84 // XOR: the union of two combined regions except for any overlapping areas.
85 bool Xor(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
86 bool Xor(const wxRect& rect) { return Xor(rect.x, rect.y, rect.width, rect.height); }
87 bool Xor(const wxRegion& region);
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(void) const ;
93
94 // Is region empty?
95 bool Empty(void) const;
96 inline bool IsEmpty(void) const { return Empty(); }
97
98 //# Tests
99 // Does the region contain the point (x,y)?
100 wxRegionContain Contains(wxCoord x, wxCoord 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(wxCoord x, wxCoord y, wxCoord w, wxCoord 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
122 // implementation from now on:
123 const MGLRegion& GetMGLRegion() const;
124
125 protected:
126 // ref counting code
127 virtual wxObjectRefData *CreateRefData() const;
128 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
129 };
130
131
132 WX_DECLARE_EXPORTED_LIST(wxRect, wxRegionRectList);
133
134 class WXDLLEXPORT wxRegionIterator : public wxObject
135 {
136 DECLARE_DYNAMIC_CLASS(wxRegionIterator);
137 public:
138 wxRegionIterator(void);
139 wxRegionIterator(const wxRegion& region);
140 ~wxRegionIterator(void);
141
142 void Reset(void) { m_currentNode = NULL; }
143 void Reset(const wxRegion& region);
144
145 #ifndef __SALFORDC__
146 operator bool (void) const { return (m_currentNode != NULL); }
147 #endif
148
149 bool HaveRects(void) const { return (m_currentNode != NULL); }
150
151 void operator ++ (void);
152 void operator ++ (int);
153
154 wxCoord GetX(void) const;
155 wxCoord GetY(void) const;
156 wxCoord GetW(void) const;
157 wxCoord GetWidth(void) const { return GetW(); }
158 wxCoord GetH(void) const;
159 wxCoord GetHeight(void) const { return GetH(); }
160 wxRect GetRect() const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }
161
162 private:
163 wxRegionRectList m_rects;
164 wxRegionRectList::Node *m_currentNode;
165 };
166
167 #endif
168 // _WX_REGION_H_