header includes cleanup
[wxWidgets.git] / include / wx / gtk / region.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/region.h
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifndef _WX_GTK_REGION_H_
11 #define _WX_GTK_REGION_H_
12
13 #include "wx/gdiobj.h"
14 #include "wx/gdicmn.h"
15
16 //-----------------------------------------------------------------------------
17 // constants
18 //-----------------------------------------------------------------------------
19
20 // So far, for internal use only
21 enum wxRegionOp
22 {
23 wxRGN_AND, // Creates the intersection of the two combined regions.
24 wxRGN_COPY, // Creates a copy of the region identified by hrgnSrc1.
25 wxRGN_DIFF, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
26 wxRGN_OR, // Creates the union of two combined regions.
27 wxRGN_XOR // Creates the union of two combined regions except for any overlapping areas.
28 };
29
30 // ----------------------------------------------------------------------------
31 // wxRegion
32 // ----------------------------------------------------------------------------
33
34 class WXDLLIMPEXP_CORE wxRegion : public wxGDIObject
35 {
36 public:
37 wxRegion() { }
38
39 wxRegion( wxCoord x, wxCoord y, wxCoord w, wxCoord h )
40 {
41 InitRect(x, y, w, h);
42 }
43
44 wxRegion( const wxPoint& topLeft, const wxPoint& bottomRight )
45 {
46 InitRect(topLeft.x, topLeft.y,
47 bottomRight.x - topLeft.x, bottomRight.y - topLeft.y);
48 }
49
50 wxRegion( const wxRect& rect )
51 {
52 InitRect(rect.x, rect.y, rect.width, rect.height);
53 }
54
55 wxRegion( size_t n, const wxPoint *points, int fillStyle = wxODDEVEN_RULE );
56
57 wxRegion( const wxBitmap& bmp)
58 {
59 Union(bmp);
60 }
61 wxRegion( const wxBitmap& bmp,
62 const wxColour& transColour, int tolerance = 0)
63 {
64 Union(bmp, transColour, tolerance);
65 }
66
67 ~wxRegion();
68
69 bool Ok() const { return m_refData != NULL; }
70
71 bool operator == ( const wxRegion& region ) const;
72 bool operator != ( const wxRegion& region ) const { return !(*this == region); }
73
74 void Clear();
75
76 bool Offset( wxCoord x, wxCoord y );
77
78 bool Union( wxCoord x, wxCoord y, wxCoord width, wxCoord height );
79 bool Union( const wxRect& rect );
80 bool Union( const wxRegion& region );
81
82 bool Intersect( wxCoord x, wxCoord y, wxCoord width, wxCoord height );
83 bool Intersect( const wxRect& rect );
84 bool Intersect( const wxRegion& region );
85
86 bool Subtract( wxCoord x, wxCoord y, wxCoord width, wxCoord height );
87 bool Subtract( const wxRect& rect );
88 bool Subtract( const wxRegion& region );
89
90 bool Xor( wxCoord x, wxCoord y, wxCoord width, wxCoord height );
91 bool Xor( const wxRect& rect );
92 bool Xor( const wxRegion& region );
93
94 void GetBox( wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h ) const;
95 wxRect GetBox() const ;
96
97 bool Empty() const;
98 bool IsEmpty() const { return Empty(); }
99
100 wxRegionContain Contains( wxCoord x, wxCoord y ) const;
101 wxRegionContain Contains( wxCoord x, wxCoord y, wxCoord w, wxCoord h ) const;
102 wxRegionContain Contains(const wxPoint& pt) const;
103 wxRegionContain Contains(const wxRect& rect) const;
104
105 // Convert the region to a B&W bitmap with the white pixels being inside
106 // the region.
107 wxBitmap ConvertToBitmap() const;
108
109 // Use the non-transparent pixels of a wxBitmap for the region to combine
110 // with this region. First version takes transparency from bitmap's mask,
111 // second lets the user specify the colour to be treated as transparent
112 // along with an optional tolerance value.
113 // NOTE: implemented in common/rgncmn.cpp
114 bool Union(const wxBitmap& bmp);
115 bool Union(const wxBitmap& bmp,
116 const wxColour& transColour, int tolerance = 0);
117
118
119 public:
120 // Init with GdkRegion, set ref count to 2 so that
121 // the C++ class will not destroy the region!
122 wxRegion( GdkRegion *region );
123
124 GdkRegion *GetRegion() const;
125
126 protected:
127 // ref counting code
128 virtual wxObjectRefData *CreateRefData() const;
129 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
130
131 // common part of ctors for a rectangle region
132 void InitRect(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
133
134 private:
135 DECLARE_DYNAMIC_CLASS(wxRegion)
136 };
137
138 // ----------------------------------------------------------------------------
139 // wxRegionIterator: decomposes a region into rectangles
140 // ----------------------------------------------------------------------------
141
142 class WXDLLIMPEXP_CORE wxRegionIterator: public wxObject
143 {
144 public:
145 wxRegionIterator();
146 wxRegionIterator(const wxRegion& region);
147
148 void Reset() { m_current = 0u; }
149 void Reset(const wxRegion& region);
150
151 bool HaveRects() const;
152 operator bool () const { return HaveRects(); }
153
154 wxRegionIterator& operator ++ ();
155 wxRegionIterator operator ++ (int);
156
157 wxCoord GetX() const;
158 wxCoord GetY() const;
159 wxCoord GetW() const;
160 wxCoord GetWidth() const { return GetW(); }
161 wxCoord GetH() const;
162 wxCoord GetHeight() const { return GetH(); }
163 wxRect GetRect() const;
164
165 private:
166 size_t m_current;
167 wxRegion m_region;
168
169 private:
170 DECLARE_DYNAMIC_CLASS(wxRegionIterator)
171 };
172
173
174 #endif
175 // _WX_GTK_REGION_H_