using a bitmap as a custom cursor

Started by
15 comments, last by Moe 23 years, 9 months ago
Okay, I kinda figured it out, but there still is a few problems. I am working with a fullscreen exclusive window, so I am not worry about the position within the window (and I don''t have any menus, or anything). I know now that I have properly loaded the bitmaps, since I can see them. Now here is the updated code:

case WM_MOUSEMOVE:
{
DDCOLORKEY key;

key.dwColorSpaceLowValue = (0,0,0);
key.dwColorSpaceHighValue = (0,0,0);
//not sure which surface to set it on, the back??
lpddsback->SetColorKey(DDCKEY_SRCBLT,&key);
lpddsprimary->SetColorKey(DDCKEY_SRCBLT, &key);

lpddsback->Blt(NULL,lpbackground,NULL,DDBLT_WAIT,NULL);

//do that neat cursor thingy here
//extract mouse position
int mouse_x = (int)LOWORD(lparam);
int mouse_y = (int)HIWORD(lparam);
int buttons = (int)wparam;

RECT dest;
dest.left = mouse_x;
dest.top = mouse_y;
dest.right = mouse_x+32;
dest.bottom = mouse_y+32;


lpddsback->Blt(&dest,lpcursor,NULL,DDBLT_WAIT | DDCKEY_SRCBLT,NULL);


} break;

The colorkey doesn''t seem to work. I want a source colorkey so that no black will appear around the cursor. I have also implimented a background bitmap, and page flipping. Now heres the new problems:

When I can''t see the cursor bitmap at all. I am not sure what it causing that. When I turn off (comment out) the colorkeying can see it but it flickers and there appears to be a ''shadow'' copy of the cursor bitmap. Anyone seen anything like that before? (I should try to post the source code and demo at my website). Anyone?

Shrapnel Games
Advertisement
key.dwColorSpaceLowValue = (0,0,0);
key.dwColorSpaceHighValue = (0,0,0);

doesn''t look right...
you need a word creating macro for the correct display mode.
And how did you get (0,0,0) to compile?
I have not tried this yet (I''m implementing a mouse pointer in my prog tomorrow).

Try saving the location of your mouse pointer in a variable and doing the mouse draw code at the end of your main loop, just before you flip.

You may be drawing your mouse cursor behind your main objects, to test this out, comment out all calls from your main loop, but not the clear and flip calls.

Saving the position and then drawing when you know it will be displayed is far better then letting the event draw your cursor.
When I find my code in tons of trouble,Friends and colleages come to me,Speaking words of wisdom:"Write in C."My Web Site
I finally got it(mostly)! Saving the position of the mouse cursor in a global variable, then blitting it as the last thing in the main loop worked. But...
I still can''t seem to get that colorkeying to work. Whenever I add the flag into the blitting for the cursor, it dissapears entirely. I think the problem might be in setting the color key high and low values. I will have to look it up in one of my many books.

oh, and annonymous poster, it compiled fine. Quite surprising anything of mine compiles fine...

Shrapnel Games
Here''s the code I use to set the colour key to blank:

    DDBLTFX ddfx;ZeroMemory( &ddfx, sizeof( ddfx ) );ddfx.dwSize = sizeof( ddfx );ddfx.ddckSrcColorkey.dwColorSpaceLowValue = 0;ddfx.ddckSrcColorkey.dwColorSpaceHighValue = 0;Engine->BBuffer->Blt( &rect2, lpDDSBalls, &rect, DDBLT_KEYSRCOVERRIDE | DDBLT_WAIT, &ddfx );    


try that, i could not get the colour key to work on the surface itself, I had to inform the Blt() to use the DDBLTFX struct info.
When I find my code in tons of trouble,Friends and colleages come to me,Speaking words of wisdom:"Write in C."My Web Site
ddckey.dwColorSpaceHighValue = 0;ddckey.dwColorSpaceLowValue = 0;hrVal = lpcursor->SetColorKey( DDCKEY_SRCBLT, &ddckey );if( FAILED( hrVal ) )// error 


You want to set the color key on the cursor''s surface not the primary and back buffer surface. And I believe you only need to set it once, not every time the mouse moves.

hth
If you never set the colorkey of the cursor surface, and tried to blt with a src color key (using the cursor as the source) you should actully get an error during the blit (because there is no color key set) I believe and from what I can see you don''t check for any errors during the blit.

hth

This topic is closed to new replies.

Advertisement