1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/dfb/region.h
3 // Purpose: wxRegion class
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2006 REA Elektronik GmbH
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_DFB_REGION_H_
12 #define _WX_DFB_REGION_H_
14 #include "wx/gdiobj.h"
15 #include "wx/gdicmn.h"
17 #warning "Move these to wx/region.h when common code is moved there"
18 class WXDLLIMPEXP_CORE wxBitmap
;
19 class WXDLLIMPEXP_CORE wxColour
;
21 class WXDLLIMPEXP_CORE wxRegion
: public wxGDIObject
25 wxRegion(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
);
26 wxRegion(const wxPoint
& topLeft
, const wxPoint
& bottomRight
);
27 wxRegion(const wxRect
& rect
);
28 wxRegion(const wxBitmap
& bmp
)
32 wxRegion(const wxBitmap
& bmp
,
33 const wxColour
& transColour
, int tolerance
= 0)
35 Union(bmp
, transColour
, tolerance
);
41 #warning "FIXME: move this to common code? at least Ok()"
42 bool Ok() const { return m_refData
!= NULL
; }
44 bool operator==(const wxRegion
& region
) const;
45 bool operator!=(const wxRegion
& region
) const { return !(*this == region
); }
47 // Clear current region
50 bool Offset(wxCoord x
, wxCoord y
);
52 // Union rectangle or region with this.
53 bool Union(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
54 { return Union(wxRect(x
, y
, width
, height
)); }
55 bool Union(const wxRect
& rect
);
56 bool Union(const wxRegion
& region
);
58 // Intersect rectangle or region with this.
59 bool Intersect(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
60 { return Intersect(wxRect(x
, y
, width
, height
)); }
61 bool Intersect(const wxRect
& rect
);
62 bool Intersect(const wxRegion
& region
);
64 // Subtract rectangle or region from this:
65 // Combines the parts of 'this' that are not part of the second region.
66 bool Subtract(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
67 { return Subtract(wxRect(x
, y
, width
, height
)); }
68 bool Subtract(const wxRect
& rect
);
69 bool Subtract(const wxRegion
& region
);
71 // XOR: the union of two combined regions except for any overlapping areas.
72 bool Xor(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
73 { return Xor(wxRect(x
, y
, width
, height
)); }
74 bool Xor(const wxRect
& rect
);
75 bool Xor(const wxRegion
& region
);
77 // Outer bounds of region
78 void GetBox(wxCoord
& x
, wxCoord
& y
, wxCoord
&w
, wxCoord
&h
) const;
79 wxRect
GetBox(void) const;
82 bool Empty(void) const;
83 inline bool IsEmpty(void) const { return Empty(); }
85 // Does the region contain the point (x,y)?
86 wxRegionContain
Contains(wxCoord x
, wxCoord y
) const;
87 // Does the region contain the point pt?
88 wxRegionContain
Contains(const wxPoint
& pt
) const
89 { return Contains(pt
.x
, pt
.y
); }
90 // Does the region contain the rectangle rect?
91 wxRegionContain
Contains(const wxRect
& rect
) const;
92 // Does the region contain the rectangle (x, y, w, h)?
93 wxRegionContain
Contains(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
) const
94 { return Contains(wxRect(x
, y
, w
, h
)); }
97 #warning "Move these union versions + ConvertToBitmap to wxRegionBase"
98 // Convert the region to a B&W bitmap with the white pixels being inside
100 wxBitmap
ConvertToBitmap() const;
102 // Use the non-transparent pixels of a wxBitmap for the region to combine
103 // with this region. First version takes transparency from bitmap's mask,
104 // second lets the user specify the colour to be treated as transparent
105 // along with an optional tolerance value.
106 // NOTE: implemented in common/rgncmn.cpp
107 bool Union(const wxBitmap
& bmp
);
108 bool Union(const wxBitmap
& bmp
,
109 const wxColour
& transColour
, int tolerance
= 0);
111 // NB: implementation detail of DirectFB, should be removed if full
112 // (i.e. not rect-only version is implemented) so that all code that
113 // assumes region==rect breaks
114 wxRect
AsRect() const { return GetBox(); }
118 virtual wxObjectRefData
*CreateRefData() const;
119 virtual wxObjectRefData
*CloneRefData(const wxObjectRefData
*data
) const;
121 friend class WXDLLIMPEXP_CORE wxRegionIterator
;
123 DECLARE_DYNAMIC_CLASS(wxRegion
);
127 class WXDLLIMPEXP_CORE wxRegionIterator
: public wxObject
130 wxRegionIterator() {}
131 wxRegionIterator(const wxRegion
& region
) { Reset(region
); }
133 void Reset() { m_rect
= wxRect(); }
134 void Reset(const wxRegion
& region
);
136 bool HaveRects() const { return !m_rect
.IsEmpty(); }
137 operator bool() const { return HaveRects(); }
139 wxRegionIterator
& operator++();
140 wxRegionIterator
operator++(int);
142 wxCoord
GetX() const { return m_rect
.GetX(); }
143 wxCoord
GetY() const { return m_rect
.GetY(); }
144 wxCoord
GetW() const { return m_rect
.GetWidth(); }
145 wxCoord
GetWidth() const { return GetW(); }
146 wxCoord
GetH() const { return m_rect
.GetHeight(); }
147 wxCoord
GetHeight() const { return GetH(); }
148 wxRect
GetRect() const { return m_rect
; }
153 DECLARE_DYNAMIC_CLASS(wxRegionIterator
);
156 #endif // _WX_DFB_REGION_H_