TimeBoxGadget - Like DateGadget..
Posted: Fri Oct 02, 2015 8:09 pm
This is a gadget what i create for my project because dategadget no have seconds. Work using canvasgadget methods.
Have two principal lenguages, change global variable 'Lenguaje'.
I hope be interesting for somebody.
Have two principal lenguages, change global variable 'Lenguaje'.
I hope be interesting for somebody.
Code: Select all
;{
Structure ColorEstructura
ti.l
pa.l
tion.l
paon.l
fold.l
EndStructure
Global AppColor.ColorEstructura
AppColor\pa = $332211
AppColor\paon = $332211
AppColor\ti = $777777
AppColor\tion = $FF9944
AppColor\fold = $443322
;AppColor\pa = $223344
;AppColor\paon = $223344
;AppColor\ti = $BBBBBB
;AppColor\tion = $6677FF
;AppColor\fold = $112233
;}
Global Lenguaje = 0 ;1=English, 0=Español
;-----------------------------------------------
Global Dim DiaDeLaSemana.s(1,6)
DiaDeLaSemana(0,0)="Domingo"
DiaDeLaSemana(0,1)="Lunes"
DiaDeLaSemana(0,2)="Martes"
DiaDeLaSemana(0,3)="Miércoles"
DiaDeLaSemana(0,4)="Jueves"
DiaDeLaSemana(0,5)="Viernes"
DiaDeLaSemana(0,6)="Sábado"
DiaDeLaSemana(1,0)="Sunday"
DiaDeLaSemana(1,1)="Monday"
DiaDeLaSemana(1,2)="Tuesday"
DiaDeLaSemana(1,3)="Wednesday"
DiaDeLaSemana(1,4)="Thursday"
DiaDeLaSemana(1,5)="Friday"
DiaDeLaSemana(1,6)="Saturday"
Structure estructuratimebox
Gadget.l
time.l
font.l
fontlt.l
titu.s
EndStructure
Global NewList Tim.estructuratimebox()
Procedure TimeBoxDraw(gadget.l)
Protected ch.s
ForEach Tim()
If Tim()\Gadget=gadget
StartDrawing(CanvasOutput(Tim()\Gadget))
DrawingMode(#PB_2DDrawing_Transparent)
DrawingFont(FontID(Tim()\font))
Box(0,0,OutputWidth(),OutputHeight(),AppColor\ti)
Box(1,1,OutputWidth()-2,OutputHeight()-2,AppColor\pa)
ch.s=DiaDeLaSemana(Lenguaje,DayOfWeek(Tim()\time))
DrawText(((OutputWidth()/2)-TextWidth(ch))/2,((OutputHeight()/2)-TextHeight(ch))/2,ch,AppColor\ti)
ch.s=FormatDate("%dd-%mm-%yyyy %hh:%ii:%ss",Tim()\time)
DrawText((OutputWidth()-TextWidth(ch))/2,((OutputHeight()/2)-TextHeight(ch))/2+(OutputHeight()/2),ch,AppColor\ti)
Box(OutputWidth()/2,2,(OutputWidth()/2)-2,OutputHeight()/2,AppColor\ti)
DrawingFont(FontID(Tim()\fontlt))
DrawText(((OutputWidth()/2)-TextWidth(Tim()\titu))/2+(OutputWidth()/2),((OutputHeight()/2)-TextHeight(Tim()\titu))/2,Tim()\titu,AppColor\pa)
StopDrawing()
Break
EndIf
Next
EndProcedure
Procedure TimeBoxSet(gadget.l,date.l)
ForEach Tim()
If Tim()\Gadget=gadget
Tim()\time=date
TimeBoxDraw(Tim()\Gadget)
Break
EndIf
Next
EndProcedure
Procedure TimeBoxGet(gadget.l)
Protected valor.l=-1
ForEach Tim()
If Tim()\Gadget=gadget
valor=Tim()\time
Break
EndIf
Next
ProcedureReturn valor
EndProcedure
Procedure TimeBoxAdd(x.i,y.i,w.i,h.i,date.l,font.s="Arial",txt.s="")
Protected size = (w+h)/20
AddElement(Tim())
Tim()\Gadget = CanvasGadget(#PB_Any,x,y,w,h,#PB_Canvas_Keyboard)
Tim()\time = date
Tim()\titu = txt
Tim()\font = LoadFont(#PB_Any,font,size,#PB_Font_HighQuality)
Tim()\fontlt = LoadFont(#PB_Any,font,size*0.75,#PB_Font_HighQuality)
TimeBoxDraw(Tim()\Gadget)
ProcedureReturn Tim()\Gadget
EndProcedure
Procedure TimEvent(EventGadget,EventType)
Static Pulsado.b
Protected gadget=-1
ForEach Tim()
If EventGadget=Tim()\gadget
StartDrawing(CanvasOutput(Tim()\Gadget))
DrawingMode(#PB_2DDrawing_Transparent)
DrawingFont(FontID(Tim()\font))
Protected x.i=GetGadgetAttribute(Tim()\gadget,#PB_Canvas_MouseX)
Protected y.i=GetGadgetAttribute(Tim()\gadget,#PB_Canvas_MouseY)
ch.s=FormatDate("%dd-%mm-%yyyy %hh:%ii:%ss",Tim()\time)
chf.s=FormatDate("%dd-%mm-%yyyy",Tim()\time)
chh.s=FormatDate("%hh:%ii:%ss",Tim()\time)
yy = (OutputHeight()-TextHeight(ch))/2;+(OutputWidth()/2)
xf0 = (OutputWidth()-TextWidth(ch))/2
xf1= xf0+TextWidth("00-")
xf2= xf1+TextWidth("00-")
xf3= xf2+TextWidth("0000")
xh0= xf3+TextWidth(" ")
xh1= xh0+TextWidth("00:")
xh2= xh1+TextWidth("00:")
; Protected LogW.i = Rule3(Tim()\scrw,GadgetWidth(Tim()\gadget),Tim()\boxw)* Tim()\boxs)
; Protected LogH.i = Rule3(Tim()\scrw,GadgetWidth(Tim()\gadget),Tim()\boxh)* Tim()\boxs)
If EventType=#PB_EventType_MouseEnter
SetGadgetAttribute(EventGadget,#PB_Canvas_Cursor,#PB_Cursor_Hand)
ElseIf EventType=#PB_EventType_MouseLeave
SetGadgetAttribute(EventGadget,#PB_Canvas_Cursor,#PB_Cursor_Default)
Box(0,0,OutputWidth(),OutputHeight(),AppColor\ti)
Box(1,1,OutputWidth()-2,OutputHeight()-2,AppColor\pa)
dia.s=DiaDeLaSemana(Lenguaje,DayOfWeek(Tim()\time))
DrawingFont(FontID(Tim()\font))
DrawText(((OutputWidth()/2)-TextWidth(dia))/2,((OutputHeight()/2)-TextHeight(dia))/2,dia,AppColor\ti)
DrawText((OutputWidth()-TextWidth(ch))/2,((OutputHeight()/2)-TextHeight(ch))/2+(OutputHeight()/2),ch,AppColor\ti)
Box(OutputWidth()/2,2,(OutputWidth()/2)-2,OutputHeight()/2,AppColor\ti)
DrawingFont(FontID(Tim()\fontlt))
DrawText(((OutputWidth()/2)-TextWidth(Tim()\titu))/2+(OutputWidth()/2),((OutputHeight()/2)-TextHeight(Tim()\titu))/2,Tim()\titu,AppColor\pa)
ElseIf EventType=#PB_EventType_MouseMove
Box(0,0,OutputWidth(),OutputHeight(),AppColor\tion)
Box(1,1,OutputWidth()-2,OutputHeight()-2,AppColor\pa)
ch.s=DiaDeLaSemana(Lenguaje,DayOfWeek(Tim()\time))
DrawText((OutputWidth()-TextWidth(ch))/2,((OutputHeight()/2)-TextHeight(ch))/2,ch,AppColor\ti)
ch.s=FormatDate("%dd-%mm-%yyyy %hh:%ii:%ss",Tim()\time)
DrawText((OutputWidth()-TextWidth(ch))/2,((OutputHeight()/2)-TextHeight(ch))/2+(OutputHeight()/2),ch,AppColor\ti)
If (x>xf0 And x<xf1) Or y<OutputHeight()/2; dia
dia.s=DiaDeLaSemana(Lenguaje,DayOfWeek(Tim()\time))
DrawText((OutputWidth()-TextWidth(dia))/2,((OutputHeight()/2)-TextHeight(dia))/2,dia,AppColor\tion)
DrawText(xf0,((OutputHeight()/2)-TextHeight(ch))/2+(OutputHeight()/2),Mid(chf,1,2),AppColor\tion)
ElseIf x>xf1 And x<xf2 And y>OutputHeight()/2; mes
DrawText(xf1,((OutputHeight()/2)-TextHeight(ch))/2+(OutputHeight()/2),Mid(chf,4,2),AppColor\tion)
ElseIf x>xf2 And x<xf3 And y>OutputHeight()/2; año
me=Val(Mid(chf,7,4)) + 1 ;: If me>12:me=1:EndIf
DrawText(xf2,((OutputHeight()/2)-TextHeight(ch))/2+(OutputHeight()/2),Mid(chf,7,4),AppColor\tion)
ElseIf x>xh0 And x<xh1 And y>OutputHeight()/2; hora
DrawText(xh0,((OutputHeight()/2)-TextHeight(ch))/2+(OutputHeight()/2),Mid(chh,1,2),AppColor\tion)
ElseIf x>xh1 And x<xh2 And y>OutputHeight()/2; min
DrawText(xh1,((OutputHeight()/2)-TextHeight(ch))/2+(OutputHeight()/2),Mid(chh,4,2),AppColor\tion)
ElseIf x>xh2 And y>OutputHeight()/2;And x<xh3 ; seg
DrawText(xh2,((OutputHeight()/2)-TextHeight(ch))/2+(OutputHeight()/2),Mid(chh,7,2),AppColor\tion)
EndIf
ElseIf EventType=#PB_EventType_LeftButtonUp
gadget=Tim()\gadget
ElseIf EventType=#PB_EventType_RightButtonUp
gadget=Tim()\gadget
ElseIf EventType=#PB_EventType_MouseWheel
wheel = GetGadgetAttribute(EventGadget,#PB_Canvas_WheelDelta)
If (x>xf0 And x<xf1) Or y<OutputHeight()/2; dia
Tim()\time=AddDate(Tim()\time, #PB_Date_Day, wheel)
ElseIf x>xf1 And x<xf2 And y>OutputHeight()/2; mes
Tim()\time=AddDate(Tim()\time, #PB_Date_Month, wheel)
ElseIf x>xf2 And x<xf3 And y>OutputHeight()/2; año
Tim()\time=AddDate(Tim()\time, #PB_Date_Year, wheel)
ElseIf x>xh0 And x<xh1 And y>OutputHeight()/2; hora
Tim()\time=AddDate(Tim()\time, #PB_Date_Hour, wheel)
ElseIf x>xh1 And x<xh2 And y>OutputHeight()/2; min
Tim()\time=AddDate(Tim()\time, #PB_Date_Minute, wheel)
ElseIf x>xh2 And y>OutputHeight()/2;And x<xh3 ; seg
Tim()\time=AddDate(Tim()\time, #PB_Date_Second, wheel)
EndIf
Box(1,1,OutputWidth()-2,OutputHeight()-2,AppColor\pa)
dia.s=DiaDeLaSemana(Lenguaje,DayOfWeek(Tim()\time))
DrawText((OutputWidth()-TextWidth(dia))/2,((OutputHeight()/2)-TextHeight(dia))/2,dia,AppColor\ti)
ch.s=FormatDate("%dd-%mm-%yyyy %hh:%ii:%ss",Tim()\time)
DrawText((OutputWidth()-TextWidth(ch))/2,((OutputHeight()/2)-TextHeight(ch))/2+(OutputHeight()/2),ch,AppColor\ti)
gadget=Tim()\gadget
ElseIf EventType=#PB_EventType_LeftButtonDown
If (x>xf0 And x<xf1) Or y<OutputHeight()/2; dia
Tim()\time=AddDate(Tim()\time, #PB_Date_Day, 1)
ElseIf x>xf1 And x<xf2 And y>OutputHeight()/2; mes
Tim()\time=AddDate(Tim()\time, #PB_Date_Month, 1)
ElseIf x>xf2 And x<xf3 And y>OutputHeight()/2; año
Tim()\time=AddDate(Tim()\time, #PB_Date_Year, 1)
ElseIf x>xh0 And x<xh1 And y>OutputHeight()/2; hora
Tim()\time=AddDate(Tim()\time, #PB_Date_Hour, 1)
ElseIf x>xh1 And x<xh2 And y>OutputHeight()/2; min
Tim()\time=AddDate(Tim()\time, #PB_Date_Minute, 1)
ElseIf x>xh2 And y>OutputHeight()/2;And x<xh3 ; seg
Tim()\time=AddDate(Tim()\time, #PB_Date_Second, 1)
EndIf
Box(1,1,OutputWidth()-2,OutputHeight()-2,AppColor\pa)
dia.s=DiaDeLaSemana(Lenguaje,DayOfWeek(Tim()\time))
DrawText((OutputWidth()-TextWidth(dia))/2,((OutputHeight()/2)-TextHeight(dia))/2,dia,AppColor\ti)
ch.s=FormatDate("%dd-%mm-%yyyy %hh:%ii:%ss",Tim()\time)
DrawText((OutputWidth()-TextWidth(ch))/2,((OutputHeight()/2)-TextHeight(ch))/2+(OutputHeight()/2),ch,AppColor\ti)
gadget=Tim()\gadget
ElseIf EventType=#PB_EventType_RightButtonDown
If (x>xf0 And x<xf1) Or y<OutputHeight()/2; dia
Tim()\time=AddDate(Tim()\time, #PB_Date_Day, -1)
ElseIf x>xf1 And x<xf2 And y>OutputHeight()/2; mes
Tim()\time=AddDate(Tim()\time, #PB_Date_Month, -1)
ElseIf x>xf2 And x<xf3 And y>OutputHeight()/2; año
Tim()\time=AddDate(Tim()\time, #PB_Date_Year, -1)
ElseIf x>xh0 And x<xh1 And y>OutputHeight()/2; hora
Tim()\time=AddDate(Tim()\time, #PB_Date_Hour, -1)
ElseIf x>xh1 And x<xh2 And y>OutputHeight()/2; min
Tim()\time=AddDate(Tim()\time, #PB_Date_Minute, -1)
ElseIf x>xh2 And y>OutputHeight()/2;And x<xh3 ; seg
Tim()\time=AddDate(Tim()\time, #PB_Date_Second, -1)
EndIf
Box(1,1,OutputWidth()-2,OutputHeight()-2,AppColor\pa)
dia.s=DiaDeLaSemana(Lenguaje,DayOfWeek(Tim()\time))
DrawText((OutputWidth()-TextWidth(dia))/2,((OutputHeight()/2)-TextHeight(dia))/2,dia,AppColor\ti)
ch.s=FormatDate("%dd-%mm-%yyyy %hh:%ii:%ss",Tim()\time)
DrawText((OutputWidth()-TextWidth(ch))/2,((OutputHeight()/2)-TextHeight(ch))/2+(OutputHeight()/2),ch,AppColor\ti)
gadget=Tim()\gadget
EndIf
StopDrawing()
Break
EndIf
Next
ProcedureReturn Gadget
EndProcedure
CompilerIf Not #PB_Compiler_IsIncludeFile
Global W_Int = OpenWindow(#PB_Any, 183, 58,1300, 600, "HORUSEYE", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered|#PB_Window_TitleBar)
SetWindowColor(W_Int,AppColor\pa)
TimPrueba = TimeBoxAdd(1050, 20,200,50,Date(),"Arial","Time")
TimPrueba2 = TimeBoxAdd(10, 10,600,150,Date(),"Arial","Wake")
Repeat
Event = WaitWindowEvent(1)
Select Event
Case #PB_Event_Gadget
EventGadget = EventGadget()
EventType = EventType()
; ------ TimeBox FECHA y HORA (date & time)
TimGadget = TimEvent(EventGadget,EventType)
If TimGadget = TimPrueba
Debug TimeBoxGet(TimGadget)
EndIf
Case #PB_Event_CloseWindow
EventWindow = EventWindow()
If EventWindow = W_Int
CloseWindow(W_Int)
W_Int = 0
Break
EndIf
EndSelect
ForEver
CompilerEndIf