ImagerDisplayContextImpl.mesa
Created April 8, 1983
Last Edit By:
Plass, April 8, 1983 7:38 pm
Last Edited by: Crow, August 23, 1983 3:22 pm
DIRECTORY
Rope      USING [ROPE],
Imager     USING [Context, ContextRep, SetT, black],
ImagerBasic    USING [IntRectangle, Transformation, Color, CIEColor],
-- Imager1bitDisplay   USING [SetUp],
Imager8bitDisplay   USING [SetUp],
ImagerDisplay   USING [Mask, MaskRep, ContextData, ContextDataRep];
ImagerDisplayContextImpl: CEDAR PROGRAM
IMPORTS Imager, Imager8bitDisplay -- , Imager1bitDisplay
EXPORTS Imager, ImagerDisplay
= BEGIN
Public Signals
UnImplementedDisplayDevice: PUBLIC SIGNAL = CODE;
NotImplementedYet: PUBLIC SIGNAL = CODE;
IncompatibleContexts: PUBLIC SIGNAL = CODE;
Client Procedures (exported to Imager)
Create: PUBLIC PROC [deviceType: ATOM, name: Rope.ROPENIL]
    RETURNS [Imager.Context] = {
Called by the viewers package, or other utilities, to set up a context. Returns NIL if unable to create the context.
RETURN [ OpenContext[deviceType, TRUE, NIL] ];
};
Flush: PUBLIC PROC [context: Imager.Context] = { 
Clear inside context. Set to current color
displayContext: ImagerDisplay.ContextData = NARROW[context.data];
displayContext.deviceProcs.loadTrapezoid[
displayContext,
displayContext.clipper.sMin + displayContext.clipper.sSize - 1,
displayContext.clipper.sMin,
displayContext.clipper.fMin,
displayContext.clipper.fMin,
displayContext.clipper.fMin + displayContext.clipper.fSize - 1,
displayContext.clipper.fMin + displayContext.clipper.fSize - 1,
displayContext.currentPxlValue
];
};
Close: PUBLIC PROC [context: Imager.Context] = {
Remove all traces of the given context, clean up VM.
displayContext: ImagerDisplay.ContextData;
IF context = NIL THEN RETURN[];
displayContext ← NARROW[context.data];
displayContext.deviceProcs.shutDown[displayContext];
};
DoSaveAll: PUBLIC PROC [context: Imager.Context, action: PROC] = {
ERROR NotImplementedYet[];
};
DoSave: PUBLIC PROC [context: Imager.Context, action: PROC] = {
ERROR NotImplementedYet[];
};
CreateBuffer: PUBLIC PROC [deviceType: ATOM, box: ImagerBasic.IntRectangle] RETURNS [Imager.Context] = {
boxMask: ImagerDisplay.Mask ← IF box.h <= 0 OR box.w <= 0
THEN NIL
ELSE NEW[ ImagerDisplay.MaskRep ← [box.y, box.x, box.h, box.w, NIL] ];
RETURN [ OpenContext[deviceType, FALSE, boxMask] ];
};
TransferBuffer: PUBLIC PROC [context, source: Imager.Context] = {
Moves the image from source to context, subject to the context clipper. May be used to move data from a display to a buffer, from a buffer to a display, or between two buffers.
displaySource: ImagerDisplay.ContextData = NARROW[source.data];
displayContext: ImagerDisplay.ContextData = NARROW[context.data];
displayContext.deviceProcs.transferPxls[displaySource, displayContext];
};
Display Procedures (exported to ImagerDisplay)
NewDisplay: PUBLIC PROC [context: Imager.Context, device: ATOM] = {
displayContext: ImagerDisplay.ContextData = NARROW[context.data];
SELECT device FROM
$CRT8 => Imager8bitDisplay.SetUp[displayContext, TRUE];
-- $LF  => Imager1bitDisplay.SetUp[displayContext, TRUE];
ENDCASE => ERROR IncompatibleContexts[];
IF ISTYPE[displayContext.currentColor, ImagerBasic.CIEColor]
THEN displayContext.currentPxlValue ← displayContext.deviceProcs.colortoPixel[
          NARROW[displayContext.currentColor, ImagerBasic.CIEColor] ];
};
Reset: PUBLIC PROC [context: Imager.Context] = {}; 
Internal Procedures
OpenContext: PROC [deviceType: ATOM, pin: BOOLEAN, box: ImagerDisplay.Mask]
    RETURNS [Imager.Context] = {
Returns NIL if unable to create the context. If pin = FALSE, sets up bit map compatible with deviceType, but doesn't try to find device.
context: Imager.Context;
displayContext: ImagerDisplay.ContextData ← NEW[ImagerDisplay.ContextDataRep];
SELECT deviceType FROM
$CRT8 => Imager8bitDisplay.SetUp[displayContext, pin, box];
-- $LF  => Imager1bitDisplay.SetUp[displayContext, pin, box];
ENDCASE => RETURN [NIL];  -- what about new devices??
displayContext.currentColor ← Imager.black;
displayContext.currentPxlValue ← displayContext.deviceProcs.colortoPixel[
          NARROW[displayContext.currentColor, ImagerBasic.CIEColor] ];
displayContext.currentPosition ← [0, 0];
context ← NEW[ Imager.ContextRep ← [NIL, displayContext] ];
Imager.SetT[context, [1., 0., 0., 0., 1., 0., identity]];
Imager.SetClipper[
context,
NEW[ ImagerDisplay.MaskRep ← [
FIRST[INTEGER]/2, FIRST[INTEGER]/2, LAST[INTEGER], LAST[INTEGER]
] ]
];
Set client xform and clipper to build composite xform and clipper
RETURN [ context ];
};
END.