SAE11_2023/src/timer.c

99 lines
2.7 KiB
C
Raw Normal View History

2023-12-02 10:13:12 +01:00
#include<stdio.h>
#include<stdlib.h>
#include<graph.h>
#define cycle 1000000L
2023-12-02 10:13:12 +01:00
unsigned long int attendre(void) {
unsigned long int temps_pause;
unsigned long int t1 = Microsecondes();
while (1) {
if (ToucheEnAttente() && Touche() == XK_space) {
break;
}
}
temps_pause = Microsecondes() - t1;
return temps_pause;
}
int afficher_seconde(int sec){
char timer[50];
int x = 120 ,y = 100;
if(sec<=9){
ChoisirCouleurDessin(CouleurParComposante(0, 0, 0));
RemplirRectangle(x-3,y-25,40,30);
ChoisirCouleurDessin(CouleurParComposante(255, 255, 255));
EcrireTexte(x,y,"0",2);
snprintf(timer,sizeof(timer),"%d",sec);
EcrireTexte(x+15,y,timer,2);
} else {
ChoisirCouleurDessin(CouleurParComposante(0, 0, 0));
RemplirRectangle(x-3,y-25,40,25);
ChoisirCouleurDessin(CouleurParComposante(255, 255, 255));
snprintf(timer,sizeof(timer),"%d",sec);
EcrireTexte(x,y,timer,2);
}
return sec;
}
int afficher_minute(int min){
char timer[50];
int x = 80 ,y = 100;
if(min<=9){
ChoisirCouleurDessin(CouleurParComposante(0, 0, 0));
RemplirRectangle(x-3,y-25,40,30);
ChoisirCouleurDessin(CouleurParComposante(255, 255, 255));
EcrireTexte(x,y,"0",2);
snprintf(timer,sizeof(timer),"%d",min);
EcrireTexte(110,100,":",2);
EcrireTexte(x+15,y,timer,2);
} else {
ChoisirCouleurDessin(CouleurParComposante(0, 0, 0));
RemplirRectangle(x-3,y-25,40,25);
ChoisirCouleurDessin(CouleurParComposante(255, 255, 255));
snprintf(timer,sizeof(timer),"%d",min);
EcrireTexte(110,100,":",2);
EcrireTexte(x,y,timer,2);
}
return min;
2023-12-05 21:22:05 +01:00
}
2023-12-02 10:13:12 +01:00
void creer_timer(void){
int sec = 0,min=0,x=1;
unsigned long int temps = 0,seconde,pause=0;
seconde=Microsecondes()+cycle;
afficher_seconde(sec);
afficher_minute(min);
EcrireTexte(110,100,":",2);
while(x=1){
if(Microsecondes()>seconde){
sec++;
afficher_seconde(sec);
seconde=Microsecondes()+cycle;
if(sec==60){
sec=0;
min++;
afficher_seconde(sec);
afficher_minute(min);
}
}
if(ToucheEnAttente()==1){
if(Touche()==XK_space){
pause=attendre();
}
if(Touche()==XK_Escape){
x=0;
}
}
2023-12-02 10:13:12 +01:00
}
}
/*
2023-12-02 10:13:12 +01:00
int main(void){
InitialiserGraphique();
CreerFenetre(1000,0,1000,1000);
2023-12-02 10:13:12 +01:00
creer_timer();
FermerGraphique();
2023-12-02 17:21:07 +01:00
return EXIT_SUCCESS;
}
*/