1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "region.h"
16 #include "wx/region.h"
18 //-----------------------------------------------------------------------------
20 //-----------------------------------------------------------------------------
22 class wxRegionRefData
: public wxObjectRefData
26 wxRegionRefData(void);
27 ~wxRegionRefData(void);
34 wxRegionRefData::wxRegionRefData(void)
39 wxRegionRefData::~wxRegionRefData(void)
41 if (m_region
) gdk_region_destroy( m_region
);
44 //-----------------------------------------------------------------------------
46 #define M_REGIONDATA ((wxRegionRefData *)m_refData)
48 IMPLEMENT_DYNAMIC_CLASS(wxRegion
,wxGDIObject
);
50 wxRegion::wxRegion( long x
, long y
, long w
, long h
)
52 m_refData
= new wxRegionRefData();
53 GdkRegion
*reg
= gdk_region_new();
59 M_REGIONDATA
->m_region
= gdk_region_union_with_rect( reg
, &rect
);
60 gdk_region_destroy( reg
);
63 wxRegion::wxRegion( const wxPoint
& topLeft
, const wxPoint
& bottomRight
)
65 m_refData
= new wxRegionRefData();
66 GdkRegion
*reg
= gdk_region_new();
70 rect
.width
= bottomRight
.x
- rect
.x
;
71 rect
.height
= bottomRight
.y
- rect
.y
;
72 M_REGIONDATA
->m_region
= gdk_region_union_with_rect( reg
, &rect
);
73 gdk_region_destroy( reg
);
76 wxRegion::wxRegion( const wxRect
& rect
)
78 m_refData
= new wxRegionRefData();
79 GdkRegion
*reg
= gdk_region_new();
83 g_rect
.width
= rect
.width
;
84 g_rect
.height
= rect
.height
;
85 M_REGIONDATA
->m_region
= gdk_region_union_with_rect( reg
, &g_rect
);
86 gdk_region_destroy( reg
);
89 wxRegion::wxRegion(void)
91 m_refData
= new wxRegionRefData();
92 M_REGIONDATA
->m_region
= gdk_region_new();
95 wxRegion::~wxRegion(void)
99 void wxRegion::Clear(void)
102 m_refData
= new wxRegionRefData();
103 M_REGIONDATA
->m_region
= gdk_region_new();
106 bool wxRegion::Union( long x
, long y
, long width
, long height
)
112 rect
.height
= height
;
113 GdkRegion
*reg
= gdk_region_union_with_rect( M_REGIONDATA
->m_region
, &rect
);
114 gdk_region_destroy( M_REGIONDATA
->m_region
);
115 M_REGIONDATA
->m_region
= reg
;
119 bool wxRegion::Union( const wxRect
& rect
)
124 g_rect
.width
= rect
.width
;
125 g_rect
.height
= rect
.height
;
126 GdkRegion
*reg
= gdk_region_union_with_rect( M_REGIONDATA
->m_region
, &g_rect
);
127 gdk_region_destroy( M_REGIONDATA
->m_region
);
128 M_REGIONDATA
->m_region
= reg
;
132 bool wxRegion::Union( const wxRegion
& region
)
134 GdkRegion
*reg
= gdk_regions_union( M_REGIONDATA
->m_region
, region
.GetRegion() );
135 gdk_region_destroy( M_REGIONDATA
->m_region
);
136 M_REGIONDATA
->m_region
= reg
;
140 bool wxRegion::Intersect( long x
, long y
, long width
, long height
)
142 wxRegion
reg( x
, y
, width
, height
);
147 bool wxRegion::Intersect( const wxRect
& rect
)
149 wxRegion
reg( rect
);
154 bool wxRegion::Intersect( const wxRegion
& region
)
156 GdkRegion
*reg
= gdk_regions_intersect( M_REGIONDATA
->m_region
, region
.GetRegion() );
157 gdk_region_destroy( M_REGIONDATA
->m_region
);
158 M_REGIONDATA
->m_region
= reg
;
162 bool wxRegion::Subtract( long x
, long y
, long width
, long height
)
164 wxRegion
reg( x
, y
, width
, height
);
169 bool wxRegion::Subtract( const wxRect
& rect
)
171 wxRegion
reg( rect
);
176 bool wxRegion::Subtract( const wxRegion
& region
)
178 GdkRegion
*reg
= gdk_regions_subtract( M_REGIONDATA
->m_region
, region
.GetRegion() );
179 gdk_region_destroy( M_REGIONDATA
->m_region
);
180 M_REGIONDATA
->m_region
= reg
;
184 bool wxRegion::Xor( long x
, long y
, long width
, long height
)
186 wxRegion
reg( x
, y
, width
, height
);
191 bool wxRegion::Xor( const wxRect
& rect
)
193 wxRegion
reg( rect
);
198 bool wxRegion::Xor( const wxRegion
& region
)
200 GdkRegion
*reg
= gdk_regions_xor( M_REGIONDATA
->m_region
, region
.GetRegion() );
201 gdk_region_destroy( M_REGIONDATA
->m_region
);
202 M_REGIONDATA
->m_region
= reg
;
206 void wxRegion::GetBox( long& x
, long& y
, long&w
, long &h
) const
214 wxRect
wxRegion::GetBox(void) const
216 return wxRect( 0, 0, -1, -1 );
219 bool wxRegion::Empty(void) const
221 return gdk_region_empty( M_REGIONDATA
->m_region
);
224 wxRegionContain
wxRegion::Contains( long x
, long y
) const
226 if (gdk_region_point_in( M_REGIONDATA
->m_region
, x
, y
))
232 wxRegionContain
wxRegion::Contains( long x
, long y
, long w
, long h
) const
239 GdkOverlapType res
= gdk_region_rect_in( M_REGIONDATA
->m_region
, &rect
);
242 case GDK_OVERLAP_RECTANGLE_IN
: return wxInRegion
;
243 case GDK_OVERLAP_RECTANGLE_OUT
: return wxOutRegion
;
244 case GDK_OVERLAP_RECTANGLE_PART
: return wxPartRegion
;
249 GdkRegion
*wxRegion::GetRegion(void) const
251 return M_REGIONDATA
->m_region
;