]> git.saurik.com Git - wxWidgets.git/blob - include/wx/dfb/region.h
add more virtual border drawing functions used by frame decorations code
[wxWidgets.git] / include / wx / dfb / region.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/dfb/region.h
3 // Purpose: wxRegion class
4 // Author: Vaclav Slavik
5 // Created: 2006-08-08
6 // RCS-ID: $Id$
7 // Copyright: (c) 2006 REA Elektronik GmbH
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_DFB_REGION_H_
12 #define _WX_DFB_REGION_H_
13
14 #include "wx/gdiobj.h"
15 #include "wx/gdicmn.h"
16
17 #warning "Move these to wx/region.h when common code is moved there"
18 class WXDLLIMPEXP_CORE wxBitmap;
19 class WXDLLIMPEXP_CORE wxColour;
20
21 class WXDLLIMPEXP_CORE wxRegion : public wxGDIObject
22 {
23
24 public:
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)
29 {
30 Union(bmp);
31 }
32 wxRegion(const wxBitmap& bmp,
33 const wxColour& transColour, int tolerance = 0)
34 {
35 Union(bmp, transColour, tolerance);
36 }
37
38 wxRegion();
39 ~wxRegion();
40
41 #warning "FIXME: move this to common code? at least Ok()"
42 bool Ok() const { return m_refData != NULL; }
43
44 bool operator==(const wxRegion& region) const;
45 bool operator!=(const wxRegion& region) const { return !(*this == region); }
46
47 // Clear current region
48 void Clear();
49
50 bool Offset(wxCoord x, wxCoord y);
51
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);
57
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);
63
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);
70
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);
76
77 // Outer bounds of region
78 void GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const;
79 wxRect GetBox() const;
80
81 // Is region empty?
82 bool Empty() const;
83 bool IsEmpty() const { return Empty(); }
84
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)); }
95
96
97 #warning "Move these union versions + ConvertToBitmap to wxRegionBase"
98 // Convert the region to a B&W bitmap with the white pixels being inside
99 // the region.
100 wxBitmap ConvertToBitmap() const;
101
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);
110
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(); }
115
116 protected:
117 // ref counting code
118 virtual wxObjectRefData *CreateRefData() const;
119 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
120
121 friend class WXDLLIMPEXP_CORE wxRegionIterator;
122
123 DECLARE_DYNAMIC_CLASS(wxRegion);
124 };
125
126
127 class WXDLLIMPEXP_CORE wxRegionIterator : public wxObject
128 {
129 public:
130 wxRegionIterator() {}
131 wxRegionIterator(const wxRegion& region) { Reset(region); }
132
133 void Reset() { m_rect = wxRect(); }
134 void Reset(const wxRegion& region);
135
136 bool HaveRects() const { return !m_rect.IsEmpty(); }
137 operator bool() const { return HaveRects(); }
138
139 wxRegionIterator& operator++();
140 wxRegionIterator operator++(int);
141
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; }
149
150 private:
151 wxRect m_rect;
152
153 DECLARE_DYNAMIC_CLASS(wxRegionIterator);
154 };
155
156 #endif // _WX_DFB_REGION_H_