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 /////////////////////////////////////////////////////////////////////////////
14 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
15 #pragma interface "region.h"
19 #include "wx/gdiobj.h"
20 #include "wx/gdicmn.h"
22 class WXDLLEXPORT wxRect
;
23 class WXDLLEXPORT wxPoint
;
33 class WXDLLEXPORT wxRegion
: public wxGDIObject
35 DECLARE_DYNAMIC_CLASS(wxRegion
);
36 friend class WXDLLEXPORT wxRegionIterator
;
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
)
47 wxRegion( const wxBitmap
& bmp
,
48 const wxColour
& transColour
, int tolerance
= 0)
50 Union(bmp
, transColour
, tolerance
);
57 inline wxRegion(const wxRegion
& r
)
59 inline wxRegion
& operator = (const wxRegion
& r
)
60 { Ref(r
); return (*this); }
63 // Clear current region
66 bool Offset(wxCoord x
, wxCoord y
);
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
);
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
);
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
);
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
);
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 ;
95 bool Empty(void) const;
96 inline bool IsEmpty(void) const { return Empty(); }
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;
108 // Convert the region to a B&W bitmap with the white pixels being inside
110 wxBitmap
ConvertToBitmap() const;
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);
122 // implementation from now on:
123 const MGLRegion
& GetMGLRegion() const;
127 virtual wxObjectRefData
*CreateRefData() const;
128 virtual wxObjectRefData
*CloneRefData(const wxObjectRefData
*data
) const;
132 WX_DECLARE_EXPORTED_LIST(wxRect
, wxRegionRectList
);
134 class WXDLLEXPORT wxRegionIterator
: public wxObject
136 DECLARE_DYNAMIC_CLASS(wxRegionIterator
);
138 wxRegionIterator(void);
139 wxRegionIterator(const wxRegion
& region
);
140 ~wxRegionIterator(void);
142 void Reset(void) { m_currentNode
= NULL
; }
143 void Reset(const wxRegion
& region
);
146 operator bool (void) const { return (m_currentNode
!= NULL
); }
149 bool HaveRects(void) const { return (m_currentNode
!= NULL
); }
151 void operator ++ (void);
152 void operator ++ (int);
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()); }
163 wxRegionRectList m_rects
;
164 wxRegionRectList::Node
*m_currentNode
;