macroScript Penciltest category:"Tools"\

				ButtonText:"PencilTest" \

				tooltip:"Render to RAM player" 

(

	rollout TestRender ""

	(

	

	fn invalidate Bname ButtonSet = 

		(

		for item in ButtonSet do 

			(if item != Bname then item.checked = not (Bname.checked))

		)

		
	fn RenderOut =
		(
		closeme =  keyboard.shiftpressed
		escapeenable = false
		reslist = #([240,160],[320,240],[512,384],[Testrender.CustH.value,Testrender.CustW.value])
		Rez = [240,160]
		for i = 1 to 4 do

			(if SzButtons[i].checked then rez = Reslist[i])

		try (pencil = render\
			fromframe:Testrender.Bstart.value\
			toframe:Testrender.BBend.value\
			nthframe:Testrender.BBy.value\
			outputsize:Rez\
			antialiasing:Testrender.Bwire.checked\
			forcewireframe:Testrender.Bwire.checked\
			outputfile:Testrender.BsavePath.Text\
			vfb:Testrender.BVFB.checked)

		catch (messagebox "Rendering Error")
		undisplay pencil	
		if Testrender.BRAM.checked then RamPlayer Testrender.Bsavepath.text ""
		escapeenable = true
		if closeme then closerolloutfloater renderdialog
		)
		
	

	group "Resolution"

		(

		checkbutton B240 "240 x 160" across:3 width:70 

		checkbutton B320 "320 x 240" width:70 checked:true

		checkbutton B512 "512 x 384" width:70

		checkbutton BCustom "Custom:" across:3 width:70 offset:[0,2]

		Spinner CustH "H:" range:[16,1024,640] type:#integer scale:16 fieldwidth:48 offset:[-10,4]

		Spinner CustW "W:" range:[16,1024,480] type:#integer scale:16 fieldwidth:48 offset:[-10,4]

		)

	group "Options"

		(

		checkbutton BSolid "Shaded"across:2 width:70 checked:true

		checkbutton Bwire "Wireframe" width:70 

	

		)	

	

	group "Render"

		(	

		button Bsaveto "Save to:" across:2 offset:[-40,0]

		edittext BsavePath fieldwidth:200 text:SavePath offset:[-70,2]

		Spinner Bstart "From:" \

			range:[0,animationrange.end.frame as integer,animationrange.start.frame as integer]\

			type:#integer scale:1 fieldwidth:32 offset:[-10,8]\

			across:3

		Spinner BBend "To:" \

		range:[0,animationrange.end.frame as integer,animationrange.end.frame as integer] \

		type:#integer scale:1 fieldwidth:32 offset:[-10,8]

		Spinner BBy "By:" \

		range:[1,16,1] \

		type:#integer scale:1 fieldwidth:32 offset:[-10,8]

		label Bx ""

		checkbox BVFB "frame buffer:" checked:true across:2 offset:[24,-8]	

		checkbox BRAM "RAM player:" checked:true offset:[24,-8] 

		)

		button Bgo "Go" width:100 across:2

		button Bshowlast "Show last render" width:100 
		

	on CustH changed value do 

		(

		BCustom.checked = true

		invalidate BCustom SzButtons

		) 	
		

	on CustW changed value do 

		(

		BCustom.checked = true

		invalidate BCustom SzButtons

		) 		
		

	on B240 changed state do (if B240.checked then invalidate TestRender.B240 SzButtons else B240.checked=true)
	

	on B320 changed state do (if B320.checked then invalidate TestRender.B320 SzButtons else B320.checked=true)
	

	on B512 changed state do (if B512.checked then invalidate TestRender.B512 SzButtons else B512.checked=true)
	

	on BCustom changed state do (if BCustom.checked then invalidate TestRender.BCustom SzButtons else BCustom.checked=true)
	

	on BSolid changed state do (if BSolid.checked then invalidate TestRender.BSolid RButtons else BSolid.checked=true)
	

	on BWire changed state do (if Bwire.checked then invalidate TestRender.Bwire RButtons else Bwire.checked=true)
	

	on BSaveto pressed do

		(

		newpath = GetSaveFileName "Save preview file:" types:".AVI|*.avi|"

		if newpath != undefined then 
			(
			BSavePath.text = newpath
			writeout = createfile "PCT.dat"
			format "%\n"  newpath to:writeOut
			close writeout
			)

		)

	on BGo pressed do (Renderout())

				

	on BShowLast pressed do

		(

		RamPlayer BsavePath.text ""

		)
	on TestRender open do 
		(
		if keyboard.shiftpressed do renderout())
	)

	global SzButtons = #(TestRender.B240, TestRender.B320, TestRender.B512, Testrender.BCustom)
	global Rbuttons = #(TestRender.Bsolid, TestRender.Bwire)
	global SavePath

	datpath = openfile "C:\\PCT.dat" 
		if datpath == undefined then
			(
			SavePath = undefined
			while SavePath == undefined do
				(
				SavePath = GetSaveFileName "Save preview file:" types:".AVI|*.avi|"
				)			
			writeout = createfile "c:\\PCT.dat"
			format "%\n"  SavePath to:writeOut
			close writeout	
			setfileattribute "C:\\PCT.dat" #hidden true
			)
		else
			(
			SavePath = readline datpath
			close datpath
			)
	



			

	RenderDialog = NewRolloutFloater "Pencil Test" 320 332

	addrollout testrender RenderDialog

)

