From 02276c6ebb13d70f73e9bb4a2b591155abd5223e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Va=CC=81clav=20Slavi=CC=81k?= Date: Wed, 8 Feb 2017 14:49:51 +0100 Subject: [PATCH] Fix wxMSW toolbar if using mix of alpha and masks If the user mixes bitmaps with alpha channel and without it, wxMSW toolbar rendered the masked bitmap with black background due to changes in 195df9af7ff9879dca92a86e718dc8fca3110743 In such case, convert bitmaps that don't have an alpha channel into ones that do so that they are all consistent and can use the same rendering method. Fixes #17795. --- src/msw/toolbar.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/msw/toolbar.cpp b/src/msw/toolbar.cpp index 634c943de9..9b0a00c654 100644 --- a/src/msw/toolbar.cpp +++ b/src/msw/toolbar.cpp @@ -838,7 +838,7 @@ bool wxToolBar::Realize() wxToolBarToolBase *tool = node->GetData(); if ( tool->IsButton() ) { - const wxBitmap& bmp = tool->GetNormalBitmap(); + wxBitmap bmp = tool->GetNormalBitmap(); const int w = bmp.GetWidth(); const int h = bmp.GetHeight(); @@ -848,6 +848,17 @@ bool wxToolBar::Realize() int xOffset = wxMax(0, (m_defaultWidth - w)/2); int yOffset = wxMax(0, (m_defaultHeight - h)/2); +#if wxUSE_IMAGE + // If a mix of icons with alpha and without is used, + // convert them all to use alpha. + if (bitmap.HasAlpha() && !bmp.HasAlpha()) + { + wxImage img = bmp.ConvertToImage(); + img.InitAlpha(); + bmp = wxBitmap(img); + } +#endif + // notice the last parameter: do use mask dcAllButtons.DrawBitmap(bmp, x + xOffset, yOffset, true);