Re: CounterGadget
Posted: Thu Apr 05, 2012 2:07 pm
Good to know ! Thanks reporting back !Kwaï chang caïne wrote:Tested today on VISTA and that's works fine too, the 00 appears
Thanks
Best regards
Guimauve
Good to know ! Thanks reporting back !Kwaï chang caïne wrote:Tested today on VISTA and that's works fine too, the 00 appears
Thanks
Code: Select all
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : CounterGadget - Module
; File Name : CounterGadget - Module.pb
; File version: 1.0.0
; Programming : OK
; Programmed by : StarBootics
; Date : 04-03-2012
; Last Update : 12-05-2016
; PureBasic code : V5.42 LTS
; Platform : Windows, Linux, MacOS X
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; This code was originally created by Guimauve.
;
; I deserve credit only to convert the original
; code into a Module.
;
; This code is free to be use where ever you like
; but you use it at your own risk.
;
; The author can in no way be held responsible
; for data loss, damage or other annoying
; situations that may occur.
;
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
DeclareModule Counter
Declare SetValue(GadgetID, Value.s)
Declare ChangeColors(GadgetID, DigitOnColor.l, DigitOffColor.l, BackColor.l = 0)
Declare Gadget(GadgetID, PosX.w, PosY.w, DigitPattern.s, DigitRadius.w, DigitOnColor.l, DigitOffColor.l, BackColor.l = 0, Option = -1)
Declare Clock(GadgetID)
Declare SetData(GadgetID, P_UserData.i)
Declare.i GetData(GadgetID)
Declare Free(GadgetID)
EndDeclareModule
Module Counter
Enumeration
#SEGMENT_DIRECTION_HORIZONTAL
#SEGMENT_DIRECTION_VERTICAL
#SEGMENT_DIRECTION_OBLIQUE
EndEnumeration
Structure Segment
X1.w
Y1.w
X2.w
Y2.w
EndStructure
Macro UpdateSegment(SegmentA, P_X1, P_Y1, P_X2, P_Y2)
SegmentA\X1 = P_X1
SegmentA\Y1 = P_Y1
SegmentA\X2 = P_X2
SegmentA\Y2 = P_Y2
EndMacro
Macro ProductByScalarSegment(SegmentR, SegmentA, Scalar)
SegmentR\X1 = SegmentA\X1 * Scalar
SegmentR\Y1 = SegmentA\Y1 * Scalar
SegmentR\X2 = SegmentA\X2 * Scalar
SegmentR\Y2 = SegmentA\Y2 * Scalar
EndMacro
Procedure DrawSegment(*SegmentA.Segment, Radius.w, Color.l, Direction.b)
Select Direction
Case #SEGMENT_DIRECTION_HORIZONTAL
For PosX = *SegmentA\X1 To *SegmentA\X2
Circle(PosX, *SegmentA\Y1, Radius, Color)
Next
Case #SEGMENT_DIRECTION_VERTICAL
For PosY = *SegmentA\Y1 To *SegmentA\Y2
Circle(*SegmentA\X1, PosY, Radius, Color)
Next
Case #SEGMENT_DIRECTION_OBLIQUE
For PosXY = *SegmentA\X1 To *SegmentA\X2
Circle(PosXY, PosXY, Radius, Color)
Next
EndSelect
EndProcedure
Global Dim Segments.Segment(10)
Structure Instance
Pattern.s
DigitRadius.w
DigitOnColor.l
DigitOffColor.l
BackColor.l
LastSecond.l
Width.w
Height.w
Numbers.l[17]
UserData.i
EndStructure
Procedure Reset(*InstanceA.Instance)
*InstanceA\Pattern = ""
*InstanceA\DigitRadius = 0
*InstanceA\DigitOnColor = 0
*InstanceA\DigitOffColor = 0
*InstanceA\BackColor = 0
*InstanceA\LastSecond = 0
*InstanceA\Width = 0
*InstanceA\Height = 0
*InstanceA\UserData = 0
For NumbersID = 0 To 16
If IsImage(*InstanceA\Numbers[NumbersID])
FreeImage(*InstanceA\Numbers[NumbersID])
*InstanceA\Numbers[NumbersID] = 0
EndIf
Next
EndProcedure
Procedure.i CreateNewCounter()
*InstanceA.Instance = AllocateMemory(SizeOf(Instance))
If *InstanceA = #Null
MessageRequester("Fatal Error", "CreateNewCounter() - Impossible to Allocate Memory !")
End
EndIf
ProcedureReturn *InstanceA
EndProcedure
Procedure DrawDigits(GadgetID)
If IsGadget(GadgetID)
UpdateSegment(Segments(0), 3, 1, 7, 1) ; SEGMENT CENTRAL HAUT
UpdateSegment(Segments(1), 3, 9, 7, 9) ; SEGMENT CENTRAL CENTRE (MOINS ET PLUS HORIZONTAL)
UpdateSegment(Segments(2), 3, 17, 7, 17) ; SEGMENT CENTRAL BAS
UpdateSegment(Segments(3), 1, 3, 1, 7) ; SEGMENT GAUCHE HAUT
UpdateSegment(Segments(4), 1, 11, 1, 15) ; SEGMENT GAUCHE BAS
UpdateSegment(Segments(5), 9, 3, 9, 7) ; SEGMENT DROIT HAUT
UpdateSegment(Segments(6), 9, 11, 9, 15) ; SEGMENT DROIT BAS
UpdateSegment(Segments(7), 1, 5, 1, 5) ; DEUX POINT HAUT
UpdateSegment(Segments(8), 1, 13, 1, 13) ; DEUX POINT BAS
UpdateSegment(Segments(9), 5, 7, 5, 11) ; PLUS VERTICAL
UpdateSegment(Segments(10), 1, 17, 1, 17) ; POINT
*InstanceA.Instance = GetGadgetData(GadgetID)
If *InstanceA <> #Null
For index = 0 To 10
ProductByScalarSegment(Segments(index), Segments(index), *InstanceA\DigitRadius)
Next
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Dessin du symbole "0" OK
If StartDrawing(ImageOutput(*InstanceA\Numbers[0]))
Box(0, 0, *InstanceA\DigitRadius * 10, *InstanceA\DigitRadius * 18, *InstanceA\BackColor)
For SegmentID = 0 To 6
Select SegmentID
Case 0, 2
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOnColor, #SEGMENT_DIRECTION_HORIZONTAL)
Case 3, 4, 5, 6
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOnColor, #SEGMENT_DIRECTION_VERTICAL)
Case 1
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOffColor, #SEGMENT_DIRECTION_HORIZONTAL)
EndSelect
Next
StopDrawing()
EndIf
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Dessin du symbole "1" OK
If StartDrawing(ImageOutput(*InstanceA\Numbers[1]))
Box(0, 0, *InstanceA\DigitRadius * 10, *InstanceA\DigitRadius * 18, *InstanceA\BackColor)
For SegmentID = 0 To 6
Select SegmentID
Case 5, 6
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOnColor, #SEGMENT_DIRECTION_VERTICAL)
Case 0, 1, 2
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOffColor, #SEGMENT_DIRECTION_HORIZONTAL)
Case 3, 4
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOffColor, #SEGMENT_DIRECTION_VERTICAL)
EndSelect
Next
StopDrawing()
EndIf
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Dessin du symbole "2" OK
If StartDrawing(ImageOutput(*InstanceA\Numbers[2]))
Box(0, 0, *InstanceA\DigitRadius * 10, *InstanceA\DigitRadius * 18, *InstanceA\BackColor)
For SegmentID = 0 To 6
Select SegmentID
Case 0, 1, 2
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOnColor, #SEGMENT_DIRECTION_HORIZONTAL)
Case 4, 5
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOnColor, #SEGMENT_DIRECTION_VERTICAL)
Case 3, 6
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOffColor, #SEGMENT_DIRECTION_VERTICAL)
EndSelect
Next
StopDrawing()
EndIf
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Dessin du symbole "3" OK
If StartDrawing(ImageOutput(*InstanceA\Numbers[3]))
Box(0, 0, *InstanceA\DigitRadius * 10, *InstanceA\DigitRadius * 18, *InstanceA\BackColor)
For SegmentID = 0 To 6
Select SegmentID
Case 0, 1, 2
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOnColor, #SEGMENT_DIRECTION_HORIZONTAL)
Case 5, 6
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOnColor, #SEGMENT_DIRECTION_VERTICAL)
Case 3, 4
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOffColor, #SEGMENT_DIRECTION_VERTICAL)
EndSelect
Next
StopDrawing()
EndIf
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Dessin du symbole "4" OK
If StartDrawing(ImageOutput(*InstanceA\Numbers[4]))
Box(0, 0, *InstanceA\DigitRadius * 10, *InstanceA\DigitRadius * 18, *InstanceA\BackColor)
For SegmentID = 0 To 6
Select SegmentID
Case 1
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOnColor, #SEGMENT_DIRECTION_HORIZONTAL)
Case 3, 5, 6
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOnColor, #SEGMENT_DIRECTION_VERTICAL)
Case 0, 2
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOffColor, #SEGMENT_DIRECTION_HORIZONTAL)
Case 4
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOffColor, #SEGMENT_DIRECTION_VERTICAL)
EndSelect
Next
StopDrawing()
EndIf
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Dessin du symbole "5"
If StartDrawing(ImageOutput(*InstanceA\Numbers[5]))
Box(0, 0, *InstanceA\DigitRadius * 10, *InstanceA\DigitRadius * 18, *InstanceA\BackColor)
For SegmentID = 0 To 6
Select SegmentID
Case 0, 1, 2
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOnColor, #SEGMENT_DIRECTION_HORIZONTAL)
Case 3, 6
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOnColor, #SEGMENT_DIRECTION_VERTICAL)
Case 4, 5
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOffColor, #SEGMENT_DIRECTION_VERTICAL)
EndSelect
Next
StopDrawing()
EndIf
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Dessin du symbole "6"
If StartDrawing(ImageOutput(*InstanceA\Numbers[6]))
Box(0, 0, *InstanceA\DigitRadius * 10, *InstanceA\DigitRadius * 18, *InstanceA\BackColor)
For SegmentID = 0 To 6
Select SegmentID
Case 0, 1, 2
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOnColor, #SEGMENT_DIRECTION_HORIZONTAL)
Case 3, 4, 6
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOnColor, #SEGMENT_DIRECTION_VERTICAL)
Case 5
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOffColor, #SEGMENT_DIRECTION_VERTICAL)
EndSelect
Next
StopDrawing()
EndIf
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Dessin du symbole "7"
If StartDrawing(ImageOutput(*InstanceA\Numbers[7]))
Box(0, 0, *InstanceA\DigitRadius * 10, *InstanceA\DigitRadius * 18, *InstanceA\BackColor)
For SegmentID = 0 To 6
Select SegmentID
Case 0
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOnColor, #SEGMENT_DIRECTION_HORIZONTAL)
Case 3, 5, 6
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOnColor, #SEGMENT_DIRECTION_VERTICAL)
Case 1, 2
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOffColor, #SEGMENT_DIRECTION_HORIZONTAL)
Case 3, 4
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOffColor, #SEGMENT_DIRECTION_VERTICAL)
EndSelect
Next
StopDrawing()
EndIf
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Dessin du symbole "8"
If StartDrawing(ImageOutput(*InstanceA\Numbers[8]))
Box(0, 0, *InstanceA\DigitRadius * 10, *InstanceA\DigitRadius * 18, *InstanceA\BackColor)
For SegmentID = 0 To 6
Select SegmentID
Case 0, 1, 2
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOnColor, #SEGMENT_DIRECTION_HORIZONTAL)
Case 3, 4, 5, 6
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOnColor, #SEGMENT_DIRECTION_VERTICAL)
EndSelect
Next
StopDrawing()
EndIf
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Dessin du symbole "9"
If StartDrawing(ImageOutput(*InstanceA\Numbers[9]))
Box(0, 0, *InstanceA\DigitRadius * 10, *InstanceA\DigitRadius * 18, *InstanceA\BackColor)
For SegmentID = 0 To 6
Select SegmentID
Case 0, 1, 2
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOnColor, #SEGMENT_DIRECTION_HORIZONTAL)
Case 3, 5, 6
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOnColor, #SEGMENT_DIRECTION_VERTICAL)
Case 4
DrawSegment(Segments(SegmentID), *InstanceA\DigitRadius, *InstanceA\DigitOffColor, #SEGMENT_DIRECTION_VERTICAL)
EndSelect
Next
StopDrawing()
EndIf
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Dessin du symbole "-"
If StartDrawing(ImageOutput(*InstanceA\Numbers[10]))
Box(0, 0, *InstanceA\DigitRadius * 10, *InstanceA\DigitRadius * 18, *InstanceA\BackColor)
DrawSegment(Segments(9), *InstanceA\DigitRadius, *InstanceA\DigitOffColor, #SEGMENT_DIRECTION_VERTICAL)
DrawSegment(Segments(1), *InstanceA\DigitRadius, *InstanceA\DigitOnColor, #SEGMENT_DIRECTION_HORIZONTAL)
StopDrawing()
EndIf
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Dessin du symbole "+"
If StartDrawing(ImageOutput(*InstanceA\Numbers[11]))
Box(0, 0, *InstanceA\DigitRadius * 10, *InstanceA\DigitRadius * 18, *InstanceA\BackColor)
DrawSegment(Segments(1), *InstanceA\DigitRadius, *InstanceA\DigitOnColor, #SEGMENT_DIRECTION_HORIZONTAL)
DrawSegment(Segments(9), *InstanceA\DigitRadius, *InstanceA\DigitOnColor, #SEGMENT_DIRECTION_VERTICAL)
StopDrawing()
EndIf
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Dessin du symbole " " (Espace)
If StartDrawing(ImageOutput(*InstanceA\Numbers[12]))
Box(0, 0, *InstanceA\DigitRadius * 10, *InstanceA\DigitRadius * 18, *InstanceA\BackColor)
StopDrawing()
EndIf
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Dessin du symbole "."
If StartDrawing(ImageOutput(*InstanceA\Numbers[13]))
Box(0, 0, *InstanceA\DigitRadius * 10, *InstanceA\DigitRadius * 18, *InstanceA\BackColor)
DrawSegment(Segments(10), *InstanceA\DigitRadius, *InstanceA\DigitOnColor, #SEGMENT_DIRECTION_HORIZONTAL)
StopDrawing()
EndIf
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Dessin du symbole ":"
If StartDrawing(ImageOutput(*InstanceA\Numbers[14]))
Box(0, 0, *InstanceA\DigitRadius * 10, *InstanceA\DigitRadius * 18, *InstanceA\BackColor)
DrawSegment(Segments(7), *InstanceA\DigitRadius, *InstanceA\DigitOnColor, #SEGMENT_DIRECTION_HORIZONTAL)
DrawSegment(Segments(8), *InstanceA\DigitRadius, *InstanceA\DigitOnColor, #SEGMENT_DIRECTION_HORIZONTAL)
StopDrawing()
EndIf
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Dessin du symbole "|" (Deux point OFF)
If StartDrawing(ImageOutput(*InstanceA\Numbers[15]))
Box(0, 0, *InstanceA\DigitRadius * 10, *InstanceA\DigitRadius * 18, *InstanceA\BackColor)
DrawSegment(Segments(7), *InstanceA\DigitRadius, *InstanceA\DigitOffColor, #SEGMENT_DIRECTION_HORIZONTAL)
DrawSegment(Segments(8), *InstanceA\DigitRadius, *InstanceA\DigitOffColor, #SEGMENT_DIRECTION_HORIZONTAL)
StopDrawing()
EndIf
EndIf
EndIf
EndProcedure
Procedure SetValue(GadgetID, Value.s)
If IsGadget(GadgetID)
*InstanceA.Instance = GetGadgetData(GadgetID)
If *InstanceA <> #Null
If StartDrawing(ImageOutput(*InstanceA\Numbers[16]))
For DigitID = 0 To Len(Value)
Number.l = FindString("0123456789-+ .:|", Mid(Value, DigitID + 1, 1), 1) - 1
Select Number
Case 0 To 12
Offset.l = 11
Case 13 To 15 ; ".", ":", "|"
Offset = 3
EndSelect
If Number >= 0 And Number <= 15
DrawImage(ImageID(*InstanceA\Numbers[Number]), PosX, 0)
PosX + *InstanceA\DigitRadius * Offset
EndIf
Next
StopDrawing()
SetGadgetState(GadgetID, ImageID(*InstanceA\Numbers[16]))
EndIf
EndIf
EndIf
EndProcedure
Procedure ChangeColors(GadgetID, DigitOnColor.l, DigitOffColor.l, BackColor.l = 0)
If IsGadget(GadgetID)
*InstanceA.Instance = GetGadgetData(GadgetID)
If *InstanceA <> #Null
*InstanceA\DigitOnColor = DigitOnColor
*InstanceA\DigitOffColor = DigitOffColor
*InstanceA\BackColor = BackColor
EndIf
DrawDigits(GadgetID)
EndIf
EndProcedure
Procedure Gadget(GadgetID, PosX.w, PosY.w, DigitPattern.s, DigitRadius.w, DigitOnColor.l, DigitOffColor.l, BackColor.l = 0, Option = -1)
*InstanceA.Instance = CreateNewCounter()
*InstanceA\Pattern = DigitPattern
Point_TwoPoint = CountString(DigitPattern, ".") + CountString(DigitPattern, ":")
DigitCount = Len(DigitPattern) - Point_TwoPoint
*InstanceA\DigitRadius = DigitRadius
*InstanceA\Width = DigitCount * DigitRadius * 11 + Point_TwoPoint * DigitRadius * 3 - DigitRadius
*InstanceA\Height = DigitRadius * 18
If Option <= 0
GadgetHandle = ImageGadget(GadgetID, PosX, PosY, *InstanceA\Width, *InstanceA\Height, 0)
ElseIf Option >= 1
GadgetHandle = ImageGadget(GadgetID, PosX, PosY, *InstanceA\Width, *InstanceA\Height, 0, #PB_Image_Border)
EndIf
If GadgetID = #PB_Any
GadgetID = GadgetHandle
EndIf
SetGadgetData(GadgetID, *InstanceA)
For NumbersID = 0 To 15
*InstanceA\Numbers[NumbersID] = CreateImage(#PB_Any, DigitRadius * 10, DigitRadius * 18)
Next
*InstanceA\Numbers[16] = CreateImage(#PB_Any, *InstanceA\Width, *InstanceA\Height)
If StartDrawing(ImageOutput(*InstanceA\Numbers[16]))
Box(0, 0, *InstanceA\Width, *InstanceA\Height, BackColor)
StopDrawing()
EndIf
ChangeColors(GadgetID, DigitOnColor, DigitOffColor, BackColor)
ProcedureReturn GadgetID
EndProcedure
Procedure Clock(GadgetID)
Time = Date()
CurrentSecond = Second(Time)
If IsGadget(GadgetID)
*InstanceA.Instance = GetGadgetData(GadgetID)
If *InstanceA <> #Null
If *InstanceA\LastSecond <> CurrentSecond
If CurrentSecond % 2 = 0
SetValue(GadgetID, FormatDate("%hh:%ii:%ss", Time))
Else
SetValue(GadgetID, FormatDate("%hh|%ii|%ss", Time))
EndIf
*InstanceA\LastSecond = CurrentSecond
EndIf
EndIf
EndIf
EndProcedure
Procedure SetData(GadgetID, P_UserData.i)
If IsGadget(GadgetID)
*InstanceA.Instance = GetGadgetData(GadgetID)
If *InstanceA <> #Null
*InstanceA\UserData = P_UserData
EndIf
EndIf
EndProcedure
Procedure.i GetData(GadgetID)
If IsGadget(GadgetID)
*InstanceA.Instance = GetGadgetData(GadgetID)
If *InstanceA <> #Null
P_UserData.i = *InstanceA\UserData
EndIf
EndIf
ProcedureReturn P_UserData
EndProcedure
Procedure Free(GadgetID)
If IsGadget(GadgetID)
*InstanceA.Instance = GetGadgetData(GadgetID)
If *InstanceA <> #Null
Reset(*InstanceA)
FreeMemory(*InstanceA)
FreeGadget(GadgetID)
EndIf
EndIf
EndProcedure
EndModule
CompilerIf #PB_Compiler_IsMainFile
Macro GadgetDown(GadgetID, Gap = 0)
(GadgetY(GadgetID) + GadgetHeight(GadgetID) + (Gap))
EndMacro
Enumeration
#Counter_01
#Counter_02
#Counter_03
#Counter_04
#Counter_05
EndEnumeration
If OpenWindow(0, 300, 300, 600, 400, "Counter Gadget", #PB_Window_SystemMenu)
Counter::Gadget(#Counter_01, 5, 5, "88:88:88", 5, RGB(000, 255, 000), RGB(000, 16, 000), 0, 1)
Counter::Gadget(#Counter_02, 5, GadgetDown(#Counter_01, 10), "88:88:88", 4, RGB(255, 100, 000), RGB(016, 010, 000), 0, 1)
Counter::Gadget(#Counter_03, 5, GadgetDown(#Counter_02, 10), "+88888888", 3, RGB(255, 255, 000), RGB(032, 032, 000), 0, 1)
Counter::Gadget(#Counter_04, 5, GadgetDown(#Counter_03, 10), "888.888.888.888", 3, RGB(255, 000, 125), RGB(032, 000, 015), 0, 1)
Counter::Gadget(#Counter_05, 5, GadgetDown(#Counter_04, 10), "88-88-8888", 3, RGB(125, 125, 255),RGB(015, 015, 015), 0, 1)
Counter::SetValue(#Counter_02, "00:00:00")
Counter::SetValue(#Counter_03, "+87654321")
Counter::SetValue(#Counter_04, "192.223.145.123")
Counter::SetValue(#Counter_05, FormatDate("%dd-%mm-%yyyy", Date()))
Repeat
Counter::Clock(#Counter_01)
Counter::Clock(#Counter_02)
EventID = WaitWindowEvent(250)
Select EventID
Case #PB_Event_Menu
Select EventMenu()
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
EndSelect
EndSelect
Until EventID = #PB_Event_CloseWindow
EndIf
Counter::Free(#Counter_01)
Counter::Free(#Counter_02)
Counter::Free(#Counter_03)
Counter::Free(#Counter_04)
Counter::Free(#Counter_05)
CompilerEndIf
; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
Little? It's almost 27 KB of code!Guimauve wrote:A little Counter Gadget.