Fix regression in wxGCDC initialization from wxGraphicsContext

The changes of ae2cb7d347 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.
This commit is contained in:
Vadim Zeitlin
2019-07-07 03:09:55 +02:00
parent a1bd57d1d8
commit 8926928a8f
2 changed files with 23 additions and 8 deletions

View File

@@ -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);
};

View File

@@ -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;