<* PRAGMA LL *> MODULE; IMPORT GraphVBT, GraphVBTExtras, R2, Animate, MG, MGV; TYPE LinearAnimation = Animation BRANDED OBJECT v: GraphVBT.Vertex; old, delta: R2.T METHODS init(v: GraphVBT.Vertex; new: R2.T): LinearAnimation := LAInit OVERRIDES size := LASize END; (* If "la := NEW(LinearAnimation).init(v, new)", then "la.size(t)" returns the size that is a linear interpolation between "v"'s initial size and "new". *) PROCEDURE VertexSizeAnim LAInit (self: LinearAnimation; v: GraphVBT.Vertex; new: R2.T): LinearAnimation = BEGIN self.v := v; self.old := v.size; self.delta := R2.Sub(new, v.size); RETURN self END LAInit; PROCEDURELASize (self: LinearAnimation; t: REAL): R2.T = BEGIN RETURN R2.Add(self.old, R2.Scale(t, self.delta)) END LASize; TYPE MyAnimation = Animate.T OBJECT v: GraphVBT.Vertex; anim: Animation; OVERRIDES length := Length; doStep := DoStep END; PROCEDURELength ( <* UNUSED *> t : MyAnimation; <* UNUSED *> v : MG.V; <* UNUSED *> mg: MG.T): INTEGER = BEGIN RETURN LAST(INTEGER); END Length; PROCEDUREDoStep ( self: MyAnimation; time: REAL; <* UNUSED *> timePrev: REAL; <* UNUSED *> v: MG.V; <* UNUSED *> mg: MG.T) = BEGIN self.v.setSize(self.anim.size(time)); END DoStep; PROCEDURERegister (v: GraphVBT.Vertex; anim: Animation) = <* LL = v.graph.mu *> BEGIN MGV.AddAnimationLocked( GraphVBTExtras.GetMG(v.graph), NEW(MyAnimation, v := v, anim := anim).init(), NIL); END Register; PROCEDURELinear (v: GraphVBT.Vertex; newW, newH: REAL) = <* LL = 0 *> BEGIN LOCK v.graph.mu DO Register(v, NEW(LinearAnimation).init(v, R2.T{newW, newH})) END END Linear; BEGIN END VertexSizeAnim.