Fix transparency in toolbar buttons when not using comctl32.dll v6.
Old versions of comctl32.dll don't support alpha in the toolbar image list, so use the masks only for them. Closes #2609. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75785 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -87,7 +87,8 @@ bool wxImageList::Create(int width, int height, bool mask, int initial)
|
|||||||
flags |= ILC_COLOR32;
|
flags |= ILC_COLOR32;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ( mask )
|
// For comctl32.dll < 6 always use masks as it doesn't support alpha.
|
||||||
|
if ( mask || wxApp::GetComCtl32Version() < 600 )
|
||||||
flags |= ILC_MASK;
|
flags |= ILC_MASK;
|
||||||
|
|
||||||
// Grow by 1, I guess this is reasonable behaviour most of the time
|
// Grow by 1, I guess this is reasonable behaviour most of the time
|
||||||
@@ -148,20 +149,37 @@ int wxImageList::Add(const wxBitmap& bitmap, const wxBitmap& mask)
|
|||||||
// course, very inefficient but it's better than wrong appearance so we do
|
// course, very inefficient but it's better than wrong appearance so we do
|
||||||
// this for now until a better way can be found.
|
// this for now until a better way can be found.
|
||||||
AutoHBITMAP hbmpRelease;
|
AutoHBITMAP hbmpRelease;
|
||||||
|
bool useMask;
|
||||||
if ( bitmap.HasAlpha() )
|
if ( bitmap.HasAlpha() )
|
||||||
{
|
{
|
||||||
hbmp = wxDIB(bitmap.ConvertToImage(),
|
wxImage img = bitmap.ConvertToImage();
|
||||||
wxDIB::PixelFormat_NotPreMultiplied).Detach();
|
|
||||||
|
// For comctl32.dll < 6 remove alpha channel from image
|
||||||
|
// to prevent possible interferences with the mask.
|
||||||
|
if ( wxApp::GetComCtl32Version() < 600 )
|
||||||
|
{
|
||||||
|
img.ClearAlpha();
|
||||||
|
useMask = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
useMask = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
hbmp = wxDIB(img, wxDIB::PixelFormat_NotPreMultiplied).Detach();
|
||||||
hbmpRelease.Init(hbmp);
|
hbmpRelease.Init(hbmp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif // wxUSE_WXDIB && wxUSE_IMAGE
|
#endif // wxUSE_WXDIB && wxUSE_IMAGE
|
||||||
|
{
|
||||||
hbmp = GetHbitmapOf(bitmap);
|
hbmp = GetHbitmapOf(bitmap);
|
||||||
|
useMask = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Use mask only if we don't have alpha, the bitmap isn't drawn correctly
|
// Use mask only if we don't have alpha, the bitmap isn't drawn correctly
|
||||||
// if we use both.
|
// if we use both.
|
||||||
AutoHBITMAP hbmpMask;
|
AutoHBITMAP hbmpMask;
|
||||||
if ( !bitmap.HasAlpha() )
|
if ( useMask )
|
||||||
hbmpMask.Init(GetMaskForImage(bitmap, mask));
|
hbmpMask.Init(GetMaskForImage(bitmap, mask));
|
||||||
|
|
||||||
int index = ImageList_Add(GetHImageList(), hbmp, hbmpMask);
|
int index = ImageList_Add(GetHImageList(), hbmp, hbmpMask);
|
||||||
@@ -185,8 +203,14 @@ int wxImageList::Add(const wxBitmap& bitmap, const wxColour& maskColour)
|
|||||||
AutoHBITMAP hbmpRelease;
|
AutoHBITMAP hbmpRelease;
|
||||||
if ( bitmap.HasAlpha() )
|
if ( bitmap.HasAlpha() )
|
||||||
{
|
{
|
||||||
hbmp = wxDIB(bitmap.ConvertToImage(),
|
wxImage img = bitmap.ConvertToImage();
|
||||||
wxDIB::PixelFormat_NotPreMultiplied).Detach();
|
|
||||||
|
if ( wxApp::GetComCtl32Version() < 600 )
|
||||||
|
{
|
||||||
|
img.ClearAlpha();
|
||||||
|
}
|
||||||
|
|
||||||
|
hbmp = wxDIB(img, wxDIB::PixelFormat_NotPreMultiplied).Detach();
|
||||||
hbmpRelease.Init(hbmp);
|
hbmpRelease.Init(hbmp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -224,21 +248,38 @@ bool wxImageList::Replace(int index,
|
|||||||
const wxBitmap& mask)
|
const wxBitmap& mask)
|
||||||
{
|
{
|
||||||
HBITMAP hbmp;
|
HBITMAP hbmp;
|
||||||
|
bool useMask;
|
||||||
|
|
||||||
#if wxUSE_WXDIB && wxUSE_IMAGE
|
#if wxUSE_WXDIB && wxUSE_IMAGE
|
||||||
// See the comment in Add() above.
|
// See the comment in Add() above.
|
||||||
AutoHBITMAP hbmpRelease;
|
AutoHBITMAP hbmpRelease;
|
||||||
if ( bitmap.HasAlpha() )
|
if ( bitmap.HasAlpha() )
|
||||||
{
|
{
|
||||||
hbmp = wxDIB(bitmap.ConvertToImage(),
|
wxImage img = bitmap.ConvertToImage();
|
||||||
wxDIB::PixelFormat_NotPreMultiplied).Detach();
|
|
||||||
|
if ( wxApp::GetComCtl32Version() < 600 )
|
||||||
|
{
|
||||||
|
img.ClearAlpha();
|
||||||
|
useMask = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
useMask = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
hbmp = wxDIB(img, wxDIB::PixelFormat_NotPreMultiplied).Detach();
|
||||||
hbmpRelease.Init(hbmp);
|
hbmpRelease.Init(hbmp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif // wxUSE_WXDIB && wxUSE_IMAGE
|
#endif // wxUSE_WXDIB && wxUSE_IMAGE
|
||||||
|
{
|
||||||
hbmp = GetHbitmapOf(bitmap);
|
hbmp = GetHbitmapOf(bitmap);
|
||||||
|
useMask = true;
|
||||||
|
}
|
||||||
|
|
||||||
AutoHBITMAP hbmpMask(GetMaskForImage(bitmap, mask));
|
AutoHBITMAP hbmpMask;
|
||||||
|
if ( useMask )
|
||||||
|
hbmpMask.Init(GetMaskForImage(bitmap, mask));
|
||||||
|
|
||||||
if ( !ImageList_Replace(GetHImageList(), index, hbmp, hbmpMask) )
|
if ( !ImageList_Replace(GetHImageList(), index, hbmp, hbmpMask) )
|
||||||
{
|
{
|
||||||
|
@@ -663,7 +663,10 @@ void wxToolBar::CreateDisabledImageList()
|
|||||||
(
|
(
|
||||||
sizeBitmap.x,
|
sizeBitmap.x,
|
||||||
sizeBitmap.y,
|
sizeBitmap.y,
|
||||||
bmpDisabled.GetMask() != NULL,
|
// Don't use mask if we have alpha
|
||||||
|
// (wxImageList will fall back to
|
||||||
|
// mask if alpha not supported)
|
||||||
|
!bmpDisabled.HasAlpha(),
|
||||||
GetToolsCount()
|
GetToolsCount()
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user