From 7be75892a3aeead203d2273b000101a6b46eb4a9 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Fri, 27 Nov 2015 21:36:21 +0100 Subject: [PATCH] Fixed drawing colours with alpha in wxSystemColourProperty (wxPG). For systems which don't support drawing with alpha on standard DC (like e.g. Win, GTK2) there is necessary to use graphics context for this purposes. --- src/propgrid/advprops.cpp | 51 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/src/propgrid/advprops.cpp b/src/propgrid/advprops.cpp index 25c9d1a01d..8ba51c7bee 100644 --- a/src/propgrid/advprops.cpp +++ b/src/propgrid/advprops.cpp @@ -64,6 +64,19 @@ #include "wx/odcombo.h" #include "wx/numformatter.h" +// Drawing ARGB on standard DC is supported by OSX and GTK3 +#if defined(__WXOSX__) || defined(__WXGTK3__) +#define wxPG_DC_SUPPORTS_ALPHA 1 +#else +#define wxPG_DC_SUPPORTS_ALPHA 0 +#endif // __WXOSX__ || __WXGTK3__ + +#define wxPG_USE_GC_FOR_ALPHA (wxUSE_GRAPHICS_CONTEXT && !wxPG_DC_SUPPORTS_ALPHA) + +#if wxPG_USE_GC_FOR_ALPHA +#include "wx/dcgraph.h" +#endif // wxPG_USE_GC_FOR_ALPHA + // ----------------------------------------------------------------------- #if defined(__WXMSW__) @@ -1396,8 +1409,42 @@ void wxSystemColourProperty::OnCustomPaint( wxDC& dc, const wxRect& rect, if ( col.IsOk() ) { - dc.SetBrush(col); - dc.DrawRectangle(rect); +#if wxPG_USE_GC_FOR_ALPHA + wxGCDC *gdc = NULL; + if ( col.Alpha() != wxALPHA_OPAQUE ) + { + if ( wxPaintDC *paintdc = wxDynamicCast(&dc, wxPaintDC) ) + { + gdc = new wxGCDC(*paintdc); + } + else if ( wxMemoryDC *memdc = wxDynamicCast(&dc, wxMemoryDC) ) + { + gdc = new wxGCDC(*memdc); + } +#if wxUSE_METAFILE && defined(wxMETAFILE_IS_ENH) + else if ( wxMetafileDC *metadc = wxDynamicCast(&dc, wxMetafileDC) ) + { + gdc = new wxGCDC(*metadc); + } +#endif + else + { + wxFAIL_MSG( wxS("Unknown wxDC kind") ); + } + } + + if ( gdc ) + { + gdc->SetBrush(col); + gdc->DrawRectangle(rect); + delete gdc; + } + else +#endif // wxPG_USE_GC_FOR_ALPHA + { + dc.SetBrush(col); + dc.DrawRectangle(rect); + } } }