RulesImpl.mesa
Copyright © 1982, 1983, 1984 Xerox Corporation. All rights reserved.
Edited by McGregor on June 2, 1982 1:55 pm
Last Edited by: Maxwell, January 3, 1983 12:28 pm
Doug Wyatt, September 4, 1984 3:40:36 pm PDT
DIRECTORY
Graphics USING [black, Color, Context],
Imager USING [Color, Context, MaskRectangleI, SetColor],
ImagerOps USING [ColorFromGraphicsColor, ImagerFromGraphics],
Rules USING [Rule],
ViewerClasses USING [PaintProc, SetProc, ViewerClass, ViewerClassRec, ViewerRec],
ViewerOps USING [CreateViewer, PaintViewer, RegisterViewerClass];
RulesImpl: CEDAR PROGRAM
IMPORTS Imager, ImagerOps, ViewerOps
EXPORTS Rules
= BEGIN OPEN ViewerClasses;
Rule: TYPE ~ Rules.Rule;
Data: TYPE ~ REF DataRep;
DataRep: TYPE ~ RECORD[color: Imager.Color];
Create:
PUBLIC
PROC [info: ViewerRec, color: Graphics.Color ← Graphics.black, paint:
BOOL ←
TRUE]
RETURNS [rule: Rule] = BEGIN
IF info.parent=NIL THEN RETURN;
info.data ← NEW[DataRep ← [ImagerOps.ColorFromGraphicsColor[color]]];
info.border ← FALSE; -- we did promise uniform color
RETURN[ViewerOps.CreateViewer[flavor: $Rule, info: info, paint: paint]];
END;
RulePaint:
PRIVATE PaintProc =
BEGIN
imager: Imager.Context ~ ImagerOps.ImagerFromGraphics[context];
data: Data ~ NARROW[self.data];
Imager.SetColor[imager, data.color];
Imager.MaskRectangleI[imager, 0, 0, self.cw, self.ch];
END;
RuleSet:
PRIVATE SetProc =
BEGIN
d: Data ~ NARROW[self.data];
WITH data
SELECT
FROM
x: REF Graphics.Color => d.color ← ImagerOps.ColorFromGraphicsColor[x^];
x: Imager.Color => d.color ← x;
ENDCASE => ERROR;
IF finalise THEN ViewerOps.PaintViewer[self, client, FALSE];
END;
ruleClass: ViewerClasses.ViewerClass ←
NEW[ViewerClasses.ViewerClassRec ← [
paint: RulePaint,
set: RuleSet
]];
ViewerOps.RegisterViewerClass[$Rule, ruleClass]; -- plug in to Viewers
END.