1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/region.h
3 // Purpose: generic wxRegion class
4 // Author: David Elliott
8 // Copyright: (c) 2004 David Elliott
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_GENERIC_REGION_H__
13 #define _WX_GENERIC_REGION_H__
15 #include "wx/gdiobj.h"
16 #include "wx/gdicmn.h"
18 class WXDLLEXPORT wxRect
;
19 class WXDLLEXPORT wxPoint
;
27 class WXDLLEXPORT wxRegionGeneric
: public wxGDIObject
29 // DECLARE_DYNAMIC_CLASS(wxRegionGeneric);
30 friend class WXDLLEXPORT wxRegionIteratorGeneric
;
32 wxRegionGeneric(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
);
33 wxRegionGeneric(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
34 wxRegionGeneric(const wxRect
& rect
);
38 bool Ok() const { return m_refData
!= NULL
; }
40 bool operator == ( const wxRegionGeneric
& region
) const;
41 bool operator != ( const wxRegionGeneric
& region
) const { return !(*this == region
); }
44 // Clear current region
48 bool Offset(wxCoord x
, wxCoord y
);
50 // Union rectangle or region with this.
51 bool Union(long x
, long y
, long width
, long height
)
52 { return Union(wxRect(x
,y
,width
,height
)); }
53 bool Union(const wxRect
& rect
);
54 bool Union(const wxRegionGeneric
& region
);
56 // Intersect rectangle or region with this.
57 bool Intersect(long x
, long y
, long width
, long height
)
58 { return Intersect(wxRect(x
,y
,width
,height
)); }
59 bool Intersect(const wxRect
& rect
);
60 bool Intersect(const wxRegionGeneric
& region
);
62 // Subtract rectangle or region from this:
63 // Combines the parts of 'this' that are not part of the second region.
64 bool Subtract(long x
, long y
, long width
, long height
)
65 { return Subtract(wxRect(x
,y
,width
,height
)); }
66 bool Subtract(const wxRect
& rect
);
67 bool Subtract(const wxRegionGeneric
& region
);
69 // XOR: the union of two combined regions except for any overlapping areas.
70 bool Xor(long x
, long y
, long width
, long height
);
71 bool Xor(const wxRect
& rect
);
72 bool Xor(const wxRegionGeneric
& region
);
74 //# Information on region
75 // Outer bounds of region
76 void GetBox(wxCoord
& x
, wxCoord
& y
, wxCoord
&w
, wxCoord
&h
) const;
77 wxRect
GetBox() const;
81 inline bool IsEmpty() const { return Empty(); }
84 // Does the region contain the point (x,y)?
85 wxRegionContain
Contains(long x
, long y
) const;
86 // Does the region contain the point pt?
87 wxRegionContain
Contains(const wxPoint
& pt
) const;
88 // Does the region contain the rectangle (x, y, w, h)?
89 wxRegionContain
Contains(long x
, long y
, long w
, long h
) const;
90 // Does the region contain the rectangle rect?
91 wxRegionContain
Contains(const wxRect
& rect
) const;
93 // Use the non-transparent pixels of a wxBitmap for the region to combine
94 // with this region. First version takes transparency from bitmap's mask,
95 // second lets the user specify the colour to be treated as transparent
96 // along with an optional tolerance value.
97 // NOTE: implemented in common/rgncmn.cpp
98 bool Union(const wxBitmap
& bmp
);
99 bool Union(const wxBitmap
& bmp
,
100 const wxColour
& transColour
, int tolerance
= 0);
102 // Convert the region to a B&W bitmap with the white pixels being inside
104 wxBitmap
ConvertToBitmap() const;
107 virtual wxObjectRefData
*CreateRefData() const;
108 virtual wxObjectRefData
*CloneRefData(const wxObjectRefData
*data
) const;
111 class WXDLLEXPORT wxRegionIteratorGeneric
: public wxObject
113 // DECLARE_DYNAMIC_CLASS(wxRegionIteratorGeneric);
115 wxRegionIteratorGeneric();
116 wxRegionIteratorGeneric(const wxRegionGeneric
& region
);
117 wxRegionIteratorGeneric(const wxRegionIteratorGeneric
& iterator
);
118 ~wxRegionIteratorGeneric();
120 wxRegionIteratorGeneric
& operator=(const wxRegionIteratorGeneric
& iterator
);
122 void Reset() { m_current
= 0; }
123 void Reset(const wxRegionGeneric
& region
);
125 operator bool () const { return HaveRects(); }
126 bool HaveRects() const;
128 wxRegionIteratorGeneric
& operator++();
129 wxRegionIteratorGeneric
operator++(int);
134 long GetWidth() const { return GetW(); }
136 long GetHeight() const { return GetH(); }
137 wxRect
GetRect() const;
140 wxRegionGeneric m_region
;
143 #endif //ndef _WX_GENERIC_REGION_H__