ImagerDisplayImpl.mesa
Created April 8, 1983
Last Edit By:
Plass, April 8, 1983 7:38 pm
Last Edited by: Crow, August 30, 1983 6:33 pm
DIRECTORY
Rope      USING [ROPE],
Atom      USING [GetProp, PutProp],
Imager     USING [Context, black, IncompatibleContexts, nullBounds],
ImagerBasic    USING [IntRectangle, IntPair, Transformation, Color, CIEColor],
ImagerMasks    USING [Mask],
ImagerDisplay   USING [ContextData, ContextDataRep, DisplayClassRep];
ImagerDisplayImpl: CEDAR PROGRAM
IMPORTS Imager, Atom
EXPORTS Imager, ImagerDisplay
~ BEGIN
Public Signals
UnImplementedDisplayDevice: PUBLIC SIGNAL ~ CODE;
NotImplementedYet: PUBLIC SIGNAL ~ CODE;
Client Procedures (exported to Imager or ImagerImpl)
Init: PUBLIC PROC [context: Imager.Context, name: Rope.ROPE,  -- exported to ImagerImpl
                bounds: ImagerBasic.IntRectangle] = {
OpenContext: PROC [deviceType: ATOM, pin: BOOLEAN, box: ImagerMasks.Mask]
    RETURNS [ImagerDisplay.ContextData] ~ {
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.
displayContext: ImagerDisplay.ContextData ← NEW[ImagerDisplay.ContextDataRep];
WITH Atom.GetProp[deviceType, imagerDisplayRegistrationKey] SELECT FROM
displayClass: REF ImagerDisplay.DisplayClassRep => {
displayContext.deviceProcs ← displayClass;
displayContext.deviceProcs.SetUp[displayContext, pin, box];
};
ENDCASE => ERROR UnImplementedDisplayDevice;
displayContext.currentColor ← Imager.black;
displayContext.currentPxlValue ← displayContext.deviceProcs.ColortoPixel[
          NARROW[displayContext.currentColor, ImagerBasic.CIEColor] ];
displayContext.currentPosition ← [0, 0];
displayContext.viewerClipper ← displayContext.deviceClipper;
displayContext.clientClipper ← displayContext.deviceClipper;
displayContext.clipper ← displayContext.deviceClipper;
displayContext.transform ← displayContext.deviceTransform;
displayContext.clientTransform ← displayContext.viewerTransform ← [1., 0., 0., 0., 1., 0.,
                        identity];
RETURN [ displayContext ];
};
IF bounds = Imager.nullBounds
THEN context.data ← OpenContext[context.class.deviceType, TRUE, [0, 0, 0, 0, NIL] ]
ELSE {
boxMask: ImagerMasks.Mask ← IF bounds.h <= 0 OR bounds.w <= 0
THEN [bounds.y, bounds.x, 0, 0, NIL]
ELSE [bounds.y, bounds.x, bounds.h, bounds.w, NIL];
context.data ← OpenContext[context.class.deviceType, FALSE, boxMask];
};
};
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];
context.data ← NIL;
context.class ← NIL;
};
DoSaveAll: PUBLIC PROC [context: Imager.Context, action: PROC] ~ {
dataRep: ImagerDisplay.ContextDataRep;
data: ImagerDisplay.ContextData = NARROW[context.data];
dataRep ← data^;
action[];
data^ ← dataRep;
};
DoSave: PUBLIC PROC [context: Imager.Context, action: PROC] ~ {
cp: ImagerBasic.IntPair;
dataRep: ImagerDisplay.ContextDataRep;
data: ImagerDisplay.ContextData = NARROW[context.data];
dataRep ← data^;
action[];
cp ← data.currentPosition;
data^ ← dataRep;
data.currentPosition ← cp;
};
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];
IF context.class.deviceType # source.class.deviceType
THEN ERROR Imager.IncompatibleContexts[];
displayContext.deviceProcs.TransferPxls[displaySource, displayContext];
};
Display Procedures (exported to ImagerDisplay)
NewDisplay: PUBLIC PROC [context: Imager.Context, deviceType: ATOM] ~ {
displayContext: ImagerDisplay.ContextData = NARROW[context.data];
WITH Atom.GetProp[deviceType, imagerDisplayRegistrationKey] SELECT FROM
displayClass: REF ImagerDisplay.DisplayClassRep => {
displayContext.deviceProcs ← displayClass;
displayContext.deviceProcs.SetUp[displayContext, TRUE, [0, 0, 0, 0, NIL] ];
};
ENDCASE => ERROR UnImplementedDisplayDevice;
IF ISTYPE[displayContext.currentColor, ImagerBasic.CIEColor]
THEN displayContext.currentPxlValue ← displayContext.deviceProcs.ColortoPixel[
          NARROW[displayContext.currentColor, ImagerBasic.CIEColor] ];
};
Reset: PUBLIC PROC [context: Imager.Context] ~ {}; 
RegisterDisplayDevice: PUBLIC PROC [class: REF ImagerDisplay.DisplayClassRep] ~ {
Atom.PutProp[class.deviceType, imagerDisplayRegistrationKey, class];
};
imagerDisplayRegistrationKey: REF TEXT ← "ImagerDisplay Display Class ";
END.