Fix image list mask and blending.

This commit is contained in:
Mike McCormack 2005-01-10 14:29:20 +00:00 committed by Alexandre Julliard
parent 1953a1ed2d
commit 07aa50bc48
1 changed files with 48 additions and 18 deletions

View File

@ -612,6 +612,8 @@ ImageList_Create (INT cx, INT cy, UINT flags,
} }
SelectObject(himl->hdcMask, himl->hbmMask); SelectObject(himl->hdcMask, himl->hbmMask);
} }
else
himl->hbmMask = 0;
/* create blending brushes */ /* create blending brushes */
hbmTemp = CreateBitmap (8, 8, 1, 1, &aBitBlend25); hbmTemp = CreateBitmap (8, 8, 1, 1, &aBitBlend25);
@ -1056,10 +1058,10 @@ ImageList_DrawIndirect (IMAGELISTDRAWPARAMS *pimldp)
INT cx, cy, lx, ly, nOvlIdx; INT cx, cy, lx, ly, nOvlIdx;
DWORD fState, dwRop; DWORD fState, dwRop;
UINT fStyle; UINT fStyle;
COLORREF clrBk, oldImageBk, oldImageFg; COLORREF oldImageBk, oldImageFg;
HDC hImageDC, hImageListDC, hMaskListDC; HDC hImageDC, hImageListDC, hMaskListDC;
HBITMAP hImageBmp, hOldImageBmp, hBlendMaskBmp; HBITMAP hImageBmp, hOldImageBmp, hBlendMaskBmp;
BOOL bIsTransparent, bBlend, bResult = FALSE; BOOL bIsTransparent, bBlend, bResult = FALSE, bMask;
HIMAGELIST himl; HIMAGELIST himl;
if (!pimldp || !(himl = pimldp->himl)) return FALSE; if (!pimldp || !(himl = pimldp->himl)) return FALSE;
@ -1073,9 +1075,14 @@ ImageList_DrawIndirect (IMAGELISTDRAWPARAMS *pimldp)
fStyle = pimldp->fStyle & ~ILD_OVERLAYMASK; fStyle = pimldp->fStyle & ~ILD_OVERLAYMASK;
cx = (pimldp->cx == 0) ? himl->cx : pimldp->cx; cx = (pimldp->cx == 0) ? himl->cx : pimldp->cx;
cy = (pimldp->cy == 0) ? himl->cy : pimldp->cy; cy = (pimldp->cy == 0) ? himl->cy : pimldp->cy;
clrBk = (pimldp->rgbBk == CLR_DEFAULT) ? himl->clrBk : pimldp->rgbBk;
bIsTransparent = (fStyle & ILD_TRANSPARENT) || clrBk == CLR_NONE; bIsTransparent = (fStyle & ILD_TRANSPARENT);
bBlend = fStyle & (ILD_BLEND25 | ILD_BLEND50); if( pimldp->rgbBk == CLR_NONE )
bIsTransparent = TRUE;
if( ( pimldp->rgbBk == CLR_DEFAULT ) && ( himl->clrBk == CLR_NONE ) )
bIsTransparent = TRUE;
bMask = (himl->flags & ILC_MASK) && (fStyle & ILD_MASK) ;
bBlend = (fStyle & (ILD_BLEND25 | ILD_BLEND50) ) && !bMask;
TRACE("himl(0x%lx) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n", TRACE("himl(0x%lx) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
(DWORD)himl, himl->hbmMask, pimldp->i, pimldp->x, pimldp->y, cx, cy); (DWORD)himl, himl->hbmMask, pimldp->i, pimldp->x, pimldp->y, cx, cy);
@ -1107,24 +1114,43 @@ ImageList_DrawIndirect (IMAGELISTDRAWPARAMS *pimldp)
/* /*
* Draw the initial image * Draw the initial image
*/ */
if (fStyle & ILD_MASK) { if( bMask ) {
if (himl->hbmMask) { if (himl->hbmMask) {
BitBlt(hImageDC, 0, 0, cx, cy, hMaskListDC, lx, ly, SRCCOPY); HBRUSH hOldBrush;
hOldBrush = SelectObject (hImageDC, CreateSolidBrush (GetTextColor(pimldp->hdcDst)));
PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
BitBlt(hImageDC, 0, 0, cx, cy, hMaskListDC, lx, ly, SRCPAINT);
DeleteObject (SelectObject (hImageDC, hOldBrush));
if( bIsTransparent )
{
BitBlt ( pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, SRCAND);
bResult = TRUE;
goto end;
}
} else { } else {
HBRUSH hOldBrush = SelectObject (hImageDC, GetStockObject(BLACK_BRUSH)); HBRUSH hOldBrush = SelectObject (hImageDC, GetStockObject(BLACK_BRUSH));
PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY); PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY);
SelectObject(hImageDC, hOldBrush); SelectObject(hImageDC, hOldBrush);
} }
} else if (himl->hbmMask && !bIsTransparent) { } else {
/* blend the image with the needed solid background */ /* blend the image with the needed solid background */
HBRUSH hOldBrush = SelectObject (hImageDC, CreateSolidBrush (clrBk)); COLORREF colour = RGB(0,0,0);
HBRUSH hOldBrush;
if( !bIsTransparent )
{
colour = pimldp->rgbBk;
if( colour == CLR_DEFAULT )
colour = himl->clrBk;
if( colour == CLR_NONE )
colour = GetBkColor(pimldp->hdcDst);
}
hOldBrush = SelectObject (hImageDC, CreateSolidBrush (colour));
PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY ); PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
BitBlt( hImageDC, 0, 0, cx, cy, hMaskListDC, lx, ly, SRCAND ); BitBlt( hImageDC, 0, 0, cx, cy, hMaskListDC, lx, ly, SRCAND );
BitBlt( hImageDC, 0, 0, cx, cy, hImageListDC, lx, ly, SRCPAINT ); BitBlt( hImageDC, 0, 0, cx, cy, hImageListDC, lx, ly, SRCPAINT );
DeleteObject (SelectObject (hImageDC, hOldBrush)); DeleteObject (SelectObject (hImageDC, hOldBrush));
} else {
/* start off with the image, if we have a mask, we'll use it later */
BitBlt( hImageDC, 0, 0, cx, cy, hImageListDC, lx, ly, SRCCOPY);
} }
/* Time for blending, if required */ /* Time for blending, if required */
@ -1179,7 +1205,7 @@ ImageList_DrawIndirect (IMAGELISTDRAWPARAMS *pimldp)
/* now copy the image to the screen */ /* now copy the image to the screen */
dwRop = SRCCOPY; dwRop = SRCCOPY;
if (himl->hbmMask && bIsTransparent && !(fStyle & ILD_MASK)) { if (himl->hbmMask && bIsTransparent ) {
COLORREF oldDstFg = SetTextColor(pimldp->hdcDst, RGB( 0, 0, 0 ) ); COLORREF oldDstFg = SetTextColor(pimldp->hdcDst, RGB( 0, 0, 0 ) );
COLORREF oldDstBk = SetBkColor(pimldp->hdcDst, RGB( 0xff, 0xff, 0xff )); COLORREF oldDstBk = SetBkColor(pimldp->hdcDst, RGB( 0xff, 0xff, 0xff ));
BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hMaskListDC, lx, ly, SRCAND); BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hMaskListDC, lx, ly, SRCAND);
@ -1191,7 +1217,7 @@ ImageList_DrawIndirect (IMAGELISTDRAWPARAMS *pimldp)
BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, dwRop); BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, dwRop);
bResult = TRUE; bResult = TRUE;
end:
/* cleanup the mess */ /* cleanup the mess */
SetBkColor(hImageDC, oldImageBk); SetBkColor(hImageDC, oldImageBk);
SetTextColor(hImageDC, oldImageFg); SetTextColor(hImageDC, oldImageFg);
@ -1388,14 +1414,18 @@ ImageList_GetIcon (HIMAGELIST himl, INT i, UINT fStyle)
/* draw mask*/ /* draw mask*/
ii.hbmMask = CreateCompatibleBitmap (hdcDst, himl->cx, himl->cy); ii.hbmMask = CreateCompatibleBitmap (hdcDst, himl->cx, himl->cy);
hOldDstBitmap = SelectObject (hdcDst, ii.hbmMask); hOldDstBitmap = SelectObject (hdcDst, ii.hbmMask);
PatBlt (hdcDst, 0, 0, himl->cx, himl->cy, WHITENESS); if (himl->hbmMask) {
ImageList_Draw(himl, i, hdcDst, 0, 0, fStyle | ILD_MASK); BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
himl->hdcMask, i * himl->cx, 0, SRCCOPY);
}
else
PatBlt (hdcDst, 0, 0, himl->cx, himl->cy, BLACKNESS);
/* draw image*/ /* draw image*/
ii.hbmColor = CreateCompatibleBitmap (himl->hdcImage, himl->cx, himl->cy); ii.hbmColor = CreateCompatibleBitmap (himl->hdcImage, himl->cx, himl->cy);
SelectObject (hdcDst, ii.hbmColor); SelectObject (hdcDst, ii.hbmColor);
PatBlt (hdcDst, 0, 0, himl->cx, himl->cy, BLACKNESS); BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
ImageList_Draw(himl, i, hdcDst, 0, 0, fStyle | ILD_TRANSPARENT); himl->hdcImage, i * himl->cx, 0, SRCCOPY);
/* /*
* CreateIconIndirect requires us to deselect the bitmaps from * CreateIconIndirect requires us to deselect the bitmaps from