From 8926928a8f880a9ab005de0f08f78cb464896e8f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 7 Jul 2019 03:09:55 +0200 Subject: [PATCH] Fix regression in wxGCDC initialization from wxGraphicsContext The changes of ae2cb7d3471755a6369b506526ade9ddab5d750c resulted in transformation matrix not being initialized correctly any more. Fix this by adding yet another helper, DoInitContext(), called both when initializing wxGCDC using an existing wxGraphicsContext in the corresponding ctor and the just created one in the other ones. Closes #18429. --- include/wx/dcgraph.h | 4 ++++ src/common/dcgraph.cpp | 27 +++++++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/include/wx/dcgraph.h b/include/wx/dcgraph.h index c29ab57876..fd413d0835 100644 --- a/include/wx/dcgraph.h +++ b/include/wx/dcgraph.h @@ -242,6 +242,10 @@ private: // is assumed to be newly created. void Init(wxGraphicsContext*); + // This method initializes m_graphicContext, m_ok and m_matrixOriginal + // fields, returns true if the context was valid. + bool DoInitContext(wxGraphicsContext* ctx); + wxDECLARE_CLASS(wxGCDCImpl); wxDECLARE_NO_COPY_CLASS(wxGCDCImpl); }; diff --git a/src/common/dcgraph.cpp b/src/common/dcgraph.cpp index 88cf61c3e0..e0baafa06d 100644 --- a/src/common/dcgraph.cpp +++ b/src/common/dcgraph.cpp @@ -126,8 +126,7 @@ wxGCDCImpl::wxGCDCImpl(wxDC *owner, wxGraphicsContext* context) : { CommonInit(); - m_graphicContext = context; - m_ok = m_graphicContext != NULL; + DoInitContext(context); // We can't currently initialize m_font, m_pen and m_brush here as we don't // have any way of converting the corresponding wxGraphicsXXX objects to @@ -146,13 +145,10 @@ wxGCDCImpl::wxGCDCImpl( wxDC *owner ) : void wxGCDCImpl::SetGraphicsContext( wxGraphicsContext* ctx ) { delete m_graphicContext; - m_graphicContext = ctx; - if ( m_graphicContext ) + + if ( DoInitContext(ctx) ) { - m_matrixOriginal = m_graphicContext->GetTransform(); - m_ok = true; - // apply the stored transformations to the passed in context - ComputeScaleAndOrigin(); + // Reapply our attributes to the context. m_graphicContext->SetFont( m_font , m_textForegroundColour ); m_graphicContext->SetPen( m_pen ); m_graphicContext->SetBrush( m_brush); @@ -220,6 +216,21 @@ void wxGCDCImpl::Init(wxGraphicsContext* ctx) SetGraphicsContext(ctx); } +bool wxGCDCImpl::DoInitContext(wxGraphicsContext* ctx) +{ + m_graphicContext = ctx; + m_ok = m_graphicContext != NULL; + + if ( m_ok ) + { + // apply the stored transformations to the passed in context + m_matrixOriginal = m_graphicContext->GetTransform(); + ComputeScaleAndOrigin(); + } + + return m_ok; +} + wxGCDCImpl::~wxGCDCImpl() { delete m_graphicContext;