Look below to see the new version. Drag the hands to set the time.
ClockGadget like CalendarGadget
ClockGadget like CalendarGadget
Deleted for new version.
Look below to see the new version. Drag the hands to set the time.
Look below to see the new version. Drag the hands to set the time.
Last edited by minimy on Tue Sep 17, 2013 6:30 pm, edited 1 time in total.
If translation=Error: reply="Sorry, Im Spanish": Endif
-
IdeasVacuum
- Always Here

- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: ClockGadget like CalendarGadget
Nice work, thanks for sharing 
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: ClockGadget like CalendarGadget
Thanks friend!IdeasVacuum wrote:Nice work, thanks for sharing
If translation=Error: reply="Sorry, Im Spanish": Endif
Re: ClockGadget like CalendarGadget
Nice, thanks for sharing
Re: ClockGadget like CalendarGadget
My first reaction was to click and drag a clock hand.
Was disappointed that it doesn't work that way.
Was disappointed that it doesn't work that way.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
Re: ClockGadget like CalendarGadget
PB wrote:My first reaction was to click and drag a clock hand.
Was disappointed that it doesn't work that way.
If translation=Error: reply="Sorry, Im Spanish": Endif
Re: ClockGadget like CalendarGadget
Android? No, why?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
Re: ClockGadget like CalendarGadget
Sorry. Just kidding! therefore drag .. like android with your finger. It is a nonsense.PB wrote:Android? No, why?
I spend too much time in front of the pc ..
If translation=Error: reply="Sorry, Im Spanish": Endif
ClockGadget 2.0 like CalendarGadget
See below!
There is new version!
There is new version!
Last edited by minimy on Thu Sep 19, 2013 9:54 pm, edited 1 time in total.
If translation=Error: reply="Sorry, Im Spanish": Endif
- NoahPhense
- Addict

- Posts: 1999
- Joined: Thu Oct 16, 2003 8:30 pm
- Location: North Florida
Re: ClockGadget 2.0 like CalendarGadget
If you grab a hand on the clock and drag it outside the form,the app crashes.
- np
- np
Re: ClockGadget 2.0 like CalendarGadget
You can't exceed the time-space continuum.NoahPhense wrote:If you grab a hand on the clock and drag it outside the form,the app crashes.
- np
Best wishes to the PB community. Thank you for the memories. 
- NoahPhense
- Addict

