BUT2/DEV/DEV1.1_suite/TP_FILES/bouton.c~

50 lines
1.3 KiB
C
Raw Permalink Normal View History

2023-10-23 13:23:36 +02:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <graph.h>
typedef struct bouton{
int xmin;
int xmax;
int ymin;
int ymax;
}bouton;
void creerBouton(bouton** boutons){
int numBouton, x, y;
*boutons= (bouton*) malloc(4*sizeof(bouton));
for (numBouton=0, y=100; y<300; y+=150){
for (x=100; x<300; x+=150, numBouton++){
printf("%d) x=%d y=%d\n",numBouton,x,y);
boutons[numBouton]->xmin=x;
boutons[numBouton]->xmax=x+100;
boutons[numBouton]->ymin=y;
boutons[numBouton]->ymax=y+100;
printf("finis\n");
printf("%d %d %d %d\n",boutons[numBouton]->xmin,boutons[numBouton]->xmax,boutons[numBouton]->ymin,boutons[numBouton]->ymax);
}
}
}
void afficheBouton(bouton* boutons, int numBouton, int etat){
char chemin[21]="images/bouton?-?.png";
chemin[13]= (char) numBouton+48;
chemin[13]= etat;
ChargerImage(chemin,boutons[numBouton].xmin,boutons[numBouton].ymin,0,0,100,100);
}
int detectClic(bouton* boutons, int choix){
int numBouton;
while(SourisCliquee());
while(1){
while (SourisCliquee()==0){}
for (numBouton=0;numBouton<4; numBouton++){
if (_X<boutons[numBouton].xmax && _X>boutons[numBouton].xmin && _Y<boutons[numBouton].ymax && _Y>boutons[numBouton].ymin){
afficheBouton(boutons,choix,0);
return numBouton;
}
}
}
}