ControlsTestImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Bloomenthal, February 25, 1987 4:50:37 pm PST
DIRECTORY Commander, Controls, Imager, ImagerFont, ImagerOps, IO, MessageWindow, Rope, VFonts, ViewerOps;
ControlsTestImpl: CEDAR PROGRAM
IMPORTS Commander, Controls, Imager, ImagerFont, ImagerOps, IO, MessageWindow, Rope, VFonts, ViewerOps
~ BEGIN
ProgramData:  TYPE ~ REF ProgramDataRec;
ProgramDataRec: TYPE ~ RECORD [
outer:    Controls.Viewer ← NIL,
graphics:   Controls.Viewer ← NIL,
mouse:   Controls.Mouse ← [0, 0, none, none],
text:    Rope.ROPE ← "Some Text",
toggleBool:  BOOLTRUE,
stateNat:   NAT ← 0,
newControl:  Controls.Control ← NIL,
newControlState: {add, del} ← add,
shownOnce:  BOOLFALSE,
lastMoused:  Controls.Control ← NIL,
vernier:   Controls.Control ← NIL
];
Top: Controls.ControlProc ~ {
m: Controls.Mouse ~ control.mouse;
IF m.state # held THEN {
MessageWindow.Append[Rope.Concat[
Rope.Cat["state: ", IF m.state = down THEN "down" ELSE "up", ", button: ", SELECT m.button FROM left => "left", middle => "middle", right => "right", ENDCASE => "none"],
Rope.Cat[", shift: ", IF m.shiftKey THEN "yes" ELSE "no", ", ctrl: ", IF m.controlKey THEN "yes" ELSE "no", IO.PutFR[", x: %g, y: %g", IO.real[m.x], IO.real[m.y]]]], TRUE];
};
};
Proc: Controls.ControlProc ~ {
p: ProgramData ← NARROW[control.data];
IF control.mouse.state # up THEN p.lastMoused ← control;
};
Vernier: Controls.ControlProc ~ {
p: ProgramData ~ NARROW[control.data];
Controls.Vernier[control, p.lastMoused];
};
ControlsTest: Commander.CommandProc ~ {
p: ProgramData ← NEW[ProgramDataRec];
top: Controls.Control ←
Controls.NewControl[name: "A Top Level Control", proc: Top, type: hSlider];
Controls.ControlViewer[NIL, NIL, top, NIL];
ViewerOps.OpenIcon[top.viewer];
p.outer ← Controls.OuterViewer[
name: "Controls Test",
controls: LIST[
Controls.NewControl["no detents", dial, p,, 360.0, 90.0, Proc],
Controls.NewControl["1 detent", dial, p,, 360.0, 60.0, Proc,,,,,,,,,,, LIST[[, 180.0]]],
Controls.NewControl["2 detents", dial, p,, 360.0,, Proc, FALSE,,,,,,,,,, LIST[[, 45], [, 290]]],
Controls.NewControl["Lin", vSlider, p,, 1.0, 0.3,,,,,,,,,,,, LIST[[, 0.6]]],
Controls.NewControl["Log", vSlider, p,, 1.0, 0.3,,,,,,,,,,,,, log],
Controls.NewControl["Exp", vSlider, p,, 1.0,,,,,,,,,,,,,, exp],
Controls.NewControl["Horiz", hSlider, p,, 1.0, 0.5,,,,,,, 120],
Controls.NewControl["dial vernier", dial, p,,,, Vernier, FALSE],
Controls.NewControl[name: "Function", type: function, w: 180, min: 0.0, max: 1., row: 1],
Controls.NewControl[name: "Contour", type: contour, w: 180],
Controls.NewControl[name: "Sketch", type: sketch, w: 180]
],
buttons: LIST[
["Toggle", ToggleButton],
["State 0", StateButton],
["Text", TextButton],
["Help", HelpButton],
["Add Control", NewControlButton],
["Clear Controls", ClearButton],
["Close Contour", CloseContourButton]
],
typeScriptHeight: 18,
graphicsHeight: 200,
graphicsProc: GraphicsProc,
graphicsShow: GraphicsShow,
data: p
];
p.graphics ← NARROW[p.outer.data, Controls.OuterData].graphics;
};
GraphicsShow: Controls.GraphicsShow ~ {
programData: ProgramData ← NARROW[data];
font: ImagerFont.Font ← ImagerFont.Scale[ImagerFont.Find["xerox/pressfonts/helvetica-mrr"], 16.0];
offset: INTEGER ← VFonts.StringWidth[programData.text, font]/2;
Action: PROC ~ {
Imager.SetFont[context, font];
Imager.SetColor[context, Imager.white];
Imager.MaskRectangleI[context, 0, 0, w, h];
Imager.SetColor[context, Imager.black];
Imager.SetXY[context, [programData.mouse.x-offset, programData.mouse.y]];
Imager.ShowRope[context, programData.text];
};
IF NOT programData.shownOnce THEN {
programData.mouse.x ← w/2;
programData.mouse.y ← h/2;
};
programData.shownOnce ← TRUE;
ImagerOps.DoWithBuffer[context, Action, 0, 0, w, h];
};
GraphicsProc: Controls.GraphicsProc ~ {
Proc called as result of mousing down in graphics viewer.
programData: ProgramData ← NARROW[graphics.data];
programData.mouse ← graphics.mouse;
IF programData.mouse.state # up
THEN ViewerOps.PaintViewer[graphics.viewer, client, FALSE, graphics];
};
ToggleButton: Controls.ClickProc ~ {
outer: Controls.OuterData ← NARROW[clientData];
programData: ProgramData ← NARROW[outer.data];
programData.toggleBool ← NOT programData.toggleBool;
Controls.ButtonStyle[
outer, "Toggle", IF programData.toggleBool THEN $BlackOnWhite ELSE $WhiteOnBlack];
};
StateButton: Controls.ClickProc ~ {
outer: Controls.OuterData ← NARROW[clientData];
programData: ProgramData ← NARROW[outer.data];
SELECT programData.stateNat FROM
0 => Controls.ButtonReLabel[outer, "State 0", "State 1"];
1 => Controls.ButtonReLabel[outer, "State 1", "State 2"];
2 => Controls.ButtonReLabel[outer, "State 2", "State 3"];
3 => Controls.ButtonReLabel[outer, "State 3", "State 0"];
ENDCASE;
programData.stateNat ← (programData.stateNat+1) MOD 4;
};
TextButton: Controls.ClickProc ~ {
outer: Controls.OuterData ← NARROW[clientData];
programData: ProgramData ← NARROW[outer.data];
Controls.TypeScriptWrite[outer, "\nType something (end with CR) "];
programData.text ← Controls.TypeScriptRead[outer];
Controls.TypeScriptWrite[outer, Rope.Concat["\nThe reply was ", programData.text]];
ViewerOps.PaintViewer[programData.graphics, client, FALSE, programData.graphics];
};
HelpButton: Controls.ClickProc ~ {
outer: Controls.OuterData ← NARROW[clientData];
IO.PutF[outer.cmdOut, "This is a help message\n"];
};
NewControlButton: Controls.ClickProc ~ {
outer: Controls.OuterData ← NARROW[clientData];
programData: ProgramData ← NARROW[outer.data];
SELECT programData.newControlState FROM
add => {
IF programData.newControl = NIL
THEN programData.newControl ← Controls.NewControl[
name: "new", type: vSlider, min: 0.0, max: 1.0, init: 0.5, x: 495, y: 15, w: 25, h: 60];
Controls.ControlViewer[
outer.parent, outer.graphics, programData.newControl, outer];
Controls.ButtonReLabel[outer, "Add Control", "Del Control"];
programData.newControlState ← del;
ViewerOps.PaintViewer[outer.parent, client, FALSE, NIL];
};
del => {
Controls.ButtonReLabel[outer, "Del Control", "Add Control"];
ViewerOps.DestroyViewer[programData.newControl.viewer, FALSE];
ViewerOps.DestroyViewer[programData.newControl.title, FALSE];
ViewerOps.DestroyViewer[programData.newControl.status, TRUE];
programData.newControlState ← add;
};
ENDCASE => NULL;
};
ClearButton: Controls.ClickProc ~ {
outerData: Controls.OuterData ← NARROW[clientData];
FOR c: Controls.ControlList ← outerData.controls, c.rest WHILE c # NIL DO
Controls.Reset[c.first];
ENDLOOP;
};
CloseContourButton: Controls.ClickProc ~ {
outerData: Controls.OuterData ← NARROW[clientData];
FOR c: Controls.ControlList ← outerData.controls, c.rest WHILE c # NIL DO
IF c.first.type = contour THEN Controls.CloseContour[c.first];
ENDLOOP;
};
Commander.Register["///Commands/ControlsTest", ControlsTest, "\nTest ControlsImpl.mesa."];
END.