Fix applying affine transformation matrix in wxGCDC

In wxGCDCImpl::ComputeScaleAndOrigin() current affine transformation matrix (applied with SetTransformMatrix, ResetTransformMatrix) has to be concatenated with current basic transformations (applied with SetDeviceOrigin, SetLogicalScale, etc.).

Closes #17674.
This commit is contained in:
Artur Wieczorek 2016-09-20 21:20:45 +02:00
parent 27627db87d
commit 41a2b3e371
3 changed files with 22 additions and 20 deletions

View File

@ -219,6 +219,9 @@ protected:
bool m_logicalFunctionSupported;
wxGraphicsMatrix m_matrixOriginal;
wxGraphicsMatrix m_matrixCurrent;
#if wxUSE_DC_TRANSFORM_MATRIX
wxAffineMatrix2D m_matrixExtTransform;
#endif // wxUSE_DC_TRANSFORM_MATRIX
double m_formerScaleX, m_formerScaleY;

View File

@ -164,13 +164,14 @@ struct wxFontMetrics
@section dc_transform_support Support for Transformation Matrix
On some platforms (currently under MSW, GTK+ 3) wxDC has support for applying
an arbitrary affine transformation matrix to its coordinate system. (Since
3.1.1 this feature is also supported by wxGCDC in all ports.)
On some platforms (currently under MSW, GTK+ 3, OS X) wxDC has support for
applying an arbitrary affine transformation matrix to its coordinate system
(since 3.1.1 this feature is also supported by wxGCDC in all ports).
Call CanUseTransformMatrix() to check if this support is available and then
call SetTransformMatrix() if it is. If the transformation matrix is not
supported, SetTransformMatrix() always simply returns false and doesn't do
anything.
supported, SetTransformMatrix() always simply returns @c false and doesn't
do anything.
This feature is only available when @c wxUSE_DC_TRANSFORM_MATRIX build
option is enabled.

View File

@ -471,6 +471,11 @@ void wxGCDCImpl::ComputeScaleAndOrigin()
m_matrixCurrent.Scale( m_scaleX * m_signX, m_scaleY * m_signY );
m_graphicContext->SetTransform( m_matrixOriginal );
#if wxUSE_DC_TRANSFORM_MATRIX
// Concatenate extended transform (affine) with basic transform of coordinate system.
wxGraphicsMatrix mtxExt = m_graphicContext->CreateMatrix(m_matrixExtTransform);
m_matrixCurrent.Concat(mtxExt);
#endif // wxUSE_DC_TRANSFORM_MATRIX
m_graphicContext->ConcatTransform( m_matrixCurrent );
m_isClipBoxValid = false;
}
@ -558,30 +563,23 @@ bool wxGCDCImpl::CanUseTransformMatrix() const
bool wxGCDCImpl::SetTransformMatrix(const wxAffineMatrix2D &matrix)
{
wxGraphicsMatrix matGr = m_graphicContext->CreateMatrix(matrix);
m_graphicContext->SetTransform(matGr);
m_isClipBoxValid = false;
// Passed affine transform will be concatenated
// with current basic transform of the coordinate system.
m_matrixExtTransform = matrix;
ComputeScaleAndOrigin();
return true;
}
wxAffineMatrix2D wxGCDCImpl::GetTransformMatrix() const
{
wxMatrix2D mat2D;
wxPoint2DDouble tr;
wxGraphicsMatrix matGr = m_graphicContext->GetTransform();
matGr.Get(&mat2D.m_11, &mat2D.m_12, &mat2D.m_21, &mat2D.m_22, &tr.m_x, &tr.m_y);
wxAffineMatrix2D matrix;
matrix.Set(mat2D, tr);
return matrix;
return m_matrixExtTransform;
}
void wxGCDCImpl::ResetTransformMatrix()
{
wxGraphicsMatrix matGr = m_graphicContext->CreateMatrix();
m_graphicContext->SetTransform(matGr);
m_isClipBoxValid = false;
// Reset affine transfrom matrix (extended) to identity matrix.
m_matrixExtTransform.Set(wxMatrix2D(), wxPoint2DDouble());
ComputeScaleAndOrigin();
}
#endif // wxUSE_DC_TRANSFORM_MATRIX