Quantcast
Viewing latest article 43
Browse Latest Browse All 66

#11097: wxGraphicsContext::DrawBitmap: x and y coords should not be affected by stretch factor

void wxCairoContext::DrawGraphicsBitmapInternal(const wxGraphicsBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ):

In the code below cairo_scale() affects also to x and y parameters. That's why the stretched bitmap is displayed with wrong (scaled!) x and y coords.

Solution: swap the following lines:

    cairo_scale(m_context, scaleX, scaleY);
    cairo_translate(m_context, x, y);

Code:

   PushState();
    // In case we're scaling the image by using a width and height different
    // than the bitmap's size create a pattern transformation on the surface and
    // draw the transformed pattern.
    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_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());
    // fill the rectangle using the pattern
    cairo_fill(m_context);
    // clean up
    PopState();

Viewing latest article 43
Browse Latest Browse All 66

Trending Articles