PieViewersImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Michael Plass, November 2, 1982 10:56 am
Last Edited by: Beach, May 24, 1983 9:13 am
Doug Wyatt, April 10, 1985 9:16:02 pm PST
DIRECTORY
Imager,
ImagerPath,
PieViewers,
Real,
RealFns,
ViewerOps,
ViewerClasses;
PieViewersImpl: CEDAR MONITOR
IMPORTS Imager, Real, RealFns, ViewerOps
EXPORTS PieViewers
= BEGIN
PieViewer: TYPE = PieViewers.PieViewer;
Data: TYPE ~ REF DataRec;
DataRec: TYPE = RECORD [
total: REAL, -- what the entire circle is worth
amount: REAL, -- what amount is currently on
granularity: REAL -- display will not change if the new amount is of the same grain
];
Create: PUBLIC PROC [parent: ViewerClasses.Viewer, x, y: INTEGER ← 0, diameter: INTEGER ← 16, total: REAL ← 100, divisions: NAT ← 25]
RETURNS [pieViewer: PieViewer] = {
data: REF DataRec ← NEW[DataRec];
data.total ← total;
data.granularity ← total/divisions;
pieViewer ← ViewerOps.CreateViewer[flavor: $PieViewer, info: [parent: parent, wx: x, wy: y, ww: diameter, wh: diameter, data: data, border: FALSE], paint: FALSE];
Set[pieViewer, 0];
};
Set: PUBLIC PROC [pieViewer: PieViewer, amount: REAL] = {
d: Data ~ NARROW[pieViewer.data];
IF d=NIL THEN RETURN;
IF amount=d.total OR amount=0 OR Real.RoundI[d.amount/d.granularity] # Real.RoundI[amount/d.granularity] THEN {
d.amount ← amount;
ViewerOps.PaintViewer[pieViewer, client, FALSE, $Update];
};
};
VEC: TYPE ~ ImagerPath.VEC;
Loc: PROC [a: REAL] RETURNS [VEC] ~ { RETURN[[RealFns.CosDeg[a], RealFns.SinDeg[a]]] };
DoArc: PROC[a0, a2: REAL, arcTo: ImagerPath.ArcToProc] ~ {
a1: REAL ~ (a0+a2)/2;
IF ABS[a2-a0]<=90 THEN arcTo[Loc[a1], Loc[a2]]
ELSE { DoArc[a0, a1, arcTo]; DoArc[a1, a2, arcTo] };
};
MaskSector: PROC [context: Imager.Context, a0, a2: REAL] ~ {
path: ImagerPath.PathProc ~ { moveTo[[0, 0]]; lineTo[Loc[a0]]; DoArc[a0, a2, arcTo] };
Imager.MaskFill[context, path];
};
PieViewerPaint: ViewerClasses.PaintProc = {
ENABLE ANY => GOTO Quit;
d: Data ~ NARROW[self.data];
delta: REAL ~ 360*(d.amount/d.total);
Imager.ScaleT[context, self.ww/2];
Imager.TranslateT[context, [1, 1]];
Imager.SetColor[context, Imager.black];
MaskSector[context, 90, 90+delta];
Imager.SetColor[context, Imager.white];
MaskSector[context, 90, 90-(360-delta)];
EXITS Quit => {}
};
pieViewer: ViewerClasses.ViewerClass ← NEW[ViewerClasses.ViewerClassRec ← [
paint: PieViewerPaint,
tipTable: NIL
]];
ViewerOps.RegisterViewerClass[$PieViewer, pieViewer]; -- plug in to Viewers
END.