1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxRegion class
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #include "wx/gdiobj.h"
17 #include "wx/gdicmn.h"
19 class WXDLLEXPORT wxRect
;
20 class WXDLLEXPORT wxPoint
;
22 enum wxRegionContain
{
23 wxOutRegion
= 0, wxPartRegion
= 1, wxInRegion
= 2
26 // So far, for internal use only
28 wxRGN_AND
, // Creates the intersection of the two combined regions.
29 wxRGN_COPY
, // Creates a copy of the region identified by hrgnSrc1.
30 wxRGN_DIFF
, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
31 wxRGN_OR
, // Creates the union of two combined regions.
32 wxRGN_XOR
// Creates the union of two combined regions except for any overlapping areas.
35 class WXDLLEXPORT wxRegion
: public wxGDIObject
{
36 DECLARE_DYNAMIC_CLASS(wxRegion
);
37 friend class WXDLLEXPORT wxRegionIterator
;
39 wxRegion(long x
, long y
, long w
, long h
);
40 wxRegion(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
41 wxRegion(const wxRect
& rect
);
42 wxRegion(WXHRGN hRegion
); // Hangs on to this region
48 inline wxRegion(const wxRegion
& r
)
50 inline wxRegion
& operator = (const wxRegion
& r
)
51 { Ref(r
); return (*this); }
54 // Clear current region
57 // Union rectangle or region with this.
58 inline bool Union(long x
, long y
, long width
, long height
) { return Combine(x
, y
, width
, height
, wxRGN_OR
); }
59 inline bool Union(const wxRect
& rect
) { return Combine(rect
, wxRGN_OR
); }
60 inline bool Union(const wxRegion
& region
) { return Combine(region
, wxRGN_OR
); }
62 // Intersect rectangle or region with this.
63 inline bool Intersect(long x
, long y
, long width
, long height
) { return Combine(x
, y
, width
, height
, wxRGN_AND
); }
64 inline bool Intersect(const wxRect
& rect
) { return Combine(rect
, wxRGN_AND
); }
65 inline bool Intersect(const wxRegion
& region
) { return Combine(region
, wxRGN_AND
); }
67 // Subtract rectangle or region from this:
68 // Combines the parts of 'this' that are not part of the second region.
69 inline bool Subtract(long x
, long y
, long width
, long height
) { return Combine(x
, y
, width
, height
, wxRGN_DIFF
); }
70 inline bool Subtract(const wxRect
& rect
) { return Combine(rect
, wxRGN_DIFF
); }
71 inline bool Subtract(const wxRegion
& region
) { return Combine(region
, wxRGN_DIFF
); }
73 // XOR: the union of two combined regions except for any overlapping areas.
74 inline bool Xor(long x
, long y
, long width
, long height
) { return Combine(x
, y
, width
, height
, wxRGN_XOR
); }
75 inline bool Xor(const wxRect
& rect
) { return Combine(rect
, wxRGN_XOR
); }
76 inline bool Xor(const wxRegion
& region
) { return Combine(region
, wxRGN_XOR
); }
78 //# Information on region
79 // Outer bounds of region
80 void GetBox(long& x
, long& y
, long&w
, long &h
) const;
81 wxRect
GetBox() const ;
85 inline bool IsEmpty() const { return Empty(); }
88 // Does the region contain the point (x,y)?
89 wxRegionContain
Contains(long x
, long y
) const;
90 // Does the region contain the point pt?
91 wxRegionContain
Contains(const wxPoint
& pt
) const;
92 // Does the region contain the rectangle (x, y, w, h)?
93 wxRegionContain
Contains(long x
, long y
, long w
, long h
) const;
94 // Does the region contain the rectangle rect?
95 wxRegionContain
Contains(const wxRect
& rect
) const;
98 bool Combine(long x
, long y
, long width
, long height
, wxRegionOp op
);
99 bool Combine(const wxRegion
& region
, wxRegionOp op
);
100 bool Combine(const wxRect
& rect
, wxRegionOp op
);
102 // Get internal region handle
103 WXHRGN
GetHRGN() const;
106 class WXDLLEXPORT wxRegionIterator
: public wxObject
{
107 DECLARE_DYNAMIC_CLASS(wxRegionIterator
);
110 wxRegionIterator(const wxRegion
& region
);
113 void Reset() { m_current
= 0; }
114 void Reset(const wxRegion
& region
);
116 operator bool () const { return m_current
< m_numRects
; }
117 bool HaveRects() const { return m_current
< m_numRects
; }
120 void operator ++ (int);
125 long GetWidth() const { return GetW(); }
127 long GetHeight() const { return GetH(); }
128 wxRect
GetRect() const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }