]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mgl/region.h
wxMultiChoiceDialog uses now wxCheckListBox if possible, wxListBox if not
[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 #include "wx/list.h"
15 #include "wx/gdiobj.h"
16 #include "wx/gdicmn.h"
17
18 class WXDLLEXPORT wxRect;
19 class WXDLLEXPORT wxPoint;
20 class MGLRegion;
21
22 enum wxRegionContain
23 {
24 wxOutRegion = 0,
25 wxPartRegion = 1,
26 wxInRegion = 2
27 };
28
29 class WXDLLEXPORT wxRegion : public wxGDIObject
30 {
31 DECLARE_DYNAMIC_CLASS(wxRegion);
32 friend class WXDLLEXPORT wxRegionIterator;
33
34 public:
35 wxRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
36 wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight);
37 wxRegion(const wxRect& rect);
38 wxRegion(const MGLRegion& region);
39 wxRegion( const wxBitmap& bmp)
40 {
41 Union(bmp);
42 }
43 wxRegion( const wxBitmap& bmp,
44 const wxColour& transColour, int tolerance = 0)
45 {
46 Union(bmp, transColour, tolerance);
47 }
48
49 wxRegion();
50 ~wxRegion();
51
52 //# Copying
53 inline wxRegion(const wxRegion& r)
54 { Ref(r); }
55 inline wxRegion& operator = (const wxRegion& r)
56 { Ref(r); return (*this); }
57
58 //# Modify region
59 // Clear current region
60 void Clear(void);
61
62 bool Offset(wxCoord x, wxCoord y);
63
64 // Union rectangle or region with this.
65 bool Union(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
66 bool Union(const wxRect& rect) { return Union(rect.x, rect.y, rect.width, rect.height); }
67 bool Union(const wxRegion& region);
68
69 // Intersect rectangle or region with this.
70 bool Intersect(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
71 bool Intersect(const wxRect& rect) { return Intersect(rect.x, rect.y, rect.width, rect.height); }
72 bool Intersect(const wxRegion& region);
73
74 // Subtract rectangle or region from this:
75 // Combines the parts of 'this' that are not part of the second region.
76 bool Subtract(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
77 bool Subtract(const wxRect& rect) { return Subtract(rect.x, rect.y, rect.width, rect.height); }
78 bool Subtract(const wxRegion& region);
79
80 // XOR: the union of two combined regions except for any overlapping areas.
81 bool Xor(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
82 bool Xor(const wxRect& rect) { return Xor(rect.x, rect.y, rect.width, rect.height); }
83 bool Xor(const wxRegion& region);
84
85 //# Information on region
86 // Outer bounds of region
87 void GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const;
88 wxRect GetBox(void) const ;
89
90 // Is region empty?
91 bool Empty(void) const;
92 inline bool IsEmpty(void) const { return Empty(); }
93
94 //# Tests
95 // Does the region contain the point (x,y)?
96 wxRegionContain Contains(wxCoord x, wxCoord y) const;
97 // Does the region contain the point pt?
98 wxRegionContain Contains(const wxPoint& pt) const;
99 // Does the region contain the rectangle (x, y, w, h)?
100 wxRegionContain Contains(wxCoord x, wxCoord y, wxCoord w, wxCoord h) const;
101 // Does the region contain the rectangle rect?
102 wxRegionContain Contains(const wxRect& rect) const;
103
104 // Convert the region to a B&W bitmap with the white pixels being inside
105 // the region.
106 wxBitmap ConvertToBitmap() const;
107
108 // Use the non-transparent pixels of a wxBitmap for the region to combine
109 // with this region. First version takes transparency from bitmap's mask,
110 // second lets the user specify the colour to be treated as transparent
111 // along with an optional tolerance value.
112 // NOTE: implemented in common/rgncmn.cpp
113 bool Union(const wxBitmap& bmp);
114 bool Union(const wxBitmap& bmp,
115 const wxColour& transColour, int tolerance = 0);
116
117
118 // implementation from now on:
119 const MGLRegion& GetMGLRegion() const;
120
121 protected:
122 // ref counting code
123 virtual wxObjectRefData *CreateRefData() const;
124 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
125 };
126
127
128 WX_DECLARE_EXPORTED_LIST(wxRect, wxRegionRectList);
129
130 class WXDLLEXPORT wxRegionIterator : public wxObject
131 {
132 DECLARE_DYNAMIC_CLASS(wxRegionIterator);
133 public:
134 wxRegionIterator(void);
135 wxRegionIterator(const wxRegion& region);
136 ~wxRegionIterator(void);
137
138 void Reset(void) { m_currentNode = NULL; }
139 void Reset(const wxRegion& region);
140
141 #ifndef __SALFORDC__
142 operator bool (void) const { return (m_currentNode != NULL); }
143 #endif
144
145 bool HaveRects(void) const { return (m_currentNode != NULL); }
146
147 void operator ++ (void);
148 void operator ++ (int);
149
150 wxCoord GetX(void) const;
151 wxCoord GetY(void) const;
152 wxCoord GetW(void) const;
153 wxCoord GetWidth(void) const { return GetW(); }
154 wxCoord GetH(void) const;
155 wxCoord GetHeight(void) const { return GetH(); }
156 wxRect GetRect() const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }
157
158 private:
159 wxRegionRectList m_rects;
160 wxRegionRectList::Node *m_currentNode;
161 };
162
163 #endif
164 // _WX_REGION_H_