From 16f111d00702f71f24193ea927e83b2840b898f3 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Fri, 25 Mar 2016 23:14:17 +0100 Subject: [PATCH] Modified drawing sample to use wxGraphicsContext::GetTextExtent function. Use GetTextExtent function to centrally align a bitmap to the text label (on Graphics screen). --- samples/drawing/drawing.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp index 84a8d5a5de..4437dab087 100644 --- a/samples/drawing/drawing.cpp +++ b/samples/drawing/drawing.cpp @@ -1168,9 +1168,15 @@ void MyCanvas::DrawGraphics(wxGraphicsContext* gc) gc->PushState(); gc->Translate(60, 400); - gc->DrawText("Scaled smiley inside a square", 0, 0); - gc->DrawRectangle(BASE2, BASE2, 100, 100); - gc->DrawBitmap(m_smile_bmp, BASE2, BASE2, 100, 100); + const wxString labelText(wxS("Scaled smiley inside a square")); + gc->DrawText(labelText, 0, 0); + // Center a bitmap horizontally + wxDouble textWidth; + gc->GetTextExtent(labelText, &textWidth, NULL); + const wxDouble rectWidth = 100; + wxDouble x0 = (textWidth - rectWidth) / 2; + gc->DrawRectangle(x0, BASE2, rectWidth, 100); + gc->DrawBitmap(m_smile_bmp, x0, BASE2, rectWidth, 100); gc->PopState(); // Draw graphics bitmap and its subbitmap