Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
You know the stopwatch class?
Message
From
13/07/1999 20:03:03
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
00240950
Message ID:
00241086
Views:
20
>Is there a way to make the digital stopwatch into an analog stopwatch instead?
>
>Thanks for helping.

First thing that comes to my mind is having three objects of Line class, and move them once per second. Shouldn't be hard to do. I'd start with building two arrays at .init, one dimensioned 12,2 and another 60,2, and calculate their values in advance. They'd hold the moving end of the line.

OK, here's the round clock. I admit I did it for my own pleasure - getting it to work (from scratch) took about one hour. The code is pasted from class browser's output, and since it's got no code in contained objects, it should work. Of course, the original idea of storing the precalculated values instead of recalculating them each time is left for later.

My sincere apologies if my choice of color looks awful - change it into something decent.

Now, just add your buttons and turn it into a stopwatch. Have fun.
**************************************************
*-- Class:        stopw 
*-- ParentClass:  container
*-- BaseClass:    container
*
DEFINE CLASS stopw AS container


	Width = 197
	Height = 166
	BackColor = RGB(128,0,255)
	Name = "stopw"

	*-- pi()*2
	twopee = .F.


	ADD OBJECT timer1 AS timer WITH ;
		Top = 12, ;
		Left = 12, ;
		Height = 23, ;
		Width = 23, ;
		Interval = 1000, ;
		Name = "Timer1"


	ADD OBJECT lineh AS line WITH ;
		BorderWidth = 4, ;
		Height = 60, ;
		Left = 96, ;
		Top = 24, ;
		Width = 0, ;
		BorderColor = RGB(0,255,0), ;
		Name = "LineH"


	ADD OBJECT linem AS line WITH ;
		BorderWidth = 3, ;
		Height = 60, ;
		Left = 96, ;
		Top = 24, ;
		Width = 0, ;
		BorderColor = RGB(255,255,255), ;
		Name = "LineM"


	ADD OBJECT lines AS line WITH ;
		BorderWidth = 2, ;
		Height = 60, ;
		Left = 96, ;
		Top = 24, ;
		Width = 0, ;
		BorderColor = RGB(255,255,0), ;
		Name = "LineS"


	*-- move the line to its proper position
	PROCEDURE putline
		Lpara x,y, oLine

		nTop=min(y, 84)
		nLeft=min(x, 96)
		nHeight=abs(y-84)
		nWidth=abs(x-96)

		if (y>84)#(x>96)
			cSlant="/"
		else
			cSlant="\"
		endif
		with oLine
			.top=nTop
			.Left=nLeft
			.Width=nWidth
			.height=nHeight
			.LineSlant=cSlant
		endwith
	ENDPROC


	PROCEDURE drawtime
		LPara lFromInit
		cTime=time()
		cHour=wordnum(cTime,1,":")
		cMinute=wordnum(cTime,2,":")
		cSecond=wordnum(cTime,3,":")
		nHour=val(cHour)%12
		nMinute=val(cMinute)
		nSecond=val(cSecond)
		This.CalcAndDraw(nSecond/60,60,This.LineS)
		if nSecond=0 or lFromInit
			This.CalcAndDraw(nMinute/60,55,This.LineM)
		*	if nMinute=0 or lFromInit
				This.CalcAndDraw((nHour+nMinute/60)/12,50,This.LineH)
		*	endif
		endif
	ENDPROC


	PROCEDURE calcanddraw
		lPara nPartOf, nLineLen, oLine

		nx=96+cos(this.TwoPee*(-.25+nPartOf))*nLineLen
		ny=84+sin(this.TwoPee*(-.25+nPartOf))*nLineLen

		this.PutLine(nx, ny, oLine)
	ENDPROC


	PROCEDURE Init
		this.setall("visible",.t.,"line")
		this.TwoPee=2*pi()
		This.DrawTime(.t.)
	ENDPROC


	PROCEDURE timer1.Timer
		This.Parent.DrawTime
	ENDPROC


ENDDEFINE
*
*-- EndDefine: stopw
**************************************************

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Reply
Map
View

Click here to load this message in the networking platform