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"
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
)
48 wxRegion( const wxBitmap
& bmp
,
49 const wxColour
& transColour
, int tolerance
= 0)
51 Union(bmp
, transColour
, tolerance
);
58 inline wxRegion(const wxRegion
& r
)
60 inline wxRegion
& operator = (const wxRegion
& r
)
61 { Ref(r
); return (*this); }
64 // Clear current region
67 bool Offset(wxCoord x
, wxCoord y
);
69 // Union rectangle or region with this.
70 bool Union(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
71 bool Union(const wxRect
& rect
) { return Union(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
72 bool Union(const wxRegion
& region
);
74 // Intersect rectangle or region with this.
75 bool Intersect(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
76 bool Intersect(const wxRect
& rect
) { return Intersect(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
77 bool Intersect(const wxRegion
& region
);
79 // Subtract rectangle or region from this:
80 // Combines the parts of 'this' that are not part of the second region.
81 bool Subtract(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
82 bool Subtract(const wxRect
& rect
) { return Subtract(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
83 bool Subtract(const wxRegion
& region
);
85 // XOR: the union of two combined regions except for any overlapping areas.
86 bool Xor(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
87 bool Xor(const wxRect
& rect
) { return Xor(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
88 bool Xor(const wxRegion
& region
);
90 //# Information on region
91 // Outer bounds of region
92 void GetBox(wxCoord
& x
, wxCoord
& y
, wxCoord
&w
, wxCoord
&h
) const;
93 wxRect
GetBox(void) const ;
96 bool Empty(void) const;
97 inline bool IsEmpty(void) const { return Empty(); }
100 // Does the region contain the point (x,y)?
101 wxRegionContain
Contains(wxCoord x
, wxCoord y
) const;
102 // Does the region contain the point pt?
103 wxRegionContain
Contains(const wxPoint
& pt
) const;
104 // Does the region contain the rectangle (x, y, w, h)?
105 wxRegionContain
Contains(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
) const;
106 // Does the region contain the rectangle rect?
107 wxRegionContain
Contains(const wxRect
& rect
) const;
109 // Convert the region to a B&W bitmap with the white pixels being inside
111 wxBitmap
ConvertToBitmap() const;
113 // Use the non-transparent pixels of a wxBitmap for the region to combine
114 // with this region. First version takes transparency from bitmap's mask,
115 // second lets the user specify the colour to be treated as transparent
116 // along with an optional tolerance value.
117 // NOTE: implemented in common/rgncmn.cpp
118 bool Union(const wxBitmap
& bmp
);
119 bool Union(const wxBitmap
& bmp
,
120 const wxColour
& transColour
, int tolerance
= 0);
123 // implementation from now on:
124 const MGLRegion
& GetMGLRegion() const;
128 virtual wxObjectRefData
*CreateRefData() const;
129 virtual wxObjectRefData
*CloneRefData(const wxObjectRefData
*data
) const;
133 WX_DECLARE_EXPORTED_LIST(wxRect
, wxRegionRectList
);
135 class WXDLLEXPORT wxRegionIterator
: public wxObject
137 DECLARE_DYNAMIC_CLASS(wxRegionIterator
);
139 wxRegionIterator(void);
140 wxRegionIterator(const wxRegion
& region
);
141 ~wxRegionIterator(void);
143 void Reset(void) { m_currentNode
= NULL
; }
144 void Reset(const wxRegion
& region
);
147 operator bool (void) const { return (m_currentNode
!= NULL
); }
150 bool HaveRects(void) const { return (m_currentNode
!= NULL
); }
152 void operator ++ (void);
153 void operator ++ (int);
155 wxCoord
GetX(void) const;
156 wxCoord
GetY(void) const;
157 wxCoord
GetW(void) const;
158 wxCoord
GetWidth(void) const { return GetW(); }
159 wxCoord
GetH(void) const;
160 wxCoord
GetHeight(void) const { return GetH(); }
161 wxRect
GetRect() const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }
164 wxRegionRectList m_rects
;
165 wxRegionRectList::Node
*m_currentNode
;