wxWidgets 2.9 handled it nicely and this issue came in wxWidgets 3.x.x
When I checked the changes, I found the difference in
wxGCDCImpl::DoStretchBlit implementation in 2.9 and 3.0
wxWidgets 2.9
Code: Select all
bool wxGCDCImpl::DoStretchBlit(
wxCoord xdest, wxCoord ydest, wxCoord dstWidth, wxCoord dstHeight,
wxDC *source, wxCoord xsrc, wxCoord ysrc, wxCoord srcWidth, wxCoord srcHeight,
wxRasterOperationMode logical_func , bool useMask,
wxCoord xsrcMask, wxCoord ysrcMask )
{
wxCHECK_MSG( IsOk(), false, wxT("wxGCDC(cg)::DoStretchBlit - invalid DC") );
wxCHECK_MSG( source->IsOk(), false, wxT("wxGCDC(cg)::DoStretchBlit - invalid source DC") );
if ( logical_func == wxNO_OP )
return true;
wxCompositionMode mode = TranslateRasterOp(logical_func);
if ( mode == wxCOMPOSITION_INVALID )
{
wxFAIL_MSG( wxT("Blitting is not supported with this logical operation.") );
return false;
}
bool retval = true;
wxCompositionMode formerMode = m_graphicContext->GetCompositionMode();
if (m_graphicContext->SetCompositionMode(mode))
{
wxAntialiasMode formerAa = m_graphicContext->GetAntialiasMode();
if (mode == wxCOMPOSITION_XOR)
{
m_graphicContext->SetAntialiasMode(wxANTIALIAS_NONE);
}
if (xsrcMask == -1 && ysrcMask == -1)
{
xsrcMask = xsrc;
ysrcMask = ysrc;
}
wxRect subrect(source->LogicalToDeviceX(xsrc),
source->LogicalToDeviceY(ysrc),
source->LogicalToDeviceXRel(srcWidth),
source->LogicalToDeviceYRel(srcHeight));
// if needed clip the subrect down to the size of the source DC
wxCoord sw, sh;
source->GetSize(&sw, &sh);
sw = source->LogicalToDeviceXRel(sw);
sh = source->LogicalToDeviceYRel(sh);
if (subrect.x + subrect.width > sw)
subrect.width = sw - subrect.x;
if (subrect.y + subrect.height > sh)
subrect.height = sh - subrect.y;
wxBitmap blit = source->GetAsBitmap( &subrect );
if ( blit.IsOk() )
{
if ( !useMask && blit.GetMask() )
blit.SetMask(NULL);
m_graphicContext->DrawBitmap( blit, xdest, ydest,
dstWidth, dstHeight);
}
else
{
wxFAIL_MSG( wxT("Cannot Blit. Unable to get contents of DC as bitmap.") );
retval = false;
}
if (mode == wxCOMPOSITION_XOR)
{
m_graphicContext->SetAntialiasMode(formerAa);
}
}
// reset composition
m_graphicContext->SetCompositionMode(formerMode);
return retval;
}
wxWidgets 3.0
Code: Select all
bool wxGCDCImpl::DoStretchBlit(
wxCoord xdest, wxCoord ydest, wxCoord dstWidth, wxCoord dstHeight,
wxDC *source, wxCoord xsrc, wxCoord ysrc, wxCoord srcWidth, wxCoord srcHeight,
wxRasterOperationMode logical_func , bool useMask,
wxCoord xsrcMask, wxCoord ysrcMask )
{
wxCHECK_MSG( IsOk(), false, wxT("wxGCDC(cg)::DoStretchBlit - invalid DC") );
wxCHECK_MSG( source->IsOk(), false, wxT("wxGCDC(cg)::DoStretchBlit - invalid source DC") );
if ( logical_func == wxNO_OP )
return true;
wxCompositionMode mode = TranslateRasterOp(logical_func);
if ( mode == wxCOMPOSITION_INVALID )
{
wxFAIL_MSG( wxT("Blitting is not supported with this logical operation.") );
return false;
}
wxRect subrect(source->LogicalToDeviceX(xsrc),
source->LogicalToDeviceY(ysrc),
source->LogicalToDeviceXRel(srcWidth),
source->LogicalToDeviceYRel(srcHeight));
const wxRect subrectOrig = subrect;
// clip the subrect down to the size of the source DC
wxRect clip;
source->GetSize(&clip.width, &clip.height);
subrect.Intersect(clip);
if (subrect.width == 0)
return true;
bool retval = true;
wxCompositionMode formerMode = m_graphicContext->GetCompositionMode();
if (m_graphicContext->SetCompositionMode(mode))
{
wxAntialiasMode formerAa = m_graphicContext->GetAntialiasMode();
if (mode == wxCOMPOSITION_XOR)
{
m_graphicContext->SetAntialiasMode(wxANTIALIAS_NONE);
}
if (xsrcMask == -1 && ysrcMask == -1)
{
xsrcMask = xsrc;
ysrcMask = ysrc;
}
wxBitmap blit = source->GetAsBitmap( &subrect );
if ( blit.IsOk() )
{
if ( !useMask && blit.GetMask() )
blit.SetMask(NULL);
double x = xdest;
double y = ydest;
double w = dstWidth;
double h = dstHeight;
// adjust dest rect if source rect is clipped
if (subrect.width != subrectOrig.width || subrect.height != subrectOrig.height)
{
x += (subrect.x - subrectOrig.x) / double(subrectOrig.width) * dstWidth;
y += (subrect.y - subrectOrig.y) / double(subrectOrig.height) * dstHeight;
w *= double(subrect.width) / subrectOrig.width;
h *= double(subrect.height) / subrectOrig.height;
}
m_graphicContext->DrawBitmap(blit, x, y, w, h);
}
else
{
wxFAIL_MSG( wxT("Cannot Blit. Unable to get contents of DC as bitmap.") );
retval = false;
}
if (mode == wxCOMPOSITION_XOR)
{
m_graphicContext->SetAntialiasMode(formerAa);
}
}
// reset composition
m_graphicContext->SetCompositionMode(formerMode);
CalcBoundingBox(xdest, ydest);
CalcBoundingBox(xdest + dstWidth, ydest + dstHeight);
return retval;
}
I can see refactoring is done in wxWidgets 3.0 and can see the following line are missing from wxWindgets 3.0. When I placed back these two line issue is fixed.
Code: Select all
sw = source->LogicalToDeviceXRel(sw);
sh = source->LogicalToDeviceYRel(sh);
Could anyone please confirm the reason of removing these lines.