ColorCRTTool.mesa
Mik Lamming - March 15, 1983 10:04 am
DIRECTORY
Buttons   USING [Button, ButtonProc, Create, ReLabel],
ColorDisplay  USING [CursorMode, SetCursorMode],
Containers  USING [Create, Container],
Graphics   USING [Box, DrawBox, GetBounds, SetColor],
GraphicsColor USING [HSVToColor],
Icons    USING [IconFlavor, NewIconFromFile],
ViewerClasses,
ViewerOps  USING [ChangeColumn, ComputeColumn, CreateViewer, PaintViewer, RegisterViewerClass],
WindowManager USING [ScreenPos, StartColorViewers, StopColorViewers];
ColorCRTTool: PROGRAM
IMPORTS Buttons, ColorDisplay, Containers, Graphics, GraphicsColor, Icons, ViewerOps, WindowManager = {
Bpp: TYPE = {B8, B24};
Toggle: TYPE = {on, off};
standard settings durring start up
NoBitsPerPoint:Bpp ← B8;
Side:WindowManager.ScreenPos ← left;
CursorColor:ColorDisplay.CursorMode ← zeros;
OnOffSwitch:Toggle ← off;
Hue:REAL ← 0.5;
Sat:REAL ← 1.0;
Val:REAL ← 1.0;
ColorBar1,ColorBar2:ViewerClasses.Viewer;
FixUpDisplay: PROC [] = {
WindowManager.StopColorViewers[];
IF OnOffSwitch=on THEN {
WindowManager.StartColorViewers[screenPos:Side, bitsPerPixel:IF NoBitsPerPoint = B8 THEN 8 ELSE 24];
ColorDisplay.SetCursorMode[CursorColor];
ViewerOps.ComputeColumn[color];
};
};
SetBpp: Buttons.ButtonProc = TRUSTED {
SELECT NoBitsPerPoint FROM
B8 => NoBitsPerPoint ← B24;
B24 => NoBitsPerPoint ← B8;
ENDCASE;
Buttons.ReLabel [button:NARROW[parent, ViewerClasses.Viewer],
newName:IF NoBitsPerPoint = B8 THEN "8 bpp" ELSE "24 bpp"];
FixUpDisplay[];
};
OnOff: Buttons.ButtonProc = TRUSTED {
SELECT OnOffSwitch FROM
on => { OnOffSwitch ← off;
IF NARROW[parent, ViewerClasses.Viewer].parent.column = color THEN
ViewerOps.ChangeColumn[NARROW[parent, ViewerClasses.Viewer].parent, left];
};
off => OnOffSwitch ← on;
ENDCASE;
Buttons.ReLabel [button:NARROW[parent, ViewerClasses.Viewer],
newName:IF OnOffSwitch = on THEN "ON " ELSE "OFF"];
FixUpDisplay[];
};
SetCursorColor: Buttons.ButtonProc = TRUSTED {
SELECT CursorColor FROM
ones => CursorColor ← zeros;
zeros => CursorColor ← ones;
ENDCASE;
Buttons.ReLabel [button:NARROW[parent, ViewerClasses.Viewer],
newName:IF CursorColor = ones THEN "white" ELSE "black "];
ColorDisplay.SetCursorMode[CursorColor];
};
SetSide: Buttons.ButtonProc = TRUSTED {
SELECT Side FROM
left => Side ← right;
right => Side ← left;
ENDCASE;
Buttons.ReLabel [button:NARROW[parent, ViewerClasses.Viewer],
newName:IF Side = left THEN "left " ELSE "right"];
FixUpDisplay[];
};
SetHue: Buttons.ButtonProc = TRUSTED {
IF mouseButton=red THEN Hue ← MIN[Hue + 0.01,1] ELSE Hue ← MAX[Hue - 0.01, 0];
ViewerOps.PaintViewer[clearClient:FALSE, viewer:ColorBar2, hint:client];
};
SetSat: Buttons.ButtonProc = TRUSTED {
IF mouseButton=red THEN Sat ← MIN[Sat + 0.1,1] ELSE Sat ← MAX[Sat - 0.1, 0];
ViewerOps.PaintViewer[clearClient:FALSE, viewer:ColorBar1, hint:client];
ViewerOps.PaintViewer[clearClient:FALSE, viewer:ColorBar2, hint:client];
};
SetVal: Buttons.ButtonProc = TRUSTED {
IF mouseButton=red THEN Val ← MIN[Val + 0.1,1] ELSE Val ← MAX[Val - 0.1, 0];
ViewerOps.PaintViewer[clearClient:FALSE, viewer:ColorBar1, hint:client];
ViewerOps.PaintViewer[clearClient:FALSE, viewer:ColorBar2, hint:client];
};
BackDropPainter:ViewerClasses.PaintProc = TRUSTED {
box:Graphics.Box ← Graphics.GetBounds[context];
IF self=ColorBar1 THEN {
i:REAL ← 0;
width:REAL ← (box.xmax - box.xmin)/101;
WHILE i<=1 DO
box.xmax ← box.xmin + width;
Graphics.SetColor[context, GraphicsColor.HSVToColor[i, Sat, Val]];
Graphics.DrawBox[context, box];
i ← i + 0.01;
box.xmin ← box.xmin + width;
ENDLOOP;
}
ELSE {
Graphics.SetColor[context, GraphicsColor.HSVToColor[Hue, Sat, Val]];
Graphics.DrawBox[context, box];
};
};
MyIcon:Icons.IconFlavor ← Icons.NewIconFromFile["CTV.icons", 0]; 
ButtonBox: Containers.Container ← Containers.Create[ info:[name:"ColorCRT Tool",
openHeight:180,
scrollable:FALSE,
icon:MyIcon]];
BackDropClassRec:ViewerClasses.ViewerClass ← NEW[ViewerClasses.ViewerClassRec];
BackDropClassRec.paint ← BackDropPainter;
ViewerOps.RegisterViewerClass[$BACKDROP, BackDropClassRec];
[] ← Buttons.Create[info:[parent:ButtonBox,
name:IF NoBitsPerPoint = B8 THEN "8 bpp" ELSE "24 bpp",
wx:25, wy:25],
proc:SetBpp,
documentation:"Set number of bits per pixel"];
[] ← Buttons.Create[info:[parent:ButtonBox,
name:IF CursorColor = ones THEN "white" ELSE "black ",
wx:75, wy:25],
proc:SetCursorColor,
documentation:"Set cursor color"];
[] ← Buttons.Create[info:[parent:ButtonBox,
name:IF Side = left THEN "left " ELSE "right",
wx:120, wy:25],
proc:SetSide,
documentation:"Set color column to LEFT/RIGHT of b/w column"];
[] ← Buttons.Create[info:[parent:ButtonBox,
name:IF OnOffSwitch = on THEN "ON" ELSE "OFF",
wx:275, wy:25],
proc:OnOff,
documentation:"Turn color display ON/OFF"];
[] ← Buttons.Create[info:[parent:ButtonBox,
name:"Hue",
wx:25, wy:50],
proc:SetHue,
documentation:"Change Hue"];
[] ← Buttons.Create[info:[parent:ButtonBox,
name:"Sat",
wx:75, wy:50],
proc:SetSat,
documentation:"Change Sat"];
[] ← Buttons.Create[info:[parent:ButtonBox,
name:"Val",
wx:120, wy:50],
proc:SetVal,
documentation:"Change Val"];
ColorBar1 ← ViewerOps.CreateViewer[flavor:$BACKDROP,
info:[parent:ButtonBox,
wx:0, wy:70, ww:1000, wh:30]];
ColorBar2 ← ViewerOps.CreateViewer[flavor:$BACKDROP,
info:[parent:ButtonBox,
wx:0, wy:100, ww:1000, wh:30]];
}.