-- Compiler ObjectXForms
-- Stone May 2, 1981 1:09 PM
DIRECTORY
ObjectDefs: FROM "ObjectDefs",
PointDefs: FROM "PointDefs",
EncodingDefs: FROM "EncodingDefs",
GriffinStartDefs: FROM "GriffinStartDefs",
MenuDefs: FROM "MenuDefs",
XFormDefs: FROM "XFormDefs";
ObjectXForms: PROGRAM IMPORTS ObjectDefs,XFormDefs,PointDefs,MenuDefs EXPORTS ObjectDefs, GriffinStartDefs =
BEGIN OPEN ObjectDefs,XFormDefs,PointDefs;
--does a translation on all control points and on the encoding
MoveObject: PUBLIC PROCEDURE[object: ObjectHandle, from,to: ScrPt]=
BEGIN
token: ObjectHandle ← ReturnSelected[object];
Move[object,from,to];
IF token # NIL THEN Move[token,from,to];
END;
Move: PROCEDURE[object: ObjectHandle, from,to: ScrPt]=
BEGIN
m1: XFormMatrix;
transmatrix: XFMDescriptor ← DESCRIPTOR[m1];
hgrid,vgrid: BOOLEAN ← FALSE;
objfrom,objto,dist: ObjPt;
dx,dy: INTEGER;
dx ← to[X]-from[X];
dy ← to[Y]-from[Y];
--move bounding box
--bounding boxes on the grid move only in one dimension
WITH objtype: object SELECT FROM
token => {hgrid ← objtype.tokenType=hgrid;
vgrid ← objtype.tokenType=vgrid};
ENDCASE;
IF ~hgrid THEN object.tl[X] ← object.tl[X]+dx;
IF ~vgrid THEN object.tl[Y] ← object.tl[Y]+dy;
IF ~hgrid THEN object.br[X] ← object.br[X]+dx;
IF ~vgrid THEN object.br[Y] ← object.br[Y]+dy;
--move encoding in screen space
WITH objtype: object SELECT FROM
shape => BEGIN
cptr: POINTER TO EncodingDefs.ChainEncoding;
aptr: POINTER TO EncodingDefs.AreaEncoding;
FOR cptr ← objtype.chainEncoding, cptr.link UNTIL cptr=NIL DO
cptr.p0[X] ← cptr.p0[X]+dx;cptr.p0[Y] ← cptr.p0[Y]+dy;
cptr.tl[X] ← cptr.tl[X]+dx;cptr.tl[Y] ← cptr.tl[Y]+dy;
cptr.br[X] ← cptr.br[X]+dx;cptr.br[Y] ← cptr.br[Y]+dy;
ENDLOOP;
FOR aptr ← objtype.areaEncoding, aptr.link UNTIL aptr=NIL DO
aptr.tl[X] ← aptr.tl[X]+dx;aptr.tl[Y] ← aptr.tl[Y]+dy;
aptr.br[X] ← aptr.br[X]+dx;aptr.br[Y] ← aptr.br[Y]+dy;
ENDLOOP;
END;
menu => BEGIN OPEN MenuDefs;
MoveMenuItem: MenuProc =
BEGIN
item.tl [X] ← item.tl [X] + dx;
item.tl [Y] ← item.tl [Y] + dy;
item.br [X] ← item.br [X] + dx;
item.br [Y] ← item.br [Y] + dy;
END;
ForAllMenuItems [@objtype, MoveMenuItem];
END;
ENDCASE;
--move the object in object space
objfrom ← ScrToObj[from];
objto ← ScrToObj[to];
dist[X] ← objto[X]-objfrom[X];
dist[Y] ← objto[Y]-objfrom[Y];
InitXForms[transmatrix];
Translate[dist,transmatrix];
XForm[object,transmatrix];
END;
XFormObject: PUBLIC PROCEDURE [object: ObjectHandle,matrix: XFMDescriptor] =
BEGIN
token: ObjectHandle ← ReturnSelected[object];
XForm[object,matrix];
IF token # NIL THEN BEGIN
XForm[token,matrix];
token.validEncoding ← FALSE;
END;
object.validEncoding ← FALSE;
END;
XForm: PROCEDURE [object: ObjectHandle,matrix: XFMDescriptor] =
BEGIN
WITH objtype: object SELECT FROM
shape => WITH traj: objtype.trajectory SELECT FROM
linked => BEGIN
link: POINTER TO Link ← traj.links;
UNTIL link=NIL
DO
XFormArray[link.knots,matrix];
link ← link.link;
ENDLOOP;
END;
cyclic => XFormArray[traj.knots,matrix];
ENDCASE;
--captions and tokens don’t do much except on translate
caption => objtype.p0 ← XFormPt[objtype.p0,matrix];
token => objtype.p0 ← XFormPt[objtype.p0,matrix];
ENDCASE;
END;
XFormArray: PROCEDURE [array: DESCRIPTOR FOR ARRAY OF ObjPt,xform: XFMDescriptor] =
BEGIN
i: INTEGER;
FOR i IN [0..LENGTH[array]) DO
array[i] ← XFormPt[array[i],xform];
ENDLOOP;
END;
END.