From 55478d95a5dbd824fce655575e94ceb799225fd0 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Fri, 6 Dec 2019 20:34:57 +0100 Subject: [PATCH] Add support for creating Cairo brush from wxBrush with non-solid colour Cairo colour patterns support only RGBA colours and therefore it is not possible to create a colour pattern from wxBrush with non-RGB colour (non-solid colour). However under wxOSX, when we have a solid wxBrush with non-solid colour, we can convert it to Cairo surface pattern (stiple) because under wxOSX non-solid colour is actually represented by a pattern image. --- src/generic/graphicc.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index 626091762d..4db5d78a0d 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -1026,9 +1026,34 @@ wxCairoBrushData::wxCairoBrushData( wxGraphicsRenderer* renderer, InitStipple(brush.GetStipple()); break; + case wxBRUSHSTYLE_SOLID: + // Non-RGB colours, which may e.g. appear under wxOSX for wxColours + // with NSColor backend, are not supported by Cairo and have to be + // handled in a special way. + if ( !brush.GetColour().IsSolid() ) + { +#if wxOSX_USE_COCOA + // Under wxOSX, non-solid NSColors are actually represented + // by pattern images and therefore a wxBrush with non-solid + // colour and wxBRUSHSTYLE_SOLID style can be converted + // to a stiple (a surface pattern). + + // Create a stiple bitmap from NSColor's pattern image + wxBitmap bmp(brush.GetColour().OSXGetNSPatternImage()); + InitStipple(&bmp); +#else + wxFAIL_MSG( "Brush with non-solid colour is not supported." ); +#endif + } + break; + default: if ( brush.IsHatch() ) + { + wxASSERT_MSG( brush.GetColour().IsSolid(), + "Brush with non-solid colour is not supported." ); InitHatch(static_cast(brush.GetStyle())); + } break; } }