Fix adding wxBitmap to generic wxImageList supporting masks
Wee need to assure that bitmap added to the internal collection always have a mask. If necessary this mask is created from alpha channel values. Also, for compatibility with wxMSW implementation we need to prevent the bitmap from having both a mask and alpha channel.
This commit is contained in:
@@ -20,6 +20,8 @@
|
|||||||
#include "wx/image.h"
|
#include "wx/image.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "wx/settings.h"
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// wxImageList
|
// wxImageList
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -84,7 +86,42 @@ int wxGenericImageList::Add( const wxBitmap &bitmap )
|
|||||||
}
|
}
|
||||||
|
|
||||||
wxBitmap bmp(bitmap);
|
wxBitmap bmp(bitmap);
|
||||||
if ( !m_useMask )
|
if ( m_useMask )
|
||||||
|
{
|
||||||
|
if ( bmp.GetMask() )
|
||||||
|
{
|
||||||
|
if ( bmp.HasAlpha() )
|
||||||
|
{
|
||||||
|
// We need to remove alpha channel for compatibility with
|
||||||
|
// native-based wxMSW wxImageList where stored images are not allowed
|
||||||
|
// to have both mask and alpha channel.
|
||||||
|
#if wxUSE_IMAGE
|
||||||
|
wxImage img = bitmap.ConvertToImage();
|
||||||
|
img.ClearAlpha();
|
||||||
|
bmp = img;
|
||||||
|
#endif // wxUSE_IMAGE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( bmp.HasAlpha() )
|
||||||
|
{
|
||||||
|
// Convert alpha channel to mask.
|
||||||
|
#if wxUSE_IMAGE
|
||||||
|
wxImage img = bmp.ConvertToImage();
|
||||||
|
img.ConvertAlphaToMask();
|
||||||
|
bmp = img;
|
||||||
|
#endif // wxUSE_IMAGE
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Like for wxMSW, use the light grey from standard colour map as transparent colour.
|
||||||
|
wxColour col = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
|
||||||
|
bmp.SetMask(new wxMask(bmp, col));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if ( bmp.GetMask() )
|
if ( bmp.GetMask() )
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user