-- CGContext.mesa
-- Last changed by Doug Wyatt, September 20, 1982 4:04 pm

DIRECTORY
GraphicsBasic USING [Box, Trap, Vec],
CGArea USING [Ref],
CGClipper USING [Ref],
CGDevice USING [Fill, Ref],
CGMatrix USING [Ref],
CGReducer USING [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
reducer: CGReducer.Ref, -- reducer
area: CGArea.Ref, -- buffer for reducer output
fill: CGDevice.Fill, -- current fill parameters (color, paint mode, and scan conversion mode)
cp: GraphicsBasic.Vec, -- current position
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,
fill: CGDevice.Fill,
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,
emitTrap: PROC[GraphicsBasic.Trap], emitBox: PROC[GraphicsBasic.Box],
box: GraphicsBasic.Box, m: CGMatrix.Ref, exclude: BOOLEANFALSE];

}.