1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/region.h
3 // Purpose: wxRegion class
4 // Author: Markus Holzem, Julian Smart
8 // Copyright: (c) 1997-2002 wxWindows team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "region.h"
19 #include "wx/gdiobj.h"
20 #include "wx/gdicmn.h"
22 class WXDLLEXPORT wxRect
;
23 class WXDLLEXPORT wxPoint
;
32 // So far, for internal use only
35 wxRGN_AND
, // Creates the intersection of the two combined regions.
36 wxRGN_COPY
, // Creates a copy of the region identified by hrgnSrc1.
37 wxRGN_DIFF
, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
38 wxRGN_OR
, // Creates the union of two combined regions.
39 wxRGN_XOR
// Creates the union of two combined regions except for any overlapping areas.
42 class WXDLLEXPORT wxRegion
: public wxGDIObject
46 wxRegion(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
);
47 wxRegion(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
48 wxRegion(const wxRect
& rect
);
49 wxRegion(WXHRGN hRegion
); // Hangs on to this region
50 wxRegion(size_t n
, const wxPoint
*points
, int fillStyle
= wxODDEVEN_RULE
);
55 wxRegion(const wxRegion
& r
)
57 wxRegion
& operator = (const wxRegion
& r
)
58 { Ref(r
); return (*this); }
63 // Clear current region
67 bool Offset(wxCoord x
, wxCoord y
);
69 // Union rectangle or region with this.
70 bool Union(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
) { return Combine(x
, y
, width
, height
, wxRGN_OR
); }
71 bool Union(const wxRect
& rect
) { return Combine(rect
, wxRGN_OR
); }
72 bool Union(const wxRegion
& region
) { return Combine(region
, wxRGN_OR
); }
74 // Intersect rectangle or region with this.
75 bool Intersect(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
) { return Combine(x
, y
, width
, height
, wxRGN_AND
); }
76 bool Intersect(const wxRect
& rect
) { return Combine(rect
, wxRGN_AND
); }
77 bool Intersect(const wxRegion
& region
) { return Combine(region
, wxRGN_AND
); }
79 // Subtract rectangle or region from this:
80 // Combines the parts of 'this' that are not part of the second region.
81 bool Subtract(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
) { return Combine(x
, y
, width
, height
, wxRGN_DIFF
); }
82 bool Subtract(const wxRect
& rect
) { return Combine(rect
, wxRGN_DIFF
); }
83 bool Subtract(const wxRegion
& region
) { return Combine(region
, wxRGN_DIFF
); }
85 // XOR: the union of two combined regions except for any overlapping areas.
86 bool Xor(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
) { return Combine(x
, y
, width
, height
, wxRGN_XOR
); }
87 bool Xor(const wxRect
& rect
) { return Combine(rect
, wxRGN_XOR
); }
88 bool Xor(const wxRegion
& region
) { return Combine(region
, wxRGN_XOR
); }
90 // Information on region
91 // ---------------------
93 // Outer bounds of region
94 void GetBox(wxCoord
& x
, wxCoord
& y
, wxCoord
&w
, wxCoord
&h
) const;
95 wxRect
GetBox() const ;
99 inline bool IsEmpty() const { return Empty(); }
102 // Does the region contain the point (x,y)?
103 wxRegionContain
Contains(wxCoord x
, wxCoord y
) const;
104 // Does the region contain the point pt?
105 wxRegionContain
Contains(const wxPoint
& pt
) const;
106 // Does the region contain the rectangle (x, y, w, h)?
107 wxRegionContain
Contains(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
) const;
108 // Does the region contain the rectangle rect?
109 wxRegionContain
Contains(const wxRect
& rect
) const;
112 bool Combine(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, wxRegionOp op
);
113 bool Combine(const wxRegion
& region
, wxRegionOp op
);
114 bool Combine(const wxRect
& rect
, wxRegionOp op
);
116 // Get internal region handle
117 WXHRGN
GetHRGN() const;
120 virtual wxObjectRefData
*CreateRefData() const;
121 virtual wxObjectRefData
*CloneRefData(const wxObjectRefData
*data
) const;
123 friend class WXDLLEXPORT wxRegionIterator
;
125 DECLARE_DYNAMIC_CLASS(wxRegion
)
128 class WXDLLEXPORT wxRegionIterator
: public wxObject
131 wxRegionIterator() { Init(); }
132 wxRegionIterator(const wxRegion
& region
);
133 wxRegionIterator(const wxRegionIterator
& ri
) { Init(); *this = ri
; }
135 wxRegionIterator
& operator=(const wxRegionIterator
& ri
);
137 virtual ~wxRegionIterator();
139 void Reset() { m_current
= 0; }
140 void Reset(const wxRegion
& region
);
142 bool HaveRects() const { return (m_current
< m_numRects
); }
145 operator bool () const { return HaveRects(); }
148 wxRegionIterator
& operator++();
149 wxRegionIterator
operator++(int);
151 wxCoord
GetX() const;
152 wxCoord
GetY() const;
153 wxCoord
GetW() const;
154 wxCoord
GetWidth() const { return GetW(); }
155 wxCoord
GetH() const;
156 wxCoord
GetHeight() const { return GetH(); }
158 wxRect
GetRect() const { return wxRect(GetX(), GetY(), GetW(), GetH()); }
161 // common part of all ctors
169 DECLARE_DYNAMIC_CLASS(wxRegionIterator
);