1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxRegion class
4 // Author: Markus Holzem, Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
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
); // Hangs on to this region
52 inline wxRegion(const wxRegion
& r
)
54 inline wxRegion
& operator = (const wxRegion
& r
)
55 { Ref(r
); return (*this); }
58 // Clear current region
61 // Union rectangle or region with this.
62 inline bool Union(long x
, long y
, long width
, long height
) { return Combine(x
, y
, width
, height
, wxRGN_OR
); }
63 inline bool Union(const wxRect
& rect
) { return Combine(rect
, wxRGN_OR
); }
64 inline bool Union(const wxRegion
& region
) { return Combine(region
, wxRGN_OR
); }
66 // Intersect rectangle or region with this.
67 inline bool Intersect(long x
, long y
, long width
, long height
) { return Combine(x
, y
, width
, height
, wxRGN_AND
); }
68 inline bool Intersect(const wxRect
& rect
) { return Combine(rect
, wxRGN_AND
); }
69 inline bool Intersect(const wxRegion
& region
) { return Combine(region
, wxRGN_AND
); }
71 // Subtract rectangle or region from this:
72 // Combines the parts of 'this' that are not part of the second region.
73 inline bool Subtract(long x
, long y
, long width
, long height
) { return Combine(x
, y
, width
, height
, wxRGN_DIFF
); }
74 inline bool Subtract(const wxRect
& rect
) { return Combine(rect
, wxRGN_DIFF
); }
75 inline bool Subtract(const wxRegion
& region
) { return Combine(region
, wxRGN_DIFF
); }
77 // XOR: the union of two combined regions except for any overlapping areas.
78 inline bool Xor(long x
, long y
, long width
, long height
) { return Combine(x
, y
, width
, height
, wxRGN_XOR
); }
79 inline bool Xor(const wxRect
& rect
) { return Combine(rect
, wxRGN_XOR
); }
80 inline bool Xor(const wxRegion
& region
) { return Combine(region
, wxRGN_XOR
); }
82 //# Information on region
83 // Outer bounds of region
84 void GetBox(long& x
, long& y
, long&w
, long &h
) const;
85 wxRect
GetBox(void) const ;
88 bool Empty(void) const;
89 inline bool IsEmpty(void) const { return Empty(); }
92 // Does the region contain the point (x,y)?
93 wxRegionContain
Contains(long x
, long y
) const;
94 // Does the region contain the point pt?
95 wxRegionContain
Contains(const wxPoint
& pt
) const;
96 // Does the region contain the rectangle (x, y, w, h)?
97 wxRegionContain
Contains(long x
, long y
, long w
, long h
) const;
98 // Does the region contain the rectangle rect?
99 wxRegionContain
Contains(const wxRect
& rect
) const;
102 bool Combine(long x
, long y
, long width
, long height
, wxRegionOp op
);
103 bool Combine(const wxRegion
& region
, wxRegionOp op
);
104 bool Combine(const wxRect
& rect
, wxRegionOp op
);
106 // Get internal region handle
107 WXHRGN
GetHRGN() const;
110 class WXDLLEXPORT wxRegionIterator
: public wxObject
{
111 DECLARE_DYNAMIC_CLASS(wxRegionIterator
);
113 wxRegionIterator(void);
114 wxRegionIterator(const wxRegion
& region
);
115 ~wxRegionIterator(void);
117 void Reset(void) { m_current
= 0; }
118 void Reset(const wxRegion
& region
);
120 operator bool (void) const { return m_current
< m_numRects
; }
121 bool HaveRects(void) const { return m_current
< m_numRects
; }
123 void operator ++ (void);
124 void operator ++ (int);
126 long GetX(void) const;
127 long GetY(void) const;
128 long GetW(void) const;
129 long GetWidth(void) const { return GetW(); }
130 long GetH(void) const;
131 long GetHeight(void) const { return GetH(); }
132 wxRect
GetRect() const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }