Modified drawing sample to use wxGraphicsContext::GetTextExtent function.

Use GetTextExtent function to centrally align a bitmap to the text label (on Graphics screen).
This commit is contained in:
Artur Wieczorek 2016-03-25 23:14:17 +01:00
parent f38485afa5
commit 16f111d007

View File

@ -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