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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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
);
51 wxRegion( const wxBitmap
& bmp
)
55 wxRegion( const wxBitmap
& bmp
,
56 const wxColour
& transColour
, int tolerance
= 0)
58 Union(bmp
, transColour
, tolerance
);
64 wxRegion(const wxRegion
& r
) : wxGDIObject(r
)
66 wxRegion
& operator = (const wxRegion
& r
)
67 { Ref(r
); return (*this); }
72 // Clear current region
76 bool Offset(wxCoord x
, wxCoord y
);
78 // Union rectangle or region with this.
79 bool Union(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
) { return Combine(x
, y
, width
, height
, wxRGN_OR
); }
80 bool Union(const wxRect
& rect
) { return Combine(rect
, wxRGN_OR
); }
81 bool Union(const wxRegion
& region
) { return Combine(region
, wxRGN_OR
); }
83 // Intersect rectangle or region with this.
84 bool Intersect(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
) { return Combine(x
, y
, width
, height
, wxRGN_AND
); }
85 bool Intersect(const wxRect
& rect
) { return Combine(rect
, wxRGN_AND
); }
86 bool Intersect(const wxRegion
& region
) { return Combine(region
, wxRGN_AND
); }
88 // Subtract rectangle or region from this:
89 // Combines the parts of 'this' that are not part of the second region.
90 bool Subtract(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
) { return Combine(x
, y
, width
, height
, wxRGN_DIFF
); }
91 bool Subtract(const wxRect
& rect
) { return Combine(rect
, wxRGN_DIFF
); }
92 bool Subtract(const wxRegion
& region
) { return Combine(region
, wxRGN_DIFF
); }
94 // XOR: the union of two combined regions except for any overlapping areas.
95 bool Xor(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
) { return Combine(x
, y
, width
, height
, wxRGN_XOR
); }
96 bool Xor(const wxRect
& rect
) { return Combine(rect
, wxRGN_XOR
); }
97 bool Xor(const wxRegion
& region
) { return Combine(region
, wxRGN_XOR
); }
99 // Information on region
100 // ---------------------
102 // Outer bounds of region
103 void GetBox(wxCoord
& x
, wxCoord
& y
, wxCoord
&w
, wxCoord
&h
) const;
104 wxRect
GetBox() const ;
108 inline bool IsEmpty() const { return Empty(); }
111 // Does the region contain the point (x,y)?
112 wxRegionContain
Contains(wxCoord x
, wxCoord y
) const;
113 // Does the region contain the point pt?
114 wxRegionContain
Contains(const wxPoint
& pt
) const;
115 // Does the region contain the rectangle (x, y, w, h)?
116 wxRegionContain
Contains(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
) const;
117 // Does the region contain the rectangle rect?
118 wxRegionContain
Contains(const wxRect
& rect
) const;
120 // Convert the region to a B&W bitmap with the white pixels being inside
122 wxBitmap
ConvertToBitmap() const;
124 // Use the non-transparent pixels of a wxBitmap for the region to combine
125 // with this region. First version takes transparency from bitmap's mask,
126 // second lets the user specify the colour to be treated as transparent
127 // along with an optional tolerance value.
128 // NOTE: implemented in common/rgncmn.cpp
129 bool Union(const wxBitmap
& bmp
);
130 bool Union(const wxBitmap
& bmp
,
131 const wxColour
& transColour
, int tolerance
= 0);
134 bool Combine(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, wxRegionOp op
);
135 bool Combine(const wxRegion
& region
, wxRegionOp op
);
136 bool Combine(const wxRect
& rect
, wxRegionOp op
);
138 // Get internal region handle
139 WXHRGN
GetHRGN() const;
142 virtual wxObjectRefData
*CreateRefData() const;
143 virtual wxObjectRefData
*CloneRefData(const wxObjectRefData
*data
) const;
145 friend class WXDLLEXPORT wxRegionIterator
;
147 DECLARE_DYNAMIC_CLASS(wxRegion
)
150 class WXDLLEXPORT wxRegionIterator
: public wxObject
153 wxRegionIterator() { Init(); }
154 wxRegionIterator(const wxRegion
& region
);
155 wxRegionIterator(const wxRegionIterator
& ri
) : wxObject(ri
) { Init(); *this = ri
; }
157 wxRegionIterator
& operator=(const wxRegionIterator
& ri
);
159 virtual ~wxRegionIterator();
161 void Reset() { m_current
= 0; }
162 void Reset(const wxRegion
& region
);
164 bool HaveRects() const { return (m_current
< m_numRects
); }
167 operator bool () const { return HaveRects(); }
170 wxRegionIterator
& operator++();
171 wxRegionIterator
operator++(int);
173 wxCoord
GetX() const;
174 wxCoord
GetY() const;
175 wxCoord
GetW() const;
176 wxCoord
GetWidth() const { return GetW(); }
177 wxCoord
GetH() const;
178 wxCoord
GetHeight() const { return GetH(); }
180 wxRect
GetRect() const { return wxRect(GetX(), GetY(), GetW(), GetH()); }
183 // common part of all ctors
191 DECLARE_DYNAMIC_CLASS(wxRegionIterator
)