improve cursor loading code

svn path=/trunk/; revision=25488
This commit is contained in:
Ged Murphy 2007-01-16 18:30:54 +00:00
parent 14060f6c04
commit 6c5af8a927

View file

@ -247,10 +247,10 @@ CreateIconFromResourceEx(
if (! fIcon) if (! fIcon)
{ {
wXHotspot = *(WORD*)pbIconBits; wXHotspot = *(WORD*)pbIconBits;
pbIconBits+=sizeof(WORD); pbIconBits += sizeof(WORD);
wYHotspot = *(WORD*)pbIconBits; wYHotspot = *(WORD*)pbIconBits;
pbIconBits+=sizeof(WORD); pbIconBits += sizeof(WORD);
cbIconBits-=2*sizeof(WORD); cbIconBits -= 2 * sizeof(WORD);
} }
else else
{ {
@ -266,7 +266,7 @@ CreateIconFromResourceEx(
} }
memcpy(SafeIconImage, pbIconBits, cbIconBits); memcpy(SafeIconImage, pbIconBits, cbIconBits);
/* take into acount the origonal height was for both the AND and XOR images */ /* take into acount the original height was for both the AND and XOR images */
if(fIcon) if(fIcon)
SafeIconImage->icHeader.biHeight /= 2; SafeIconImage->icHeader.biHeight /= 2;
@ -326,7 +326,7 @@ CreateIconIndirect(PICONINFO IconInfo)
return (HICON)0; return (HICON)0;
} }
/* FIXME - does there really *have* to be a color bitmap? monochrome cursors don't have one */ /* FIXME - does there really *have* to be a color bitmap? monochrome cursors don't have one */
if(IconInfo->hbmColor && !GetObjectW(IconInfo->hbmColor, sizeof(BITMAP), &ColorBitmap)) if(/*IconInfo->hbmColor &&*/ !GetObjectW(IconInfo->hbmColor, sizeof(BITMAP), &ColorBitmap))
{ {
return (HICON)0; return (HICON)0;
} }
@ -526,40 +526,43 @@ CURSORICON_FindBestCursor(LPVOID dir,
int Height, int Height,
int ColorBits) int ColorBits)
{ {
int i, MaxWidth, MaxHeight, cx, cy, Bits, BestEntry = -1; int i, cx, cy, Bits, BestBits = 0, BestEntry = -1;
UINT iTotalDiff, iXDiff=0, iYDiff=0, iColorDiff;
UINT iTempXDiff, iTempYDiff, iTempColorDiff;
/* Double height to account for AND and XOR masks */ /* Find Best Fit */
Height *= 2; iTotalDiff = 0xFFFFFFFF;
iColorDiff = 0xFFFFFFFF;
/* First find the largest one smaller than or equal to the requested size*/
MaxWidth = MaxHeight = 0;
for (i = 0; get_entry(dir, i, &cx, &cy, &Bits); i++ ) for (i = 0; get_entry(dir, i, &cx, &cy, &Bits); i++ )
{ {
if ((cx <= Width) && (cy <= Height) && iTempXDiff = abs(Width - cx);
(cx > MaxWidth) && (cy > MaxHeight) && iTempYDiff = abs(Height - cy);
(Bits == 1))
if(iTotalDiff > (iTempXDiff + iTempYDiff))
{ {
BestEntry = i; iXDiff = iTempXDiff;
MaxWidth = cx; iYDiff = iTempYDiff;
MaxHeight = cy; iTotalDiff = iXDiff + iYDiff;
} }
} }
if (BestEntry != -1)
return BestEntry;
/* Now find the smallest one larger than the requested size */ /* Find Best Colors for Best Fit */
MaxWidth = MaxHeight = 255;
for (i = 0; get_entry(dir, i, &cx, &cy, &Bits); i++ ) for (i = 0; get_entry(dir, i, &cx, &cy, &Bits); i++ )
{ {
if (((cx < MaxWidth) && (cy < MaxHeight) && (Bits == 1)) || if(abs(Width - cx) == iXDiff && abs(Height - cy) == iYDiff)
(BestEntry == -1))
{ {
BestEntry = i; iTempColorDiff = abs(ColorBits - Bits);
MaxWidth = cx; if(iColorDiff > iTempColorDiff)
MaxHeight = cy; {
BestEntry = i;
BestBits = Bits;
iColorDiff = iTempColorDiff;
}
} }
} }
DPRINT("Best Cursor: ResId: %d, bits : %d\n", BestEntry, BestBits);
return BestEntry; return BestEntry;
} }