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