TwilCynder

Un code bien sale qui est supposé afficher un chronomètre

May 7th, 2017
611
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Procedure ButtonChrono(ChronoBaseText$,ChronoFontID,ChronoFontColor,ButtonFontID,ButtonHeight=75,ButtonWidth=100,ChronoHeight=100,ChronoWidth=500,ButtonTextX=30,ButtonTextY=15,ChronoTextX=10,ChronoTextY=50,ButtonBackColor=0,ButtonFrontColorPassive=$0000BB,ButtonFrontColorActive=255,ChronoImageBack=0,ChronoImageFront=0)
  2.  
  3. ChronoTime.l
  4. ChronoPauseStartTime.l
  5. ChronoPauseTime.l
  6.  
  7. Macro UpdateChronoText
  8.  
  9.  
  10.   ChronoTimeSeconds = ChronoTime / 1000
  11.   ChronoText$ = FormatDate(ChronoBaseText$,ChronoTimeSeconds)
  12.   ChronoText$ = ReplaceString(ChronoText$,"%h",Str(Hour(ChronoTimeSeconds)))
  13.   ChronoText$ = ReplaceString(ChronoText$,"%i",Str(Minute(ChronoTimeSeconds)))
  14.   ChronoText$ = ReplaceString(ChronoText$,"%s",Str(Second(ChronoTimeSeconds)))
  15.   ChronoText$ = ReplaceString(ChronoText$,"%cc",RSet(Str((ChronoTime - ((ChronoTimeSeconds)*1000))/10),2,"0"))
  16.   ChronoText$ = ReplaceString(ChronoText$,"%mll",RSet(Str(ChronoTime - ChronoTimeSeconds*1000),3,"0"))
  17.   ChronoText$ = ReplaceString(ChronoText$,"%c",Str((ChronoTime - ((ChronoTimeSeconds)*1000))/10))
  18.   ChronoText$ = ReplaceString(ChronoText$,"%ml",Str(ChronoTime - ((ChronoTimeSeconds)*1000)))
  19.   ChronoText$ = ReplaceString(ChronoText$,"%ti",Str(ChronoTimeSeconds/60))
  20.   ChronoText$ = ReplaceString(ChronoText$,"%ts",Str(ChronoTimeSeconds))
  21.   ChronoText$ = ReplaceString(ChronoText$,"%tml",Str(ChronoTime))
  22.  
  23.   If ChronoBaseText$ = ChronoText$
  24.     ChronoText$ = ChronoBaseText$ + Str(ChronoTime)
  25.   EndIf
  26. EndMacro  
  27.  
  28. Dim ImageButton(2,1)
  29.  
  30.  
  31. ;- Bouton Start
  32.  ImageButton(0,0) =  CreateImage(#PB_Any,ButtonWidth,ButtonHeight)  
  33.     StartDrawing(ImageOutput(ImageButton(0,0)))
  34.     Box(0,0,ButtonWidth,ButtonHeight,ButtonFrontColorActive)
  35.     Box(3,3,ButtonWidth-6,ButtonHeight-6,ButtonBackColor)
  36.     DrawingFont(ButtonFontID)
  37.     DrawText(ButtonTextX,ButtonTextY,"Start",ButtonFrontColorActive,ButtonBackColor)
  38.     StopDrawing()
  39.    
  40.  ImageButton(1,0) =  CreateImage(#PB_Any,ButtonWidth,ButtonHeight)  
  41.     StartDrawing(ImageOutput(ImageButton(1,0)))
  42.     Box(0,0,ButtonWidth,ButtonHeight,ButtonFrontColorActive)
  43.     Box(6,6,ButtonWidth-12,ButtonHeight-12,ButtonBackColor)
  44.     DrawingFont(ButtonFontID)
  45.     DrawText(ButtonTextX,ButtonTextY,"Start",ButtonFrontColorActive,ButtonBackColor)
  46.     StopDrawing()
  47.    
  48.  ImageButton(2,0) = CreateImage(#PB_Any,ButtonWidth,ButtonHeight)  
  49.     StartDrawing(ImageOutput(ImageButton(2,0)))
  50.     Box(0,0,ButtonWidth,ButtonHeight,ButtonFrontColorPassive)
  51.     Box(3,3,ButtonWidth-6,ButtonHeight-6,ButtonBackColor)
  52.     DrawingFont(ButtonFontID)
  53.     DrawText(ButtonTextX,ButtonTextY,"Start",ButtonFrontColorPassive,ButtonBackColor)
  54.     StopDrawing()
  55.    
  56. ;- Bouton Stop    
  57.    
  58.    ImageButton(0,1) =  CreateImage(#PB_Any,ButtonWidth,ButtonHeight)  
  59.     StartDrawing(ImageOutput(ImageButton(0,1)))
  60.     Box(0,0,ButtonWidth,ButtonHeight,ButtonFrontColorActive)
  61.     Box(3,3,ButtonWidth-6,ButtonHeight-6,ButtonBackColor)
  62.     DrawingFont(ButtonFontID)
  63.     DrawText(ButtonTextX,ButtonTextY,"Stop",ButtonFrontColorActive,ButtonBackColor)
  64.     StopDrawing()
  65.    
  66.  ImageButton(1,1) =  CreateImage(#PB_Any,ButtonWidth,ButtonHeight)  
  67.     StartDrawing(ImageOutput(ImageButton(1,1)))
  68.     Box(0,0,ButtonWidth,ButtonHeight,ButtonFrontColorActive)
  69.     Box(6,6,ButtonWidth-12,ButtonHeight-12,ButtonBackColor)
  70.     DrawingFont(ButtonFontID)
  71.     DrawText(ButtonTextX,ButtonTextY,"Stop",ButtonFrontColorActive,ButtonBackColor)
  72.     StopDrawing()
  73.    
  74.  ImageButton(2,1) = CreateImage(#PB_Any,ButtonWidth,ButtonHeight)  
  75.     StartDrawing(ImageOutput(ImageButton(2,1)))
  76.     Box(0,0,ButtonWidth,ButtonHeight,ButtonFrontColorPassive)
  77.     Box(3,3,ButtonWidth-6,ButtonHeight-6,ButtonBackColor)
  78.     DrawingFont(ButtonFontID)
  79.     DrawText(ButtonTextX,ButtonTextY,"Stop",ButtonFrontColorPassive,ButtonBackColor)
  80.     StopDrawing()  
  81.    
  82.     ;- Bouton Reset
  83.    
  84.      ImageButtonReset0 =  CreateImage(#PB_Any,ButtonWidth,ButtonHeight)  
  85.     StartDrawing(ImageOutput(ImageButtonReset0))
  86.     Box(0,0,ButtonWidth,ButtonHeight,ButtonFrontColorActive)
  87.     Box(3,3,ButtonWidth-6,ButtonHeight-6,ButtonBackColor)
  88.     DrawingFont(ButtonFontID)
  89.     DrawText(ButtonTextX,ButtonTextY,"Reset",ButtonFrontColorActive,ButtonBackColor)
  90.     StopDrawing()
  91.    
  92.  ImageButtonReset1 =  CreateImage(#PB_Any,ButtonWidth,ButtonHeight)  
  93.     StartDrawing(ImageOutput(ImageButtonReset1))
  94.     Box(0,0,ButtonWidth,ButtonHeight,ButtonFrontColorActive)
  95.     Box(6,6,ButtonWidth-12,ButtonHeight-12,ButtonBackColor)
  96.     DrawingFont(ButtonFontID)
  97.     DrawText(ButtonTextX,ButtonTextY,"Reset",ButtonFrontColorActive,ButtonBackColor)
  98.     StopDrawing()
  99.    
  100.  ImageButtonReset2 = CreateImage(#PB_Any,ButtonWidth,ButtonHeight)  
  101.     StartDrawing(ImageOutput(ImageButtonReset2))
  102.     Box(0,0,ButtonWidth,ButtonHeight,ButtonFrontColorPassive)
  103.     Box(3,3,ButtonWidth-6,ButtonHeight-6,ButtonBackColor)
  104.     DrawingFont(ButtonFontID)
  105.     DrawText(ButtonTextX,ButtonTextY,"Reset",ButtonFrontColorPassive,ButtonBackColor)
  106.     StopDrawing()
  107.    
  108. ButtonWindow = OpenWindow(#PB_Any,0,0,ButtonWidth*2+30,ButtonHeight+20,"Button")
  109. ButtonCanvas = CanvasGadget(#PB_Any,10,10,ButtonWidth,ButtonHeight,#PB_Canvas_Keyboard)
  110. ButtonResetCanvas = CanvasGadget(#PB_Any,ButtonWidth+20,10,ButtonWidth,ButtonHeight,#PB_Canvas_Keyboard)
  111. AddKeyboardShortcut(ButtonWindow,#PB_Shortcut_Control | #PB_Shortcut_Shift | #PB_Shortcut_M,3)
  112.  
  113. ChronoWindow = OpenWindow(#PB_Any,0,0,ChronoWidth,ChronoHeight,"Chrono",#PB_Window_BorderLess|#PB_Window_ScreenCentered)
  114. ChronoCanvas = CanvasGadget(#PB_Any,0,0,ChronoWidth,ChronoHeight)
  115.  
  116. UpdateChronoText
  117. StartDrawing(CanvasOutput(ChronoCanvas))
  118. Box(0,0,ChronoWidth,ChronoHeight,0)
  119. DrawingMode(#PB_2DDrawing_Transparent)
  120. If Not ChronoImageBack = 0
  121.   DrawImage(ChronoImageBack,0,0)
  122. Else
  123.   Box(0,0,ChronoWidth,ChronoHeight,0)
  124. EndIf  
  125. DrawingFont(ChronoFontID)
  126. DrawText(10,5,ChronoText$,ChronoFontColor)
  127. If Not ChronoImageFront = 0
  128.   DrawImage(ChronoImageFront,0,0)
  129. EndIf  
  130. StopDrawing()  
  131.  
  132. Macro UpdateChrono        
  133. StartDrawing(CanvasOutput(ChronoCanvas))
  134. Box(0,0,ChronoWidth,ChronoHeight,0)
  135. DrawingMode(#PB_2DDrawing_Transparent)
  136. If Not ChronoImageBack = 0
  137.   DrawImage(ChronoImageBack,0,0)
  138. Else
  139.   Box(0,0,ChronoWidth,ChronoHeight,0)
  140. EndIf  
  141. DrawingFont(ChronoFontID)
  142. DrawText(10,5,ChronoText$,ChronoFontColor)
  143. If Not ChronoImageFront = 0
  144.   DrawImage(ChronoImageFront,0,0)
  145. EndIf  
  146. StopDrawing()
  147. EndMacro                      
  148.  
  149. Pause = 1
  150. ChronoPauseStartTime = ElapsedMilliseconds()
  151. SetGadgetAttribute(ButtonCanvas,#PB_Canvas_Image,ImageID(ImageButton(2,0)))
  152.  
  153.  
  154. ChronoStartTime = ElapsedMilliseconds()
  155.  
  156.  
  157. Repeat
  158.  
  159.  ; Time = ElapsedMilliseconds()
  160.  ; ElapsedTime = Time - PreviousTime
  161.  ; previousTime = Time
  162.  
  163.  
  164.   ChronoTime = (ElapsedMilliseconds - ChronoStartTime) - ChronoPauseTime
  165.   If Pause = 1
  166.     ChronoTime - (ElapsedMilliseconds() - ChronoPauseStartTime)
  167.   EndIf  
  168.  
  169.   UpdateChrono
  170.  
  171.    WindowEvent = WaitWindowEvent()
  172.       Select WindowEvent
  173.         Case #PB_Event_Gadget
  174.           EventGadget = EventGadget()
  175.           Select EventGadget
  176.             Case ButtonCanvas
  177.               Select EventType()
  178.                   Case #PB_EventType_LeftClick
  179.                     Pause = 1 - Pause
  180.                     If Pause = 1
  181.                       ChronoPauseStartTime = ElapsedMilliseconds()
  182.                     Else
  183.                       ChronoPauseTime + (ElapsedMilliseconds() - ChronoPauseStartTime)
  184.                     EndIf
  185.                    
  186.                   Case #PB_EventType_MouseLeave, #PB_EventType_LostFocus
  187.                     ActivateRUNbutton = 0
  188.                     SetGadgetAttribute(ButtonCanvas,#PB_Canvas_Image,ImageID(ImageButton(2,1-Pause)))  
  189.                   Case #PB_EventType_MouseEnter, #PB_EventType_Focus
  190.                     ActivateRUNbutton = 1
  191.                     SetGadgetAttribute(ButtonCanvas,#PB_Canvas_Image,ImageID(ImageButton(0,1-Pause)))
  192.                   Case #PB_EventType_LeftButtonDown
  193.                     If ActivateRUNbutton = 1
  194.                       SetGadgetAttribute(ButtonCanvas,#PB_Canvas_Image,ImageID(ImageButton(1,1-Pause)))
  195.                     EndIf  
  196.                   Case #PB_EventType_LeftButtonUp
  197.                     SetGadgetAttribute(ButtonCanvas,#PB_Canvas_Image,ImageID(ImageButton(0,Pause)))  
  198.                 EndSelect    
  199.             Case ButtonResetCanvas
  200.               Select EventType()
  201.                   Case #PB_EventType_LeftClick
  202.                     ChronoStartTime = ElapsedMilliseconds()
  203.                   Case #PB_EventType_MouseLeave, #PB_EventType_LostFocus
  204.                     ActivateRUNbutton = 0
  205.                     SetGadgetAttribute(ButtonResetCanvas,#PB_Canvas_Image,ImageID(ImageButtonReset2))  
  206.                   Case #PB_EventType_MouseEnter, #PB_EventType_Focus
  207.                     ActivateRUNbutton = 1
  208.                     SetGadgetAttribute(ButtonResetCanvas,#PB_Canvas_Image,ImageID(ImageButtonReset0))  
  209.                   Case #PB_EventType_LeftButtonDown
  210.                     If ActivateRUNbutton = 1
  211.                       SetGadgetAttribute(ButtonResetCanvas,#PB_Canvas_Image,ImageID(ImageButtonReset1))
  212.                     EndIf  
  213.                   Case #PB_EventType_LeftButtonUp
  214.                     SetGadgetAttribute(ButtonResetCanvas,#PB_Canvas_Image,ImageID(ImageButtonReset2))  
  215.                 EndSelect        
  216.           EndSelect
  217.         Case #PB_Event_DeactivateWindow
  218.           RUNbuttonKeyboardActivated = 0
  219.           RUNbuttonMouseActivated = 0
  220.        EndSelect  
  221.   Delay(15)
  222. Until WindowEvent = #PB_Event_CloseWindow
  223.  
  224. EndProcedure
RAW Paste Data