From 6b9c8463967eafcc831a687dacb50bd7050620ca Mon Sep 17 00:00:00 2001 From: orfao Date: Thu, 7 Dec 2023 17:31:54 +0100 Subject: [PATCH] =?UTF-8?q?timer=20op=C3=A9rationnel=20+=20peut=20=C3=AAtr?= =?UTF-8?q?e=20mis=20en=20pause?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/timer.c | 94 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 81 insertions(+), 13 deletions(-) diff --git a/src/timer.c b/src/timer.c index ec2c69e..8af00ba 100644 --- a/src/timer.c +++ b/src/timer.c @@ -1,28 +1,96 @@ #include #include #include +#define cycle 1000000L -void afficher_timer(void){ - EcrireTexte(0,0,coucou,2); +unsigned long int attendre(void){ + int x=1; + unsigned long int temps_pause; + unsigned long int t1=Microsecondes(); + while(x==1){ + if(Touche()==XK_space){ + x=0; + } + } + 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; } void creer_timer(void){ - int sec = 0,mil_sec=0,min=0; - unsigned long temps = 0,t1=0; - t1=Microsecondes(); - while(min<=12){ - printf("[%0.2d:%0.2d]\n",min,sec); - temps=Microsecondes()-t1; - min=(temps/60000000)%60; - temps=temps%60000000; - sec=(temps/1000000)%60; - EcrireTexte(); + int sec = 0,min=0; + unsigned long int temps = 0,seconde,pause=0; + seconde=Microsecondes()+cycle; + afficher_seconde(sec); + afficher_minute(min); + EcrireTexte(110,100,":",2); + while(1){ + if(Microsecondes()>seconde){ + sec++; + printf("%d\n",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(); + } + } } } int main(void){ InitialiserGraphique(); + CreerFenetre(1000,0,1000,1000); creer_timer(); FermerGraphique(); return EXIT_SUCCESS; -} \ No newline at end of file +}