1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxRegion class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart, Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #include "wx/gdiobj.h"
17 #include "wx/gdicmn.h"
19 //-----------------------------------------------------------------------------
21 //-----------------------------------------------------------------------------
23 class WXDLLIMPEXP_CORE wxRegion
;
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 // So far, for internal use only
32 wxRGN_AND
, // Creates the intersection of the two combined regions.
33 wxRGN_COPY
, // Creates a copy of the region identified by hrgnSrc1.
34 wxRGN_DIFF
, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
35 wxRGN_OR
, // Creates the union of two combined regions.
36 wxRGN_XOR
// Creates the union of two combined regions except for any overlapping areas.
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 class WXDLLIMPEXP_CORE wxRegion
: public wxGDIObject
48 wxRegion( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
53 wxRegion( const wxPoint
& topLeft
, const wxPoint
& bottomRight
)
55 InitRect(topLeft
.x
, topLeft
.y
,
56 bottomRight
.x
- topLeft
.x
, bottomRight
.y
- topLeft
.y
);
59 wxRegion( const wxRect
& rect
)
61 InitRect(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
64 wxRegion( size_t n
, const wxPoint
*points
, int fillStyle
= wxODDEVEN_RULE
);
66 wxRegion( const wxBitmap
& bmp
)
70 wxRegion( const wxBitmap
& bmp
,
71 const wxColour
& transColour
, int tolerance
= 0)
73 Union(bmp
, transColour
, tolerance
);
78 bool Ok() const { return m_refData
!= NULL
; }
80 bool operator == ( const wxRegion
& region
) const;
81 bool operator != ( const wxRegion
& region
) const { return !(*this == region
); }
85 bool Offset( wxCoord x
, wxCoord y
);
87 bool Union( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
88 bool Union( const wxRect
& rect
);
89 bool Union( const wxRegion
& region
);
91 bool Intersect( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
92 bool Intersect( const wxRect
& rect
);
93 bool Intersect( const wxRegion
& region
);
95 bool Subtract( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
96 bool Subtract( const wxRect
& rect
);
97 bool Subtract( const wxRegion
& region
);
99 bool Xor( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
100 bool Xor( const wxRect
& rect
);
101 bool Xor( const wxRegion
& region
);
103 void GetBox( wxCoord
& x
, wxCoord
& y
, wxCoord
&w
, wxCoord
&h
) const;
104 wxRect
GetBox() const ;
107 bool IsEmpty() const { return Empty(); }
109 wxRegionContain
Contains( wxCoord x
, wxCoord y
) const;
110 wxRegionContain
Contains( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
) const;
111 wxRegionContain
Contains(const wxPoint
& pt
) const;
112 wxRegionContain
Contains(const wxRect
& rect
) const;
114 // Convert the region to a B&W bitmap with the white pixels being inside
116 wxBitmap
ConvertToBitmap() const;
118 // Use the non-transparent pixels of a wxBitmap for the region to combine
119 // with this region. First version takes transparency from bitmap's mask,
120 // second lets the user specify the colour to be treated as transparent
121 // along with an optional tolerance value.
122 // NOTE: implemented in common/rgncmn.cpp
123 bool Union(const wxBitmap
& bmp
);
124 bool Union(const wxBitmap
& bmp
,
125 const wxColour
& transColour
, int tolerance
= 0);
129 WXRegion
*GetX11Region() const;
133 virtual wxObjectRefData
*CreateRefData() const;
134 virtual wxObjectRefData
*CloneRefData(const wxObjectRefData
*data
) const;
136 // common part of ctors for a rectangle region
137 void InitRect(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
);
140 DECLARE_DYNAMIC_CLASS(wxRegion
)
143 // ----------------------------------------------------------------------------
144 // wxRegionIterator: decomposes a region into rectangles
145 // ----------------------------------------------------------------------------
147 class WXDLLIMPEXP_CORE wxRegionIterator
: public wxObject
151 wxRegionIterator(const wxRegion
& region
);
153 void Reset() { m_current
= 0u; }
154 void Reset(const wxRegion
& region
);
156 operator bool () const;
157 bool HaveRects() const;
160 void operator ++ (int);
162 wxCoord
GetX() const;
163 wxCoord
GetY() const;
164 wxCoord
GetW() const;
165 wxCoord
GetWidth() const { return GetW(); }
166 wxCoord
GetH() const;
167 wxCoord
GetHeight() const { return GetH(); }
168 wxRect
GetRect() const;
175 DECLARE_DYNAMIC_CLASS(wxRegionIterator
)