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 #include "wx/gdiobj.h"
16 #include "wx/gdicmn.h"
18 class WXDLLEXPORT wxRect
;
19 class WXDLLEXPORT wxPoint
;
22 class WXDLLEXPORT wxRegion
: public wxGDIObject
24 DECLARE_DYNAMIC_CLASS(wxRegion
);
25 friend class WXDLLEXPORT wxRegionIterator
;
28 wxRegion(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
);
29 wxRegion(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
30 wxRegion(const wxRect
& rect
);
31 wxRegion(const MGLRegion
& region
);
32 wxRegion( const wxBitmap
& bmp
)
36 wxRegion( const wxBitmap
& bmp
,
37 const wxColour
& transColour
, int tolerance
= 0)
39 Union(bmp
, transColour
, tolerance
);
46 // Clear current region
49 bool Offset(wxCoord x
, wxCoord y
);
51 // Union rectangle or region with this.
52 bool Union(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
53 bool Union(const wxRect
& rect
) { return Union(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
54 bool Union(const wxRegion
& region
);
56 // Intersect rectangle or region with this.
57 bool Intersect(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
58 bool Intersect(const wxRect
& rect
) { return Intersect(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
59 bool Intersect(const wxRegion
& region
);
61 // Subtract rectangle or region from this:
62 // Combines the parts of 'this' that are not part of the second region.
63 bool Subtract(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
64 bool Subtract(const wxRect
& rect
) { return Subtract(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
65 bool Subtract(const wxRegion
& region
);
67 // XOR: the union of two combined regions except for any overlapping areas.
68 bool Xor(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
69 bool Xor(const wxRect
& rect
) { return Xor(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
70 bool Xor(const wxRegion
& region
);
72 //# Information on region
73 // Outer bounds of region
74 void GetBox(wxCoord
& x
, wxCoord
& y
, wxCoord
&w
, wxCoord
&h
) const;
75 wxRect
GetBox(void) const ;
78 bool Empty(void) const;
79 inline bool IsEmpty(void) const { return Empty(); }
82 // Does the region contain the point (x,y)?
83 wxRegionContain
Contains(wxCoord x
, wxCoord y
) const;
84 // Does the region contain the point pt?
85 wxRegionContain
Contains(const wxPoint
& pt
) const;
86 // Does the region contain the rectangle (x, y, w, h)?
87 wxRegionContain
Contains(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
) const;
88 // Does the region contain the rectangle rect?
89 wxRegionContain
Contains(const wxRect
& rect
) const;
91 // Convert the region to a B&W bitmap with the white pixels being inside
93 wxBitmap
ConvertToBitmap() const;
95 // Use the non-transparent pixels of a wxBitmap for the region to combine
96 // with this region. First version takes transparency from bitmap's mask,
97 // second lets the user specify the colour to be treated as transparent
98 // along with an optional tolerance value.
99 // NOTE: implemented in common/rgncmn.cpp
100 bool Union(const wxBitmap
& bmp
);
101 bool Union(const wxBitmap
& bmp
,
102 const wxColour
& transColour
, int tolerance
= 0);
105 // implementation from now on:
106 const MGLRegion
& GetMGLRegion() const;
110 virtual wxObjectRefData
*CreateRefData() const;
111 virtual wxObjectRefData
*CloneRefData(const wxObjectRefData
*data
) const;
115 WX_DECLARE_EXPORTED_LIST(wxRect
, wxRegionRectList
);
117 class WXDLLEXPORT wxRegionIterator
: public wxObject
119 DECLARE_DYNAMIC_CLASS(wxRegionIterator
);
121 wxRegionIterator(void);
122 wxRegionIterator(const wxRegion
& region
);
123 ~wxRegionIterator(void);
125 void Reset(void) { m_currentNode
= NULL
; }
126 void Reset(const wxRegion
& region
);
129 operator bool (void) const { return (m_currentNode
!= NULL
); }
132 bool HaveRects(void) const { return (m_currentNode
!= NULL
); }
134 void operator ++ (void);
135 void operator ++ (int);
137 wxCoord
GetX(void) const;
138 wxCoord
GetY(void) const;
139 wxCoord
GetW(void) const;
140 wxCoord
GetWidth(void) const { return GetW(); }
141 wxCoord
GetH(void) const;
142 wxCoord
GetHeight(void) const { return GetH(); }
143 wxRect
GetRect() const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }
146 wxRegionRectList m_rects
;
147 wxRegionRectList::Node
*m_currentNode
;