diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index b554b343d1..fbb6375a39 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -181,6 +181,10 @@ public : private : GraphicsPath* m_path; + bool m_logCurrentPointSet; + PointF m_logCurrentPoint; + bool m_figureOpened; + PointF m_figureStart; }; class wxGDIPlusMatrixData : public wxGraphicsMatrixData @@ -1161,6 +1165,10 @@ wxGDIPlusBitmapData::~wxGDIPlusBitmapData() //----------------------------------------------------------------------------- wxGDIPlusPathData::wxGDIPlusPathData(wxGraphicsRenderer* renderer, GraphicsPath* path ) : wxGraphicsPathData(renderer) + , m_logCurrentPointSet(false) + , m_logCurrentPoint(0.0, 0.0) + , m_figureOpened(false) + , m_figureStart(0.0, 0.0) { if ( path ) m_path = path; @@ -1175,7 +1183,14 @@ wxGDIPlusPathData::~wxGDIPlusPathData() wxGraphicsObjectRefData* wxGDIPlusPathData::Clone() const { - return new wxGDIPlusPathData( GetRenderer() , m_path->Clone()); + wxGDIPlusPathData* newPathData = + new wxGDIPlusPathData(GetRenderer(), m_path->Clone()); + newPathData->m_logCurrentPointSet = m_logCurrentPointSet; + newPathData->m_logCurrentPoint = m_logCurrentPoint; + newPathData->m_figureOpened = m_figureOpened; + newPathData->m_figureStart = m_figureStart; + + return newPathData; } // @@ -1185,19 +1200,40 @@ wxGraphicsObjectRefData* wxGDIPlusPathData::Clone() const void wxGDIPlusPathData::MoveToPoint( wxDouble x , wxDouble y ) { m_path->StartFigure(); - m_path->AddLine((REAL) x,(REAL) y,(REAL) x,(REAL) y); + m_figureOpened = true; + m_figureStart = PointF((REAL)x, (REAL)y); + // Since native current point is not updated in any way + // we have to maintain current point location on our own in this case. + m_logCurrentPoint = m_figureStart; + m_logCurrentPointSet = true; } void wxGDIPlusPathData::AddLineToPoint( wxDouble x , wxDouble y ) { PointF start; - m_path->GetLastPoint(&start); + if ( m_logCurrentPointSet ) + { + start = m_logCurrentPoint; + // After calling AddLine() the native current point + // will be updated and can be used. + m_logCurrentPointSet = false; + } + else + { + m_path->GetLastPoint(&start); + } m_path->AddLine(start.X, start.Y, (REAL)x, (REAL)y); } void wxGDIPlusPathData::CloseSubpath() { m_path->CloseFigure(); + m_figureOpened = false; + // Since native GDI+ renderer doesn't move its current point + // to the starting point of the figure we need to maintain + // it on our own in this case. + m_logCurrentPoint = m_figureStart; + m_logCurrentPointSet = true; } void wxGDIPlusPathData::AddCurveToPoint( wxDouble cx1, wxDouble cy1, wxDouble cx2, wxDouble cy2, wxDouble x, wxDouble y ) @@ -1206,7 +1242,17 @@ void wxGDIPlusPathData::AddCurveToPoint( wxDouble cx1, wxDouble cy1, wxDouble cx PointF c2(cx2,cy2); PointF end(x,y); PointF start; - m_path->GetLastPoint(&start); + if ( m_logCurrentPointSet ) + { + start = m_logCurrentPoint; + // After calling AddBezier() the native current point + // will be updated and can be used. + m_logCurrentPointSet = false; + } + else + { + m_path->GetLastPoint(&start); + } m_path->AddBezier(start,c1,c2,end); } @@ -1214,7 +1260,11 @@ void wxGDIPlusPathData::AddCurveToPoint( wxDouble cx1, wxDouble cy1, wxDouble cx void wxGDIPlusPathData::GetCurrentPoint( wxDouble* x, wxDouble* y) const { PointF start; - m_path->GetLastPoint(&start); + if ( m_logCurrentPointSet ) + start = m_logCurrentPoint; + else + m_path->GetLastPoint(&start); + *x = start.X ; *y = start.Y ; } @@ -1241,16 +1291,26 @@ void wxGDIPlusPathData::AddArc( wxDouble x, wxDouble y, wxDouble r, double start } } m_path->AddArc((REAL) (x-r),(REAL) (y-r),(REAL) (2*r),(REAL) (2*r),wxRadToDeg(startAngle),wxRadToDeg(sweepAngle)); + // After calling AddArc() the native current point will be updated and can be used. + m_logCurrentPointSet = false; } void wxGDIPlusPathData::AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h ) { m_path->AddRectangle(RectF(x,y,w,h)); + // Drawn rectangle is an intrinsically closed shape but native + // current point is not moved to the starting point of the figure + // (the same case as with CloseFigure) so we need to maintain it + // on our own in this case. + m_logCurrentPoint = PointF((REAL)x, (REAL)y); + m_logCurrentPointSet = true; } void wxGDIPlusPathData::AddPath( const wxGraphicsPathData* path ) { m_path->AddPath( (GraphicsPath*) path->GetNativePath(), FALSE); + // We have to switch to the native current point. + m_logCurrentPointSet = false; }