-- CGContext.mesa
-- Last changed by Doug Wyatt, September 1, 1982 12:49 pm

DIRECTORY
GraphicsBasic USING [Box, Color, Vec],
CGArea USING [Ref],
CGClipper USING [Ref],
CGDevice USING [Ref],
CGMatrix USING [Ref],
CGReducer USING [Ref],
CGSource USING [Mode, Ref];

CGContext: CEDAR DEFINITIONS = {

Ref: TYPE = REF Rep;

Rep: TYPE = RECORD [
device: CGDevice.Ref, -- output device
matrix: CGMatrix.Ref, -- transformation matrix
clipper: CGClipper.Ref, -- clipper
src: CGSource.Ref, -- current source
cp: GraphicsBasic.Vec, -- current position
reducer: CGReducer.Ref, -- reducer
area: CGArea.Ref, -- buffer for reducer output
bbox: REF GraphicsBasic.Box, -- bounding box
dbase: LONG POINTERNIL, -- base address of device raster
drast: CARDINAL ← 0, -- words per line for device raster
yUp: BOOLEANTRUE, -- increasing y is down (FALSE) or up (TRUE)
boxing,newbox: BOOLEAN, -- bounding box state
haveRaster: BOOLEAN, -- TRUE if device raster is available
-- Pool information
level: Level ← 0, -- current level
matrixLevel: Level ← 0,
clipperLevel: Level ← 0,
fillLevel: Level ← 0,
cpLevel: Level ← 0,
poolnode: PoolNode ← NIL,
pooldata: PoolData ← NIL,
-- Optional data
textdata: TextData ← NIL, -- data specific to text
bitmapdata: BitmapData ← NIL -- data specific to bitmap images
];

TextData: TYPE = REF TextDataRep;
TextDataRep: TYPE;

BitmapData: TYPE = REF BitmapDataRep;
BitmapDataRep: TYPE;

Level: TYPE = [0..256);

PoolData: TYPE = REF PoolDataRep;
PoolDataRep: TYPE = RECORD[SEQUENCE space: NAT OF PoolNode];

PoolNode: TYPE = REF PoolNodeRep;
PoolNodeRep: TYPE = RECORD [
matrixLevel: Level,
clipperLevel: Level,
fillLevel: Level,
cpLevel: Level,
yUp: BOOLEAN,
mode: CGSource.Mode,
fat: BOOLEAN,
color: GraphicsBasic.Color,
matrix: CGMatrix.Ref,
clipper: CGClipper.Ref,
cp: GraphicsBasic.Vec
];

-- Procedures --

TouchMatrix: PROC[self: Ref] = INLINE {
IF self.matrixLevel<self.level THEN SaveMatrix[self] };
TouchClipper: PROC[self: Ref] = INLINE {
IF self.clipperLevel<self.level THEN SaveClipper[self] };
TouchFill: PROC[self: Ref] = INLINE {
IF self.fillLevel<self.level THEN SaveFill[self] };
TouchCP: PROC[self: Ref] = INLINE { }; -- noop for now

SaveMatrix: PROC[self: Ref];
SaveClipper: PROC[self: Ref];
SaveFill: PROC[self: Ref];
SaveCP: PROC[self: Ref];

ResetPool: PROC[self: Ref];

GenBox: PROC[d: Ref, box: GraphicsBasic.Box, m: CGMatrix.Ref,
exclude: BOOLEANFALSE] RETURNS[CGArea.Ref];

}.