From: Vadim Zeitlin Date: Wed, 2 Jun 2010 11:58:25 +0000 (+0000) Subject: Fix drawing of scaled bitmaps in wxCairoContext. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/ce6b1014bfc5a1451149fa19a95772be3b57236a?ds=sidebyside Fix drawing of scaled bitmaps in wxCairoContext. We must offset the coordinate system before scaling it, otherwise incorrect offset is used. Add a test for drawing translated/scaled bitmaps to the drawing sample. See #11097. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64463 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp index 36ecfb4489..afebb30869 100644 --- a/samples/drawing/drawing.cpp +++ b/samples/drawing/drawing.cpp @@ -1052,8 +1052,15 @@ void MyCanvas::DrawGraphics(wxGraphicsContext* gc) gc->PopState(); } gc->PopState(); + + 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); + gc->PopState(); } -#endif +#endif // wxUSE_GRAPHICS_CONTEXT void MyCanvas::DrawCircles(wxDC& dc) { diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index b21d03e9d7..9b9e88b22f 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -1471,10 +1471,10 @@ void wxCairoContext::DrawBitmap(const wxGraphicsBitmap &bmp, wxDouble x, wxDoubl wxDouble scaleX = w / size.GetWidth(); wxDouble scaleY = h / size.GetHeight(); - cairo_scale(m_context, scaleX, scaleY); // prepare to draw the image cairo_translate(m_context, x, y); + cairo_scale(m_context, scaleX, scaleY); cairo_set_source(m_context, pattern); // use the original size here since the context is scaled already... cairo_rectangle(m_context, 0, 0, size.GetWidth(), size.GetHeight());