hi,
the following function puts a bitmap(cross-hair) where the current mouse
pointer is on the surface. So the idea is to move the cross-hair when we move
the mouse. Its working but the only problem is that ugly pointer trails are
left behind. I tried clearing the screen (with SDL_FillRect()) before after
Blit but that does’nt seem to work.
Is there some way to refresh the surface so I can remove the trails ?
thanks,
nasir-------------------------------------------------------------------------------------------------------------------
#include “SDL.h”
static char *crosshair = “./crosshair.bmp”;
void display_bmp(SDL_Surface *screen,char *bmp,int xcord,int ycord)
{
SDL_Surface *image;
SDL_Rect src,dest;
SDL_Color black={0,0,0,0};
int x;
image = SDL_LoadBMP(bmp);
if(image==NULL)
{
printf("Failed loading bitmap");
return;
}
src.x=0;
src.y=0;
src.h=image->h;
src.w=image->w;
dest.x=xcord;
dest.y=ycord;
dest.h=image->h;
dest.w=image->w;
if(SDL_BlitSurface(image,&src,screen,&dest)<0)
{
printf("error blitting : %s\n",SDL_GetError());
return;
}
SDL_UpdateRect(screen,xcord,ycord,image->h,image->w);
SDL_FreeSurface(image);
// SDL_FillRect(screen,&dest,0);
}
int main()
{
SDL_Surface *screen;
if(SDL_Init(SDL_INIT_VIDEO)<0)
{
printf("Failed Initializing Video : %s\n",SDL_GetError());
exit(1);
}
atexit(SDL_Quit);
// Dont show the mouse cursor
SDL_ShowCursor(0);
screen = SDL_SetVideoMode(800,768,16,SDL_HWSURFACE|SDL_ANYFORMAT);
if(screen==NULL)
{
printf("Error setting video mode : %s",SDL_GetError());
exit(1);
}
SDL_Event event;
for(;;)
{
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_KEYDOWN: // Press escape to exit
if(event.key.keysym.sym == SDLK_ESCAPE)
{
SDL_Quit();
exit(0);
break;
}
case SDL_MOUSEMOTION: // throw current mouse co-ordinates on title bar
{ // this is where the cross-hair will be thrown
// SDL_FillRect(screen,NULL,0);
display_bmp(screen,crosshair,event.motion.x,event.motion.y);
break;
}
default:
// unhandled events
break;
}
}
}
return 0;
}