From 329aee56604f9f763ced089bde03bab7fa6fef7c Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Thu, 5 May 2016 10:10:03 +0200 Subject: [PATCH] Fixed closing sub-path of wxGraphicsPath with Direct2D renderer. When sub-path is closed with CloseSubpath() then current point should be moved to the joined endpoint of the sub-path (what is equivalent of moving it to the starting point of the sub-path). To implement this behaviour we need to store on our own the starting point of the figure in a dedicate data member because native D2D renderer apparently doesn't offer any support for retrieving it. See #17520 --- interface/wx/graphics.h | 6 ++++-- src/msw/graphicsd2d.cpp | 19 ++++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/interface/wx/graphics.h b/interface/wx/graphics.h index e6611a5843..03aef54908 100644 --- a/interface/wx/graphics.h +++ b/interface/wx/graphics.h @@ -99,7 +99,8 @@ public: wxDouble x, wxDouble y); /** - Appends a rectangle as a new closed subpath. + Appends a rectangle as a new closed subpath. After this call + the current point will be at (@a x, @a y). */ virtual void AddRectangle(wxDouble x, wxDouble y, wxDouble w, wxDouble h); @@ -110,7 +111,8 @@ public: wxDouble h, wxDouble radius); /** - Closes the current sub-path. + Closes the current sub-path. After this call the current point will be + at the joined endpoint of the sub-path. */ virtual void CloseSubpath(); diff --git a/src/msw/graphicsd2d.cpp b/src/msw/graphicsd2d.cpp index bb86cbdcd1..013f0ea061 100644 --- a/src/msw/graphicsd2d.cpp +++ b/src/msw/graphicsd2d.cpp @@ -1033,6 +1033,7 @@ private : D2D1_MATRIX_3X2_F m_transformMatrix; bool m_figureOpened; + D2D1_POINT_2F m_figureStart; bool m_geometryWritable; }; @@ -1045,7 +1046,9 @@ wxD2DPathData::wxD2DPathData(wxGraphicsRenderer* renderer, ID2D1Factory* d2dFact wxGraphicsPathData(renderer), m_direct2dfactory(d2dFactory), m_currentPoint(D2D1::Point2F(0.0f, 0.0f)), m_transformMatrix(D2D1::Matrix3x2F::Identity()), - m_figureOpened(false), m_geometryWritable(true) + m_figureOpened(false), + m_figureStart(D2D1::Point2F(0.0f, 0.0f)), + m_geometryWritable(true) { m_direct2dfactory->CreatePathGeometry(&m_pathGeometry); // To properly initialize path geometry there is also @@ -1069,6 +1072,10 @@ wxD2DPathData::wxGraphicsObjectRefData* wxD2DPathData::Clone() const newPathData->EnsureGeometryOpen(); m_pathGeometry->Stream(newPathData->m_geometrySink); + newPathData->m_currentPoint = m_currentPoint; + newPathData->m_transformMatrix = m_transformMatrix; + newPathData->m_figureOpened = m_figureOpened; + newPathData->m_figureStart = m_figureStart; return newPathData; } @@ -1125,9 +1132,10 @@ void wxD2DPathData::EnsureFigureOpen(wxDouble x, wxDouble y) if (!m_figureOpened) { - m_geometrySink->BeginFigure(D2D1::Point2F(x, y), D2D1_FIGURE_BEGIN_FILLED); + m_figureStart = D2D1::Point2F(x, y); + m_geometrySink->BeginFigure(m_figureStart, D2D1_FIGURE_BEGIN_FILLED); m_figureOpened = true; - m_currentPoint = D2D1::Point2F(x, y); + m_currentPoint = m_figureStart; } } @@ -1137,6 +1145,11 @@ void wxD2DPathData::EndFigure(D2D1_FIGURE_END figureEnd) { m_geometrySink->EndFigure(figureEnd); m_figureOpened = false; + + // If the figure is closed then current point + // should be moved to the beginning of the figure. + if( figureEnd == D2D1_FIGURE_END_CLOSED ) + m_currentPoint = m_figureStart; } }