1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxRegion class
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
15 #pragma interface "region.h"
19 #include "wx/gdiobj.h"
20 #include "wx/gdicmn.h"
23 class WXDLLEXPORT wxRect
;
24 class WXDLLEXPORT wxPoint
;
34 class WXDLLEXPORT wxRegion
: public wxGDIObject
36 DECLARE_DYNAMIC_CLASS(wxRegion
);
37 friend class WXDLLEXPORT wxRegionIterator
;
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
,
48 Union(bmp
, transColour
, tolerance
);
55 inline wxRegion(const wxRegion
& r
)
57 inline wxRegion
& operator = (const wxRegion
& r
)
58 { Ref(r
); return (*this); }
61 // Clear current region
64 bool Offset(wxCoord x
, wxCoord y
);
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
);
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
);
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
);
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
);
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 ;
93 bool Empty(void) const;
94 inline bool IsEmpty(void) const { return Empty(); }
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;
106 // Convert the region to a B&W bitmap with the white pixels being inside
108 wxBitmap
ConvertToBitmap() const;
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
,
119 // implementation from now on:
120 const MGLRegion
& GetMGLRegion() const;
124 virtual wxObjectRefData
*CreateRefData() const;
125 virtual wxObjectRefData
*CloneRefData(const wxObjectRefData
*data
) const;
129 WX_DECLARE_EXPORTED_LIST(wxRect
, wxRegionRectList
);
131 class WXDLLEXPORT wxRegionIterator
: public wxObject
133 DECLARE_DYNAMIC_CLASS(wxRegionIterator
);
135 wxRegionIterator(void);
136 wxRegionIterator(const wxRegion
& region
);
137 ~wxRegionIterator(void);
139 void Reset(void) { m_currentNode
= NULL
; }
140 void Reset(const wxRegion
& region
);
143 operator bool (void) const { return (m_currentNode
!= NULL
); }
146 bool HaveRects(void) const { return (m_currentNode
!= NULL
); }
148 void operator ++ (void);
149 void operator ++ (int);
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()); }
160 wxRegionRectList m_rects
;
161 wxRegionRectList::Node
*m_currentNode
;