From 49000defcfb11b409d8935126981b14169ee62a3 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Wed, 7 Sep 2016 23:49:06 +0200 Subject: [PATCH] Add support for affine transformation matrix in wxGCDC Graphics renderers (exposed through wxGraphicsContext) support arbitrary affine transformations so it is possible to add support for affine transformations in wxGCDC by implementing all wxGCDC::*TransformMatrix() functions with calls to respective wxGraphicsContext functions. Additionally, this implementation adds support for affine transformations in wxDC under wxGTK3 because in this port wxDC is equivalent to wxGCDC. --- docs/changes.txt | 2 ++ include/wx/dcgraph.h | 7 +++++++ include/wx/msw/setup0.h | 6 +++--- interface/wx/dc.h | 16 ++++++++++------ src/common/dcgraph.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 63 insertions(+), 9 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index e2b4e581b3..49d00182b4 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -101,6 +101,7 @@ All (GUI): - Add wxGraphicsContext::GetClipBox(). - Fix wxGCDC::Clear() for rotated graphics context. - Fix wxGCDC::GetClippingBox() for transformed wxDC (MSW, GTK+). +- Add support for affine transformation matrix in wxGCDC. wxGTK: @@ -114,6 +115,7 @@ wxGTK: - Fix crashes in wxFileSystemWatcher implementation (David Hart). - Fix wxBitmap ctor from XBM for non-square bitmaps. - Fix wxDC::GetClippingBox() for transformed wxDC. +- Add support for affine transformation matrix in wxDC (GTK+ 3). wxMSW: diff --git a/include/wx/dcgraph.h b/include/wx/dcgraph.h index 171b69ffaa..ad3f78634c 100644 --- a/include/wx/dcgraph.h +++ b/include/wx/dcgraph.h @@ -107,6 +107,13 @@ public: virtual void* GetHandle() const wxOVERRIDE; +#if wxUSE_DC_TRANSFORM_MATRIX + virtual bool CanUseTransformMatrix() const wxOVERRIDE; + virtual bool SetTransformMatrix(const wxAffineMatrix2D& matrix) wxOVERRIDE; + virtual wxAffineMatrix2D GetTransformMatrix() const wxOVERRIDE; + virtual void ResetTransformMatrix() wxOVERRIDE; +#endif // wxUSE_DC_TRANSFORM_MATRIX + // the true implementations virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, wxFloodFillStyle style = wxFLOOD_SURFACE) wxOVERRIDE; diff --git a/include/wx/msw/setup0.h b/include/wx/msw/setup0.h index 2da023406c..ed3f9d89e0 100644 --- a/include/wx/msw/setup0.h +++ b/include/wx/msw/setup0.h @@ -1428,9 +1428,9 @@ // Should wxDC provide SetTransformMatrix() and related methods? // // Default is 1 but can be set to 0 if this functionality is not used. Notice -// that currently only wxMSW supports this so setting this to 0 doesn't change -// much for non-MSW platforms (although it will still save a few bytes -// probably). +// that currently wxMSW, wxGTK3 support this for wxDC and all platforms support +// this for wxGCDC so setting this to 0 doesn't change much if neither of these +// is used (although it will still save a few bytes probably). // // Recommended setting: 1. #define wxUSE_DC_TRANSFORM_MATRIX 1 diff --git a/interface/wx/dc.h b/interface/wx/dc.h index 44aed88a41..351cfef253 100644 --- a/interface/wx/dc.h +++ b/interface/wx/dc.h @@ -155,7 +155,7 @@ struct wxFontMetrics In general wxDC methods don't support alpha transparency and the alpha component of wxColour is simply ignored and you need to use wxGraphicsContext for full transparency support. There are, however, a few exceptions: first, - under OS X colours with alpha channel are supported in all the normal + under OS X and GTK+ 3 colours with alpha channel are supported in all the normal wxDC-derived classes as they use wxGraphicsContext internally. Second, under all platforms wxSVGFileDC also fully supports alpha channel. In both of these cases the instances of wxPen or wxBrush that are built from @@ -164,12 +164,15 @@ struct wxFontMetrics @section dc_transform_support Support for Transformation Matrix - On some platforms (currently only under MSW) wxDC has support for applying - an arbitrary affine transformation matrix to its coordinate system. Call - CanUseTransformMatrix() to check if this support is available and then call - SetTransformMatrix() if it is. If the transformation matrix is not + 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.) + 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. + This feature is only available when @c wxUSE_DC_TRANSFORM_MATRIX build + option is enabled. @library{wxcore} @@ -1530,7 +1533,8 @@ public: Check if the use of transformation matrix is supported by the current system. - Currently this function always returns @false for non-MSW platforms. + This function returns @true for MSW and GTK+ 3 platforms and since + 3.1.1 also for wxGCDC in all ports. @since 2.9.2 */ diff --git a/src/common/dcgraph.cpp b/src/common/dcgraph.cpp index 6d10931fc7..ad6d0b89da 100644 --- a/src/common/dcgraph.cpp +++ b/src/common/dcgraph.cpp @@ -545,6 +545,47 @@ void wxGCDCImpl::SetLogicalFunction( wxRasterOperationMode function ) m_graphicContext->SetAntialiasMode(wxANTIALIAS_DEFAULT); } +// ---------------------------------------------------------------------------- +// Transform matrix +// ---------------------------------------------------------------------------- + +#if wxUSE_DC_TRANSFORM_MATRIX + +bool wxGCDCImpl::CanUseTransformMatrix() const +{ + return true; +} + +bool wxGCDCImpl::SetTransformMatrix(const wxAffineMatrix2D &matrix) +{ + wxGraphicsMatrix matGr = m_graphicContext->CreateMatrix(matrix); + m_graphicContext->SetTransform(matGr); + + m_isClipBoxValid = false; + 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; +} + +void wxGCDCImpl::ResetTransformMatrix() +{ + wxGraphicsMatrix matGr = m_graphicContext->CreateMatrix(); + m_graphicContext->SetTransform(matGr); + m_isClipBoxValid = false; +} + +#endif // wxUSE_DC_TRANSFORM_MATRIX + bool wxGCDCImpl::DoFloodFill(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), const wxColour& WXUNUSED(col), wxFloodFillStyle WXUNUSED(style))