From 41a2b3e37121ef84956941762b3a3b6ce4c52f19 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Tue, 20 Sep 2016 21:20:45 +0200 Subject: [PATCH] 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. --- include/wx/dcgraph.h | 3 +++ interface/wx/dc.h | 11 ++++++----- src/common/dcgraph.cpp | 28 +++++++++++++--------------- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/include/wx/dcgraph.h b/include/wx/dcgraph.h index ad3f78634c..0cca24e22f 100644 --- a/include/wx/dcgraph.h +++ b/include/wx/dcgraph.h @@ -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; diff --git a/interface/wx/dc.h b/interface/wx/dc.h index e0e0597823..dd45441a39 100644 --- a/interface/wx/dc.h +++ b/interface/wx/dc.h @@ -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. diff --git a/src/common/dcgraph.cpp b/src/common/dcgraph.cpp index ad6d0b89da..308c9765cf 100644 --- a/src/common/dcgraph.cpp +++ b/src/common/dcgraph.cpp @@ -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