ColorDisplayCommand.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Created from old ColorDisplay by Mik Lamming and Ken Pier
Last Edited by: Nickell, June 19, 1984 11:43:29 am PDT
Last Edited by: Beach, August 17, 1984 5:41:30 pm PDT
Beach, March 4, 1985 12:04:56 pm PST
DIRECTORY
Ascii USING [Lower],
Buttons USING [Button, ButtonProc, Create, SetDisplayStyle],
ColorDisplay USING [SetColorDisplayStatus, GetColorDisplayStatus, GetColorDisplayProfile],
Commander USING [CommandProc, Register],
Containers USING [Container, Create],
IO USING [card, EndOfStream, GetTokenRope, IDProc, PutF, RIS, rope, STREAM],
Process USING [Pause, SecondsToTicks],
Rope USING [Equal, Fetch, Length, ROPE, Translate, TranslatorType],
ViewerOps USING [OpenIcon, SetOpenHeight];
~
BEGIN
FiddleWithDisplay: Commander.CommandProc ~ {
MyLower:Rope.TranslatorType = BEGIN RETURN[Ascii.Lower[old]]; END;
myOn: BOOLEAN;
myBpp: CARDINAL;
myOnLeft: BOOLEAN;
myMonType: Rope.ROPE;
displayCurrentStatus: BOOLEAN ← FALSE;
s: IO.STREAM ← IO.RIS[Rope.Translate[base:cmd.commandLine, translator:MyLower]];
[myOn, myOnLeft, myBpp, myMonType] ← ColorDisplay.GetColorDisplayStatus[];
DO
f:Rope.ROPE ← IO.GetTokenRope[s, IO.IDProc ! IO.EndOfStream => EXIT].token;
SELECT Rope.Fetch[f, 0]
FROM
'0 => myOn ← FALSE;
'1 =>
IF Rope.Equal[f, "1024x768"] THEN { myMonType ← "1024x768"; myOn ← TRUE }
ELSE IF Rope.Length[f]=1 THEN {myBpp ← 1; myOn ← TRUE; }
ELSE {
IO.PutF[cmd.err, "Option %g that begins with a 1 has to be 1024x768 or 1 exactly.\n", IO.rope[f]];
RETURN;
};
'2 =>
IF Rope.Equal[f, "24"] THEN { myOn ← TRUE; myBpp ← 24 }
ELSE IF Rope.Length[f]=1 THEN { myBpp ← 2; myOn ← TRUE }
ELSE {
IO.PutF[cmd.err, "Can't do %g bpp\n", IO.rope[f]];
RETURN;
};
'4 => { myBpp ← 4; myOn ← TRUE };
'6 =>
{
IF Rope.Equal[f, "640x480"] THEN { myMonType ← "640x480"; myOn ← TRUE }
ELSE {
IO.PutF[cmd.err, "%g is an invalid key\n", IO.rope[f]];
RETURN;
};
};
'8 => { myBpp ← 8; myOn ← TRUE };
'l => { myOnLeft ← TRUE; myOn ← TRUE };
'r => { myOnLeft ← FALSE; myOn ← TRUE };
'd => {
[myOn, myOnLeft, myBpp, myMonType] ← ColorDisplay.GetColorDisplayProfile[];
};
'o =>
IF Rope.Equal[f, "on"] THEN myOn ← TRUE
ELSE IF Rope.Equal[f, "off"] THEN myOn ← FALSE
ELSE {
IO.PutF[cmd.err, "%g is an invalid key\n", IO.rope[f]];
RETURN;
};
'? => displayCurrentStatus ← TRUE;
ENDCASE => {
IO.PutF[cmd.err, "%g is an invalid key\n", IO.rope[f]];
RETURN[];
};
ENDLOOP;
ColorDisplay.SetColorDisplayStatus[myOn, myOnLeft, myBpp, myMonType];
IF displayCurrentStatus
THEN
IO.PutF[cmd.err, "%g, %g bpp, %g, %g\n",
IO.rope[IF myOn THEN "on" ELSE "off"],
IO.card[myBpp],
IO.rope[IF myOnLeft THEN "left" ELSE "right"],
IO.rope[myMonType]];
};
CreateColorDisplayTool:
PROC ~ {
p: PROCESS RETURNS []; --To fork away a process
prev, on, off, left, right, lowres, highres, c1, c2, c4, c8, c24: Buttons.Button;
hMargin: INT ~ -1;
hSeparator: INT ~ 20;
vMargin: INT ~ 5;
vHeight: INT ~ 10;
thisX, thisY: INT;
colorDisplayTool: Containers.Container ← Containers.Create[
info: [
name: "ColorDisplayTool",
column: right,
scrollable: FALSE
]
];
thisX ← hMargin+hSeparator; thisY ← vMargin;
On Button
prev ← on ← Buttons.Create[
info: [
name: "On",
wx: thisX,
wy: thisY,
parent: colorDisplayTool,
border: TRUE
],
proc: CDTOn,
fork: FALSE
];
thisX ← thisX + prev.ww + hMargin;
Off Button
prev ← off ← Buttons.Create[
info: [
name: "Off",
wx: thisX,
wy: thisY,
parent: colorDisplayTool,
border: TRUE
],
proc: CDTOff,
fork: FALSE
];
thisX ← thisX + prev.ww + hMargin + hSeparator;
1 Button
prev ← c1 ← Buttons.Create[
info: [
name: "1 ",
wx: thisX,
wy: thisY,
parent: colorDisplayTool,
border: TRUE
],
proc: CDT1,
fork: FALSE
];
thisX ← thisX + prev.ww + hMargin;
2 Button
prev ← c2 ← Buttons.Create[
info: [
name: "2 ",
wx: thisX,
wy: thisY,
parent: colorDisplayTool,
border: TRUE
],
proc: CDT2,
fork: FALSE
];
thisX ← thisX + prev.ww + hMargin;
4 Button
prev ← c4 ← Buttons.Create[
info: [
name: "4 ",
wx: thisX,
wy: thisY,
parent: colorDisplayTool,
border: TRUE
],
proc: CDT4,
fork: FALSE
];
thisX ← thisX + prev.ww + hMargin;
8 Button
prev ← c8 ← Buttons.Create[
info: [
name: "8 ",
wx: thisX,
wy: thisY,
parent: colorDisplayTool,
border: TRUE
],
proc: CDT8,
fork: FALSE
];
thisX ← thisX + prev.ww + hMargin;
24 Button
prev ← c24 ← Buttons.Create[
info: [
name: "24 ",
wx: thisX,
wy: thisY,
parent: colorDisplayTool,
border: TRUE
],
proc: CDT24,
fork: FALSE
];
thisX ← thisX + prev.ww + hMargin + hSeparator;
Left Button
prev ← left ← Buttons.Create[
info: [
name: "Left",
wx: thisX,
wy: thisY,
parent: colorDisplayTool,
border: TRUE
],
proc: CDTLeft,
fork: FALSE
];
thisX ← thisX + prev.ww + hMargin;
Right Button
prev ← right ← Buttons.Create[
info: [
name: "Right",
wx: thisX,
wy: thisY,
parent: colorDisplayTool,
border: TRUE
],
proc: CDTRight,
fork: FALSE
];
thisX ← thisX + prev.ww + hMargin + hSeparator;
640x480 Button
prev ← lowres ← Buttons.Create[
info: [
name: "640x480",
wx: thisX,
wy: thisY,
parent: colorDisplayTool,
border: TRUE
],
proc: CDTLowRes,
fork: FALSE
];
thisX ← thisX + prev.ww + hMargin;
1024x768 Button
prev ← highres ← Buttons.Create[
info: [
name: "1024x768",
wx: thisX,
wy: thisY,
parent: colorDisplayTool,
border: TRUE
],
proc: CDTHighRes,
fork: FALSE
];
thisX ← thisX + prev.ww + hMargin + hSeparator;
Set the height of the viewer as a whole
ViewerOps.SetOpenHeight[colorDisplayTool, thisY + vHeight + 2*vMargin];
ViewerOps.OpenIcon[icon: colorDisplayTool, bottom: FALSE];
Start the process that updates the color of the buttons
p ← FORK MonitorButtons[on, off, c1, c2, c4, c8, c24, left, right, lowres, highres];
};
MonitorButtons:
PROC [on, off, c1, c2, c4, c8, c24, left, right, lowres, highres: Buttons.Button] ~ {
OPEN Buttons;
RepaintColorDisplayButtons:
PROC [displayOn, displayOff:
BOOL, bpp:
INT, displayLowRes:
BOOL] ~ {
This proc toggles the color of the buttons to show currect state of display
SetDisplayStyle[on, IF displayOn THEN $WhiteOnBlack ELSE $BlackOnWhite];
SetDisplayStyle[off, IF displayOn THEN $BlackOnWhite ELSE $WhiteOnBlack];
SetDisplayStyle[c1, IF bpp=1 THEN $WhiteOnBlack ELSE $BlackOnWhite];
SetDisplayStyle[c2, IF bpp=2 THEN $WhiteOnBlack ELSE $BlackOnWhite];
SetDisplayStyle[c4, IF bpp=4 THEN $WhiteOnBlack ELSE $BlackOnWhite];
SetDisplayStyle[c8, IF bpp=8 THEN $WhiteOnBlack ELSE $BlackOnWhite];
SetDisplayStyle[c24, IF bpp=24 THEN $WhiteOnBlack ELSE $BlackOnWhite];
SetDisplayStyle[left, IF displayOnLeft THEN $WhiteOnBlack ELSE $BlackOnWhite];
SetDisplayStyle[right, IF displayOnLeft THEN $BlackOnWhite ELSE $WhiteOnBlack];
SetDisplayStyle[lowres, IF displayLowRes THEN $WhiteOnBlack ELSE $BlackOnWhite];
SetDisplayStyle[highres, IF displayLowRes THEN $BlackOnWhite ELSE $WhiteOnBlack];
};
displayOn, displayOnLeft, displayLowRes, wasOn, wasOnLeft, wasLowRes: BOOLEAN;
bpp, wasBpp: INT;
monitorType: Rope.ROPE;
Set up the initial state and color of the buttons
[displayOn, displayOnLeft, bpp, monitorType] ← ColorDisplay.GetColorDisplayStatus[];
displayLowRes ← monitorType.Equal["640x480"];
RepaintColorDisplayButtons[displayOn, displayOnLeft, bpp, displayLowRes];
DO
Make the current reading the last one, and get a new current, and see if different
wasOn ← displayOn; wasOnLeft ← displayOnLeft;
wasBpp ← bpp; wasLowRes ← displayLowRes;
[displayOn, displayOnLeft, bpp, monitorType] ← ColorDisplay.GetColorDisplayStatus[];
displayLowRes ← monitorType.Equal["640x480"];
IF wasOn#displayOn
OR wasOnLeft#displayOnLeft
OR wasBpp#bpp
OR wasLowRes#displayLowRes
THEN
RepaintColorDisplayButtons[displayOn, displayOnLeft, bpp, displayLowRes];
Process.Pause[Process.SecondsToTicks[1]];
ENDLOOP;
};
CDTOn: Buttons.ButtonProc ~ {ColorDisplay.SetColorDisplayStatus[on: TRUE]};
CDTOff: Buttons.ButtonProc ~ {ColorDisplay.SetColorDisplayStatus[on: FALSE]};
CDTLeft: Buttons.ButtonProc ~ {ColorDisplay.SetColorDisplayStatus[onLeft: TRUE]};
CDTRight: Buttons.ButtonProc ~ {ColorDisplay.SetColorDisplayStatus[onLeft: FALSE]};
CDTLowRes: Buttons.ButtonProc ~ {ColorDisplay.SetColorDisplayStatus[monitorType: "640x480"]};
CDTHighRes: Buttons.ButtonProc ~ {ColorDisplay.SetColorDisplayStatus[monitorType: "1024x768"]};
CDT1: Buttons.ButtonProc ~ {ColorDisplay.SetColorDisplayStatus[on: TRUE, bpp: 1]};
CDT2: Buttons.ButtonProc ~ {ColorDisplay.SetColorDisplayStatus[on: TRUE, bpp: 2]};
CDT4: Buttons.ButtonProc ~ {ColorDisplay.SetColorDisplayStatus[on: TRUE, bpp: 4]};
CDT8: Buttons.ButtonProc ~ {ColorDisplay.SetColorDisplayStatus[on: TRUE, bpp: 8]};
CDT24: Buttons.ButtonProc ~ {ColorDisplay.SetColorDisplayStatus[on: TRUE, bpp: 24]};
BugColor: Buttons.ButtonProc ~ {
SELECT mouseButton
FROM
red => ColorDisplay.SetColorDisplayStatus[on: ~ColorDisplay.GetColorDisplayStatus[].on];
blue => CreateColorDisplayTool[];
ENDCASE;
};
Init:
PROC[]
RETURNS[] =
BEGIN
Register the program with the commander and read user profile
Commander.Register[key:"ColorDisplay", proc:FiddleWithDisplay, doc:"Configure color monitor"];
Establish the 'color' button up at the top
[] ← Buttons.Create[
info: [name: "Color"],
proc: BugColor,
fork: FALSE
];
END;
Init[];