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
| #include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
int main(int argc, char *argv[])
{
// variables
SDL_Surface *ecran = NULL;
SDL_Event event;
unsigned char encore=1, c=200, mode=1;
int clic = 0;
// initialisation
SDL_Init(SDL_INIT_VIDEO);
ecran = SDL_SetVideoMode(400, 300, 32, SDL_HWSURFACE);
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, c, c, c));
// boucle
while(encore){
SDL_Delay(40);
while(SDL_PollEvent(&event));
if(event.type == SDL_QUIT) encore=0;
// changement de mode
if(event.type == SDL_MOUSEBUTTONUP){
if(event.button.button == SDL_BUTTON_RIGHT && clic){
clic = 0;
if(mode) mode=0; else mode=1;
if(mode) c=100; else c=200;
}
}
else if (event.type == SDL_MOUSEBUTTONDOWN) {
if (event.button.button == SDL_BUTTON_RIGHT)
clic = 1;
}
// mise à jour ecran
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, c, c, c));
SDL_Flip(ecran);
}
SDL_Quit();
return EXIT_SUCCESS;
} |
Partager