menutest.mesa; Written by R. Pausch
Last Edited by: Pausch, August 26, 1983 6:18 pm
DIRECTORY
AMTypes,
RTBasic,
Interpreter,
AMBridge,
ViewerSpecs,
ViewerOps,
Containers,
Imager,
ImagerBasic,
MessageWindow,
PressScreen,
Menus,
MenusPrivate,
Rope,
VFonts,
ViewerClasses;

menutest: CEDAR PROGRAM IMPORTS -- Interpreter, AMBridge, -- Containers, Imager, Menus, --VFonts, -- --MenusPrivate, -- MessageWindow, PressScreen, Rope = BEGIN
c: Containers.Container;
earsH: INTEGER = ViewerSpecs.menuHeight;
earsW: INTEGER = 16;
pEars: bitmapArray ← [
000000B,
034070B,
076174B,
076174B,
076174B,
077774B,
037760B,
007760B,
007760B,
007760B,
003700B,
001600B
];
pFlag: bitmapArray ← [
000000B,
000000B,
152400B,
177777B,
152400B,
177777B,
100001B,
177777B,
100001B,
177777B,
100001B,
177777B
];
bitmapArray : TYPE = ARRAY [0..earsH) OF UNSPECIFIED;
DoRedraw: PROC = {
temp: RTBasic.TV;
myRef: REF ANY;
RETURN; -- until we convert the commander
[temp, ----, ----] ← Interpreter.Evaluate["ViewerOpsImplB.PaintEverything"];
TRUSTED {myRef ← AMBridge.SomeRefFromTV[temp]};
WITH myRef SELECT FROM
r: REF PROC => {
MessageWindow.Append["repainting .."];
r^[];
MessageWindow.Append["done repainting"];
};
ENDCASE => MessageWindow.Append["wrong type!!"];
};
Mynotify: ViewerClasses.NotifyProc = {
[self: Viewer, input: LIST OF REF ANY]
FOR current: LIST OF REF ANY ← input, current.rest UNTIL current = NIL DO
SELECT current.first FROM
$A12 => MessageWindow.Append["container menu 12 hit", TRUE];
$A13 => MessageWindow.Append["container menu 13 hit", TRUE];
$A14 => MessageWindow.Append["container menu 14 hit", TRUE];
$A21 => MessageWindow.Append["container menu 21 hit", TRUE];
$A22 => MessageWindow.Append["container menu 22 hit", TRUE];
$A23 => MessageWindow.Append["container menu 23 hit", TRUE];
$LEFTPRESS => {
MessageWindow.Append["LEFTPRESS hit", TRUE];
TRUSTED {PressScreen.PressScreen[PressScreen.NewPressName[], leftSide];};
};
$MIDDLEPRESS => {
MessageWindow.Append["MIDDLEPRESS hit", TRUE];
TRUSTED {PressScreen.PressScreen[PressScreen.NewPressName[], bothSides];};
};
$RIGHTPRESS => {
MessageWindow.Append["RIGHTPRESS hit", TRUE];
TRUSTED {PressScreen.PressScreen[PressScreen.NewPressName[], rightSide];};
};
$repaint => {
MessageWindow.Append["container menu 24 hit, REDRAW", TRUE];
DoRedraw[];
};
$A31 => MessageWindow.Append["container menu 31 hit", TRUE];
$A32 => MessageWindow.Append["container menu 32 hit", TRUE];
$A33 => MessageWindow.Append["container menu 33 hit", TRUE];
$A34 => MessageWindow.Append["container menu 34 hit", TRUE];
$A35 => MessageWindow.Append["container menu 35 hit", TRUE];
$A36 => MessageWindow.Append["container menu 36 hit", TRUE];
ENDCASE => ERROR;
ENDLOOP;
};
myDrawingRec: Menus.DrawingRec ~ [myDrawingProc, "M23M"];
myDrawingRec2: Menus.DrawingRec ~ [myDrawingProc2, "M23M"];
myUnGuardingRec: Menus.UnGuardRec ~ [myUnGuardingProc, "hello"];
OctRep: TYPE = RECORD[x: REAL, y: REAL, radius: REAL];
myGenerateProc: PROC [path: Imager.Path, move: PROC [ImagerBasic.Pair], line: PROC [ImagerBasic.Pair], curve: PROC [ImagerBasic.Pair, ImagerBasic.Pair, ImagerBasic.Pair]] =
{
MenusPrivate.Debug["inside myGenerateProc"];
path.data ← NARROW[path.data, REF OctRep];
MenusPrivate.Debug["after the narrow"];
move[[path.data.x + path.data.radius , path.data.y - path.data.radius/3.]];
line[[path.data.x + path.data.radius , path.data.y + path.data.radius/3.]];
line[[path.data.x + path.data.radius/3., path.data.y + path.data.radius]];
line[[path.data.x - path.data.radius/3., path.data.y + path.data.radius]];
line[[path.data.x - path.data.radius, path.data.y + path.data.radius/3.]];
line[[path.data.x - path.data.radius, path.data.y - path.data.radius/3.]];
line[[path.data.x - path.data.radius/3., path.data.y - path.data.radius]];
line[[path.data.x + path.data.radius/3., path.data.y - path.data.radius]];
line[[path.data.x + path.data.radius, path.data.y - path.data.radius/3.]];
MenusPrivate.Debug["after the drawing, now leaving myGenerateProc"];
};
myUnGuardingProc: Menus.UnGuardProc = {
MessageWindow.Append[Rope.Cat["unguardproc called with -->", NARROW[clientData,Rope.ROPE]]];
};
myDrawingProc: Menus.DrawingProc = {
p: Imager.IntPair;
IF op = query THEN RETURN[earsW];
p ← Imager.GetIntCP[ctx];
TRUSTED {Imager.MaskBits[ctx, @pEars, 1, [p.x,p.y, earsW, earsH], [p.x,p.y, earsW, earsH] ]};
};
myDrawingProc2: Menus.DrawingProc = {
p: Imager.IntPair;
IF op = query THEN RETURN[earsW];
p ← Imager.GetIntCP[ctx];
TRUSTED {Imager.MaskBits[ctx, @pFlag, 1, [p.x,p.y, earsW, earsH], [p.x,p.y, earsW, earsH] ]};
};
myOldDrawingProc: Menus.DrawingProc = {
edge: REAL = 3.0;
myGrey1: REF CARDINAL = NEW[CARDINAL ← 001001B];
myGrey2: REF CARDINAL = NEW[CARDINAL ← 001011B];
myGrey3: REF CARDINAL = NEW[CARDINAL ← 011011B];
numBoxes: INTEGER = 15;
eachWidth: REAL = 100.0 / numBoxes;
p: ImagerBasic.Pair;
mod: INTEGER ← 0;
myPath: ImagerBasic.Path;
[op: ViewerClasses.MenuEntryDisplayOp, ctx: Imager.Context ← NIL, clientData: REF ANY ← NIL] RETURNS[width: INTEGER ← 64]
IF op = query THEN RETURN[100];
p ← Imager.GetCP[ctx];
Imager.MaskRectangle[ctx, [p.x, p.y, 100, ViewerSpecs.menuHeight] ];
Imager.SetColor[ctx, Imager.white];
Imager.MaskRectangle[ctx, [p.x + edge, p.y + edge, 100 - (2 * edge), ViewerSpecs.menuHeight - (2 * edge)] ];
FOR i: INTEGER ← 0, i+1 UNTIL i = numBoxes DO
IF mod = 0 THEN {
mod ← 1;
Imager.SetColor[ctx, myGrey1];
}
ELSE IF mod = 1 THEN {
mod ← 2;
Imager.SetColor[ctx, myGrey2];
}
ELSE {
mod ← 0;
Imager.SetColor[ctx, myGrey3];
};
Imager.MaskRectangle[ctx, [p.x + (i*eachWidth), p.y, eachWidth, ViewerSpecs.menuHeight]];
ENDLOOP;
Imager.MaskCharacters[ctx, VFonts.defaultFont, NARROW[clientData, REF TEXT]];
draw a stop sign
MenusPrivate.Debug["about to call maskFill ..."];
p ← Imager.GetCP[ctx];
myPath ← ImagerBasic.Path[myGenerateProc, NEW[OctRep ← [p.x + 50.0, p.y + (0.5 * ViewerSpecs.menuHeight), (0.4 * ViewerSpecs.menuHeight) ] ] ];
Imager.MaskFill[ctx, myPath];
MenusPrivate.Debug["... after call to maskFill"];
};
-- note: this should be read from a file, but FIleIO hasn't been converted to the new world yet.
myMenuDescription: Rope.ROPE = "
[ m1 breakBefore: FALSE
[printScreen =>
[leftup => $LEFTPRESS]
[allnonshifTS => $MIDDLEPRESS]
[allshifTS => $RIGHTPRESS]
]
[Save display: \"2--putupmenuThree\" => [ all makeActive: \"m3\" => $A12 ] ]
[Sort display: threeputdownmenuThree => [ all makeInActive: \"m3\" => $A13 ] ]
[DisplayErrors display: \"4, toggles menu 2 puts up menu 3\" => [ [all] makeActive: \"m3\" toggle: \"m2\" => $A14 ] ]
]
[ m2 beginsActive: TRUE breakBefore: FALSE
[Save => $A21]
[Compile => $A22]
[RepaintViewers => $repaint]
[Sort => $A23]
]
[ m3 beginsActive: TRUE breakBefore: FALSE breakAfter: TRUE
[ThisHasLongMenuButtons => $A31]
[ThisHasLongMenuButtons => $A32]
[ThisHasLongMenuButtons => $A33]
[ThisHasLongMenuButtons => $A34]
[ThisHasLongMenuButtons => $A35]
[ThisHasLongMenuButtons => $A36]
]
RElabel[ Sort LetsSort ]
relabel [ m2 Save MenuTwoSave ]
";
menus: LIST OF Menus.Menu ← Menus.ParseDescription[myMenuDescription];
menus: LIST OF Menus.Menu = LIST [
[name: "m1",
beginsActive: TRUE,
breakBefore: FALSE,
breakAfter: TRUE,
notify: Mynotify,
entries: LIST[
["printScreen", FALSE, NIL, LIST[
[LIST[leftup], LIST[$LEFTPRESS], "DOC", "", NIL, NIL, NIL],
[LIST[middleup], LIST[$MIDDLEPRESS], "DOC", "", NIL, NIL, NIL],
[LIST[rightup], LIST[$RIGHTPRESS], "DOC", "", NIL, NIL, NIL],
] ],
["Save", FALSE, "2--putupmenuThree", LIST[
[LIST[all], LIST[$A12], "DOC", "", LIST["m3"], NIL, NIL]
] ],
["Sort", FALSE, "3--putdownmenuThree", LIST[
[LIST[all], LIST[$A13], "DOC", "", NIL, LIST["m3"], NIL]
] ],
["DisplayErrors", FALSE, "4, toggles menu 2 puts up menu 3", LIST[
[LIST[all], LIST[$A14], "DOC ", "", LIST["m3"], NIL, LIST["m2"]],
] ]
]
],
[name: "m2",
beginsActive: TRUE,
breakBefore: FALSE,
breakAfter: TRUE,
notify: Mynotify,
entries: LIST[
["Search", FALSE, NIL, LIST[
[LIST[all], LIST[$A21], "DOC", "", NIL, NIL, NIL]
] ],
["Compile", FALSE, NEW[Menus.DrawingRec ← myDrawingRec], LIST[
[LIST[all], LIST[$A22], "DOC", "", NIL, NIL, NIL]
] ],
["RepaintViewers", FALSE, NIL, LIST[
[LIST[all], LIST[$repaint], "DOC", "", NIL, NIL, NIL]
] ],
["StartSession", FALSE, --NIL-- NEW[Menus.DrawingRec ← myDrawingRec2], LIST[
[LIST[all], LIST[$A23], "DOC", "", NIL, NIL, NIL]
] ]
]
],
[name: "m3",
beginsActive: TRUE,
breakBefore: FALSE,
breakAfter: TRUE,
notify: Mynotify,
entries: LIST[
["ThisHasLongMenuButtons", FALSE, NIL, LIST[
[LIST[all], LIST[$A31], "DOC", "", NIL, NIL, NIL]
] ],
["ThisHasLongMenuButtons", FALSE, NIL, LIST[
[LIST[all], LIST[$A32], "DOC", "", NIL, NIL, NIL]
] ],
["ThisHasLongMenuButtons", FALSE, NIL, LIST[
[LIST[all], LIST[$A33], "DOC", "", NIL, NIL, NIL]
] ],
["ThisHasLongMenuButtons", FALSE, NIL, LIST[
[LIST[all], LIST[$A34], "DOC", "", NIL, NIL, NIL]
] ],
["ThisHasLongMenuButtons", FALSE, NIL, LIST[
[LIST[all], LIST[$A35], "DOC", "", NIL, NIL, NIL]
] ],
["ThisHasLongMenuButtons", FALSE, NIL, LIST[
[LIST[all], LIST[$A36], "DOC", "", NIL, NIL, NIL]
] ]
]
]
] ;-- end list of type ViewerMenus
c ← Containers.Create[[name: "#4 Empty PROTECTED Container #4", guardDestroy: TRUE]];
FOR m: LIST OF Menus.Menu ← menus, m.rest UNTIL m = NIL DO
Menus.RegisterMenu[m.first];
Menus.AddMenu[c, m.first.name, FALSE];
ENDLOOP;
c ← Containers.Create[[name: "#5 Empty PROTECTED Container #5", guardDestroy: TRUE]];
FOR m: LIST OF Menus.Menu ← menus, m.rest UNTIL m = NIL DO
Menus.AddMenu[c, m.first.name, FALSE];
ENDLOOP;
c ← Containers.Create[[name: "#6 Empty PROTECTED Container #6", guardDestroy: TRUE]];
FOR m: LIST OF Menus.Menu ← menus, m.rest UNTIL m = NIL DO
Menus.AddMenu[c, m.first.name, FALSE];
ENDLOOP;
END.