Compiler ShowObjects/n;bind griffin;griffin
mstone April 24, 1981 3:10 PM
geoff November 26, 1979 10:45 AM
Last Edited by: Stone, February 18, 1983 1:03 pm
Last Edited by: Pier, February 14, 1984 10:52:01 am PST
DIRECTORY
GriffinDisplay,
RefreshDefs USING [EraseAndSaveBox],
GriffinText USING [GetBoundingBox],
GriffinViewer USING [PaintProc, DoPaint],
ImagerInterpress USING [Create, Ref, DoPage, Close],
CubicSplines,
StyleDefs,
Imager USING [Context, metersPerPoint],
Rope USING [ROPE],
GriffinDefs,
PointDefs,
MenuDefs,
GriffinEncoding,
ObjectDefs;
ShowObjects: CEDAR PROGRAM
IMPORTS GriffinDisplay, ObjectDefs, PointDefs, MenuDefs, GriffinViewer, GriffinEncoding, RefreshDefs, GriffinText, ImagerInterpress
EXPORTS ObjectDefs =
BEGIN OPEN ObjectDefs,PointDefs;
Context: TYPE=Imager.Context;
debug: BOOLEANFALSE;
ReplotAllObjects: PUBLIC PROCEDURE[dc: Context] = {
proc: ObjectProc = {PlotObject[obj, dc]};
ForAllObjects[proc];
};
ObjectsToInterpress: PUBLIC PROCEDURE[s: Rope.ROPE] = {
action: PROC [dc: Imager.Context] = {
proc: ObjectProc = {PlotObject[obj, dc]};
ForAllPictureObjects[proc];
};
Get an interpress context from the rope, "display" only the visible objects
ip: ImagerInterpress.Ref ← ImagerInterpress.Create[s];
GriffinDisplay.ResetClipEdges[];
ImagerInterpress.DoPage[ip, action, Imager.metersPerPoint];
ImagerInterpress.Close[ip];
};
replots all objects linked to allObjects
ReplotFromObject: PUBLIC PROCEDURE[startObj: ObjectHandle, dc: Context] =
BEGIN
obj: REF Object ← startObj;
UNTIL obj=NIL DO
PlotObject[obj, dc];
obj ← obj.link;
ENDLOOP;
END;
calls the correct type of plotting routine, be it splines, encoding, whatever
PlotObject: PUBLIC PROCEDURE [object: ObjectHandle, dc: Context] =
BEGIN
IF object=NIL THEN RETURN;
IF ~Visible[object] THEN RETURN;
IF NOT object.validEncoding THEN ERROR;
IF GriffinDisplay.IsCull[object.tl,object.br, dc] THEN RETURN;
WITH object SELECT FROM
obj: REF Object[shape] => BEGIN
IF NOT obj.closed THEN { --Strokes
IF object.cluster=OpenCluster AND obj.style.outlined=FALSE
THEN GriffinDisplay.DrawFastStroke[obj.edgeEncoding, dc]
ELSE GriffinDisplay.DrawStroke[obj.edgeEncoding, obj.style, dc];
}
ELSE { --Areas
GriffinDisplay.DrawArea[obj.edgeEncoding, obj.style, dc];
};
END;
obj: REF Object[caption] =>
GriffinDisplay.DrawCaption[ObjToScrReal[obj.p0], obj.text, obj.style, dc];
obj: REF Object[menu] => MenuDefs.PlotMenu[obj, dc];
obj: REF Object[selectToken] => DrawSelectToken[obj, dc];
obj: REF Object[token] => SELECT obj.tokenType FROM
CP => GriffinDisplay.DrawToken[ObjToScr[obj.p0],cp,dc];
open => GriffinDisplay.DrawToken[ObjToScr[obj.p0],open,dc];
vgrid => GriffinDisplay.DrawVGrid[ObjToScr[obj.p0], dc];
hgrid => GriffinDisplay.DrawHGrid[ObjToScr[obj.p0], dc];
ENDCASE;
ENDCASE;
END;
DrawSelectToken: PROCEDURE [token: REF selectToken Object, dc: Context] =
BEGIN
selectedObject: ObjectHandle ← token.selectedObj;
coverObj: ObjectHandle ← NIL;
covered: BOOLEANFALSE;
clustered: BOOLEANFALSE;
pt: ScrPt;
IF NOT token.located THEN ERROR;
is token covered?
coverObj ← GetObjectHandleBetweenObjects[pt, GetTopPictureObj[], selectedObject] ;
if not, is object covered at position of token?
IF coverObj=token THEN
coverObj ← GetObjectHandleBetweenObjects[pt,GetTopPictureObj[],selectedObject];
covered ← (coverObj#token AND coverObj#NIL);
clustered ← selectedObject.cluster # 0;
pt ← ObjToScr[token.p0];
GriffinDisplay.DrawSelection[pt,covered, clustered, dc];
END;
ReplotBoxFromObject: PUBLIC PROCEDURE[tl,br: ScrPt, object: ObjectHandle, dc: Context]=
BEGIN
GriffinDisplay.SetClipEdges[tl,br];
ReplotFromObject[object, dc];
GriffinDisplay.ResetClipEdges[];
END;
ReplotBox: PUBLIC PROCEDURE[tl,br: ScrPt, dc: Context]=
BEGIN
GriffinDisplay.SetClipEdges[tl,br];
ReplotAllObjects[dc];
reset them
GriffinDisplay.ResetClipEdges[];
END;
PlotOneObject: PUBLIC PROCEDURE [object: ObjectHandle] = {
painter: GriffinViewer.PaintProc = {
PlotObject[object,dc];
};
GriffinViewer.DoPaint[painter];
};
EraseObject: PUBLIC PROCEDURE [object: ObjectHandle] =
BEGIN
select: REF Object[selectToken] ← NIL;
painter: GriffinViewer.PaintProc = {
do: ObjectProc = BEGIN
IF obj#object AND obj#select THEN PlotObject[obj, dc];
END;
GriffinDisplay.SetClipEdges[object.tl, object.br];
GriffinDisplay.ClearScreen[dc];
ForAllObjects[do];
reset them
GriffinDisplay.ResetClipEdges[];
};
IF object=NIL THEN RETURN;
IF NOT object.validEncoding THEN ERROR;
GriffinViewer.DoPaint[painter];
END;
PlotLink: PUBLIC PROCEDURE[link: GriffinEncoding.Link, style: StyleDefs.StyleHandle]=
BEGIN
paint: GriffinViewer.PaintProc = {
IF style = NIL THEN GriffinDisplay.DrawFastStroke[encoding, dc]
ELSE GriffinDisplay.DrawStroke[encoding, style, dc];
};
encoding: GriffinEncoding.EdgeEncoding ← GriffinEncoding.EncodeEdge[LIST[link]];
GriffinViewer.DoPaint[paint];
END;
EraseLink: PUBLIC PROCEDURE[link: GriffinEncoding.Link] =
BEGIN
RefreshDefs.EraseAndSaveBox[ScrRealToScr[link.tl], ScrRealToScr[link.br]];
END;
EncodeObject: PUBLIC PROC [shape: REF shape Object] ~ TRUSTED {
WITH traj: shape.trajectory SELECT FROM
cyclic => {
link: GriffinEncoding.Link ←
GriffinEncoding.EncodeCubicLink[traj.knots, traj.splineType];
shape.edgeEncoding ← GriffinEncoding.EncodeEdge[LIST[link]];
};
linked => {
list, rList: LIST OF GriffinEncoding.Link;
FOR l: REF ObjectDefs.Link ← traj.links, l.link UNTIL l=NIL DO
new: GriffinEncoding.Link ←
IF l.degree=D1 THEN GriffinEncoding.EncodeLinearLink[l.knots]
ELSE GriffinEncoding.EncodeCubicLink[l.knots, traj.splineType];
list ← CONS[new, list];
ENDLOOP;
FOR l: LIST OF GriffinEncoding.Link ← list, l.rest UNTIL l=NIL DO
rList ← CONS[l.first, rList];
ENDLOOP;
shape.edgeEncoding ← GriffinEncoding.EncodeEdge[rList];
};
ENDCASE;
IF shape.closed THEN shape.areaEncoding ← GriffinEncoding.EncodeArea[shape.edgeEncoding];
shape.tl ← ScrRealToScr[shape.edgeEncoding.tl];
shape.br ← ScrRealToScr[shape.edgeEncoding.br];
shape.validEncoding ← TRUE;
};
AdjustBoxForStyle: PUBLIC PROC [object: ObjectHandle] ~ TRUSTED {
WITH obj: object SELECT FROM
shape => {
w: INTEGER ← ObjValToScrVal[obj.style.width/2]+tokenSize;
IF (obj.closed AND obj.style.outlined) OR NOT obj.closed THEN {
obj.tl ← ScrRealToScr[[obj.edgeEncoding.tl[X]-w, obj.edgeEncoding.tl[Y]+w]];
obj.br ←ScrRealToScr[[obj.edgeEncoding.br[X]+w, obj.edgeEncoding.br[Y]-w]];
};
};
caption => [obj.tl, obj.br] ← GriffinText.GetBoundingBox[obj.text, obj.style, obj.p0];
ENDCASE;
};
Hit Test..
GetObjectHandle: PUBLIC PROCEDURE [pt: PointDefs.ScrPt] RETURNS [ObjectHandle] =
BEGIN
found: ObjectHandle ← NIL;
do: ObjectProc = {
IF HitTest[pt, obj] THEN {found ← obj; RETURN[TRUE]};
};
ForAllObjectsReversed[do];
IF found#NIL THEN WITH found SELECT FROM
type: REF selectToken Object => RETURN[type.selectedObj];
ENDCASE;
RETURN[found];
END;
GetObjectHandleBetweenObjects: PUBLIC PROCEDURE [pt: PointDefs.ScrPt,
topObject,bottomObject: ObjectHandle] RETURNS [ObjectHandle] =
BEGIN
FOR obj: ObjectHandle ← topObject, obj.backLink UNTIL obj = bottomObject DO
IF HitTest[pt, obj] THEN RETURN[obj];
ENDLOOP;
RETURN[NIL];
END;
HitTest: PROC [pt: PointDefs.ScrPt, obj: ObjectHandle] RETURNS [BOOLEAN] ~ TRUSTED {
tol: REAL;
IF ~Visible[obj] THEN RETURN[FALSE];
IF pt[X]<obj.tl[X] OR pt[X]>obj.br[X]
OR pt[Y]>obj.tl[Y] OR pt[Y]<obj.br[Y] THEN RETURN[FALSE];
obj may be touched
WITH object: obj SELECT FROM
shape => BEGIN
tol ← MAX[1,ObjValToScrVal[object.style.width/2.0]];
IF GriffinEncoding.PointOnEdge[pt,object.edgeEncoding,tol] THEN RETURN[TRUE]
ELSE IF object.closed AND obj.style.filled
AND GriffinEncoding.PointInArea[pt,object.areaEncoding,tol] THEN RETURN[TRUE];
END;
caption,token,menu, selectToken => RETURN[TRUE];
ENDCASE;
RETURN[FALSE];
};
END.