BSTest.Mesa
Last Edited by: Spreitzer, April 2, 1985 6:00:29 pm PST
DIRECTORY Atom, BiScrollers, Geom2D, Graphics, Icons, Rope, TIPUser, ViewerClasses, ViewerOps;
BSTest: CEDAR PROGRAM
IMPORTS Atom, BiScrollers, Geom2D, Graphics, Rope, TIPUser, ViewerOps
= {OPEN BiScrollers;
Data: TYPE = REF DataRep;
DataRep: TYPE = RECORD [
style: BiScrollerStyle,
moving: BOOLFALSE,
x, y: REAL ← 0.0];
Delta: TYPE = REF DeltaRep;
DeltaRep: TYPE = RECORD [
drawOld, drawNew: BOOL,
oldX, oldY: REAL];
className: ROPE ← "BS Test ";
InStyle: PROC [style: BiScrollerStyle, preferIntegers: BOOLFALSE] RETURNS [class: BiScrollerClass] = {
className ← className.Cat["I"];
class ← style.NewBiScrollerClass[[
flavor: Atom.MakeAtom[className],
extrema: Extrema,
paint: Paint,
notify: Notify,
finish: LIST[$Exit],
menu: bsMenu,
icon: fileCabinet,
tipTable: TIPUser.InstantiateNewTIPTable["BSTest.TIP"],
mayStretch: FALSE,
offsetsMustBeIntegers: TRUE,
preferIntegerCoefficients: preferIntegers
]];
};
Extrema: PROC [clientData: REF ANY, direction: Vec] RETURNS [min, max: Vec] --ExtremaProc-- = {
d: Data ← NARROW[clientData];
[min, max] ← Geom2D.ExtremaOfBounds[
[d.x + 0, d.y + 0, d.x + 23, d.y + 47],
direction];
};
whats: LORANIL;
log: BOOLFALSE;
Paint: PROC [self: Viewer, context: Graphics.Context, whatChanged: REF ANY, clear: BOOL] --ViewerClasses.PaintProc-- = {
DrawAt: PROC [x, y: REAL] = {
Graphics.DrawBox[self: context, box: [x + 0, y + 0, x + 13, y + 47]];
Graphics.DrawBox[self: context, box: [x + 0, y + 45, x + 23, y + 46]];
};
d: Data ← NARROW[BiScrollers.ClientDataOfViewer[self]];
IF log THEN whats ← CONS[whatChanged, whats];
IF whatChanged # NIL THEN {
da: Delta ← NARROW[whatChanged];
[] ← Graphics.SetPaintMode[context, invert];
Graphics.SetStipple[context, 257 * (5*16 + 10)];
IF da.drawOld AND NOT clear THEN DrawAt[da.oldX, da.oldY];
IF da.drawNew THEN DrawAt[d.x, d.y]}
ELSE DrawAt[d.x, d.y];
};
inputs: LIST OF LORANIL;
Notify: PROC [self: Viewer, input: LIST OF REF ANY] --ViewerClases.NotifyProc-- = {
bs: BiScroller ← BiScrollers.QuaBiScroller[self];
d: Data ← NARROW[bs.ClientDataOf[]];
IF log THEN inputs ← CONS[input, inputs];
SELECT input.first FROM
$Track => {
cc: ClientCoords ← NARROW[input.rest.first];
D: Delta ← NEW [DeltaRep ← [d.moving, TRUE, d.x, d.y]];
d.x ← cc.x; d.y ← cc.y; d.moving ← TRUE;
ViewerOps.PaintViewer[self, client, FALSE, D];
d.style.SetButtonsCapturedness[bs, TRUE];
};
$End => {
cc: ClientCoords ← NARROW[input.rest.first];
D: Delta ← NEW [DeltaRep ← [d.moving, FALSE, d.x, d.y]];
d.x ← cc.x; d.y ← cc.y; d.moving ← FALSE;
ViewerOps.PaintViewer[self, client, FALSE, D];
ViewerOps.PaintViewer[self, client, FALSE, NIL];
d.style.SetButtonsCapturedness[bs, FALSE];
};
$Exit => {
D: Delta ← NEW [DeltaRep ← [d.moving, FALSE, d.x, d.y]];
d.moving ← FALSE;
ViewerOps.PaintViewer[self, client, FALSE, D];
d.style.SetButtonsCapturedness[bs, FALSE];
};
ENDCASE => ERROR;
};
Create: PROC [class: BiScrollerClass, info: ViewerClasses.ViewerRec] RETURNS [bs: BiScroller] = {
info.data ← NEW [DataRep ← [style: class.style]];
bs ← class.style.CreateBiScroller[class: class, info: info];
};
}.