SleepPeekImpl.mesa
Copyright (C) 1984 by Xerox Corporation. All rights reserved.
Michael Plass, April 12, 1984 10:15:30 am PST
Last Edited by: Beach, October 9, 1984 8:51:00 pm PDT
Pier, June 19, 1985 4:28:15 pm PDT
DIRECTORY Idle, ImagerPixelMap, LFBoundingBox, Terminal, Buttons;
SleepPeekImpl: CEDAR PROGRAM
IMPORTS Idle, ImagerPixelMap, LFBoundingBox, Terminal, Buttons
= BEGIN
sMin, fMin: INTEGER;
sSize, fSize: NAT;
screen: ImagerPixelMap.PixelMap;
shadow: ImagerPixelMap.PixelMap;
bitmapRef: Idle.BitmapRef;
Bits: TYPE = RECORD [SEQUENCE COMPUTED CARDINAL OF WORD];
Image: Idle.ImageProc ~ {
shadow ← shadow.refRep.Reshape[0, [sMin, fMin, MIN[sSize, h], MIN[fSize, w]]];
shadow.Transfer[screen];
RETURN [bitmapRef];
};
Lg: PROC [n: NAT] RETURNS [NAT] ~ {
RETURN[SELECT n FROM 1 => 0, 2 => 1, 4 => 2, 8 => 3, 16 => 4, ENDCASE => ERROR]
};
PixelMapFromFrameBuffer: PROC [frameBuffer: Terminal.FrameBuffer]
RETURNS
[ImagerPixelMap.PixelMap] ~ {
refRep: REF ImagerPixelMap.PixelMapRep ~ NEW[ImagerPixelMap.PixelMapRep ← [
ref: frameBuffer,
pointer: frameBuffer.base,
words: INT[frameBuffer.wordsPerLine]*INT[frameBuffer.height],
lgBitsPerPixel: Lg[frameBuffer.bitsPerPixel],
rast: frameBuffer.wordsPerLine,
lines: frameBuffer.height
]];
frame: ImagerPixelMap.PixelMap ~ [
sOrigin: 0, fOrigin: 0, sMin: 0, fMin: 0,
sSize: frameBuffer.height, fSize: frameBuffer.width, refRep: refRep
];
RETURN[frame];
};
SleepProc: Buttons.ButtonProc ~ BEGIN
IF mouseButton = red OR sSize = 0 OR fSize = 0 OR shadow.refRep = NIL THEN {
get bounding box of the area
sMin ← -1;
[y: sMin, x: fMin, h: sSize, w: fSize] ← LFBoundingBox.GetArea[!LFBoundingBox.AbortAdjust => CONTINUE];
IF sMin < 0 THEN
shadow.refRep ← NIL
ELSE {
TRUSTED {screen ← PixelMapFromFrameBuffer[Terminal.GetBWFrameBuffer[Terminal.Current[]]]};
sMin ← screen.sSize - sMin - sSize;
shadow ← ImagerPixelMap.Create[0, [sMin, fMin, sSize, fSize]];
WHILE shadow.refRep.words > 64000 DO
sSize ← sSize * 7 / 8;
fSize ← fSize * 7 / 8;
shadow ← ImagerPixelMap.Create[0, [sMin, fMin, sSize, fSize]];
ENDLOOP;
shadow.refRep.pointer ← NIL;
shadow.refRep.ref ← NEW[Bits[shadow.refRep.words]];
TRUSTED {shadow.refRep.pointer ← LOOPHOLE[shadow.refRep.ref]};
bitmapRef ← NEW[Idle.BitmapRep ← [base: shadow.refRep.ref, raster: shadow.refRep.rast, width: shadow.fSize, height: shadow.sSize]];
};
};
IF shadow.refRep # NIL THEN Idle.Sleep[Image];
END;
[] ← Buttons.Create[[name: "Sleep"], SleepProc];
END.