- Posts: 1999
- Joined: Thu Oct 16, 2003 8:30 pm
- Location: North Florida
Re: ClockGadget like CalendarGadget
Oh. But I can. Maybe that's the problem.Kuron wrote:You can't exceed the time-space continuum.NoahPhense wrote:If you grab a hand on the clock and drag it outside the form,the app crashes.
- np
Re: Solved!
down is the new version. 
Last edited by minimy on Thu Sep 19, 2013 10:17 pm, edited 1 time in total.
If translation=Error: reply="Sorry, Im Spanish": Endif
Re: Solved!
It still crashed for me with the same issue. It was more difficult to invoke the crash, but still possible. (W7-64 running PB5.2 x86).minimy wrote:solved! where is my applause?NoahPhense wrote:If you grab a hand on the clock and drag it outside the form,the app crashes.
- np![]()
Re: Solved!
Tenaja wrote:It still crashed for me with the same issue. It was more difficult to invoke the crash, but still possible. (W7-64 running PB5.2 x86).minimy wrote:solved! where is my applause?NoahPhense wrote:If you grab a hand on the clock and drag it outside the form,the app crashes.
- np![]()
It is true!. After a few seconds Crash.
You're right. I will continue looking for the solution.
Thank you friends!
But... this not!
Code: Select all
; CLOCKGADGET v2.2
; Toni Manrique 2013 (E) ;-)
; This is a 'draghand' ClockGadget
Structure datos
Conten.l
Horas.l
Minut.l
Segun.l
Image.l
Canvas.l
Hora24.l
InkHor.l
InkMin.l
InkSeg.l
InkOut.l
InkCir.l
InkDot.l
Paper.l
WithDots.i
Result.s
Talla.w
; Counter.l
EndStructure
Global NewList Reloj.datos()
;----Fonts
LoadFont(1,"Arial",12,#PB_Font_HighQuality|#PB_Font_Bold)
Procedure DefaultFontID()
ProcedureReturn GetStockObject_(#SYSTEM_FONT)
EndProcedure
;---Maths
;give the real angle
Procedure AtanEx(Diametro,X,Y)
Protected grad,grado
grad = Degree(ATan2(x-(Diametro/2),y-(Diametro/2)))+90 : If grad <0 : grado = grad+360 :Else :grado = grad :EndIf
ProcedureReturn Grado
EndProcedure
Procedure SinPointX(Center.l, Angle.l, Radius.l)
; Angulos en grados
ProcedureReturn Center+Sin(Angle*0.01745329)*Radius
EndProcedure
Procedure CosPointY(Center.l, Angle.l, Radius.l)
; Angulos en grados
ProcedureReturn Center-Cos(Angle*0.01745329)*Radius
EndProcedure
;create line from third part
Procedure LineFrom(x,y,AngDist,Dist,Angulo,Largo)
Protected Xx1=SinPointX(x,Angulo-AngDist,Dist)
Protected yy1=CosPointY(y,Angulo-AngDist,Dist)
Protected Xx2=SinPointX(xx1,Angulo,Largo)
Protected yy2=CosPointY(yy1,Angulo,Largo)
LineXY(xx1,yy1,xx2,yy2,$0000FF)
EndProcedure
;create fat line
Procedure BoxFrom(x.l ,y.l ,Ancho.l ,Angulo.l ,Largo.l ,color.l)
Protected Xx1=SinPointX(x,Angulo+225,Ancho)
Protected yy1=CosPointY(y,Angulo+225,Ancho)
Protected Xx2=SinPointX(xx1,Angulo,Largo)
Protected yy2=CosPointY(yy1,Angulo,Largo)
LineXY(xx1,yy1,xx2,yy2,Color)
xx1=xx2:yy1=yy2
Xx2=SinPointX(xx1,Angulo+90,ancho*2)
yy2=CosPointY(yy1,Angulo+90,ancho*2)
LineXY(xx1,yy1,xx2,yy2,Color)
xx1=xx2:yy1=yy2
Xx2=SinPointX(xx1,Angulo+180,Largo)
yy2=CosPointY(yy1,Angulo+180,Largo)
LineXY(xx1,yy1,xx2,yy2,Color)
xx1=xx2:yy1=yy2
Xx2=SinPointX(xx1,Angulo+270,ancho*2)
yy2=CosPointY(yy1,Angulo+270,ancho*2)
LineXY(xx1,yy1,xx2,yy2,Color)
EndProcedure
;Draw clock
Procedure DrawClock(Canvas ,H.l ,M.l ,S.l)
Protected Size = GadgetWidth(Canvas)
Protected Center = Size/2
Protected OutLine= Center*0.95
Protected Circulo= Center*0.90
Protected F1,F2,F3,F4,X,Y,Color
Box(0,0,Size,Size,Reloj()\Paper)
Circle(Center,Center,OutLine,Reloj()\InkOut)
Circle(Center,Center,Circulo,Reloj()\InkCir)
If Reloj()\WithDots > 0
For p=0 To 11
x=SinPointX(Center,p*30,Circulo*0.9)
Y=CosPointY(Center,p*30,Circulo*0.9)
If Reloj()\WithDots = 1
BoxFrom(x,y,2,p*30,8,Reloj()\InkDot)
FillArea(x,y,Reloj()\InkDot,Reloj()\InkDot)
EndIf
If Reloj()\WithDots = 2
Circle(x,y,5,Reloj()\InkDot)
FillArea(x,y,Reloj()\InkDot,Reloj()\InkDot)
EndIf
Next p
EndIf
If Reloj()\WithDots = 0
For p=0 To 11
x=SinPointX(Center,p*30,Circulo*0.9)
Y=CosPointY(Center,p*30,Circulo*0.9)
F1=H-1:If F1<0:F1=23:EndIf
F2=H+1:If F2>23:F2=0:EndIf
F3=H-2:If F3<0:F3=0:EndIf
F4=H+2:If F4>23:F4=0:EndIf
If F1=p Or F1=p+12
BoxFrom(x,y,2,p*30,8,Reloj()\InkSeg)
FillArea(x,y,Reloj()\InkSeg,Reloj()\InkSeg)
EndIf
If F2=p Or F2=p+12
BoxFrom(x,y,2,p*30,8,Reloj()\InkSeg)
FillArea(x,y,Reloj()\InkSeg,Reloj()\InkSeg)
EndIf
If F3=p Or F3=p+12
BoxFrom(x,y,2,p*30,8,Reloj()\InkMin)
FillArea(x,y,Reloj()\InkMin,Reloj()\InkMin)
EndIf
If F4=p Or F4=p+12
BoxFrom(x,y,2,p*30,8,Reloj()\InkMin)
FillArea(x,y,Reloj()\InkMin,Reloj()\InkMin)
EndIf
If H=p Or H=p+12
BoxFrom(x,y,2,p*30,8,Reloj()\InkHor)
FillArea(x,y,Reloj()\InkHor,Reloj()\InkHor)
EndIf
Next p
EndIf
color=Reloj()\InkHor
BoxFrom(Center,Center,5,H,36,color)
FillArea(Center,Center,Color,color)
Circle(Center,Center,14,color)
color=Reloj()\InkMin
BoxFrom(Center,Center,4,M,46,color)
FillArea(Center,Center,Color,color)
Circle(Center,Center,11,Color)
color=Reloj()\InkSeg
BoxFrom(Center,Center,3,S,56,color)
FillArea(Center,Center,Color,color)
Circle(Center,Center,8,Color)
; StopDrawing()
EndProcedure
;Colours more easy
Procedure SetGadgetColorEx(Gadget.l, Ink.l, Paper.l)
SetGadgetColor(Gadget,#PB_Gadget_BackColor,Paper)
SetGadgetColor(Gadget,#PB_Gadget_FrontColor,Ink)
EndProcedure
Procedure SpinGadgetSet(Gadget.l, Min.l, Max.l, v.l, WidthString.l)
If v<Min:v=Max:EndIf
If v>Max:v=Min:EndIf
SetGadgetState (Gadget, V)
SetGadgetText(Gadget, RSet(Str(v),WidthString,"0"))
EndProcedure
;some body make clik?
Procedure SpinGadgetClik(Gadget.l, Min.l, Max.l)
If GetGadgetState(Gadget)<Min:SetGadgetState(Gadget,Max):EndIf
If GetGadgetState(Gadget)>Max:SetGadgetState(Gadget,Min):EndIf
SpinGadgetSet(Gadget,Min,Max,GetGadgetState(Gadget),2)
SetActiveGadget(-1)
EndProcedure
;create spingadget with attributes
Procedure SpinGadgetEx(Gadget.l, X.l, y.l, w.l, h.l, Min.l, Max.l, Flags.l, V.l, Ink.l, Paper.l=-1, Font.l=-1)
Protected FontID
If Gadget = #PB_Any:Gadget = SpinGadget(#PB_Any ,x,y,w,h,Min,Max,Flags):Else:SpinGadget(Gadget,x,y,w,h,Min,Max,flags):EndIf
If ink > -1 : SetGadgetColor(Gadget,#PB_Gadget_FrontColor,Ink) : EndIf
If Paper > -1 : SetGadgetColor(Gadget,#PB_Gadget_BackColor,Paper) :EndIf
If IsFont(Font) = 0 Or font=-1 :FontID = DefaultFontID():Else:FontID = FontID(Font):EndIf
SetGadgetFont(Gadget,FontID)
SpinGadgetSet(Gadget, Min,Max,v,2)
ProcedureReturn Gadget
EndProcedure
;Create clock & store datas
Procedure ClockGadget(x.l, y.l, h.l, m.l, s.l, InkHor.l, InkMin.l, InkSeg.l, InkOut.l, InkCir.l, InkDot.l, Paper.l, Font.l, WithDots.i=1,Hours24.i=0,flags.l=0)
Protected mifont.l
AddElement(Reloj())
Reloj()\Conten = ContainerGadget(#PB_Any, x, y, 210, 240, flags)
If Reloj()\Conten
SetGadgetColor(Reloj()\Conten,#PB_Gadget_BackColor,Paper)
Reloj()\InkCir= InkCir
Reloj()\InkDot= InkDot
Reloj()\InkHor= InkHor
Reloj()\InkMin= InkMin
Reloj()\InkOut= InkOut
Reloj()\InkSeg= InkSeg
Reloj()\Paper = Paper
Reloj()\WithDots = WithDots
Reloj()\Canvas = CanvasGadget(#PB_Any, 5, 35, 195, 195)
StartDrawing(CanvasOutput(Reloj()\Canvas))
DrawClock(Reloj()\Canvas ,H*30 ,M*6 ,S*6)
StopDrawing()
Reloj()\Horas = SpinGadgetEx(#PB_Any, 5, 5, 40, 25, -1, 100,0, h,Tinta,Papel,Font)
Reloj()\Minut = SpinGadgetEx(#PB_Any, 50, 5, 40, 25, -1, 100,0, m,Tinta,Papel,Font)
Reloj()\Segun = SpinGadgetEx(#PB_Any, 95, 5, 40, 25, -1, 100,0, s,Tinta,Papel,Font)
Reloj()\Hora24 = ButtonGadget(#PB_Any, 140, 5, 60, 25,"12h",#PB_Button_Toggle)
If Hours24=1:SetGadgetState(Reloj()\Hora24,1):SetGadgetText(Reloj()\Hora24,"24h"):EndIf
CloseGadgetList()
SetGadgetColorEx(Reloj()\Horas,Reloj()\InkHor,Reloj()\InkCir)
SetGadgetColorEx(Reloj()\Minut,Reloj()\InkMin,Reloj()\InkCir)
SetGadgetColorEx(Reloj()\Segun,Reloj()\InkSeg,Reloj()\InkCir)
If IsFont(font)=0:mifont=DefaultFontID():Else: mifont=FontID(font):EndIf
If font=-1:mifont=DefaultFontID():EndIf
SetGadgetFont(Reloj()\Hora24,mifont)
EndIf
EndProcedure
;watch the events
Procedure EventClock(Window)
Protected TFour.l, talla.w
ForEach Reloj()
If DesktopMouseX()>WindowX(Window)+GadgetX(Reloj()\Conten)+GadgetX(Reloj()\Canvas) And DesktopMouseX()<WindowX(Window)+GadgetX(Reloj()\Conten)+GadgetX(Reloj()\Canvas)+GadgetWidth(Reloj()\Canvas)
If DesktopMouseY()>WindowY(Window)+GadgetY(Reloj()\Conten)+GadgetY(Reloj()\Canvas)+35 And DesktopMouseY()<WindowY(Window)+GadgetY(Reloj()\Conten)+GadgetY(Reloj()\Canvas)+GadgetHeight(Reloj()\Canvas)
If EventGadget() = Reloj()\Horas
If GetGadgetState(Reloj()\Hora24)=1: SpinGadgetClik(EventGadget(), 0, 23) :Else: SpinGadgetClik(EventGadget(), 1, 12) :EndIf
StartDrawing(CanvasOutput(Reloj()\Canvas))
DrawClock(Reloj()\Canvas,GetGadgetState(Reloj()\Horas)*30,GetGadgetState(Reloj()\Minut)*6,GetGadgetState(Reloj()\Segun)*6)
StopDrawing()
Reloj()\Result = GetGadgetText(Reloj()\Horas)+":"+GetGadgetText(Reloj()\Minut)+":"+GetGadgetText(Reloj()\Segun)
EndIf
If EventGadget() = Reloj()\Minut
SpinGadgetClik(EventGadget(), 0, 59)
StartDrawing(CanvasOutput(Reloj()\Canvas))
DrawClock(Reloj()\Canvas,GetGadgetState(Reloj()\Horas)*30,GetGadgetState(Reloj()\Minut)*6,GetGadgetState(Reloj()\Segun)*6)
StopDrawing()
Reloj()\Result = GetGadgetText(Reloj()\Horas)+":"+GetGadgetText(Reloj()\Minut)+":"+GetGadgetText(Reloj()\Segun)
EndIf
If EventGadget() = Reloj()\Segun
SpinGadgetClik(EventGadget(), 0, 59)
StartDrawing(CanvasOutput(Reloj()\Canvas))
DrawClock(Reloj()\Canvas,GetGadgetState(Reloj()\Horas)*30,GetGadgetState(Reloj()\Minut)*6,GetGadgetState(Reloj()\Segun)*6)
StopDrawing()
Reloj()\Result = GetGadgetText(Reloj()\Horas)+":"+GetGadgetText(Reloj()\Minut)+":"+GetGadgetText(Reloj()\Segun)
EndIf
If EventGadget() = Reloj()\Canvas
If GetGadgetState(Reloj()\Hora24)=1:TFour=12 :Else:TFour=0:EndIf
If EventType() = #PB_EventType_LeftButtonDown Or (EventType() = #PB_EventType_MouseMove And GetGadgetAttribute(Reloj()\Canvas, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
; Reloj()\Counter+1:If Reloj()\Counter=500:Reloj()\Counter=0:SetCursorPos_(WindowX(Window)+GadgetX(Reloj()\Conten)+GadgetX(Reloj()\Canvas)+5,WindowY(Window)+GadgetY(Reloj()\Conten)+GadgetY(Reloj()\Canvas)+40):RightClick():EndIf
If StartDrawing(CanvasOutput(Reloj()\Canvas))
talla=GadgetWidth(Reloj()\Canvas)
x = GetGadgetAttribute(Reloj()\Canvas, #PB_Canvas_MouseX)
y = GetGadgetAttribute(Reloj()\Canvas, #PB_Canvas_MouseY)
If x>0 And x<GadgetWidth(Reloj()\Canvas) And y>0 And y<GadgetHeight(Reloj()\Canvas)
If Point(x,y)=Reloj()\InkSeg
grado = AtanEx(Talla,x,y)
DrawClock(Reloj()\Canvas,GetGadgetState(Reloj()\Horas)*30,GetGadgetState(Reloj()\Minut)*6,grado)
SpinGadgetSet(Reloj()\Segun,0,59,grado/6,2)
EndIf
If Point(x,y)=Reloj()\InkMin
grado = AtanEx(Talla,x,y)
DrawClock(Reloj()\Canvas,GetGadgetState(Reloj()\Horas)*30,grado,GetGadgetState(Reloj()\Segun)*6)
SpinGadgetSet(Reloj()\Minut,0,59,grado/6,2)
EndIf
If Point(x,y)=Reloj()\InkHor
grado = AtanEx(Talla,x,y)
DrawClock(Reloj()\Canvas,grado,GetGadgetState(Reloj()\Minut)*6,GetGadgetState(Reloj()\Segun)*6)
SpinGadgetSet(Reloj()\Horas,0,23,(grado/30)+TFour,2)
EndIf
EndIf
StopDrawing()
EndIf
EndIf
If EventType() = #PB_EventType_LeftButtonUp
; Reloj()\Counter=0
EndIf
Reloj()\Result = GetGadgetText(Reloj()\Horas)+":"+GetGadgetText(Reloj()\Minut)+":"+GetGadgetText(Reloj()\Segun)
EndIf
If EventGadget() = Reloj()\Hora24
If GetGadgetState(Reloj()\Hora24)=1
SetGadgetText(Reloj()\Hora24,"24h")
If GetGadgetState(Reloj()\Horas)<12
SetGadgetState(Reloj()\Horas,GetGadgetState(Reloj()\Horas)+12):SetGadgetText(Reloj()\Horas,RSet(Str(GetGadgetState(Reloj()\Horas)),2,"0"))
EndIf
Else
SetGadgetText(Reloj()\Hora24,"12h")
If GetGadgetState(Reloj()\Horas)>11
SetGadgetState(Reloj()\Horas,GetGadgetState(Reloj()\Horas)-12):SetGadgetText(Reloj()\Horas,RSet(Str(GetGadgetState(Reloj()\Horas)),2,"0"))
EndIf
EndIf
EndIf
EndIf
EndIf
Next
EndProcedure
CompilerIf Not #PB_Compiler_IsIncludeFile
Global Window_0
Define.l Event, EventWindow, EventGadget, EventType, EventMenu
Procedure OpenWindow_Window_0()
Window_0 = OpenWindow(#PB_Any, 100, 200, 650, 400, "ClockGadget v2.0 (Drag the hand)", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
SetWindowColor(Window_0,$444444)
; DO NOT USE SAME COLORS FOR HOURS, MINUTES AND SECONDS
ClockGadget(5,5,Random(23),Random(59),Random(59),$0000FF,$FF0000,$00FF00,$0,$FFFFFF,$0,$CCCCCC,1,2,1)
ClockGadget(220,5,Random(12),Random(59),Random(59),$FFFFFF,$CCCCCC,$999999,$0,$333333,$0,$444444,0,1,0,#PB_Canvas_Border)
ClockGadget(440,5,Random(23),Random(59),Random(59),$55FFFF,$22FF22,$00CC00,$00FFFF,$005500,$99FFFF,$444444,0,1,1)
EndProcedure
OpenWindow_Window_0()
Repeat
Event = WaitWindowEvent(1)
Select Event
Case #PB_Event_Gadget
EventGadget = EventGadget()
EventType = EventType()
; If EventGadget = Container_0
; ElseIf EventGadget = CanvasReloj
; EndIf
EventClock(Window_0)
Case #PB_Event_CloseWindow
EventWindow = EventWindow()
If EventWindow = Window_0
CloseWindow(Window_0)
Window_0 = 0
Break
EndIf
EndSelect
ForEver
CompilerEndIfIf translation=Error: reply="Sorry, Im Spanish": Endif

