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.
This commit is contained in:
Artur Wieczorek
2016-09-07 23:49:06 +02:00
parent 0bf38e11a3
commit 49000defcf
5 changed files with 63 additions and 9 deletions

View File

@@ -101,6 +101,7 @@ All (GUI):
- Add wxGraphicsContext::GetClipBox(). - Add wxGraphicsContext::GetClipBox().
- Fix wxGCDC::Clear() for rotated graphics context. - Fix wxGCDC::Clear() for rotated graphics context.
- Fix wxGCDC::GetClippingBox() for transformed wxDC (MSW, GTK+). - Fix wxGCDC::GetClippingBox() for transformed wxDC (MSW, GTK+).
- Add support for affine transformation matrix in wxGCDC.
wxGTK: wxGTK:
@@ -114,6 +115,7 @@ wxGTK:
- Fix crashes in wxFileSystemWatcher implementation (David Hart). - Fix crashes in wxFileSystemWatcher implementation (David Hart).
- Fix wxBitmap ctor from XBM for non-square bitmaps. - Fix wxBitmap ctor from XBM for non-square bitmaps.
- Fix wxDC::GetClippingBox() for transformed wxDC. - Fix wxDC::GetClippingBox() for transformed wxDC.
- Add support for affine transformation matrix in wxDC (GTK+ 3).
wxMSW: wxMSW:

View File

@@ -107,6 +107,13 @@ public:
virtual void* GetHandle() const wxOVERRIDE; 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 // the true implementations
virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
wxFloodFillStyle style = wxFLOOD_SURFACE) wxOVERRIDE; wxFloodFillStyle style = wxFLOOD_SURFACE) wxOVERRIDE;

View File

@@ -1428,9 +1428,9 @@
// Should wxDC provide SetTransformMatrix() and related methods? // Should wxDC provide SetTransformMatrix() and related methods?
// //
// Default is 1 but can be set to 0 if this functionality is not used. Notice // 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 // that currently wxMSW, wxGTK3 support this for wxDC and all platforms support
// much for non-MSW platforms (although it will still save a few bytes // this for wxGCDC so setting this to 0 doesn't change much if neither of these
// probably). // is used (although it will still save a few bytes probably).
// //
// Recommended setting: 1. // Recommended setting: 1.
#define wxUSE_DC_TRANSFORM_MATRIX 1 #define wxUSE_DC_TRANSFORM_MATRIX 1

View File

@@ -155,7 +155,7 @@ struct wxFontMetrics
In general wxDC methods don't support alpha transparency and the alpha In general wxDC methods don't support alpha transparency and the alpha
component of wxColour is simply ignored and you need to use wxGraphicsContext component of wxColour is simply ignored and you need to use wxGraphicsContext
for full transparency support. There are, however, a few exceptions: first, 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, wxDC-derived classes as they use wxGraphicsContext internally. Second,
under all platforms wxSVGFileDC also fully supports alpha channel. In both under all platforms wxSVGFileDC also fully supports alpha channel. In both
of these cases the instances of wxPen or wxBrush that are built from 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 @section dc_transform_support Support for Transformation Matrix
On some platforms (currently only under MSW) wxDC has support for applying On some platforms (currently under MSW, GTK+ 3) wxDC has support for applying
an arbitrary affine transformation matrix to its coordinate system. Call an arbitrary affine transformation matrix to its coordinate system. (Since
CanUseTransformMatrix() to check if this support is available and then call 3.1.1 this feature is also supported by wxGCDC in all ports.)
SetTransformMatrix() if it is. If the transformation matrix is not 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 supported, SetTransformMatrix() always simply returns false and doesn't do
anything. anything.
This feature is only available when @c wxUSE_DC_TRANSFORM_MATRIX build
option is enabled.
@library{wxcore} @library{wxcore}
@@ -1530,7 +1533,8 @@ public:
Check if the use of transformation matrix is supported by the current Check if the use of transformation matrix is supported by the current
system. 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 @since 2.9.2
*/ */

View File

@@ -545,6 +545,47 @@ void wxGCDCImpl::SetLogicalFunction( wxRasterOperationMode function )
m_graphicContext->SetAntialiasMode(wxANTIALIAS_DEFAULT); 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), bool wxGCDCImpl::DoFloodFill(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
const wxColour& WXUNUSED(col), const wxColour& WXUNUSED(col),
wxFloodFillStyle WXUNUSED(style)) wxFloodFillStyle WXUNUSED(style))