//**************************************************
//	Digit Widgets Module
// 	Stroke Intropolation
//**************************************************
[PD]
[FontSetColor,255,200,0]Stroke Interpolation Functions[FontSetColor,160,160,160]
[VarDef,Snumpts,0]
[VarDef,Enumpts,0]
[VarDef,Minh,0]
[VarDef,Maxh,0]
[VarDef,Minv,0]
[VarDef,Maxv,0]
[VarDef,MaxDeltaH,0]
[VarDef,MaxDeltaV,0]
[VarDef,cnt,0]
[VarDef,cnt1,0]
[VarDef,ox,0]
[VarDef,oy,0]
[VarDef,ex,0]
[VarDef,ey,0]
[VarDef,SStroke,0]
[VarDef,EStroke,0]
[VarDef,Pixcnt,0]
[VarDef,Zdelta,0]
[VarDef,cptr,0]
[VarDef,ISkip,1]
[VarSet,ICTime,.1]
[VarDef,zinit,0]
[VarDef,zfinis,0]
[VarDef,SelTool,8]
[PD]
[iSlider,"Number of Points ",10,1,0,1000,"Number of Points in Interpolation", 
	[varSet,Ipoints,zscript:NumberofPoints]
	[VarSet,ICtime,1.0/Ipoints]

,0,[TextCalcWidth,Distance14537890123]]
[iSlider,"Skip ",1,1,0,1000,"Number of Points in Interpolation to Skip", 
	[varSet,ISkip,zscript:Skip]
,0,[TextCalcWidth,Distance14537890123]]

[iSwitch,"Use Object",0,"Size to Position"]
[iSlider,"SizeIncr",0,1,0,360,"Select Angle Increment ",[VarSet,ssize,zscript:SizeIncr],0,[TextCalcWidth,SizeIncr4123]]
[iSlider,"ZStart",0,1,-4000,4000,"Select Starting Z ",[VarSet,Zinit,zscript:ZStart],0,[TextCalcWidth,SizeIncr4123]]
[iSlider,"ZEnd",0,1,-4000,4000,"Select Ending Z ",[VarSet,zfinis,zscript:ZEnd],0,[TextCalcWidth,SizeIncr4123]]
[iSwitch,"SColorit",0,"Set color to Canvas"]
[PD]
[IButton,"ZPicker ","Pick Zstart and Zend by draggin XYZ Pixol on Canvas",
	[RoutineCall,Mouselook,Hval1,Vval1,Hval2,Vval2,Clicked]
	[RoutineCall,PixolLook,Hval1,Vval1,1,Zval1,dummy,dummy,dummy]
	[Iset,zscript:Zstart,Zval1]
	[VarSet,Zinit,Zval1]
	[RoutineCall,PixolLook,Hval2,Vval2,1,Zval2,dummy,dummy,dummy]
	[Iset,zscript:ZEnd,Zval2]
	[VarSet,Zfinis,Zval2]
]
//[iSlider,"ZTool",0,1,0,11,"Select ZTool ",[VarSet,SelTool,zscript:Ztool],0,[TextCalcWidth,SizeIncr4123]]
[IButton,"ZTool","Set Object that you wish to use",
	[note,"Selecting Tool....",,-1]
	[VarSet,SelTool,[IGet,TOOL:iteminfo]]
	[note,SelTool,,1]
]

