Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
- ChronoTime.l
- ChronoPauseStartTime.l
- ChronoPauseTime.l
- Macro UpdateChronoText
- ChronoTimeSeconds = ChronoTime / 1000
- ChronoText$ = FormatDate(ChronoBaseText$,ChronoTimeSeconds)
- ChronoText$ = ReplaceString(ChronoText$,"%h",Str(Hour(ChronoTimeSeconds)))
- ChronoText$ = ReplaceString(ChronoText$,"%i",Str(Minute(ChronoTimeSeconds)))
- ChronoText$ = ReplaceString(ChronoText$,"%s",Str(Second(ChronoTimeSeconds)))
- ChronoText$ = ReplaceString(ChronoText$,"%cc",RSet(Str((ChronoTime - ((ChronoTimeSeconds)*1000))/10),2,"0"))
- ChronoText$ = ReplaceString(ChronoText$,"%mll",RSet(Str(ChronoTime - ChronoTimeSeconds*1000),3,"0"))
- ChronoText$ = ReplaceString(ChronoText$,"%c",Str((ChronoTime - ((ChronoTimeSeconds)*1000))/10))
- ChronoText$ = ReplaceString(ChronoText$,"%ml",Str(ChronoTime - ((ChronoTimeSeconds)*1000)))
- ChronoText$ = ReplaceString(ChronoText$,"%ti",Str(ChronoTimeSeconds/60))
- ChronoText$ = ReplaceString(ChronoText$,"%ts",Str(ChronoTimeSeconds))
- ChronoText$ = ReplaceString(ChronoText$,"%tml",Str(ChronoTime))
- If ChronoBaseText$ = ChronoText$
- ChronoText$ = ChronoBaseText$ + Str(ChronoTime)
- EndIf
- EndMacro
- Dim ImageButton(2,1)
- ;- Bouton Start
- ImageButton(0,0) = CreateImage(#PB_Any,ButtonWidth,ButtonHeight)
- StartDrawing(ImageOutput(ImageButton(0,0)))
- Box(0,0,ButtonWidth,ButtonHeight,ButtonFrontColorActive)
- Box(3,3,ButtonWidth-6,ButtonHeight-6,ButtonBackColor)
- DrawingFont(ButtonFontID)
- DrawText(ButtonTextX,ButtonTextY,"Start",ButtonFrontColorActive,ButtonBackColor)
- StopDrawing()
- ImageButton(1,0) = CreateImage(#PB_Any,ButtonWidth,ButtonHeight)
- StartDrawing(ImageOutput(ImageButton(1,0)))
- Box(0,0,ButtonWidth,ButtonHeight,ButtonFrontColorActive)
- Box(6,6,ButtonWidth-12,ButtonHeight-12,ButtonBackColor)
- DrawingFont(ButtonFontID)
- DrawText(ButtonTextX,ButtonTextY,"Start",ButtonFrontColorActive,ButtonBackColor)
- StopDrawing()
- ImageButton(2,0) = CreateImage(#PB_Any,ButtonWidth,ButtonHeight)
- StartDrawing(ImageOutput(ImageButton(2,0)))
- Box(0,0,ButtonWidth,ButtonHeight,ButtonFrontColorPassive)
- Box(3,3,ButtonWidth-6,ButtonHeight-6,ButtonBackColor)
- DrawingFont(ButtonFontID)
- DrawText(ButtonTextX,ButtonTextY,"Start",ButtonFrontColorPassive,ButtonBackColor)
- StopDrawing()
- ;- Bouton Stop
- ImageButton(0,1) = CreateImage(#PB_Any,ButtonWidth,ButtonHeight)
- StartDrawing(ImageOutput(ImageButton(0,1)))
- Box(0,0,ButtonWidth,ButtonHeight,ButtonFrontColorActive)
- Box(3,3,ButtonWidth-6,ButtonHeight-6,ButtonBackColor)
- DrawingFont(ButtonFontID)
- DrawText(ButtonTextX,ButtonTextY,"Stop",ButtonFrontColorActive,ButtonBackColor)
- StopDrawing()
- ImageButton(1,1) = CreateImage(#PB_Any,ButtonWidth,ButtonHeight)
- StartDrawing(ImageOutput(ImageButton(1,1)))
- Box(0,0,ButtonWidth,ButtonHeight,ButtonFrontColorActive)
- Box(6,6,ButtonWidth-12,ButtonHeight-12,ButtonBackColor)
- DrawingFont(ButtonFontID)
- DrawText(ButtonTextX,ButtonTextY,"Stop",ButtonFrontColorActive,ButtonBackColor)
- StopDrawing()
- ImageButton(2,1) = CreateImage(#PB_Any,ButtonWidth,ButtonHeight)
- StartDrawing(ImageOutput(ImageButton(2,1)))
- Box(0,0,ButtonWidth,ButtonHeight,ButtonFrontColorPassive)
- Box(3,3,ButtonWidth-6,ButtonHeight-6,ButtonBackColor)
- DrawingFont(ButtonFontID)
- DrawText(ButtonTextX,ButtonTextY,"Stop",ButtonFrontColorPassive,ButtonBackColor)
- StopDrawing()
- ;- Bouton Reset
- ImageButtonReset0 = CreateImage(#PB_Any,ButtonWidth,ButtonHeight)
- StartDrawing(ImageOutput(ImageButtonReset0))
- Box(0,0,ButtonWidth,ButtonHeight,ButtonFrontColorActive)
- Box(3,3,ButtonWidth-6,ButtonHeight-6,ButtonBackColor)
- DrawingFont(ButtonFontID)
- DrawText(ButtonTextX,ButtonTextY,"Reset",ButtonFrontColorActive,ButtonBackColor)
- StopDrawing()
- ImageButtonReset1 = CreateImage(#PB_Any,ButtonWidth,ButtonHeight)
- StartDrawing(ImageOutput(ImageButtonReset1))
- Box(0,0,ButtonWidth,ButtonHeight,ButtonFrontColorActive)
- Box(6,6,ButtonWidth-12,ButtonHeight-12,ButtonBackColor)
- DrawingFont(ButtonFontID)
- DrawText(ButtonTextX,ButtonTextY,"Reset",ButtonFrontColorActive,ButtonBackColor)
- StopDrawing()
- ImageButtonReset2 = CreateImage(#PB_Any,ButtonWidth,ButtonHeight)
- StartDrawing(ImageOutput(ImageButtonReset2))
- Box(0,0,ButtonWidth,ButtonHeight,ButtonFrontColorPassive)
- Box(3,3,ButtonWidth-6,ButtonHeight-6,ButtonBackColor)
- DrawingFont(ButtonFontID)
- DrawText(ButtonTextX,ButtonTextY,"Reset",ButtonFrontColorPassive,ButtonBackColor)
- StopDrawing()
- ButtonWindow = OpenWindow(#PB_Any,0,0,ButtonWidth*2+30,ButtonHeight+20,"Button")
- ButtonCanvas = CanvasGadget(#PB_Any,10,10,ButtonWidth,ButtonHeight,#PB_Canvas_Keyboard)
- ButtonResetCanvas = CanvasGadget(#PB_Any,ButtonWidth+20,10,ButtonWidth,ButtonHeight,#PB_Canvas_Keyboard)
- AddKeyboardShortcut(ButtonWindow,#PB_Shortcut_Control | #PB_Shortcut_Shift | #PB_Shortcut_M,3)
- ChronoWindow = OpenWindow(#PB_Any,0,0,ChronoWidth,ChronoHeight,"Chrono",#PB_Window_BorderLess|#PB_Window_ScreenCentered)
- ChronoCanvas = CanvasGadget(#PB_Any,0,0,ChronoWidth,ChronoHeight)
- UpdateChronoText
- StartDrawing(CanvasOutput(ChronoCanvas))
- Box(0,0,ChronoWidth,ChronoHeight,0)
- DrawingMode(#PB_2DDrawing_Transparent)
- If Not ChronoImageBack = 0
- DrawImage(ChronoImageBack,0,0)
- Else
- Box(0,0,ChronoWidth,ChronoHeight,0)
- EndIf
- DrawingFont(ChronoFontID)
- DrawText(10,5,ChronoText$,ChronoFontColor)
- If Not ChronoImageFront = 0
- DrawImage(ChronoImageFront,0,0)
- EndIf
- StopDrawing()
- Macro UpdateChrono
- StartDrawing(CanvasOutput(ChronoCanvas))
- Box(0,0,ChronoWidth,ChronoHeight,0)
- DrawingMode(#PB_2DDrawing_Transparent)
- If Not ChronoImageBack = 0
- DrawImage(ChronoImageBack,0,0)
- Else
- Box(0,0,ChronoWidth,ChronoHeight,0)
- EndIf
- DrawingFont(ChronoFontID)
- DrawText(10,5,ChronoText$,ChronoFontColor)
- If Not ChronoImageFront = 0
- DrawImage(ChronoImageFront,0,0)
- EndIf
- StopDrawing()
- EndMacro
- Pause = 1
- ChronoPauseStartTime = ElapsedMilliseconds()
- SetGadgetAttribute(ButtonCanvas,#PB_Canvas_Image,ImageID(ImageButton(2,0)))
- ChronoStartTime = ElapsedMilliseconds()
- Repeat
- ; Time = ElapsedMilliseconds()
- ; ElapsedTime = Time - PreviousTime
- ; previousTime = Time
- ChronoTime = (ElapsedMilliseconds - ChronoStartTime) - ChronoPauseTime
- If Pause = 1
- ChronoTime - (ElapsedMilliseconds() - ChronoPauseStartTime)
- EndIf
- UpdateChrono
- WindowEvent = WaitWindowEvent()
- Select WindowEvent
- Case #PB_Event_Gadget
- EventGadget = EventGadget()
- Select EventGadget
- Case ButtonCanvas
- Select EventType()
- Case #PB_EventType_LeftClick
- Pause = 1 - Pause
- If Pause = 1
- ChronoPauseStartTime = ElapsedMilliseconds()
- Else
- ChronoPauseTime + (ElapsedMilliseconds() - ChronoPauseStartTime)
- EndIf
- Case #PB_EventType_MouseLeave, #PB_EventType_LostFocus
- ActivateRUNbutton = 0
- SetGadgetAttribute(ButtonCanvas,#PB_Canvas_Image,ImageID(ImageButton(2,1-Pause)))
- Case #PB_EventType_MouseEnter, #PB_EventType_Focus
- ActivateRUNbutton = 1
- SetGadgetAttribute(ButtonCanvas,#PB_Canvas_Image,ImageID(ImageButton(0,1-Pause)))
- Case #PB_EventType_LeftButtonDown
- If ActivateRUNbutton = 1
- SetGadgetAttribute(ButtonCanvas,#PB_Canvas_Image,ImageID(ImageButton(1,1-Pause)))
- EndIf
- Case #PB_EventType_LeftButtonUp
- SetGadgetAttribute(ButtonCanvas,#PB_Canvas_Image,ImageID(ImageButton(0,Pause)))
- EndSelect
- Case ButtonResetCanvas
- Select EventType()
- Case #PB_EventType_LeftClick
- ChronoStartTime = ElapsedMilliseconds()
- Case #PB_EventType_MouseLeave, #PB_EventType_LostFocus
- ActivateRUNbutton = 0
- SetGadgetAttribute(ButtonResetCanvas,#PB_Canvas_Image,ImageID(ImageButtonReset2))
- Case #PB_EventType_MouseEnter, #PB_EventType_Focus
- ActivateRUNbutton = 1
- SetGadgetAttribute(ButtonResetCanvas,#PB_Canvas_Image,ImageID(ImageButtonReset0))
- Case #PB_EventType_LeftButtonDown
- If ActivateRUNbutton = 1
- SetGadgetAttribute(ButtonResetCanvas,#PB_Canvas_Image,ImageID(ImageButtonReset1))
- EndIf
- Case #PB_EventType_LeftButtonUp
- SetGadgetAttribute(ButtonResetCanvas,#PB_Canvas_Image,ImageID(ImageButtonReset2))
- EndSelect
- EndSelect
- Case #PB_Event_DeactivateWindow
- RUNbuttonKeyboardActivated = 0
- RUNbuttonMouseActivated = 0
- EndSelect
- Delay(15)
- Until WindowEvent = #PB_Event_CloseWindow
- EndProcedure
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement