From 159b5088ee303f7adf6a4c0e5e72b32c37f9f910 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Mon, 5 Mar 2012 09:13:55 +0000 Subject: Resolves: fdo#31306 some icons don't get grayed when disabled some of our menu icons are not RGBA, but our fade-out code only handled images with an alpha channel, so we need to extend it for bitmaps with alpha channel icons --- vcl/source/gdi/outdev2.cxx | 54 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/vcl/source/gdi/outdev2.cxx b/vcl/source/gdi/outdev2.cxx index 6d8987e43c14..d6553ab70edf 100644 --- a/vcl/source/gdi/outdev2.cxx +++ b/vcl/source/gdi/outdev2.cxx @@ -1162,6 +1162,44 @@ void OutputDevice::ImplDrawMask( const Point& rDestPt, const Size& rDestSize, } } +namespace +{ + BitmapEx makeDisabledBitmap(const Bitmap &rBitmap) + { + const Size aTotalSize( rBitmap.GetSizePixel() ); + Bitmap aGrey( aTotalSize, 8, &Bitmap::GetGreyPalette( 256 ) ); + AlphaMask aGreyAlphaMask( aTotalSize ); + BitmapReadAccess* pBmp = const_cast(rBitmap).AcquireReadAccess(); + BitmapWriteAccess* pGrey = aGrey.AcquireWriteAccess(); + BitmapWriteAccess* pGreyAlphaMask = aGreyAlphaMask.AcquireWriteAccess(); + + if( pBmp && pGrey && pGreyAlphaMask ) + { + BitmapColor aGreyVal( 0 ); + BitmapColor aGreyAlphaMaskVal( 0 ); + const int nLeft = 0, nRight = aTotalSize.Width(); + const int nTop = 0, nBottom = nTop + aTotalSize.Height(); + + for( int nY = nTop; nY < nBottom; ++nY ) + { + for( int nX = nLeft; nX < nRight; ++nX ) + { + aGreyVal.SetIndex( pBmp->GetLuminance( nY, nX ) ); + pGrey->SetPixel( nY, nX, aGreyVal ); + + aGreyAlphaMaskVal.SetIndex( static_cast< sal_uInt8 >( 128ul ) ); + pGreyAlphaMask->SetPixel( nY, nX, aGreyAlphaMaskVal ); + } + } + } + + const_cast(rBitmap).ReleaseAccess( pBmp ); + aGrey.ReleaseAccess( pGrey ); + aGreyAlphaMask.ReleaseAccess( pGreyAlphaMask ); + return BitmapEx( aGrey, aGreyAlphaMask ); + } +} + // ------------------------------------------------------------------ void OutputDevice::DrawImage( const Point& rPos, const Image& rImage, sal_uInt16 nStyle ) @@ -1174,7 +1212,13 @@ void OutputDevice::DrawImage( const Point& rPos, const Image& rImage, sal_uInt16 switch( rImage.mpImplData->meType ) { case IMAGETYPE_BITMAP: - DrawBitmap( rPos, *static_cast< Bitmap* >( rImage.mpImplData->mpData ) ); + { + const Bitmap &rBitmap = *static_cast< Bitmap* >( rImage.mpImplData->mpData ); + if( nStyle & IMAGE_DRAW_DISABLE ) + DrawBitmapEx( rPos, makeDisabledBitmap(rBitmap) ); + else + DrawBitmap( rPos, rBitmap ); + } break; case IMAGETYPE_IMAGE: @@ -1210,7 +1254,13 @@ void OutputDevice::DrawImage( const Point& rPos, const Size& rSize, switch( rImage.mpImplData->meType ) { case IMAGETYPE_BITMAP: - DrawBitmap( rPos, rSize, *static_cast< Bitmap* >( rImage.mpImplData->mpData ) ); + { + const Bitmap &rBitmap = *static_cast< Bitmap* >( rImage.mpImplData->mpData ); + if( nStyle & IMAGE_DRAW_DISABLE ) + DrawBitmapEx( rPos, rSize, makeDisabledBitmap(rBitmap) ); + else + DrawBitmap( rPos, rSize, rBitmap ); + } break; case IMAGETYPE_IMAGE: -- cgit v1.2.3