File: SVArtworkToolImpl.mesa
Last edited by Bier on August 1, 1985 6:11:05 pm PDT
Copyright © 1984 by Xerox Corporation. All rights reserved.
Created on March 22, 1983 2:04 pm
Contents: Viewer for Two dimensional artwork for mappings
DIRECTORY
Buttons,
Containers,
Imager,
ImagerColor,
PadGraphics,
Rope,
SV2d,
SVArtwork,
SVArtworkTool,
SVArtworkUser,
SVCoordSys2d,
SVInterfaceTypes,
TIPUser,
VFonts,
ViewerClasses,
ViewerOps,
ViewerTools;
SVArtworkToolImpl: PROGRAM
IMPORTS Buttons, Containers, ImagerColor, PadGraphics, SVArtwork, SVArtworkUser, SVCoordSys2d, TIPUser, VFonts, ViewerOps, ViewerTools
EXPORTS SVArtworkTool =
BEGIN
EditToolData: TYPE = SVInterfaceTypes.EditToolData;
Declare the standard distances between menu lines.
entryHeight: CARDINAL = 15;-- height of a line of items
entryVSpace: CARDINAL = 1;-- vertical leading between lines
entryHSpace: CARDINAL = 4; -- horizontal space between items on a line
column0: CARDINAL = 0; -- horizontal space between margin and column 0;
column1: CARDINAL = 80; -- horizontal space between margin and column 1;
column2: CARDINAL = 160; -- horizontal space between margin and column 2.
column3: CARDINAL = 290; -- horizontal space between margin and column 3;
ArtworkToolData: TYPE = REF ArtworkToolDataObj;
ArtworkToolDataObj: TYPE = SVInterfaceTypes.ArtworkToolDataObj;
Point2d: TYPE = SV2d.Point2d;
Viewer: TYPE = ViewerClasses.Viewer;
ArtworkPadPaint: SAFE PROC [self: Viewer, context: Imager.Context,
whatChanged: REF ANY, clear: BOOL] RETURNS [quit: BOOLFALSE] = TRUSTED {
whatChanged is a ArtworkToolData
self is a $Artwork
artworkToolData: ArtworkToolData;
IF whatChanged = NIL THEN { --we are being called by Window Manager
artworkToolData ← NARROW[self.data];
SVArtworkUser.PlaceOrigin[self, artworkToolData, red, FALSE, FALSE];
SVArtwork.DrawArtwork[context, artworkToolData.artwork, artworkToolData.origin, artworkToolData.scalar];
}
ELSE {
proc: PROC [Imager.Context];
artworkToolData ← NARROW[whatChanged];
proc ← artworkToolData.proc;
proc[context];
RETURN;
};
};
Init: PROC = {
artworkPadClass: ViewerClasses.ViewerClass;
artworkPadClass ←
NEW[ViewerClasses.ViewerClassRec ← [
paint: ArtworkPadPaint,
notify: InputNotify,
tipTable: TIPUser.InstantiateNewTIPTable["SVArtworkPad.tip"]
]];
ViewerOps.RegisterViewerClass[$ArtworkPad, artworkPadClass];
};
Create: PUBLIC PROC [editToolData: EditToolData, paint: BOOL] RETURNS [viewer: Viewer] = {
Has no menu
artworkToolData: ArtworkToolData ← NEW[ArtworkToolDataObj];
artworkToolData.height ← 0;
artworkToolData.artwork ← SVArtwork.CreateColorArtwork[ImagerColor.ColorFromAtom[$Blue], plastic];
artworkToolData.origin ← [0,0]; -- will be updated by PlaceOrigin
artworkToolData.scalar ← 1.0;
artworkToolData.editToolData ← editToolData;
artworkToolData.outer ← Containers.Create[[
name: "Artwork: ",
iconic: TRUE,
column: left,
scrollable: FALSE
]];
AddTextSection[artworkToolData];
artworkToolData.picture ← ViewerOps.CreateViewer[
flavor: $ArtworkPad,
info: [
parent: artworkToolData.outer,
wx: 0, wy: artworkToolData.height,
ww: artworkToolData.outer.ww,
wh: artworkToolData.outer.wh,-- only initial values for ww and wh. They are constrained below
data: artworkToolData,-- contains the current scene
scrollable: FALSE
]
];
Containers.ChildXBound[artworkToolData.outer, artworkToolData.picture];
Containers.ChildYBound[artworkToolData.outer, artworkToolData.picture];
artworkToolData.height ← artworkToolData.height + artworkToolData.picture.wh;
IF paint THEN ViewerOps.PaintViewer[artworkToolData.outer, all];
viewer ← artworkToolData.picture;
}; -- end of Create
AddTextSection: PRIVATE PROC [artworkToolData: ArtworkToolData] = {
Creates a text section with buttons and text viewers as follows:
DrawArtwork! scalar: <real>
drawButton, scalarSetPrompt, scalarPrompt, positionButton, colorSet, openFileButton, closeFileButton, pressButton: Buttons.Button;
drawButton ← Buttons.Create[
info: [name: "DrawArtwork!", wy: artworkToolData.height, wh: entryHeight, parent: artworkToolData.outer, border: FALSE],
proc: SVArtworkUser.DrawArtwork,
clientData: artworkToolData
];
scalarSetPrompt ← Buttons.Create[
info: [
name: " ← ",
wx: drawButton.wx + drawButton.ww + entryHSpace,
wy: artworkToolData.height, wh: entryHeight,
parent: artworkToolData.outer, border: TRUE],
proc: SVArtworkUser.ScalarSetPrompt,
clientData: artworkToolData
];
scalarPrompt ← Buttons.Create[
info: [
name: "scalar",
wx: scalarSetPrompt.wx + scalarSetPrompt.ww + entryHSpace,
wy: artworkToolData.height, wh: entryHeight,
parent: artworkToolData.outer, border: FALSE],
proc: SVArtworkUser.ScalarPrompt,
clientData: artworkToolData
];
artworkToolData.textSection.scalar ← ViewerTools.MakeNewTextViewer[[
parent: artworkToolData.outer,
wx: scalarPrompt.wx + scalarPrompt.ww + entryHSpace,
wy: artworkToolData.height,
ww: VFonts.StringWidth["188.88 "],
wh: entryHeight,
data: "1",
scrollable: FALSE, border: FALSE]];
positionButton ← Buttons.Create[
info: [
name: "Position",
wx: artworkToolData.textSection.scalar.wx +
artworkToolData.textSection.scalar.ww + entryHSpace,
wy: artworkToolData.height, wh: entryHeight,
parent: artworkToolData.outer, border: FALSE],
proc: SVArtworkUser.Position,
clientData: artworkToolData
];
colorSet ← Buttons.Create[
info: [
name: " ← ",
wx: positionButton.wx + positionButton.ww + entryHSpace,
wy: artworkToolData.height, wh: entryHeight,
parent: artworkToolData.outer,
border: TRUE],
proc: SVArtworkUser.SetColor,
clientData: artworkToolData
];
artworkToolData.textSection.color ← ViewerTools.MakeNewTextViewer[[
parent: artworkToolData.outer,
wx: colorSet.wx + colorSet.ww + entryHSpace,
wy: artworkToolData.height,
ww: VFonts.StringWidth["188.88, 188.88, 188.88 "],
wh: entryHeight,
data: ".9, .5, .5",
scrollable: FALSE, border: FALSE]];
openFileButton ← Buttons.Create[
info: [
name: "OpenFile",
wx: artworkToolData.textSection.color.wx +
artworkToolData.textSection.color.ww + entryHSpace,
wy: artworkToolData.height, wh: entryHeight,
parent: artworkToolData.outer,
border: FALSE],
proc: SVArtworkUser.OpenFileButton,
clientData: artworkToolData
];
closeFileButton ← Buttons.Create[
info: [
name: "CloseFile",
wx: openFileButton.wx + openFileButton.ww + entryHSpace,
wy: artworkToolData.height, wh: entryHeight,
parent: artworkToolData.outer,
border: FALSE],
proc: SVArtworkUser.CloseFileButton,
clientData: artworkToolData
];
pressButton ← Buttons.Create[
info: [
name: "Press",
wx: closeFileButton.wx + closeFileButton.ww + entryHSpace,
wy: artworkToolData.height, wh: entryHeight,
parent: artworkToolData.outer,
border: FALSE],
proc: SVArtworkUser.PressButton,
clientData: artworkToolData
];
artworkToolData.height ← artworkToolData.height + entryVSpace + entryHeight;
}; -- end of AddTextSection
InputNotify: PUBLIC SAFE PROCEDURE [self: ViewerClasses.Viewer, input: LIST OF REF ANY] = TRUSTED {
self is a Scratchpad2d
artworkToolData: ArtworkToolData ← NARROW[self.data];
IF ISTYPE[input.first, TIPUser.TIPScreenCoords] THEN {
controlPoint: Point2d;
mousePlace: TIPUser.TIPScreenCoords ← NARROW[input.first];
controlPoint[1] ← mousePlace.mouseX; -- this is a fix to float conversion
controlPoint[2] ← mousePlace.mouseY;
controlPoint ← PadGraphics.ScreenToPad[controlPoint, artworkToolData.origin, artworkToolData.scalar];
IF ISTYPE[input.rest.first, ATOM] THEN
SELECT input.rest.first FROM
$MOVESTART => {-- Change mouse to a plus--};
$MOVEEND => { -- Change mouse back and update displacement of artwork.
SVCoordSys2d.PlaceTranslationAwrtB[artworkToolData.artwork.artWRTPad, NIL, controlPoint];
SVArtworkUser.DrawArtwork[NIL, artworkToolData, yellow, FALSE, FALSE];
};
ENDCASE => ERROR;
}; -- end is a mouse point
}; -- end of InputNotify
Init[];
END.