[Rés] Comment éviter qu'un événement ne se reproduise intemp
Publié : ven. 04/mars/2016 11:14
Bonjour à tous,
j'ai programmé une horloge avec en plus, les jours de semaines et les jours du mois et un tic pour les secondes.
Malheureusement, si on bouge la souris dans l'image, ce n'est plus un tic qu'on entend, mais un compteur Geiger, d'où ma question comment éviter qu'un événement ne se reproduise intempestivement.
j'ai programmé une horloge avec en plus, les jours de semaines et les jours du mois et un tic pour les secondes.
Malheureusement, si on bouge la souris dans l'image, ce n'est plus un tic qu'on entend, mais un compteur Geiger, d'où ma question comment éviter qu'un événement ne se reproduise intempestivement.
Code : Tout sélectionner
EnableExplicit
Enumeration
#Fenetre_principale
EndEnumeration
Enumeration
#Trotteuse
#GrandeAiguille
#PetiteAiguille
#Spr_Jour_Sem
#Spr_Jour_Mois
#Fond
#Son
EndEnumeration
Enumeration Font
#FontHeure
#FontMinute
#FontHeureGrasse
EndEnumeration
Define.l Evenement, EvenementGadget
Global StyleFen.i=#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_ScreenCentered
Global Image.i
Global XC.i, YC.i, Rayon.i ;Coordonnées et rayon du point central du cercle
Global X.f, Y.f ;Coordonnées des points sur le cercle
Global N.i, Nj.f, xsec.s, xmin.s, xheure.s, xjour.s, s, m, h, j, jm, TailleImage = 1000, Texte.s, Jour.s, Digit, Tampon.s
If InitSprite()
Else
End
EndIf
If InitSound()
Else
End
EndIf
OpenWindow(#Fenetre_principale, 0, 0, TailleImage, TailleImage, "Horloge calendrier", StyleFen)
If OpenWindowedScreen(WindowID(#Fenetre_principale), 0, 0, TailleImage, TailleImage, 1, 0, 0)
CatchSound(#son, ?Son)
SoundVolume(#son, 20)
CreateSprite(#Spr_Jour_Sem, 800, 800)
CreateSprite(#Spr_Jour_Mois, 800, 800)
CreateSprite(#Trotteuse, 800, 800)
CreateSprite(#GrandeAiguille, 800, 800)
CreateSprite(#PetiteAiguille, 800, 800)
CreateSprite(#Fond, 800, 800)
LoadFont(#FontHeure, "Arial", 30, #PB_Font_Bold)
LoadFont(#FontMinute, "Arial", 15)
LoadFont(#FontHeureGrasse, "Arial", 40, #PB_Font_Bold)
If StartDrawing(SpriteOutput(#Spr_Jour_Sem))
LineXY(398, 400, 398, 265, $23F5C8)
LineXY(399, 400, 399, 260, $23F5C8)
LineXY(400, 400, 400, 255, $23F5C8)
LineXY(401, 400, 401, 260, $23F5C8)
LineXY(402, 400, 402, 265, $23F5C8)
Circle(400, 400, 15, $23F5C8)
StopDrawing()
EndIf
If StartDrawing(SpriteOutput(#Spr_Jour_Mois))
LineXY(398, 400, 398, 225, $23F5C8)
LineXY(399, 400, 399, 220, $23F5C8)
LineXY(400, 400, 400, 215, $23F5C8)
LineXY(401, 400, 401, 210, $23F5C8)
LineXY(402, 400, 402, 215, $23F5C8)
Circle(400, 400, 15, $23F5C8) ;Centre
StopDrawing()
EndIf
If StartDrawing(SpriteOutput(#Trotteuse))
LineXY(398, 550, 398, 65, $2323C8)
LineXY(399, 550, 399, 60, $2323C8)
LineXY(400, 550, 400, 55, $2323C8)
LineXY(401, 550, 401, 60, $2323C8)
LineXY(402, 550, 402, 65, $2323C8)
Circle(400, 530, 10, $2323C8) ; la
Circle(400, 535, 9, $2323C8) ; queue
Circle(400, 540, 8, $2323C8) ; de
Circle(400, 545, 7, $2323C8) ; la
Circle(400, 550, 6, $2323C8) ; trotteuse
Circle(400, 400, 15, $2323C8) ;le centre de la trotteuse
Circle(400, 400, 25, $2323C8)
StopDrawing()
EndIf
If StartDrawing(SpriteOutput(#GrandeAiguille))
LineXY(390, 400, 390, 20, $FF)
LineXY(390, 20, 400, 12, $FF) ;\
LineXY(400, 12, 410, 20, $FF) ;/
LineXY(410, 20, 410, 400, $FF)
LineXY(410, 400, 390, 400, $FF)
FillArea(400, 300, $FF, $FFFFFF)
Circle(400, 400, 10, $FF)
StopDrawing()
EndIf
If StartDrawing(SpriteOutput(#PetiteAiguille))
LineXY(390, 160, 390, 410, $FF)
LineXY(390, 160, 400, 145, $FF) ;pointe \
LineXY(400, 145, 410, 160, $FF) ;pointe /
LineXY(410, 160, 410, 410, $FF)
LineXY(390, 410, 410, 410, $FF)
FillArea(400, 300, $FF, $FFFFFF)
StopDrawing()
EndIf
If StartDrawing(SpriteOutput(#Fond)) ;- fond
;Coordonnées et rayon du point central du cercle
XC = 400
YC = 400
Circle(XC, YC, 800, $600000) ;Contour
;Point central
Circle(XC, YC, 400, $E13736)
;Les secondes (0 à 59)
Rayon = 350
For N = 0 To 364 Step 6
X = XC + Rayon * Cos(N * #PI / 180)
Y = YC + Rayon * Sin(N * #PI / 180)
Circle(X,Y,3, $97FB98)
Next
;Les jours de semaine (lundi à dimanche)
Rayon = 150
Circle(XC, YC, 200, $FF0000)
DrawText(400-TextWidth("Dim")/2, 235, "Dim", $00FFFF, $FF0000)
DrawText(515, 290, "Lun", $00FFFF, $FF0000)
DrawText(545, 425, "Mar", $00FFFF, $FF0000)
DrawText(455, 535, "Mer", $00FFFF, $FF0000)
DrawText(345-TextWidth("Jeu"), 535, "Jeu", $00FFFF, $FF0000)
DrawText(255-TextWidth("Ven"), 435, "Ven", $00FFFF, $FF0000)
DrawText(280-TextWidth("Sam"), 290, "Sam", $00FFFF, $FF0000)
;Les Chiffres des jours (1 à 31)
Digit=0
Rayon = 190
Nj.f = 0
While Nj < 360
Digit+1
X = XC + Rayon * Cos(Nj * #PI / 180)
Y = YC + Rayon * Sin(Nj * #PI / 180)
Tampon=Str(Digit)
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(X-TextWidth(Tampon)/2, Y-TextHeight(Tampon)/2, Tampon, RGB(255, 255, 0))
DrawingMode(#PB_2DDrawing_Default)
Nj + 11.613
Wend
;Les Chiffres des heures (1 à 12)
Digit=2
Rayon = 270
DrawingFont(FontID(#FontHeure))
For N = 0 To 345 Step 30
Digit+1
If Digit>12
Digit = Mod(12,4) + 1
EndIf
X = XC + Rayon * Cos(N * #PI / 180)
Y = YC + Rayon * Sin(N * #PI / 180)
Tampon=Str(Digit)
DrawingMode(#PB_2DDrawing_Transparent)
If Digit % 3 <> 0
DrawText(X-TextWidth(Tampon)/2, Y-TextHeight(Tampon)/2, Tampon, RGB(255, 255, 255))
ElseIf Digit % 3 = 0
DrawingFont(FontID(#FontHeureGrasse))
DrawText(X-TextWidth(Tampon)/2, Y-TextHeight(Tampon)/2, Tampon, RGB(255, 255, 255))
DrawingFont(FontID(#FontHeure))
EndIf
DrawingMode(#PB_2DDrawing_Default)
Next
;Les Chiffres des minutes (0 à 59)
Digit=15
Rayon = 390
DrawingFont(FontID(#FontMinute))
For N = 0 To 359 Step 6
Digit+1
If Digit>60
Digit = 1
EndIf
X = XC + Rayon * Cos(N * #PI / 180)
Y = YC + Rayon * Sin(N * #PI / 180)
Tampon=Str(Digit-1)
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(X-TextWidth(Tampon)/2, Y-TextHeight(Tampon)/2, Tampon, RGB(255, 255, 255))
DrawingMode(#PB_2DDrawing_Default)
Next
StopDrawing()
EndIf
EndIf
Repeat
PlaySound(#son)
Evenement = WaitWindowEvent(1000)
EvenementGadget = EventGadget()
ClearScreen(RGB(0, 0, 0))
xsec.s = FormatDate("%ss", Date())
xmin.s = FormatDate("%ii", Date())
xheure.s = FormatDate("%hh", Date())
xjour.s = FormatDate("%dd", Date())
jm = (Val(xjour)-1)*11.613
If Val(xheure) > 11
xheure = Str(Val(xheure)-12)
EndIf
s = Val(xsec) * 6
m = (Val(xmin) * 60 + Val(xsec)) / 10
h = (Val(xheure) * 60 + Val(xmin)) / 2
j = DayOfWeek(Date()) * (360 / 7)
ZoomSprite(#Trotteuse, TailleImage, TailleImage)
ZoomSprite(#GrandeAiguille, TailleImage, TailleImage)
ZoomSprite(#PetiteAiguille, TailleImage, TailleImage)
ZoomSprite(#Spr_Jour_Sem, TailleImage, TailleImage)
ZoomSprite(#Spr_Jour_Mois, TailleImage, TailleImage)
ZoomSprite(#Fond, TailleImage, TailleImage)
RotateSprite(#Trotteuse, s, 0)
RotateSprite(#GrandeAiguille, m, 0)
RotateSprite(#PetiteAiguille, h, 0)
RotateSprite(#Spr_Jour_Sem, j, 0)
RotateSprite(#Spr_Jour_Mois, jm+90, 0)
DisplayTransparentSprite(#Fond, 0, 0, 255)
DisplayTransparentSprite(#Spr_Jour_Sem, 0, 0, 255)
DisplayTransparentSprite(#Spr_Jour_Mois, 0, 0, 255)
DisplayTransparentSprite(#PetiteAiguille, 0, 0, 255)
DisplayTransparentSprite(#GrandeAiguille, 0, 0, 255)
DisplayTransparentSprite(#Trotteuse, 0, 0, 255)
FlipBuffers()
Delay(20)
Select Evenement
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
DataSection
Son:
IncludeBinary #PB_Compiler_FilePath + "\Data\Tic.Wav"
FinSon:
EndDataSection