FitJaMImpl.mesa
organizing the JaM registered procedures for Fit.
Maureen Stone July 2, 1984 3:08:54 pm PDT
DIRECTORY
Cubic,
JaMImager USING [Painter],
FitJaM,
FitState USING [Handle, Create],
FitIO USING [Context, ContextRec, FeedbackRec],
ImagerTransform, --implicit for Imager.TranslateT
Imager USING [black, MoveTo, LineTo, CurveTo, Context, SetColor, XOR, TranslateT, MaskFill, MaskStroke, DoSaveAll, Trajectory],
JaM USING [State, RegisterInit, PopRope, RopeToAtom, Register];
FitJaMImpl: CEDAR PROGRAM
IMPORTS JaM, Imager, FitState, JaMImager
EXPORTS FitJaM = {
InitProc: TYPE = FitJaM.InitProc;
StartRec: TYPE = RECORD[id: ATOM, proc: InitProc];
startList: LIST OF REF StartRec;
defaultFitState: PUBLIC FitState.Handle ← FitState.Create[];
defaultFitIO: PUBLIC FitIO.Context ← NEW[FitIO.ContextRec ← [
imager: NIL, --set in paint proc
magnify: 1,
position: [0,0],
feedback: NEW[FitIO.FeedbackRec ← [
color: Imager.black,
sampleSize: 1,
jointSize: 2,
nodeLength: 2,
nodeLineWidth: 0,
lineWidth: 0--for DrawSamples and DrawContour
]],
logActions: FALSE,
log: NIL
]];
RegisterInit: PUBLIC PROC[id: ATOM, proc: InitProc] = {
FOR ls: LIST OF REF StartRec ← startList, ls.rest UNTIL ls=NIL DO
IF ls.first.id=id THEN ERROR;
ENDLOOP;
startList ← CONS[NEW[StartRec ← [id: id, proc: proc]],startList];
};
InitAll: PROC [state: JaM.State] = {
FOR ls: LIST OF REF StartRec ← startList, ls.rest UNTIL ls=NIL DO
ls.first.proc[state];
ENDLOOP;
};
InitAtom: PROC [state: JaM.State] = {
atom: ATOM ← JaM.RopeToAtom[JaM.PopRope[state]];
FOR ls: LIST OF REF StartRec ← startList, ls.rest UNTIL ls=NIL DO
IF atom=ls.first.id THEN {ls.first.proc[state]; EXIT};
ENDLOOP;
};
octagonPath: Imager.Trajectory ← OctagonPath[];
OctagonPath: PROC RETURNS [path: Imager.Trajectory] = {
path ← Imager.MoveTo[[1, 2]];
path ← Imager.LineTo[path, [2, 1]];
path ← Imager.LineTo[path, [2, -1]];
path ← Imager.LineTo[path, [1, -2]];
path ← Imager.LineTo[path, [-1, -2]];
path ← Imager.LineTo[path, [-2, -1]];
path ← Imager.LineTo[path, [-2, 1]];
path ← Imager.LineTo[path, [-1, 2]];
};
HiLight: PUBLIC PROC[state: JaM.State, x, y: REAL] = {
Paint: PROC[dc: Imager.Context] = {
doIt: PROC = {
Imager.SetColor[dc, Imager.XOR];
Imager.TranslateT[dc, x, y];
Imager.MaskFill[dc, octagonPath];
Imager.TranslateT[dc, -x, -y];
};
Imager.DoSaveAll[dc,doIt];
};
JaMImager.Painter[Paint, state];
};
ShowBezierInverted: PUBLIC PROC[state: JaM.State, bezier: Cubic.Bezier] = {
Paint: PROC[dc: Imager.Context] = {
doIt: PROC = {Imager.SetColor[dc, Imager.XOR]; Imager.MaskStroke[dc, bezierPath, 0]};
Imager.DoSaveAll[dc,doIt];
};
bezierPath: Imager.Trajectory ← Imager.MoveTo[[bezier.b0.x, bezier.b0.y]];
bezierPath ← Imager.CurveTo[bezierPath, [bezier.b1.x, bezier.b1.y], [bezier.b2.x, bezier.b2.y], [bezier.b3.x, bezier.b3.y]];
JaMImager.Painter[Paint, state];
};
JaMInit: PROC [state: JaM.State] = {
JaM.Register[state,"FitJaM.InitAll",InitAll];
JaM.Register[state,"FitJaM.InitAtom",InitAtom];
};
JaM.RegisterInit["FitJaM",JaMInit];
}.