in attach the file
“In questo non paese non c’e’ un un solo beota, lo facciamo tutti
a turno”–
Michel Morelli michel at enter.it
http://ziobudda.enter.it
Italian Linux FAQ http://ziobudda.enter.it/FAQ/
Italian Linux Press http://ziobudda.enter.it/ILP/
-------------- next part --------------
#include "SDL.h"
SDL_Event event;
SDL_Rect rett;
int MouseInRect()
{ printf(“dati event: %d - %d\n dati rett: %d - %d - %d - %d”,event.motion.x,
event.motion.y, rett.x,rett.y, rett.x+rett.w,rett.y+rett.h);
if (event.motion.x > rett.x &&
event.motion.x < (rett.x+rett.w) &&
event.motion.y > rett.y &&
event.motion.y < (rett.y+rett.h))
{ return (0);
}
else {
return(1);
}
}
/* This function may run in a separate event thread */
int FilterEvents(const SDL_Event *event) {
static int boycott = 1;
printf("Event type = %d\n",event->type);
if ( event->type == SDL_MOUSEMOTION ) {
/*printf("Mouse moved to (%d,%d)\n",
event->motion.x, event->motion.y);
*/
if (MouseInRect())
{ printf("mouse nel rett\n");
}
else { printf("mouse non nel rett\n");
}
return(0); /* Drop it, we've handled it */
}
else {
if (event->type == SDL_KEYDOWN)
{ printf("pulito!!!");
exit(0);
}
}
return(1);
}
/*
** Function name : main
**
** Description :
** Input :
** Output :
*/
int main(void)
{ SDL_Surface *screen, *screen2;
char *bmpfile = “”;
int i;
SDL_Surface *picture;
Uint32 color2;
//SDL_Rect rett;
//SDL_Event event;
rett.x=10; rett.y=10; rett.w=100; rett.h=100;
/* Initialize the SDL library */
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr,
“Couldn’t initialize SDL: %s\n”, SDL_GetError());
exit(1);
}
/* Clean up on exit */
atexit(SDL_Quit);
SDL_EventState(SDL_KEYDOWN,SDL_ENABLE);
//SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
SDL_SetEventFilter(FilterEvents);
/* Initialize the display in a 640x480 8-bit palettized mode */
screen = SDL_SetVideoMode(640, 480, 8, 0);
if ( screen == NULL ) {
fprintf(stderr, “Couldn’t set 640x480x8 video mode: %s\n”,
SDL_GetError());
exit(1);
}
/* Definisco lo sfondo */
if ( SDL_LockSurface(screen) == 0 ) {
Uint32 black;
Uint8 *pixels;
black = SDL_MapRGB(screen->format, 10, 50, 90);
color2 = SDL_MapRGB(screen->format, 100,100,100);
SDL_FillRect(screen, NULL, black);
SDL_FillRect(screen, &rett, color2);
SDL_UnlockSurface(screen);
SDL_UpdateRect(screen, 0, 0, 0, 0);
}
if ( bmpfile == NULL ) {
bmpfile = “sample.bmp”; /* Sample image */
}
picture = SDL_LoadBMP(bmpfile);
/* Definisco lo sfondo */
while ( SDL_WaitEvent(&event) >= 0 ) {
}
}