1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
#include<stdio.h>
#include<stdlib.h>
#include<SDL/SDL.h>
int main(int argc, char *argv[])
{
int continuer = 1; //pour la boucle principale
int clickleft = 0;
SDL_Surface *ecran;
SDL_Surface *pointeur;
SDL_Rect positionPointeur;
SDL_Event event;
SDL_Init(SDL_INIT_VIDEO);
SDL_WM_SetCaption("Mon paint tentative 1",NULL);
ecran = SDL_SetVideoMode(640,480,32,SDL_HWSURFACE | SDL_DOUBLEBUF);
if(ecran == NULL)
{
fprintf(stderr,"Erreur d'initialisation %s\n",SDL_GetError());
exit(EXIT_FAILURE);
}
pointeur = SDL_LoadBMP("pointeur.bmp"); //chargement de l'image
//initialisation de la position du pointeur
positionPointeur.x = ecran->w/2 - pointeur->w/2;
positionPointeur.y = ecran->h/2 - pointeur->h/2;
SDL_ShowCursor(SDL_DISABLE);//masque le curseur de la souris
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format,255,255,255));
SDL_Flip(ecran);
while(continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT : continuer = 0;
break;
case SDL_MOUSEBUTTONDOWN:
switch (event.button.button)
{
case SDL_BUTTON_LEFT : clickleft=1;
break;
}
case SDL_MOUSEBUTTONUP:
switch (event.button.button)
{
case SDL_BUTTON_RIGHT :
//*pour effacer l'ecran
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
SDL_BlitSurface(pointeur,NULL,ecran,&positionPointeur);
SDL_Flip(ecran);
break;
case SDL_BUTTON_LEFT : clickleft=0;
}
case SDL_MOUSEMOTION:
positionPointeur.x = event.motion.x;
positionPointeur.y = event.motion.y;
break;
case SDL_KEYDOWN :
switch(event.key.keysym.sym)
{
case SDLK_ESCAPE : continuer = 0;
break;
}
break;
}
if(clickleft = 1)
/*Je n'ai pas trouver une methode pour coller continuellement le pointeur lors du clickleft=1 */
}
SDL_FreeSurface(pointeur);
SDL_Quit();
return EXIT_SUCCESS;
} |
Partager