IconEditorImplA.mesa
Converted to the Viewers world by Rick Beach, April 30, 1982 4:32 pm
Last edit by Michael Plass, January 31, 1983 3:47 pm
Written by Werner Winiger, 24-Aug-81 13:14:53
Last Edited by: Teitelman, April 23, 1983 1:35 pm
Last Edited by: Doug Wyatt, April 22, 1983 1:42 pm
DIRECTORY
Containers USING [Container],
FileIO USING [Open],
IconEditorDefs,
IconRegistry USING [RegisterIcon],
IO,
Menus USING [ClickProc, CreateMenu, CreateEntry, InsertMenuEntry, Menu, MenuProc],
MessageWindow USING [Append, Blink, Confirm],
Rope USING [Cat, ROPE, Size],
Runtime USING [IsBound],
ViewerClasses USING [Viewer, ViewerClass, ViewerClassRec],
ViewerOps USING [PaintViewer, SetNewVersion],
ViewerTools USING [GetContents];
IconEditorImplA: CEDAR PROGRAM
IMPORTS IconEditorDefs, IconRegistry, IO, Menus, MessageWindow, Rope, Runtime,
ViewerOps, ViewerTools, FileIO
EXPORTS IconEditorDefs = {
OPEN IconEditorDefs;
CreateMenu: PUBLIC PROC [handle: IconHandle] RETURNS [iconMenu: Menus.Menu] = {
iconMenu ← Menus.CreateMenu[lines: 3];
Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"BlackLabel", proc:BlackLabelProc, fork:TRUE, clientData:handle], 2];
Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"WhiteLabel", proc:WhiteLabelProc, fork:TRUE, clientData:handle], 2];
Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"DrawLine", proc:LineProc, fork:TRUE, clientData:handle], 2];
Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"InvertColor", proc:InvertProc, fork:TRUE, clientData:handle], 2];
Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"Black", proc:BlackProc, fork:TRUE, clientData:handle], 2];
Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"DarkGray", proc:DarkGrayProc, fork:TRUE, clientData:handle], 2];
Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"DeskTopGray", proc:DeskTopGrayProc, fork:TRUE, clientData:handle], 2];
Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"White", proc:WhiteProc, fork:TRUE, clientData:handle], 2];
Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"Register", proc:RegisterIconProc, fork:TRUE, clientData:handle], 1]; -- w.t.
Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"UnSetLabel", proc:UnLabelIconProc, fork:TRUE, clientData:handle], 1];
Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"SetLabel", proc:LabelIconProc, fork:TRUE, clientData:handle], 1];
Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"Mirror", proc:MirrorProc, fork:TRUE, clientData:handle], 1];
Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"ShiftRt", proc:RightProc, fork:TRUE, clientData:handle], 1];
Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"ShiftLf", proc:LeftProc, fork:TRUE, clientData:handle], 1];
Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"ShiftDn", proc:DownProc, fork:TRUE, clientData:handle], 1];
Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"ShiftUp", proc:UpProc, fork:TRUE, clientData:handle], 1];
Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"UNDO", proc:UndoProc, fork:TRUE, clientData:handle], 1];
Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"ShowLabel", proc:ShowLabelProc, fork:TRUE, clientData:handle], 0];
Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"CreateIcon", proc:CreateIconProc, fork:TRUE, clientData:handle], 0];
Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"DeleteIcon", proc:DeleteIconProc, fork:TRUE, clientData:handle], 0];
Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"RotateDisplay", proc:RotateDisplayProc, fork:TRUE, clientData:handle], 0];
Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"Load", proc:LoadIconProc, fork:TRUE, clientData:handle], 0];
Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"Save", proc:SaveProc, fork:TRUE, clientData:handle, guarded: TRUE, documentation:"Confirm write to Icon file"], 0];
Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"Reset", proc:ResetProc, fork:TRUE, clientData:handle], 0];
};
LoadIconProc: PUBLIC Menus.MenuProc = {
handle: IconHandle ← NARROW[clientData];
iconInfo: iconInfoRef ← NEW[iconInfoRec ← [handle, screen, handle.currentIC]];
IF handle.container.newVersion THEN
IF ~MessageWindow.Confirm["Confirm discard of current icon edits..."] THEN
RETURN;
handle.iconFileName ← ViewerTools.GetContents[handle.iconFileWindow];
IF Rope.Size[handle.iconFileName]=0 THEN {
MessageWindow.Append[message: "Enter file name prior to Load.", clearFirst: TRUE];
RETURN};
[handle.numberReadIn, handle.iconFile] ← IconEditorDefs.LoadIcons[handle,
handle.iconFileName ! IconEditorDefs.CouldntLoadIcons => {MessageWindow.Append[
Rope.Cat["Icon file ", handle.iconFileName," could not be loaded"], TRUE];
GOTO BadFile}];
handle.numberOfIcons ← handle.numberReadIn;
handle.startDisplay ← 0;
handle.container.newVersion ← FALSE;
handle.drewLine ← FALSE;
handle.drewRectangle ← FALSE;
ViewerOps.PaintViewer[viewer: handle.container, hint: client, whatChanged: iconInfo];
ViewerOps.PaintViewer[viewer: handle.container, hint: all];
EXITS BadFile => RETURN
};
RotateDisplayProc: PUBLIC Menus.MenuProc = {
rotates the display incrementally by moving up the starting position in the icons array
handle: IconHandle ← NARROW[clientData];
iconInfo: iconInfoRef;
IF (mouseButton = red) THEN
handle.startDisplay ← (handle.startDisplay + 1) MOD handle.numberOfIcons
ELSE handle.startDisplay ← (handle.startDisplay + 4) MOD handle.numberOfIcons;
handle.currentIC ← LOOPHOLE[handle.startDisplay];
iconInfo ← NEW[iconInfoRec ← [handle, screen, handle.currentIC]];
ViewerOps.SetNewVersion[handle.container];
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo, clearClient: FALSE];
};
BlackProc: PUBLIC Menus.MenuProc = {
handle: IconHandle ← NARROW[clientData];
iconInfo: iconInfoRef ← NEW[iconInfoRec ← [handle, icon, handle.currentIC]];
IF IconEditorDefs.PointsMarked[handle, rect] THEN {
IconEditorDefs.SaveBitMap[handle];
ViewerOps.SetNewVersion[handle.container];
IconEditorDefs.SetBlack[handle, handle.currentIC, handle.currentRectangle];
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo,
clearClient: FALSE];
};
};
InvertProc: PUBLIC Menus.MenuProc = {
handle: IconHandle ← NARROW[clientData];
iconInfo: iconInfoRef ← NEW[iconInfoRec ← [handle, icon, handle.currentIC]];
IF IconEditorDefs.PointsMarked[handle, rect] THEN {
IconEditorDefs.SaveBitMap[handle];
ViewerOps.SetNewVersion[handle.container];
IconEditorDefs.Invert[handle, handle.currentIC, handle.currentRectangle];
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo,
clearClient: FALSE];
};
};
MirrorProc: PUBLIC Menus.MenuProc = {
handle: IconHandle ← NARROW[clientData];
iconInfo: iconInfoRef ← NEW[iconInfoRec ← [handle, icon, handle.currentIC]];
IF IconEditorDefs.PointsMarked[handle, rect] THEN {
IconEditorDefs.SaveBitMap[handle];
ViewerOps.SetNewVersion[handle.container];
IconEditorDefs.MirrorIcon[handle, handle.currentIC, handle.currentRectangle];
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo,
clearClient: FALSE];
};
};
DeskTopGrayProc: PUBLIC Menus.MenuProc = {
handle: IconHandle ← NARROW[clientData];
iconInfo: iconInfoRef ← NEW[iconInfoRec ← [handle, icon, handle.currentIC]];
IF IconEditorDefs.PointsMarked[handle, rect] THEN {
IconEditorDefs.SaveBitMap[handle];
ViewerOps.SetNewVersion[handle.container];
IconEditorDefs.SetDeskTopGray[handle, handle.currentIC, handle.currentRectangle];
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo,
clearClient: FALSE];
};
};
DarkGrayProc: PUBLIC Menus.MenuProc = {
handle: IconHandle ← NARROW[clientData];
iconInfo: iconInfoRef ← NEW[iconInfoRec ← [handle, icon, handle.currentIC]];
IF IconEditorDefs.PointsMarked[handle, rect] THEN {
IconEditorDefs.SaveBitMap[handle];
ViewerOps.SetNewVersion[handle.container];
IconEditorDefs.SetDarkGray[handle, handle.currentIC, handle.currentRectangle];
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo,
clearClient: FALSE];
};
};
WhiteProc: PUBLIC Menus.MenuProc = {
handle: IconHandle ← NARROW[clientData];
iconInfo: iconInfoRef ← NEW[iconInfoRec ← [handle, icon, handle.currentIC]];
IF IconEditorDefs.PointsMarked[handle, rect] THEN {
IconEditorDefs.SaveBitMap[handle];
ViewerOps.SetNewVersion[handle.container];
IconEditorDefs.SetWhite[handle, handle.currentIC, handle.currentRectangle];
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo,
clearClient: FALSE];
};
};
RightProc: PUBLIC Menus.MenuProc = { 
OPEN IconEditorDefs;
handle: IconHandle ← NARROW[clientData];
iconInfo: iconInfoRef ← NEW[iconInfoRec ← [handle, icon, handle.currentIC]];
IconEditorDefs.SaveBitMap[handle];
IconEditorDefs.MoveRight[handle, handle.currentIC, (mouseButton = red)];
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo,
clearClient: FALSE];
};
LeftProc: PUBLIC Menus.MenuProc = {
handle: IconHandle ← NARROW[clientData];
iconInfo: iconInfoRef ← NEW[iconInfoRec ← [handle, icon, handle.currentIC]];
IconEditorDefs.SaveBitMap[handle];
IconEditorDefs.MoveLeft[handle, handle.currentIC, (mouseButton = red)];
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo,
clearClient: FALSE];
};
UpProc: PUBLIC Menus.MenuProc = {
handle: IconHandle ← NARROW[clientData];
iconInfo: iconInfoRef ← NEW[iconInfoRec ← [handle, icon, handle.currentIC]];
IconEditorDefs.SaveBitMap[handle];
IconEditorDefs.MoveUp[handle, handle.currentIC, (mouseButton = red)];
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo,
clearClient: FALSE];
};
DownProc: PUBLIC Menus.MenuProc = {
handle: IconHandle ← NARROW[clientData];
iconInfo: iconInfoRef ← NEW[iconInfoRec ← [handle, icon, handle.currentIC]];
IconEditorDefs.SaveBitMap[handle];
IconEditorDefs.MoveDown[handle, handle.currentIC, (mouseButton = red)];
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo,
clearClient: FALSE];
};
LineProc: PUBLIC Menus.MenuProc = {
OPEN IconEditorDefs;  -- for DrawLine and mark1 and mark2.
handle: IconHandle ← NARROW[clientData];
iconInfo: iconInfoRef ← NEW[iconInfoRec ← [handle, icon, handle.currentIC]];
IF IconEditorDefs.PointsMarked[handle, line] THEN {
IconEditorDefs.SaveBitMap[handle];
ViewerOps.SetNewVersion[handle.container];
DrawLine[handle, handle.currentLine, handle.currentIC];
handle.drewLine ← FALSE;
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo,
clearClient: FALSE];
};
};
CreateIconProc: PUBLIC Menus.MenuProc = {
This allows a new icon to be created. It creates a completely "blank" icon and causes this to become the new current icon.
handle: IconHandle ← NARROW[clientData];
iconInfo: iconInfoRef;
handle.currentIC ← IconEditorDefs.GetNewFlavor[handle];
handle.currentIconRep ← handle.icons[LOOPHOLE[handle.currentIC]] ← NEW[IconEditorDefs.iconFileFormat];
iconInfo ← NEW[iconInfoRec ← [handle, newIcon, handle.currentIC]];
handle.numberOfIcons ← handle.numberOfIcons + 1;
ViewerOps.SetNewVersion[handle.container];
make sure the new icon is blank
IconEditorDefs.ClearIcon[handle, handle.currentIC];
before we paint the screen, make sure new icon is visible
IF LOOPHOLE[handle.currentIC, CARDINAL] >= maxIconsOnDisplay THEN
handle.startDisplay ← (handle.startDisplay + 1) MOD handle.numberOfIcons;
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo,
clearClient: FALSE];
};
ShowLabelProc: PUBLIC Menus.MenuProc = {
handle: IconHandle ← NARROW[clientData];
iconInfo: iconInfoRef ← NEW[iconInfoRec ← [handle, rect, handle.currentIC]];
ViewerOps.SetNewVersion[handle.container];
IF ~handle.currentIconRep.label THEN {
MessageWindow.Append[message: "Current icon has no label.", clearFirst: TRUE];
MessageWindow.Blink[];
RETURN }
ELSE {
handle.labelRect.x ← handle.currentIconRep.lx;
handle.labelRect.y ←
IconEditorDefs.iconH-1-(handle.currentIconRep.ly+handle.currentIconRep.lh);
handle.labelRect.w ← handle.currentIconRep.lw;
handle.labelRect.h ← handle.currentIconRep.lh };
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo,
clearClient: FALSE];
};
WhiteLabelProc: PUBLIC Menus.MenuProc = {
handle: IconHandle ← NARROW[clientData];
ViewerOps.SetNewVersion[handle.container];
IconEditorDefs.WhiteLabel[handle, handle.currentIC];
};
BlackLabelProc: PUBLIC Menus.MenuProc = {
handle: IconHandle ← NARROW[clientData];
ViewerOps.SetNewVersion[handle.container];
IconEditorDefs.BlackLabel[handle, handle.currentIC];
};
LabelIconProc: PUBLIC Menus.MenuProc = {
handle: IconHandle ← NARROW[clientData];
iconInfo: iconInfoRef ← NEW[iconInfoRec ← [handle, rect, handle.currentIC]];
ViewerOps.SetNewVersion[handle.container];
IconEditorDefs.SetLabel[handle, handle.currentIC, handle.currentRectangle];
now erase the sketch
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo, clearClient: FALSE];};
UnLabelIconProc: PUBLIC Menus.MenuProc = {
handle: IconHandle ← NARROW[clientData];
ViewerOps.SetNewVersion[handle.container];
IconEditorDefs.UnSetLabel[handle, handle.currentIC];
};
RegisterIconProc: Menus.MenuProc = TRUSTED{
handle: IconHandle ← NARROW[clientData];
IF NOT Runtime.IsBound[IconRegistry.RegisterIcon] THEN {
MessageWindow.Append["IconRegistryImpl.bcd has not been run", TRUE];
MessageWindow.Blink[]}
ELSE IconRegistry.RegisterIcon[iconName: ViewerTools.GetContents[handle.iconNameWindow], fileName: ViewerTools.GetContents[handle.iconFileWindow], index: LOOPHOLE[handle.currentIC, CARDINAL], saveInCatalogue: TRUE];
};
SaveProc: PUBLIC Menus.MenuProc = {
handle: IconHandle ← NARROW[clientData];
handle.iconFileName ← ViewerTools.GetContents[handle.iconFileWindow];
IF Rope.Size[handle.iconFileName]=0 THEN {
MessageWindow.Append[message: "Enter file name prior to Save.", clearFirst: TRUE];
RETURN};
handle.iconFile ← IconEditorDefs.SaveIcons[handle, handle.iconFileName, handle.numberOfIcons
! IconEditorDefs.CouldntSaveIcons => {MessageWindow.Append[
Rope.Cat["Icon file ", handle.iconFileName, " could not be saved"], TRUE];
GOTO BadFile}];
MessageWindow.Append[message: Rope.Cat["Icons saved in ", handle.iconFileName], clearFirst: TRUE];
handle.container.newVersion ← FALSE;
ViewerOps.PaintViewer[handle.container, caption];
EXITS BadFile => RETURN
};
ResetProc: PUBLIC Menus.MenuProc = TRUSTED {
handle: IconHandle ← NARROW[clientData];
iconInfo: iconInfoRef ← NEW[iconInfoRec ← [handle, screen, handle.currentIC]];
newFlavor: IconEditorDefs.iconFlavor;
IF ~handle.container.newVersion THEN RETURN
ELSE IF ~MessageWindow.Confirm["Confirm discard of new icon edits..."] THEN
RETURN;
Create a new file stream again
handle.iconFile ← FileIO.Open[fileName: handle.iconFileName];
handle.nextFlavor ← FIRST[IconEditorDefs.iconFlavor];  -- reset nextFlavor
FOR n: CARDINAL IN [0 .. handle.numberReadIn) DO
newFlavor ← IconEditorDefs.GetNewFlavor[handle];
[]← IO.UnsafeGetBlock[handle.iconFile,
[LOOPHOLE[handle.icons[LOOPHOLE[newFlavor]]], 0,
SIZE[IconEditorDefs.iconFileFormat]*2]];
ENDLOOP;
handle.numberOfIcons ← handle.numberReadIn;
handle.startDisplay ← 0;
handle.container.newVersion ← FALSE;
ViewerOps.PaintViewer[viewer: handle.container, hint: all, whatChanged: iconInfo];
};
}.
Edited on April 11, 1983 4:09 pm, by Teitelman
added Register button which calls IconRegistry to register an icon
changes to: CreateMenu, RegisterIconProc, SaveProc, DIRECTORY, CreateMenu, RegisterIconProc, SaveProc, IconEditorStorageOverflowInPass3, DIRECTORY, IconEditorStorageOverflowInPass3, handle (local of RegisterIconProc), RegisterIconProc
Edited on April 12, 1983 5:03 pm, by Teitelman
changes to: RegisterIconProc, handle (local of RegisterIconProc), DIRECTORY, IconEditorStorageOverflowInPass3
Edited on April 22, 1983 1:41 pm, by Wyatt
Removed redundant menu items: Close Grow --> <-- Destroy
Edited on April 23, 1983 1:35 pm, by Teitelman
Register command was getting name of file from fetchIconFileWindow rather than fetchFileWIndow
changes to: RegisterIconProc