1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxRegion class
4 // Author: Markus Holzem, Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "region.h"
20 #include "wx/gdiobj.h"
22 class WXDLLEXPORT wxRect
;
23 class WXDLLEXPORT wxPoint
;
25 enum wxRegionContain
{
26 wxOutRegion
= 0, wxPartRegion
= 1, wxInRegion
= 2
29 // So far, for internal use only
31 wxRGN_AND
, // Creates the intersection of the two combined regions.
32 wxRGN_COPY
, // Creates a copy of the region identified by hrgnSrc1.
33 wxRGN_DIFF
, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
34 wxRGN_OR
, // Creates the union of two combined regions.
35 wxRGN_XOR
// Creates the union of two combined regions except for any overlapping areas.
38 class WXDLLEXPORT wxRegion
: public wxGDIObject
{
39 DECLARE_DYNAMIC_CLASS(wxRegion
);
40 friend class WXDLLEXPORT wxRegionIterator
;
42 wxRegion(long x
, long y
, long w
, long h
);
43 wxRegion(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
44 wxRegion(const wxRect
& rect
);
50 inline wxRegion(const wxRegion
& r
)
52 inline wxRegion
& operator = (const wxRegion
& r
)
53 { Ref(r
); return (*this); }
56 // Clear current region
59 // Union rectangle or region with this.
60 inline bool Union(long x
, long y
, long width
, long height
) { return Combine(x
, y
, width
, height
, wxRGN_OR
); }
61 inline bool Union(const wxRect
& rect
) { return Combine(rect
, wxRGN_OR
); }
62 inline bool Union(const wxRegion
& region
) { return Combine(region
, wxRGN_OR
); }
64 // Intersect rectangle or region with this.
65 inline bool Intersect(long x
, long y
, long width
, long height
) { return Combine(x
, y
, width
, height
, wxRGN_AND
); }
66 inline bool Intersect(const wxRect
& rect
) { return Combine(rect
, wxRGN_AND
); }
67 inline bool Intersect(const wxRegion
& region
) { return Combine(region
, wxRGN_AND
); }
69 // Subtract rectangle or region from this:
70 // Combines the parts of 'this' that are not part of the second region.
71 inline bool Subtract(long x
, long y
, long width
, long height
) { return Combine(x
, y
, width
, height
, wxRGN_DIFF
); }
72 inline bool Subtract(const wxRect
& rect
) { return Combine(rect
, wxRGN_DIFF
); }
73 inline bool Subtract(const wxRegion
& region
) { return Combine(region
, wxRGN_DIFF
); }
75 // XOR: the union of two combined regions except for any overlapping areas.
76 inline bool Xor(long x
, long y
, long width
, long height
) { return Combine(x
, y
, width
, height
, wxRGN_XOR
); }
77 inline bool Xor(const wxRect
& rect
) { return Combine(rect
, wxRGN_XOR
); }
78 inline bool Xor(const wxRegion
& region
) { return Combine(region
, wxRGN_XOR
); }
80 //# Information on region
81 // Outer bounds of region
82 void GetBox(long& x
, long& y
, long&w
, long &h
) const;
83 wxRect
GetBox(void) const ;
86 bool Empty(void) const;
87 inline bool IsEmpty(void) const { return Empty(); }
90 // Does the region contain the point (x,y)?
91 wxRegionContain
Contains(long x
, long y
) const;
92 // Does the region contain the point pt?
93 wxRegionContain
Contains(const wxPoint
& pt
) const;
94 // Does the region contain the rectangle (x, y, w, h)?
95 wxRegionContain
Contains(long x
, long y
, long w
, long h
) const;
96 // Does the region contain the rectangle rect?
97 wxRegionContain
Contains(const wxRect
& rect
) const;
100 bool Combine(long x
, long y
, long width
, long height
, wxRegionOp op
);
101 bool Combine(const wxRegion
& region
, wxRegionOp op
);
102 bool Combine(const wxRect
& rect
, wxRegionOp op
);
105 class WXDLLEXPORT wxRegionIterator
: public wxObject
{
106 DECLARE_DYNAMIC_CLASS(wxRegionIterator
);
108 wxRegionIterator(void);
109 wxRegionIterator(const wxRegion
& region
);
110 ~wxRegionIterator(void);
112 void Reset(void) { m_current
= 0; }
113 void Reset(const wxRegion
& region
);
115 operator bool (void) const { return m_current
< m_numRects
; }
116 bool HaveRects(void) const { return m_current
< m_numRects
; }
118 void operator ++ (void);
119 void operator ++ (int);
121 long GetX(void) const;
122 long GetY(void) const;
123 long GetW(void) const;
124 long GetWidth(void) const { return GetW(); }
125 long GetH(void) const;
126 long GetHeight(void) const { return GetH(); }