From da66e81fb96239de63c54f4ebd8eb848b96b41f5 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Mon, 6 Mar 2017 18:48:49 +0100 Subject: [PATCH] Update bounding box when drawing gradients in drawing sample Advanced gradients are drawn using wxGraphicsContext and hence bounding box for underlying wxDC is not updated automatically. We need to update bounding box with extents of all used graphics paths. --- samples/drawing/drawing.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp index ba6070de97..71a901a1e3 100644 --- a/samples/drawing/drawing.cpp +++ b/samples/drawing/drawing.cpp @@ -1452,6 +1452,7 @@ void MyCanvas::DrawGradients(wxDC& dc) wxGraphicsContext *gc = gdc.GetGraphicsContext(); wxGraphicsPath pth; wxGraphicsGradientStops stops; + double boxX, boxY, boxWidth, boxHeight; gfr.Offset(0, gfr.height + 10); dc.DrawText(wxT("Linear Gradient with Stops"), gfr.x, gfr.y); @@ -1471,6 +1472,9 @@ void MyCanvas::DrawGradients(wxDC& dc) pth.AddLineToPoint(gfr.x,gfr.y+gfr.height); pth.CloseSubpath(); gc->FillPath(pth); + pth.GetBox(&boxX, &boxY, &boxWidth, &boxHeight); + dc.CalcBoundingBox(wxRound(boxX), wxRound(boxY)); + dc.CalcBoundingBox(wxRound(boxX+boxWidth), wxRound(boxY+boxHeight)); wxGraphicsGradientStops simpleStops(*wxRED, *wxBLUE); @@ -1493,6 +1497,9 @@ void MyCanvas::DrawGradients(wxDC& dc) pth.AddLineToPoint(gfr.x,gfr.y+gfr.height); pth.CloseSubpath(); gc->FillPath(pth); + pth.GetBox(&boxX, &boxY, &boxWidth, &boxHeight); + dc.CalcBoundingBox(wxRound(boxX), wxRound(boxY)); + dc.CalcBoundingBox(wxRound(boxX+boxWidth), wxRound(boxY+boxHeight)); gfr.Offset(0, gfr.height + 10); dc.DrawText(wxT("Radial Gradient from Red to Blue with Yellow and Green Stops"), @@ -1512,6 +1519,9 @@ void MyCanvas::DrawGradients(wxDC& dc) pth.AddLineToPoint(gfr.x,gfr.y+gfr.height); pth.CloseSubpath(); gc->FillPath(pth); + pth.GetBox(&boxX, &boxY, &boxWidth, &boxHeight); + dc.CalcBoundingBox(wxRound(boxX), wxRound(boxY)); + dc.CalcBoundingBox(wxRound(boxX+boxWidth), wxRound(boxY+boxHeight)); gfr.Offset(0, gfr.height + 10); dc.DrawText(wxT("Linear Gradient with Stops and Gaps"), gfr.x, gfr.y); @@ -1533,6 +1543,9 @@ void MyCanvas::DrawGradients(wxDC& dc) pth.AddLineToPoint(gfr.x,gfr.y+gfr.height); pth.CloseSubpath(); gc->FillPath(pth); + pth.GetBox(&boxX, &boxY, &boxWidth, &boxHeight); + dc.CalcBoundingBox(wxRound(boxX), wxRound(boxY)); + dc.CalcBoundingBox(wxRound(boxX+boxWidth), wxRound(boxY+boxHeight)); gfr.Offset(0, gfr.height + 10); dc.DrawText(wxT("Radial Gradient with Stops and Gaps"), gfr.x, gfr.y); @@ -1551,6 +1564,9 @@ void MyCanvas::DrawGradients(wxDC& dc) pth.AddLineToPoint(gfr.x,gfr.y+gfr.height); pth.CloseSubpath(); gc->FillPath(pth); + pth.GetBox(&boxX, &boxY, &boxWidth, &boxHeight); + dc.CalcBoundingBox(wxRound(boxX), wxRound(boxY)); + dc.CalcBoundingBox(wxRound(boxX+boxWidth), wxRound(boxY+boxHeight)); gfr.Offset(0, gfr.height + 10); dc.DrawText(wxT("Gradients with Stops and Transparency"), gfr.x, gfr.y); @@ -1586,6 +1602,9 @@ void MyCanvas::DrawGradients(wxDC& dc) gfr.x + gfr.width, gfr.y, stops)); gc->FillPath(pth); + pth.GetBox(&boxX, &boxY, &boxWidth, &boxHeight); + dc.CalcBoundingBox(wxRound(boxX), wxRound(boxY)); + dc.CalcBoundingBox(wxRound(boxX+boxWidth), wxRound(boxY+boxHeight)); } #endif // wxUSE_GRAPHICS_CONTEXT }