From af6e478182b4cb6c054454d9b55e0bc600ff8731 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 15 Dec 2018 16:57:15 +0100 Subject: [PATCH] Don't reset wxGraphicsContext attributes in wxGCDC ctor from it When creating wxGCDC from an existing wxGraphicsContext, it is better to keep using the attributes (such as font, pen, brush) already configured for it rather than overwriting them with the default values, which is not very useful, unlike the new behaviour, which allows to configure wxGraphicsContext using features not supported by wxDC API (e.g. alpha channel for pens/brushes) and then use it via wxDC API only (allowing the existing legacy code to use alpha, for example). --- interface/wx/dcgraph.h | 11 +++++++++++ src/common/dcgraph.cpp | 12 +++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/interface/wx/dcgraph.h b/interface/wx/dcgraph.h index 0f4d75c2bd..197f0e5a9b 100644 --- a/interface/wx/dcgraph.h +++ b/interface/wx/dcgraph.h @@ -62,6 +62,17 @@ public: Note that this object takes ownership of @a context and will delete it when it is destroyed or when SetGraphicsContext() is called with a different context object. + + Also notice that @a context will continue using the same font, pen and + brush as before until SetFont(), SetPen() or SetBrush() is explicitly + called to change them. This means that the code can use this + wxDC-derived object to work using pens and brushes with alpha component, + for example (which normally isn't supported by wxDC API), but it also + means that the return values of GetFont(), GetPen() and GetBrush() won't + really correspond to the actually used objects because they simply can't + represent them anyhow. If you wish to avoid such discrepancy, you need + to call the setter methods to bring wxDC and wxGraphicsContext font, pen + and brush in sync with each other. */ wxGCDC(wxGraphicsContext* context); diff --git a/src/common/dcgraph.cpp b/src/common/dcgraph.cpp index a13546fbb7..88cf61c3e0 100644 --- a/src/common/dcgraph.cpp +++ b/src/common/dcgraph.cpp @@ -124,7 +124,17 @@ wxIMPLEMENT_ABSTRACT_CLASS(wxGCDCImpl, wxDCImpl); wxGCDCImpl::wxGCDCImpl(wxDC *owner, wxGraphicsContext* context) : wxDCImpl(owner) { - Init(context); + CommonInit(); + + m_graphicContext = context; + m_ok = m_graphicContext != NULL; + + // 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 + // plain wxXXX ones. This is obviously not ideal as it means that GetXXX() + // won't return the actual object being used, but is better than the only + // alternative which is overwriting the objects currently used in the + // graphics context with the defaults. } wxGCDCImpl::wxGCDCImpl( wxDC *owner ) :