winex11: Add support for retrieving multi-rate animated cursor data.
This commit is contained in:
parent
3e35caa7b2
commit
eddffff780
|
@ -294,7 +294,7 @@ static XcursorImage *create_xcursor_frame( HDC hdc, const ICONINFOEXW *iinfo, HA
|
||||||
int width, int height, int istep )
|
int width, int height, int istep )
|
||||||
{
|
{
|
||||||
XcursorImage *image, *ret = NULL;
|
XcursorImage *image, *ret = NULL;
|
||||||
DWORD delay_jiffies, is_static;
|
DWORD delay_jiffies, num_steps;
|
||||||
int x, y, i, has_alpha;
|
int x, y, i, has_alpha;
|
||||||
XcursorPixel *ptr;
|
XcursorPixel *ptr;
|
||||||
|
|
||||||
|
@ -310,12 +310,11 @@ static XcursorImage *create_xcursor_frame( HDC hdc, const ICONINFOEXW *iinfo, HA
|
||||||
image->xhot = iinfo->xHotspot;
|
image->xhot = iinfo->xHotspot;
|
||||||
image->yhot = iinfo->yHotspot;
|
image->yhot = iinfo->yHotspot;
|
||||||
|
|
||||||
/* TODO: Handle animated cursors that use multiple rates */
|
|
||||||
image->delay = 100; /* fallback delay, 100 ms */
|
image->delay = 100; /* fallback delay, 100 ms */
|
||||||
if (GetCursorFrameInfo(icon, 0x0 /* unknown parameter */, 0 /* obtain first rate */, &delay_jiffies, &is_static) != 0)
|
if (GetCursorFrameInfo(icon, 0x0 /* unknown parameter */, istep, &delay_jiffies, &num_steps) != 0)
|
||||||
image->delay = (100 * delay_jiffies) / 6; /* convert jiffies (1/60s) to milliseconds */
|
image->delay = (100 * delay_jiffies) / 6; /* convert jiffies (1/60s) to milliseconds */
|
||||||
else
|
else
|
||||||
WARN("Failed to retrieve animated cursor framerate.\n");
|
WARN("Failed to retrieve animated cursor frame-rate for frame %d.\n", istep);
|
||||||
|
|
||||||
/* draw the cursor frame to a temporary buffer then copy it into the XcursorImage */
|
/* draw the cursor frame to a temporary buffer then copy it into the XcursorImage */
|
||||||
memset( color_bits, 0x00, color_size );
|
memset( color_bits, 0x00, color_size );
|
||||||
|
@ -366,14 +365,16 @@ static Cursor create_xcursor_cursor( HDC hdc, const ICONINFOEXW *iinfo, HANDLE i
|
||||||
{
|
{
|
||||||
unsigned char *color_bits, *mask_bits;
|
unsigned char *color_bits, *mask_bits;
|
||||||
HBITMAP hbmColor = 0, hbmMask = 0;
|
HBITMAP hbmColor = 0, hbmMask = 0;
|
||||||
XcursorImage **imgs, *image;
|
DWORD nFrames, delay_jiffies, i;
|
||||||
int color_size, mask_size;
|
int color_size, mask_size;
|
||||||
BITMAPINFO *info = NULL;
|
BITMAPINFO *info = NULL;
|
||||||
XcursorImages *images;
|
XcursorImages *images;
|
||||||
|
XcursorImage **imgs;
|
||||||
Cursor cursor = 0;
|
Cursor cursor = 0;
|
||||||
int nFrames = 0;
|
|
||||||
|
|
||||||
if (!(imgs = HeapAlloc( GetProcessHeap(), 0, sizeof(XcursorImage*) ))) return 0;
|
/* Retrieve the number of frames to render */
|
||||||
|
if (!GetCursorFrameInfo(icon, 0x0 /* unknown parameter */, 0, &delay_jiffies, &nFrames)) return 0;
|
||||||
|
if (!(imgs = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(XcursorImage*)*nFrames ))) return 0;
|
||||||
|
|
||||||
/* Allocate all of the resources necessary to obtain a cursor frame */
|
/* Allocate all of the resources necessary to obtain a cursor frame */
|
||||||
if (!(info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[256] )))) goto cleanup;
|
if (!(info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[256] )))) goto cleanup;
|
||||||
|
@ -406,19 +407,13 @@ static Cursor create_xcursor_cursor( HDC hdc, const ICONINFOEXW *iinfo, HANDLE i
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create an XcursorImage for each frame of the cursor */
|
/* Create an XcursorImage for each frame of the cursor */
|
||||||
while (1)
|
for (i=0; i<nFrames; i++)
|
||||||
{
|
{
|
||||||
XcursorImage **imgstmp;
|
imgs[i] = create_xcursor_frame( hdc, iinfo, icon,
|
||||||
|
|
||||||
image = create_xcursor_frame( hdc, iinfo, icon,
|
|
||||||
hbmColor, color_bits, color_size,
|
hbmColor, color_bits, color_size,
|
||||||
hbmMask, mask_bits, mask_size,
|
hbmMask, mask_bits, mask_size,
|
||||||
width, height, nFrames );
|
width, height, i );
|
||||||
if (!image) break; /* no more drawable frames */
|
if (!imgs[i]) goto cleanup;
|
||||||
|
|
||||||
imgs[nFrames++] = image;
|
|
||||||
if (!(imgstmp = HeapReAlloc( GetProcessHeap(), 0, imgs, (nFrames+1)*sizeof(XcursorImage*) ))) goto cleanup;
|
|
||||||
imgs = imgstmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Build an X cursor out of all of the frames */
|
/* Build an X cursor out of all of the frames */
|
||||||
|
@ -436,8 +431,8 @@ cleanup:
|
||||||
if (imgs)
|
if (imgs)
|
||||||
{
|
{
|
||||||
/* Failed to produce a cursor, free previously allocated frames */
|
/* Failed to produce a cursor, free previously allocated frames */
|
||||||
for (nFrames--; nFrames >= 0; nFrames--)
|
for (i=0; i<nFrames && imgs[i]; i++)
|
||||||
pXcursorImageDestroy( imgs[nFrames] );
|
pXcursorImageDestroy( imgs[i] );
|
||||||
HeapFree( GetProcessHeap(), 0, imgs );
|
HeapFree( GetProcessHeap(), 0, imgs );
|
||||||
}
|
}
|
||||||
/* Cleanup all of the resources used to obtain the frame data */
|
/* Cleanup all of the resources used to obtain the frame data */
|
||||||
|
|
Loading…
Reference in New Issue