1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/palmos/region.h
3 // Purpose: wxRegion class
4 // Author: Julian Smart
8 // Copyright: (c) 1997-2002 wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #include "wx/gdiobj.h"
16 #include "wx/gdicmn.h"
18 class WXDLLEXPORT wxRect
;
19 class WXDLLEXPORT wxPoint
;
21 // So far, for internal use only
24 wxRGN_AND
, // Creates the intersection of the two combined regions.
25 wxRGN_COPY
, // Creates a copy of the region identified by hrgnSrc1.
26 wxRGN_DIFF
, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
27 wxRGN_OR
, // Creates the union of two combined regions.
28 wxRGN_XOR
// Creates the union of two combined regions except for any overlapping areas.
31 class WXDLLEXPORT wxRegion
: public wxGDIObject
35 wxRegion(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
);
36 wxRegion(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
37 wxRegion(const wxRect
& rect
);
38 wxRegion(WXHRGN hRegion
); // Hangs on to this region
39 wxRegion(size_t n
, const wxPoint
*points
, int fillStyle
= wxODDEVEN_RULE
);
40 wxRegion( const wxBitmap
& bmp
)
44 wxRegion( const wxBitmap
& bmp
,
45 const wxColour
& transColour
, int tolerance
= 0)
47 Union(bmp
, transColour
, tolerance
);
55 // Clear current region
59 bool Offset(wxCoord x
, wxCoord y
);
61 // Union rectangle or region with this.
62 bool Union(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
) { return Combine(x
, y
, width
, height
, wxRGN_OR
); }
63 bool Union(const wxRect
& rect
) { return Combine(rect
, wxRGN_OR
); }
64 bool Union(const wxRegion
& region
) { return Combine(region
, wxRGN_OR
); }
66 // Intersect rectangle or region with this.
67 bool Intersect(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
) { return Combine(x
, y
, width
, height
, wxRGN_AND
); }
68 bool Intersect(const wxRect
& rect
) { return Combine(rect
, wxRGN_AND
); }
69 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 bool Subtract(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
) { return Combine(x
, y
, width
, height
, wxRGN_DIFF
); }
74 bool Subtract(const wxRect
& rect
) { return Combine(rect
, wxRGN_DIFF
); }
75 bool Subtract(const wxRegion
& region
) { return Combine(region
, wxRGN_DIFF
); }
77 // XOR: the union of two combined regions except for any overlapping areas.
78 bool Xor(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
) { return Combine(x
, y
, width
, height
, wxRGN_XOR
); }
79 bool Xor(const wxRect
& rect
) { return Combine(rect
, wxRGN_XOR
); }
80 bool Xor(const wxRegion
& region
) { return Combine(region
, wxRGN_XOR
); }
82 // Information on region
83 // ---------------------
85 // Outer bounds of region
86 void GetBox(wxCoord
& x
, wxCoord
& y
, wxCoord
&w
, wxCoord
&h
) const;
87 wxRect
GetBox() const ;
91 inline bool IsEmpty() const { return Empty(); }
94 // Does the region contain the point (x,y)?
95 wxRegionContain
Contains(wxCoord x
, wxCoord y
) const;
96 // Does the region contain the point pt?
97 wxRegionContain
Contains(const wxPoint
& pt
) const;
98 // Does the region contain the rectangle (x, y, w, h)?
99 wxRegionContain
Contains(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
) const;
100 // Does the region contain the rectangle rect?
101 wxRegionContain
Contains(const wxRect
& rect
) const;
103 // Convert the region to a B&W bitmap with the white pixels being inside
105 wxBitmap
ConvertToBitmap() const;
107 // Use the non-transparent pixels of a wxBitmap for the region to combine
108 // with this region. First version takes transparency from bitmap's mask,
109 // second lets the user specify the colour to be treated as transparent
110 // along with an optional tolerance value.
111 // NOTE: implemented in common/rgncmn.cpp
112 bool Union(const wxBitmap
& bmp
);
113 bool Union(const wxBitmap
& bmp
,
114 const wxColour
& transColour
, int tolerance
= 0);
117 bool Combine(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, wxRegionOp op
);
118 bool Combine(const wxRegion
& region
, wxRegionOp op
);
119 bool Combine(const wxRect
& rect
, wxRegionOp op
);
121 // Get internal region handle
122 WXHRGN
GetHRGN() const;
125 virtual wxObjectRefData
*CreateRefData() const;
126 virtual wxObjectRefData
*CloneRefData(const wxObjectRefData
*data
) const;
128 friend class WXDLLEXPORT wxRegionIterator
;
130 DECLARE_DYNAMIC_CLASS(wxRegion
)
133 class WXDLLEXPORT wxRegionIterator
: public wxObject
136 wxRegionIterator() { Init(); }
137 wxRegionIterator(const wxRegion
& region
);
138 wxRegionIterator(const wxRegionIterator
& ri
) : wxObject(ri
) { Init(); *this = ri
; }
140 wxRegionIterator
& operator=(const wxRegionIterator
& ri
);
142 virtual ~wxRegionIterator();
144 void Reset() { m_current
= 0; }
145 void Reset(const wxRegion
& region
);
147 bool HaveRects() const { return (m_current
< m_numRects
); }
150 operator bool () const { return HaveRects(); }
153 wxRegionIterator
& operator++();
154 wxRegionIterator
operator++(int);
156 wxCoord
GetX() const;
157 wxCoord
GetY() const;
158 wxCoord
GetW() const;
159 wxCoord
GetWidth() const { return GetW(); }
160 wxCoord
GetH() const;
161 wxCoord
GetHeight() const { return GetH(); }
163 wxRect
GetRect() const { return wxRect(GetX(), GetY(), GetW(), GetH()); }
166 // common part of all ctors
174 DECLARE_DYNAMIC_CLASS(wxRegionIterator
)