Fix adding image using bitmap and mask colour to nonmasked wxImageList (wxMSW)
If image using bitmap and mask colour is added to nonmasked wxImageList we need to convert effective mask to alpha channel values prior to adding the image to the native list to preserve transparency.
This commit is contained in:
@@ -231,26 +231,11 @@ int wxImageList::Add(const wxBitmap& bitmap, const wxBitmap& mask)
|
||||
// 'bitmap'.
|
||||
int wxImageList::Add(const wxBitmap& bitmap, const wxColour& maskColour)
|
||||
{
|
||||
HBITMAP hbmp;
|
||||
|
||||
#if wxUSE_WXDIB && wxUSE_IMAGE
|
||||
// See the comment in overloaded Add() above.
|
||||
HBITMAP hbmp = NULL;
|
||||
AutoHBITMAP hbmpRelease;
|
||||
if ( bitmap.HasAlpha() )
|
||||
{
|
||||
wxImage img = bitmap.ConvertToImage();
|
||||
|
||||
if ( wxApp::GetComCtl32Version() < 600 )
|
||||
{
|
||||
img.ClearAlpha();
|
||||
}
|
||||
|
||||
hbmp = wxDIB(img, wxDIB::PixelFormat_NotPreMultiplied).Detach();
|
||||
hbmpRelease.Init(hbmp);
|
||||
}
|
||||
else
|
||||
#endif // wxUSE_WXDIB && wxUSE_IMAGE
|
||||
hbmp = GetHbitmapOf(bitmap);
|
||||
AutoHBITMAP hbmpMask;
|
||||
wxMask mask(bitmap, maskColour);
|
||||
GetImageListBitmaps(bitmap, mask.GetBitmap(), m_useMask, hbmpRelease, hbmpMask, hbmp);
|
||||
|
||||
int index = ImageList_AddMasked(GetHImageList(),
|
||||
hbmp,
|
||||
|
@@ -100,6 +100,14 @@ TEST_CASE("ImageList:WithMask", "[imagelist][withmask]")
|
||||
CHECK(bmp2.GetMask() != NULL);
|
||||
CHECK(bmp2.GetWidth() == 32);
|
||||
CHECK(bmp2.GetHeight() == 32);
|
||||
|
||||
idx = il.Add(bmpRGB, *wxRED);
|
||||
CHECK(il.GetImageCount() == 3);
|
||||
wxBitmap bmp3 = il.GetBitmap(idx);
|
||||
CHECK(bmp3.HasAlpha() == false);
|
||||
CHECK(bmp3.GetMask() != NULL);
|
||||
CHECK(bmp3.GetWidth() == 32);
|
||||
CHECK(bmp3.GetHeight() == 32);
|
||||
}
|
||||
|
||||
SECTION("Add RGBA image to list")
|
||||
@@ -120,6 +128,14 @@ TEST_CASE("ImageList:WithMask", "[imagelist][withmask]")
|
||||
CHECK(bmp2.GetMask() != NULL);
|
||||
CHECK(bmp2.GetWidth() == 32);
|
||||
CHECK(bmp2.GetHeight() == 32);
|
||||
|
||||
idx = il.Add(bmpRGBA, *wxRED);
|
||||
CHECK(il.GetImageCount() == 3);
|
||||
wxBitmap bmp3 = il.GetBitmap(idx);
|
||||
CHECK(bmp3.HasAlpha() == false);
|
||||
CHECK(bmp3.GetMask() != NULL);
|
||||
CHECK(bmp3.GetWidth() == 32);
|
||||
CHECK(bmp3.GetHeight() == 32);
|
||||
}
|
||||
|
||||
SECTION("Add icon to list")
|
||||
@@ -257,6 +273,14 @@ TEST_CASE("ImageList:NoMask", "[imagelist][nomask]")
|
||||
CHECK(bmp2.GetMask() == NULL);
|
||||
CHECK(bmp2.GetWidth() == 32);
|
||||
CHECK(bmp2.GetHeight() == 32);
|
||||
|
||||
idx = il.Add(bmpRGB, *wxRED);
|
||||
CHECK(il.GetImageCount() == 3);
|
||||
wxBitmap bmp3 = il.GetBitmap(idx);
|
||||
CHECK(bmp3.HasAlpha() == true);
|
||||
CHECK(bmp3.GetMask() == NULL);
|
||||
CHECK(bmp3.GetWidth() == 32);
|
||||
CHECK(bmp3.GetHeight() == 32);
|
||||
}
|
||||
|
||||
SECTION("Add RGBA image to list")
|
||||
@@ -277,6 +301,14 @@ TEST_CASE("ImageList:NoMask", "[imagelist][nomask]")
|
||||
CHECK(bmp2.GetMask() == NULL);
|
||||
CHECK(bmp2.GetWidth() == 32);
|
||||
CHECK(bmp2.GetHeight() == 32);
|
||||
|
||||
idx = il.Add(bmpRGBA, *wxRED);
|
||||
CHECK(il.GetImageCount() == 3);
|
||||
wxBitmap bmp3 = il.GetBitmap(idx);
|
||||
CHECK(bmp3.HasAlpha() == true);
|
||||
CHECK(bmp3.GetMask() == NULL);
|
||||
CHECK(bmp3.GetWidth() == 32);
|
||||
CHECK(bmp3.GetHeight() == 32);
|
||||
}
|
||||
|
||||
SECTION("Add icon to list")
|
||||
|
Reference in New Issue
Block a user