1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxRegion class
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "region.h"
20 #include "wx/gdiobj.h"
21 #include "wx/gdicmn.h"
23 class WXDLLEXPORT wxRect
;
24 class WXDLLEXPORT wxPoint
;
26 enum wxRegionContain
{
27 wxOutRegion
= 0, wxPartRegion
= 1, wxInRegion
= 2
30 // 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 class WXDLLEXPORT wxRegion
: public wxGDIObject
{
40 DECLARE_DYNAMIC_CLASS(wxRegion
);
41 friend class WXDLLEXPORT wxRegionIterator
;
43 wxRegion(long x
, long y
, long w
, long h
);
44 wxRegion(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
45 wxRegion(const wxRect
& rect
);
46 wxRegion( WXHRGN hRegion
);
51 wxRegion(const wxRegion
& r
)
54 wxRegion
& operator = (const wxRegion
& r
)
55 { Ref(r
); return (*this); }
58 // Clear current region
61 // Union rectangle or region with this.
62 bool Union(long x
, long y
, long width
, long height
)
63 { return Combine(x
, y
, width
, height
, wxRGN_OR
); }
64 bool Union(const wxRect
& rect
)
65 { return Combine(rect
, wxRGN_OR
); }
66 bool Union(const wxRegion
& region
)
67 { return Combine(region
, wxRGN_OR
); }
69 // Intersect rectangle or region with this.
70 bool Intersect(long x
, long y
, long width
, long height
)
71 { return Combine(x
, y
, width
, height
, wxRGN_AND
); }
72 bool Intersect(const wxRect
& rect
)
73 { return Combine(rect
, wxRGN_AND
); }
74 bool Intersect(const wxRegion
& region
)
75 { return Combine(region
, wxRGN_AND
); }
77 // Subtract rectangle or region from this:
78 // Combines the parts of 'this' that are not part of the second region.
79 bool Subtract(long x
, long y
, long width
, long height
)
80 { return Combine(x
, y
, width
, height
, wxRGN_DIFF
); }
81 bool Subtract(const wxRect
& rect
)
82 { return Combine(rect
, wxRGN_DIFF
); }
83 bool Subtract(const wxRegion
& region
)
84 { return Combine(region
, wxRGN_DIFF
); }
86 // XOR: the union of two combined regions except for any overlapping areas.
87 bool Xor(long x
, long y
, long width
, long height
)
88 { return Combine(x
, y
, width
, height
, wxRGN_XOR
); }
89 bool Xor(const wxRect
& rect
)
90 { return Combine(rect
, wxRGN_XOR
); }
91 bool Xor(const wxRegion
& region
)
92 { return Combine(region
, wxRGN_XOR
); }
94 //# Information on region
95 // Outer bounds of region
96 void GetBox(wxCoord
& x
, wxCoord
& y
, wxCoord
&w
, wxCoord
&h
) const;
97 wxRect
GetBox() const ;
101 inline bool IsEmpty() const { return Empty(); }
104 // Does the region contain the point (x,y)?
105 wxRegionContain
Contains(long x
, long y
) const;
106 // Does the region contain the point pt?
107 wxRegionContain
Contains(const wxPoint
& pt
) const;
108 // Does the region contain the rectangle (x, y, w, h)?
109 wxRegionContain
Contains(long x
, long y
, long w
, long h
) const;
110 // Does the region contain the rectangle rect?
111 wxRegionContain
Contains(const wxRect
& rect
) const;
114 bool Combine(long x
, long y
, long width
, long height
, wxRegionOp op
);
115 bool Combine(const wxRegion
& region
, wxRegionOp op
);
116 bool Combine(const wxRect
& rect
, wxRegionOp op
);
117 const WXHRGN
GetWXHRGN() const ;
120 class WXDLLEXPORT wxRegionIterator
: public wxObject
122 DECLARE_DYNAMIC_CLASS(wxRegionIterator
)
126 wxRegionIterator(const wxRegion
& region
);
127 wxRegionIterator(const wxRegionIterator
& iterator
);
130 wxRegionIterator
& operator=(const wxRegionIterator
& iterator
);
132 void Reset() { m_current
= 0; }
133 void Reset(const wxRegion
& region
);
135 operator bool () const { return m_current
< m_numRects
; }
136 bool HaveRects() const { return m_current
< m_numRects
; }
138 wxRegionIterator
& operator++();
139 wxRegionIterator
operator++(int);
144 long GetWidth() const { return GetW(); }
146 long GetHeight() const { return GetH(); }
147 wxRect
GetRect() const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }
149 void SetRects(long numRects
, wxRect
*rects
);