[iButton," GetStartstroke ","Grab the Start Stroke Data",
	[VarSet,SStroke,[StrokeGetLast]] //get the last drawn stroke
]
[iButton," GetEndstroke ","Grab the End Stroke Data",
	[VarSet,EStroke,[StrokeGetLast]] //get the last drawn stroke
]
[iButton," DoObjStroke ","Look at Stroke Data",
	[VarSet,Snumpts,[StrokeGetInfo,SStroke,0]]
	[VarSet,Enumpts,[StrokeGetInfo,EStroke,0]]
	[VarSet,Pixcnt,max(Snumpts,Enumpts)]
	[if,Snumpts>=Enumpts,
		[VarSet,Zdelta,pixcnt/Enumpts]
	,
		[VarSet,Zdelta,pixcnt/Snumpts]
	]
	[VarSet,cnt,0]
	[VarSet,cnt1,0]
	[VarSet,ccntr,1.0/ICTime]
	[VarSet,cptr,0]
	[VarInc,ccntr]
	[VarSet,ssize,5]
	
	[if,zscript:useobject,
		[VarSet,ssize,[IGet,Draw:DrawSize]]
		[ISet,Tool:ItemInfo,SelTool]
		//put tool on the canvas
		[canvasclick,320,240,320+10,240+10]
		[IPress,Transform:Move]
		//Size it accordingly
		[TransformSet,320,240,0,ssize,ssize,ssize]
	]

	[Loop,ccntr,
		[VarSet,crecurse,ICTime*cptr]
		[if,zscript:useobject,
				[VarSet,resultz,[Interpolate,crecurse,zinit,zfinis]]
		]
		[Loop,Pixcnt,
	
			[VarSet,ox,[StrokeGetInfo,SStroke,1,cnt]]
			[VarSet,oy,[StrokeGetInfo,SStroke,2,cnt]]
			[VarSet,ex,[StrokeGetInfo,EStroke,1,cnt1]]
			[VarSet,ey,[StrokeGetInfo,EStroke,2,cnt1]]

			[VarSet,resultx,[Interpolate,crecurse,ox,ex]]
			[VarSet,resulty,[Interpolate,crecurse,oy,ey]]
			[if,[iGet,zscript:SColorit],
				[RoutineCall,ZcolorCalc,resultx,resulty,resultz]
			]
			[if,zscript:useobject,
				[TransformSet,resultx,resulty,resultz,ssize,ssize,ssize]
				[IPress,Transform:Snapshot]
			,//else
				[CanvasClick,resultx,resulty]
			]

			[if,Snumpts>=Enumpts,
				[VarSet,cnt,cnt+(1*Iskip)]
				[VarSet,cnt1,cnt1+(zdelta*ISkip)]
			,//else
				[VarSet,cnt1,cnt1+(1*Iskip)]
				[VarSet,cnt,cnt+(zdelta*ISkip)]
			]
			[if,cnt1>Pixcnt,[LoopExit]]
			[if,cnt>Pixcnt,[LoopExit]]
		]

		[VarSet,cnt,0]
		[VarSet,cnt1,0]
		[varInc,cptr]
		[if,cptr>ccntr,[LoopExit]]
	]
]
[varDef,SStrok,( 
 )]
[varDef,EStrok,( 
 )]
[iButton,"Example ","Interpolation Widget Example",
	[if,[Ireset],
		//[Iset,zscript:skip,10]
		[IcolorSet,239,234,30]
		[Note,"Setting Draw Size to 10",zscript:example,2]
		[ISet,Draw:Drawsize,10]
		[note,"Setting Number of Points to 10",zscript:NumberofPoints,2]

		[ISet,zscript:NumberofPoints,10]

		[note,"Next I will draw the first Stroke",zscript:example,0]

		[CanvasStroke,SStrok]

		[note,"And press the GetStartStroke Button",zscript:getstartstroke,0]
		[VarSet,SSTroke,SStrok]

		[note,"I will draw the second Stroke",zscript:example,0]

		[CanvasStroke,EStrok]

		[note,"And press the GetEndStroke Button",zscript:getendstroke,0]
		[VarSet,ESTroke,EStrok]

		[Note,"Next I will press the DoObjStroke button to do the Morph",zscript:DoObjStroke ,0]
		[IPress,zscript:DoObjStroke]

		[Note,"You can also use tools by selecting the tool you wish and pressing Ztool",zscript:ztool,0]
		[Note,"Also select Use Object and enter Start and End Zdepth",zscript:useobject,0]
		[Note,"Size of the objects are controlled by DrawSize",Draw:Drawsize,0]
		[if,zscript:useobject,,	[IToggle,zscript:useobject]]
		[Iset,zscript:zstart,-100]		
		[note,"Setting Zstart to -100",zscript:Zstart,2]
		[Iset,zscript:zEnd,-500]		
		[note,"Setting ZEnd to -500 you can also use the Zpicker and grab and drag mouse",zscript:ZEnd,0]
		[Note,"Next I will press the DoObjStroke button to do the Morph",zscript:DoObjStroke ,0]
		[IPress,zscript:DoObjStroke]
		[Note,"You can control the resolution of the objects by setting the Skip slider",zscript:skip,0]
		[Iset,zscript:skip,10]
		[ISet,Draw:Drawsize,5]
		[IcolorSet,255,0,30]
		[Iset,zscript:zstart,-200]		
		[Iset,zscript:zEnd,-600]		
		[IPress,zscript:DoObjStroke]
	]
]
