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
;
21 class WXDLLEXPORT wxRegionGeneric
: public wxGDIObject
23 // DECLARE_DYNAMIC_CLASS(wxRegionGeneric);
24 friend class WXDLLEXPORT wxRegionIteratorGeneric
;
26 wxRegionGeneric(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
);
27 wxRegionGeneric(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
28 wxRegionGeneric(const wxRect
& rect
);
30 virtual ~wxRegionGeneric();
32 bool Ok() const { return m_refData
!= NULL
; }
34 bool operator == ( const wxRegionGeneric
& region
) const;
35 bool operator != ( const wxRegionGeneric
& region
) const { return !(*this == region
); }
38 // Clear current region
42 bool Offset(wxCoord x
, wxCoord y
);
44 // Union rectangle or region with this.
45 bool Union(long x
, long y
, long width
, long height
)
46 { return Union(wxRect(x
,y
,width
,height
)); }
47 bool Union(const wxRect
& rect
);
48 bool Union(const wxRegionGeneric
& region
);
50 // Intersect rectangle or region with this.
51 bool Intersect(long x
, long y
, long width
, long height
)
52 { return Intersect(wxRect(x
,y
,width
,height
)); }
53 bool Intersect(const wxRect
& rect
);
54 bool Intersect(const wxRegionGeneric
& region
);
56 // Subtract rectangle or region from this:
57 // Combines the parts of 'this' that are not part of the second region.
58 bool Subtract(long x
, long y
, long width
, long height
)
59 { return Subtract(wxRect(x
,y
,width
,height
)); }
60 bool Subtract(const wxRect
& rect
);
61 bool Subtract(const wxRegionGeneric
& region
);
63 // XOR: the union of two combined regions except for any overlapping areas.
64 bool Xor(long x
, long y
, long width
, long height
);
65 bool Xor(const wxRect
& rect
);
66 bool Xor(const wxRegionGeneric
& region
);
68 //# Information on region
69 // Outer bounds of region
70 void GetBox(wxCoord
& x
, wxCoord
& y
, wxCoord
&w
, wxCoord
&h
) const;
71 wxRect
GetBox() const;
75 inline bool IsEmpty() const { return Empty(); }
78 // Does the region contain the point (x,y)?
79 wxRegionContain
Contains(long x
, long y
) const;
80 // Does the region contain the point pt?
81 wxRegionContain
Contains(const wxPoint
& pt
) const;
82 // Does the region contain the rectangle (x, y, w, h)?
83 wxRegionContain
Contains(long x
, long y
, long w
, long h
) const;
84 // Does the region contain the rectangle rect?
85 wxRegionContain
Contains(const wxRect
& rect
) const;
87 // Use the non-transparent pixels of a wxBitmap for the region to combine
88 // with this region. First version takes transparency from bitmap's mask,
89 // second lets the user specify the colour to be treated as transparent
90 // along with an optional tolerance value.
91 // NOTE: implemented in common/rgncmn.cpp
92 bool Union(const wxBitmap
& bmp
);
93 bool Union(const wxBitmap
& bmp
,
94 const wxColour
& transColour
, int tolerance
= 0);
96 // Convert the region to a B&W bitmap with the white pixels being inside
98 wxBitmap
ConvertToBitmap() const;
101 virtual wxObjectRefData
*CreateRefData() const;
102 virtual wxObjectRefData
*CloneRefData(const wxObjectRefData
*data
) const;
105 class WXDLLEXPORT wxRegionIteratorGeneric
: public wxObject
107 // DECLARE_DYNAMIC_CLASS(wxRegionIteratorGeneric);
109 wxRegionIteratorGeneric();
110 wxRegionIteratorGeneric(const wxRegionGeneric
& region
);
111 wxRegionIteratorGeneric(const wxRegionIteratorGeneric
& iterator
);
112 virtual ~wxRegionIteratorGeneric();
114 wxRegionIteratorGeneric
& operator=(const wxRegionIteratorGeneric
& iterator
);
116 void Reset() { m_current
= 0; }
117 void Reset(const wxRegionGeneric
& region
);
119 operator bool () const { return HaveRects(); }
120 bool HaveRects() const;
122 wxRegionIteratorGeneric
& operator++();
123 wxRegionIteratorGeneric
operator++(int);
128 long GetWidth() const { return GetW(); }
130 long GetHeight() const { return GetH(); }
131 wxRect
GetRect() const;
134 wxRegionGeneric m_region
;
137 #endif //ndef _WX_GENERIC_REGION_H__