1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/region.h
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_GTK_REGION_H_
11 #define _WX_GTK_REGION_H_
14 #include "wx/gdiobj.h"
15 #include "wx/gdicmn.h"
17 //-----------------------------------------------------------------------------
19 //-----------------------------------------------------------------------------
21 class WXDLLIMPEXP_CORE wxRegion
;
23 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
27 // So far, for internal use only
30 wxRGN_AND
, // Creates the intersection of the two combined regions.
31 wxRGN_COPY
, // Creates a copy of the region identified by hrgnSrc1.
32 wxRGN_DIFF
, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
33 wxRGN_OR
, // Creates the union of two combined regions.
34 wxRGN_XOR
// Creates the union of two combined regions except for any overlapping areas.
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 class WXDLLIMPEXP_CORE wxRegion
: public wxGDIObject
46 wxRegion( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
51 wxRegion( const wxPoint
& topLeft
, const wxPoint
& bottomRight
)
53 InitRect(topLeft
.x
, topLeft
.y
,
54 bottomRight
.x
- topLeft
.x
, bottomRight
.y
- topLeft
.y
);
57 wxRegion( const wxRect
& rect
)
59 InitRect(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
62 wxRegion( size_t n
, const wxPoint
*points
, int fillStyle
= wxODDEVEN_RULE
);
64 wxRegion( const wxBitmap
& bmp
)
68 wxRegion( const wxBitmap
& bmp
,
69 const wxColour
& transColour
, int tolerance
= 0)
71 Union(bmp
, transColour
, tolerance
);
76 bool Ok() const { return m_refData
!= NULL
; }
78 bool operator == ( const wxRegion
& region
) const;
79 bool operator != ( const wxRegion
& region
) const { return !(*this == region
); }
83 bool Offset( wxCoord x
, wxCoord y
);
85 bool Union( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
86 bool Union( const wxRect
& rect
);
87 bool Union( const wxRegion
& region
);
89 bool Intersect( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
90 bool Intersect( const wxRect
& rect
);
91 bool Intersect( const wxRegion
& region
);
93 bool Subtract( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
94 bool Subtract( const wxRect
& rect
);
95 bool Subtract( const wxRegion
& region
);
97 bool Xor( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
98 bool Xor( const wxRect
& rect
);
99 bool Xor( const wxRegion
& region
);
101 void GetBox( wxCoord
& x
, wxCoord
& y
, wxCoord
&w
, wxCoord
&h
) const;
102 wxRect
GetBox() const ;
105 bool IsEmpty() const { return Empty(); }
107 wxRegionContain
Contains( wxCoord x
, wxCoord y
) const;
108 wxRegionContain
Contains( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
) const;
109 wxRegionContain
Contains(const wxPoint
& pt
) const;
110 wxRegionContain
Contains(const wxRect
& rect
) const;
112 // Convert the region to a B&W bitmap with the white pixels being inside
114 wxBitmap
ConvertToBitmap() const;
116 // Use the non-transparent pixels of a wxBitmap for the region to combine
117 // with this region. First version takes transparency from bitmap's mask,
118 // second lets the user specify the colour to be treated as transparent
119 // along with an optional tolerance value.
120 // NOTE: implemented in common/rgncmn.cpp
121 bool Union(const wxBitmap
& bmp
);
122 bool Union(const wxBitmap
& bmp
,
123 const wxColour
& transColour
, int tolerance
= 0);
127 // Init with GdkRegion, set ref count to 2 so that
128 // the C++ class will not destroy the region!
129 wxRegion( GdkRegion
*region
);
131 GdkRegion
*GetRegion() const;
135 virtual wxObjectRefData
*CreateRefData() const;
136 virtual wxObjectRefData
*CloneRefData(const wxObjectRefData
*data
) const;
138 // common part of ctors for a rectangle region
139 void InitRect(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
);
142 DECLARE_DYNAMIC_CLASS(wxRegion
)
145 // ----------------------------------------------------------------------------
146 // wxRegionIterator: decomposes a region into rectangles
147 // ----------------------------------------------------------------------------
149 class WXDLLIMPEXP_CORE wxRegionIterator
: public wxObject
153 wxRegionIterator(const wxRegion
& region
);
155 void Reset() { m_current
= 0u; }
156 void Reset(const wxRegion
& region
);
158 bool HaveRects() const;
159 operator bool () const { return HaveRects(); }
161 wxRegionIterator
& operator ++ ();
162 wxRegionIterator
operator ++ (int);
164 wxCoord
GetX() const;
165 wxCoord
GetY() const;
166 wxCoord
GetW() const;
167 wxCoord
GetWidth() const { return GetW(); }
168 wxCoord
GetH() const;
169 wxCoord
GetHeight() const { return GetH(); }
170 wxRect
GetRect() const;
177 DECLARE_DYNAMIC_CLASS(wxRegionIterator
)