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_
13 #include "wx/gdiobj.h"
14 #include "wx/gdicmn.h"
16 //-----------------------------------------------------------------------------
18 //-----------------------------------------------------------------------------
20 // So far, for internal use only
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.
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
34 class WXDLLIMPEXP_CORE wxRegion
: public wxGDIObject
39 wxRegion( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
44 wxRegion( const wxPoint
& topLeft
, const wxPoint
& bottomRight
)
46 InitRect(topLeft
.x
, topLeft
.y
,
47 bottomRight
.x
- topLeft
.x
, bottomRight
.y
- topLeft
.y
);
50 wxRegion( const wxRect
& rect
)
52 InitRect(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
55 wxRegion( size_t n
, const wxPoint
*points
, int fillStyle
= wxODDEVEN_RULE
);
57 wxRegion( const wxBitmap
& bmp
)
61 wxRegion( const wxBitmap
& bmp
,
62 const wxColour
& transColour
, int tolerance
= 0)
64 Union(bmp
, transColour
, tolerance
);
69 bool Ok() const { return m_refData
!= NULL
; }
71 bool operator == ( const wxRegion
& region
) const;
72 bool operator != ( const wxRegion
& region
) const { return !(*this == region
); }
76 bool Offset( wxCoord x
, wxCoord y
);
78 bool Union( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
79 bool Union( const wxRect
& rect
);
80 bool Union( const wxRegion
& region
);
82 bool Intersect( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
83 bool Intersect( const wxRect
& rect
);
84 bool Intersect( const wxRegion
& region
);
86 bool Subtract( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
87 bool Subtract( const wxRect
& rect
);
88 bool Subtract( const wxRegion
& region
);
90 bool Xor( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
91 bool Xor( const wxRect
& rect
);
92 bool Xor( const wxRegion
& region
);
94 void GetBox( wxCoord
& x
, wxCoord
& y
, wxCoord
&w
, wxCoord
&h
) const;
95 wxRect
GetBox() const ;
98 bool IsEmpty() const { return Empty(); }
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;
105 // Convert the region to a B&W bitmap with the white pixels being inside
107 wxBitmap
ConvertToBitmap() const;
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);
120 // Init with GdkRegion, set ref count to 2 so that
121 // the C++ class will not destroy the region!
122 wxRegion( GdkRegion
*region
);
124 GdkRegion
*GetRegion() const;
128 virtual wxObjectRefData
*CreateRefData() const;
129 virtual wxObjectRefData
*CloneRefData(const wxObjectRefData
*data
) const;
131 // common part of ctors for a rectangle region
132 void InitRect(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
);
135 DECLARE_DYNAMIC_CLASS(wxRegion
)
138 // ----------------------------------------------------------------------------
139 // wxRegionIterator: decomposes a region into rectangles
140 // ----------------------------------------------------------------------------
142 class WXDLLIMPEXP_CORE wxRegionIterator
: public wxObject
146 wxRegionIterator(const wxRegion
& region
);
148 void Reset() { m_current
= 0u; }
149 void Reset(const wxRegion
& region
);
151 bool HaveRects() const;
152 operator bool () const { return HaveRects(); }
154 wxRegionIterator
& operator ++ ();
155 wxRegionIterator
operator ++ (int);
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;
170 DECLARE_DYNAMIC_CLASS(wxRegionIterator
)