-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-- *  Rescales spline sub-objects from their first vertex.  *
-- *  GARP - 2009                                          *
-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

(
global rltRescaleShapeFromFirst
try destroyDialog rltRescaleShapeFromFirst catch()

rollout rltRescaleShapeFromFirst "Rescale From First" width:150
(
	spinner spnMulti "Multiplier: " range:[0, 10000, 1] align:#center
	fn filterShape obj = superClassOf obj == Shape
	pickButton btnShape "Pick Shape" width:112 align:#center filter:filterShape
	checkBox chkSel "Use Spline Selection"
	
	on btnShape picked obj do undo "Rescale Splines" on
	(
		local m = spnMulti.value
		convertToSplineShape obj
		local aSS = getSplineSelection obj
		
		fn resizeSpline obj si m =
		(
			for vi = 1 to numKnots obj si do
			(
				setKnotPoint obj si vi (m * getKnotPoint obj si vi + (1 - m) * getKnotPoint obj si 1)
				if getKnotType obj si vi == #bezier or getKnotType obj si vi == #bezierCorner do
				(
					setInVec obj si vi (m * getInVec obj si vi + (1 - m) * getKnotPoint obj si 1)
					setOutVec obj si vi (m * getOutVec obj si vi + (1 - m) * getKnotPoint obj si 1)
				)
			)

		)
		
		if chkSel.checked and aSS.count != 0 then for si in aSS do resizeSpline obj si m
		else for si = 1 to numSplines obj do resizeSpline obj si m
		
		updateShape obj
		completeRedraw()
	)
)

createDialog rltRescaleShapeFromFirst
)