Following the theory that something lame is better than nothing at all, provide a very generic implementation of the ctor wxRegion::wxRegion(size_t n, const wxPoint *points, wxPolygonFillMode fillStyle) by drawing the polygon into a bitmap and using that to create the region.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70537 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2012-02-08 00:20:38 +00:00
parent eb74c22a0b
commit 4e17cf82ff

View File

@@ -91,63 +91,41 @@ wxRegion::wxRegion(const wxRect& rect)
m_refData = new wxRegionRefData(rect.x , rect.y , rect.width , rect.height); m_refData = new wxRegionRefData(rect.x , rect.y , rect.width , rect.height);
} }
wxRegion::wxRegion(size_t n, const wxPoint *points, wxPolygonFillMode WXUNUSED(fillStyle)) wxRegion::wxRegion(size_t n, const wxPoint *points, wxPolygonFillMode fillStyle)
{ {
wxUnusedVar(n); // Set the region to a polygon shape generically using a bitmap with the
wxUnusedVar(points); // polygon drawn on it.
#if 0 m_refData = new wxRegionRefData();
// no non-QD APIs available
// TODO : remove ? wxCoord mx = 0;
// OS X somehow does not collect the region invisibly as before, so sometimes things wxCoord my = 0;
// get drawn on screen instead of just being combined into a region, therefore we allocate a temp gworld now wxPoint p;
size_t idx;
GWorldPtr gWorld = NULL;
GWorldPtr oldWorld; // Find the max size needed to draw the polygon
GDHandle oldGDHandle; for (idx=0; idx<n; idx++)
OSStatus err; {
Rect destRect = { 0, 0, 1, 1 }; wxPoint pt = points[idx];
if (pt.x > mx)
::GetGWorld( &oldWorld, &oldGDHandle ); mx = pt.x;
err = ::NewGWorld( &gWorld, 32, &destRect, NULL, NULL, 0 ); if (pt.y > my)
if ( err == noErr ) my = pt.y;
{ }
::SetGWorld( gWorld, GetGDevice() );
// Make the bitmap
OpenRgn(); wxBitmap bmp(mx, my);
wxMemoryDC dc(bmp);
wxCoord x1, x2 , y1 , y2 ; dc.SetBackground(*wxBLACK_BRUSH);
x2 = x1 = points[0].x ; dc.Clear();
y2 = y1 = points[0].y ; dc.SetPen(*wxWHITE_PEN);
dc.SetBrush(*wxWHITE_BRUSH);
::MoveTo( x1, y1 ); dc.DrawPolygon(n, (wxPoint*)points, 0, 0, fillStyle);
for (size_t i = 1; i < n; i++) dc.SelectObject(wxNullBitmap);
{ bmp.SetMask(new wxMask(bmp, *wxBLACK));
x2 = points[i].x ;
y2 = points[i].y ; // Use it to set this region
::LineTo( x2, y2 ); Union(bmp);
}
// close the polyline if necessary
if ( x1 != x2 || y1 != y2 )
::LineTo( x1, y1 ) ;
RgnHandle tempRgn = NewRgn();
CloseRgn( tempRgn ) ;
::SetGWorld( oldWorld, oldGDHandle );
wxCFRef<HIShapeRef> tempShape( HIShapeCreateWithQDRgn(tempRgn ) );
m_refData = new wxRegionRefData(tempShape);
DisposeRgn( tempRgn );
}
else
{
m_refData = new wxRegionRefData;
}
#else
wxFAIL_MSG( "not implemented" );
m_refData = NULL;
#endif
} }
wxRegion::~wxRegion() wxRegion::~wxRegion()