File: GGWindowImpl.mesa
Author: Eric Bier on June 5, 1985 11:34:50 pm PDT
Copyright c 1985, 1986 by Xerox Corporation. All rights reserved.
Last edited by Bier on January 28, 1987 3:56:19 pm PST
Contents: Code to create a Gargoyle window. Calls GGContainer to make the container and adds menus at the top. The graphics part of the Gargoyle window is an inner viewer of a BiScroller of class $ActionArea. The paint proc for a $ActionArea is defined herein.
Pier, January 16, 1987 6:52:46 pm PST
DIRECTORY
BiScrollers, Buttons, Commander, CommandTool, Cursors, FileNames, GGAlign, GGBasicTypes, GGBoundBox, AtomButtons, GGCaret, GGContainer, GGError, GGEvent, GGGraphicsButton, GGGravity, GGInterfaceTypes, GGMeasure, GGMenus, GGModelTypes, GGMultiGravity, GGObjects, GGRefresh, GGSegmentTypes, GGSessionLog, GGUserInput, GGVector, GGViewerOps, GGWindow, Geom2D, Icons, Imager, ImagerBackdoor, ImagerFastShow, ImagerPixelMap, ImagerTransformation, IO, Rope, SlackProcess, Terminal, TiogaButtons, TIPUser, ViewerClasses, ViewerOps;
GGWindowImpl: CEDAR PROGRAM
IMPORTS BiScrollers, Buttons, Commander, CommandTool, Cursors, FileNames, GGAlign, GGCaret, GGEvent, GGGravity, GGBoundBox, AtomButtons, GGContainer, GGError, GGGraphicsButton, GGMeasure, GGMenus, GGMultiGravity, GGObjects, GGRefresh, GGSessionLog, GGUserInput, GGVector, GGViewerOps, Geom2D, Icons, Imager, ImagerBackdoor, ImagerTransformation, ImagerFastShow, SlackProcess, Terminal, TIPUser, Rope, ViewerOps
EXPORTS GGWindow = BEGIN
Caret: TYPE = REF CaretObj;
CaretObj: TYPE = GGInterfaceTypes.CaretObj;
CameraDataObj: TYPE = GGModelTypes.CameraDataObj;
Filters: TYPE = REF FiltersObj;
FiltersObj: TYPE = GGInterfaceTypes.FiltersObj;
Slice: TYPE = GGModelTypes.Slice;
ImagerProc: TYPE = GGInterfaceTypes.ImagerProc;
Outline: TYPE = GGModelTypes.Outline;
Point: TYPE = GGBasicTypes.Point;
Scene: TYPE = REF SceneObj;
SceneObj: TYPE = GGModelTypes.SceneObj;
Segment: TYPE = GGSegmentTypes.Segment;
Sequence: TYPE = GGModelTypes.Sequence;
Traj: TYPE = GGModelTypes.Traj;
Viewer: TYPE = ViewerClasses.Viewer;
ForegroundParts: TYPE = GGWindow.ForegroundParts;
GargoyleData: TYPE = REF GargoyleDataObj;
GargoyleDataObj: TYPE = GGInterfaceTypes.GargoyleDataObj;
buttonAlign: INTEGER ← 2; -- align popUp and standard buttons in first button line
entryHeight: CARDINAL = 15; -- height of a line of items
entryVSpace: CARDINAL = 2; -- vertical leading between lines
entryHSpace: CARDINAL = 2; -- horizontal space between items on a line
column1: CARDINAL = 200; -- horizontal space between margin and column 1;
column2: CARDINAL = 250; -- horizontal space between margin and column 2.
column3: CARDINAL = 500; -- horizontal space between margin and column 3;
nameSize: CARDINAL = 140;
smallNumberSize: CARDINAL = 45;
numberSize: CARDINAL = 80;
bigNumberSize: CARDINAL = 160;
pointSize: CARDINAL = 160;
GGActionAreaPaint: PROC [self: Viewer, context: Imager.Context, whatChanged: REF ANY, clear: BOOL] RETURNS [quit: BOOLFALSE] = TRUSTED {
ViewerClasses.PaintProc
whatChanged is a GargoyleData. self is an ActionArea.
PaintEntireViewer: PROC = CHECKED {
PlaceOrigin[self];
RestoreScreenAndInvariants[paintAction: $PaintEntireScene, gargoyleData: gargoyleData, remake: none, backgndOK: TRUE, edited: FALSE, okToClearFeedback: FALSE];
};
gargoyleData: GargoyleData;
IF whatChanged = NIL THEN { --we are being called by Window Manager
gargoyleData ← NARROW[BiScrollers.ClientDataOfViewer[self]];
PlaceOrigin[self];
RestoreScreenAndInvariants[paintAction: $ViewersPaintEntireScene, gargoyleData: gargoyleData, remake: none, backgndOK: TRUE, edited: FALSE, okToClearFeedback: FALSE];
}
ELSE {
gargoyleData ← NARROW[whatChanged];
IF gargoyleData.refresh.paintAction=$PaintEntireViewer THEN PaintEntireViewer[] ELSE
GGRefresh.ActionAreaPaint[context, gargoyleData.refresh.paintAction, gargoyleData];
};
};
RestoreScreenAndInvariants: PUBLIC PROC [paintAction: ATOM, gargoyleData: GargoyleData, remake: ForegroundParts ← triggerBag, backgndOK: BOOLFALSE, edited: BOOLTRUE, okToClearFeedback: BOOL] = {
IF okToClearFeedback THEN GGError.ClearHerald[gargoyleData.feedback];
Fix the foreground Chain.
IF gargoyleData.aborted[bags] THEN {
GGAlign.SetBagsForAction[gargoyleData, $CaretPos];
gargoyleData.refresh.foregndBitmapOK ← FALSE;
gargoyleData.refresh.backgndBitmapOK ← FALSE;
gargoyleData.aborted[bags] ← FALSE;
}
ELSE {
SELECT remake FROM
none => NULL;
triggerBag => {
GGAlign.SetBagsForAction[gargoyleData, $CaretPos];
gargoyleData.refresh.foregndBitmapOK ← FALSE;
};
objectBag => {
GGGravity.FlushObjectBag[gargoyleData.hitTest.currentObjectBag];
GGAlign.BuiltInFilters[gargoyleData.hitTest.currentTriggerBag, gargoyleData.hitTest.currentObjectBag, gargoyleData];
GGAlign.AddAllMidpoints[gargoyleData.hitTest.sceneTriggerBag, gargoyleData.hitTest.currentObjectBag, gargoyleData];
gargoyleData.refresh.foregndBitmapOK ← FALSE;
};
bitMap => {
gargoyleData.refresh.foregndBitmapOK ← FALSE;
};
sceneBag => {
GGAlign.SetSceneBagForAction[gargoyleData, $CaretPos];
GGAlign.AddAllMidpoints[gargoyleData.hitTest.sceneTriggerBag, gargoyleData.hitTest.currentObjectBag, gargoyleData];
};
ENDCASE => ERROR;
Fix the background invariant.
gargoyleData.refresh.backgndBitmapOK ← backgndOK;
};
Show the viewer as edited, if appropriate.
IF edited THEN {
IF NOT gargoyleData.outer.newVersion THEN {
gargoyleData.outer.icon ← dirtyIcon;
gargoyleData.outer.newVersion ← TRUE;
ViewerOps.PaintViewer[gargoyleData.outer, caption];
};
};
Refresh the screen.
gargoyleData.refresh.paintAction ← paintAction;
ViewerOps.PaintViewer[
viewer: gargoyleData.actionArea,
hint: client,
whatChanged: gargoyleData,
clearClient: FALSE]
};
MakeGGViewer: PROC [fileName: Rope.ROPENIL] = {
gargoyleData: GargoyleData ← CreateWindow[GGObjects.CreateScene[], TRUE, FALSE, FileNames.CurrentWorkingDirectory[] ]; -- create brand new GG window
IF fileName#NIL AND ~Rope.Equal[fileName, ""] THEN GGEvent.Get[event: LIST[$Get, fileName], clientData: gargoyleData]; -- tell GGEvent.Get to try for this file
ViewerOps.PaintViewer[gargoyleData.outer, caption]; -- just to get the icon to appear
};
CreateWindow: PUBLIC PROC [scene: Scene, iconic: BOOL, paint: BOOL, workingDirectory: Rope.ROPE] RETURNS [gargoyleData: GargoyleData] = {
tV: Viewer;
gargoyleData ← NEW[GargoyleDataObj];
gargoyleData.currentWDir ← workingDirectory;
gargoyleData.originalWDir ← originalWDir; --global
gargoyleData.hitTest ← NEW[FiltersObj];
gargoyleData.hitTest.currentTriggerBag ← GGAlign.CreateTriggerBag[];
gargoyleData.hitTest.sceneTriggerBag ← GGAlign.CreateTriggerBag[];
gargoyleData.hitTest.currentObjectBag ← GGGravity.CreateObjectBag[];
gargoyleData.scene ← scene;
gargoyleData.caret ← NEW[CaretObj];
gargoyleData.anchor ← NEW[CaretObj];
gargoyleData.camera ← NEW[CameraDataObj];
gargoyleData.state ← $None;
gargoyleData.mouseMode ← $None;
gargoyleData.drag.savedCaret ← NEW[CaretObj];
gargoyleData.drag.selectState ← none;
gargoyleData.drag.extendMode ← none;
gargoyleData.refresh.startBoundBox ← GGBoundBox.CopyBoundBox[GGBoundBox.emptyBoundBox];
Construct the outer container.
gargoyleData.outer ← GGContainer.Create[
info: [
name: "Gargoyle",
menu: NIL,
data: gargoyleData,
iconic: TRUE,
column: left,
scrollable: FALSE,
icon: cleanIcon
],
paint: FALSE];
BuildActionArea[gargoyleData];
gargoyleData.height ← 0;
tV ← BiScrollers.CreateScale[ [parent: gargoyleData.outer, wx: 0, wy: buttonAlign, border: FALSE], gargoyleData.biScroller];
tV ← BiScrollers.CreateRotate[ [parent: gargoyleData.outer, wx: tV.wx+tV.ww+entryHSpace, wy: buttonAlign, border: FALSE], gargoyleData.biScroller];
tV ← BiScrollers.CreateFit[ [parent: gargoyleData.outer, wx: tV.wx+tV.ww+entryHSpace, wy: buttonAlign, border: FALSE], gargoyleData.biScroller];
tV ← BiScrollers.CreateReset[ [parent: gargoyleData.outer, wx: tV.wx+tV.ww+entryHSpace, wy: buttonAlign, border: FALSE], gargoyleData.biScroller];
tV ← BiScrollers.CreateEdge[ [parent: gargoyleData.outer, wx: tV.wx+tV.ww+entryHSpace, wy: buttonAlign, border: FALSE], gargoyleData.biScroller];
tV ← BiScrollers.CreatePrev[ [parent: gargoyleData.outer, wx: tV.wx+tV.ww+entryHSpace, wy: buttonAlign, border: FALSE], gargoyleData.biScroller];
tV ← Buttons.Create[info: [parent: gargoyleData.outer, name: "CenterSel", wx: tV.wx+tV.ww+entryHSpace, wy: 0, border: FALSE], proc: CenterSel, clientData: gargoyleData, paint: FALSE];
tV ← Buttons.Create[info: [parent: gargoyleData.outer, name: "FitSel", wx: tV.wx+tV.ww+entryHSpace, wy: 0, border: FALSE], proc: FitSel, clientData: gargoyleData, paint: FALSE];
gargoyleData.height ← entryHeight;
slack process must be created before call to GGMenus.BuildControlPanel
gargoyleData.slackHandle ← SlackProcess.Create[queueSize: 50, logSize: 50, optimizeProc: OptimizeQueue, loggingProc: GGSessionLog.EnterAction, abortProc: GGAbortProc, abortData: gargoyleData, abortViewer: gargoyleData.actionArea];
GGMenus.BuildControlPanel[gargoyleData, NIL];
tV ← BiScrollers.QuaViewer[gargoyleData.biScroller];
ViewerOps.MoveViewer[tV, 0, gargoyleData.height, gargoyleData.outer.cw, gargoyleData.outer.ch-gargoyleData.height, FALSE];
gargoyleData.outer.newVersion ← FALSE;
gargoyleData.gravityPool ← GGGravity.NewGravityPool[];
gargoyleData.multiGravityPool ← GGMultiGravity.NewMultiGravityPool[];
SetCursorLooks[gargoyleData.hitTest.gravityType, gargoyleData]; -- assumes gravity is turned ON
[] ← SlackProcess.EnableAborts[handle: gargoyleData.slackHandle];
};
OptimizeQueue: SlackProcess.OptimizeProc = {
PROC [qeGen: QueueEntryGenerator, actionsOnQueue: NAT] RETURNS [skipActions: NAT];
Notice that skipActions will be at most summary.count -1; The most recent action on the queue will be done if nothing else is appropriate. Always do the last During.
atom, nextAtom: ATOM;
action: LIST OF REF ANY;
IF actionsOnQueue < 2 THEN RETURN [0];
skipActions ← 0;
FOR i: NAT IN [0..actionsOnQueue-2] DO
[----, ----, action, ----] ← SlackProcess.GetQueueEntry[qeGen, i];
atom ← NARROW[action.first];
[----, ----, action, ----] ← SlackProcess.GetQueueEntry[qeGen, i+1];
nextAtom ← NARROW[action.first];
IF atom = $During AND nextAtom = $During THEN {
skipActions ← skipActions + 1;
}
ELSE RETURN;
ENDLOOP;
};
GGAbortProc: PROC [data: REF ANY] = { -- called by SlackProcess when user signals for abort
gargoyleData: GargoyleData ← NARROW[data];
gargoyleData.refresh.suppressRefresh ← FALSE; -- in case you killed FastPlayback
gargoyleData.aborted ← ALL[TRUE]; -- copies of aborted for all purposes
};
CenterSel: Buttons.ButtonProc = {
gargoyleData: GargoyleData ← NARROW[clientData];
caretPos: Point ← GGCaret.GetPoint[gargoyleData.caret];
bBox: GGBoundBox.BoundBox ← GGBoundBox.BoundBoxOfSelected[scene: gargoyleData.scene, selectClass: normal];
IF bBox.null THEN BiScrollers.Align[bs: gargoyleData.biScroller, client: [variant: coord[x: caretPos.x, y: caretPos.y]], viewer: [variant: fraction[fx: 0.5, fy: 0.5]], paint: TRUE]
ELSE BiScrollers.Align[bs: gargoyleData.biScroller, client: [variant: coord[x: (bBox.loX+bBox.hiX)/2.0, y: (bBox.loY+bBox.hiY)/2.0]], viewer: [variant: fraction[fx: 0.5, fy: 0.5]], paint: TRUE];
};
FitSel: Buttons.ButtonProc = {
gargoyleData: GargoyleData ← NARROW[clientData];
tbBox, vBox, tvBox: Geom2D.Rect;
cToV: ImagerTransformation.Transformation;
bBox: GGBoundBox.BoundBox ← GGBoundBox.BoundBoxOfSelected[scene: gargoyleData.scene, selectClass: normal];
IF NOT bBox.null THEN {
cToV ← BiScrollers.GetStyle[].GetTransforms[gargoyleData.biScroller].clientToViewer;
tbBox ← ImagerTransformation.TransformRectangle[cToV, GGBoundBox.RectangleFromBoundBox[bBox] ];
vBox ← BiScrollers.ViewportBox[gargoyleData.biScroller];
tvBox ← ImagerTransformation.TransformRectangle[cToV, vBox];
BiScrollers.BoxScale[bs: gargoyleData.biScroller, from: tbBox, to: tvBox];
Change scale and offsets so that client data previously in `from' covers as much as possible of `to' (from and to in viewer coords).
};
};
PlaceOrigin: PROC [viewer: Viewer] = TRUSTED {
viewer is the ActionArea. The created bitmap contexts have their transformations concatted with the analogous BiScrollers transformation so that operations on the new bitmaps will match the viewer when they are finally displayed.
clientToViewer, viewerToClient: Imager.Transformation;
rect: Imager.Rectangle;
pm: ImagerPixelMap.PixelMap;
pmRef: REF ImagerPixelMap.PixelMapRep;
bitmap: ImagerBackdoor.Bitmap;
gargoyleData: GargoyleData ← NARROW[BiScrollers.ClientDataOfViewer[viewer]];
[clientToViewer, viewerToClient] ← BiScrollers.GetStyle[].GetTransforms[BiScrollers.QuaBiScroller[viewer]];
Construct the foreground bitmap.
bitmap ← gargoyleData.refresh.foregroundBitmap ← ImagerBackdoor.NewBitmap[viewer.cw, viewer.ch];
pmRef ← NEW[ImagerPixelMap.PixelMapRep ← [
ref: bitmap.ref, pointer: bitmap.base, words: LONG[bitmap.wordsPerLine]*bitmap.height,
lgBitsPerPixel: 0, rast: bitmap.wordsPerLine, lines: bitmap.height
]];
pm ← [
sOrigin: 0, fOrigin: 0, sMin: 0, fMin: 0,
sSize: bitmap.height, fSize: bitmap.width, refRep: pmRef
];
gargoyleData.refresh.foregroundContext ← ImagerFastShow.Create[pm, 72, TRUE];
Imager.ConcatT[gargoyleData.refresh.foregroundContext, clientToViewer];
Construct the background bitMap or pixelMap.
IF gargoyleData.refresh.showColors.state = off THEN { -- use 1 bit per pixel bitmap
gargoyleData.refresh.backgroundPixelMap.refRep ← NIL;
bitmap ← gargoyleData.refresh.backgroundBitmap ← ImagerBackdoor.NewBitmap[viewer.cw, viewer.ch];
pmRef ← NEW[ImagerPixelMap.PixelMapRep ← [
ref: bitmap.ref, pointer: bitmap.base, words: LONG[bitmap.wordsPerLine]*bitmap.height,
lgBitsPerPixel: 0, rast: bitmap.wordsPerLine, lines: bitmap.height
]];
pm ← [
sOrigin: 0, fOrigin: 0, sMin: 0, fMin: 0,
sSize: bitmap.height, fSize: bitmap.width, refRep: pmRef
];
gargoyleData.refresh.backgroundContext ← ImagerFastShow.Create[pm, 72, TRUE];
};
ELSE { -- use 8 bit per pixel pixelMap for color display
gargoyleData.refresh.backgroundBitmap ← NIL;
pm ← gargoyleData.refresh.backgroundPixelMap ← ImagerPixelMap.Create[lgBitsPerPixel: 3, bounds: [0, 0, viewer.ch, viewer.cw] ];
gargoyleData.refresh.backgroundContext ← ImagerDitheredDevice.ContextFromPixelMap[frame: pm, displayHeight: viewer.ch, pixelUnits: TRUE];
};
Imager.ConcatT[gargoyleData.refresh.backgroundContext, clientToViewer];
Construct the chunking bitMap or pixelMap.
IF gargoyleData.refresh.showColors.state = off THEN { -- use 1 bit per pixel bitmap
bitmap ← gargoyleData.refresh.chunkingBitmap ← ImagerBackdoor.NewBitmap[viewer.cw, viewer.ch];
pmRef ← NEW[ImagerPixelMap.PixelMapRep ← [
ref: bitmap.ref, pointer: bitmap.base, words: LONG[bitmap.wordsPerLine]*bitmap.height,
lgBitsPerPixel: 0, rast: bitmap.wordsPerLine, lines: bitmap.height
]];
pm ← [
sOrigin: 0, fOrigin: 0, sMin: 0, fMin: 0,
sSize: bitmap.height, fSize: bitmap.width, refRep: pmRef
];
gargoyleData.refresh.chunkingContext ← ImagerFastShow.Create[pm, 72, TRUE];
};
ELSE { -- use 8 bit per pixel pixelMap for color display
gargoyleData.refresh.chunkingBitmap ← NIL;
pm ← gargoyleData.refresh.chunkingPixelMap ← ImagerPixelMap.Create[lgBitsPerPixel: 3, bounds: [0, 0, viewer.ch, viewer.cw] ];
gargoyleData.refresh.chunkingContext ← ImagerDitheredDevice.ContextFromPixelMap[frame: pm, displayHeight: viewer.ch, pixelUnits: TRUE];
};
Imager.ConcatT[gargoyleData.refresh.chunkingContext, clientToViewer];
Initialize the context to white.
rect ← ImagerBackdoor.GetBounds[gargoyleData.refresh.backgroundContext];
Imager.SetColor[gargoyleData.refresh.backgroundContext, Imager.white];
Imager.MaskRectangle[gargoyleData.refresh.backgroundContext, rect];
};
ViewerToWorld: PUBLIC PROC [viewerPoint: Point, gargoyleData: GargoyleData] RETURNS [worldPoint: Point] = {
vec: Imager.VEC;
viewerToClient: Imager.Transformation ← BiScrollers.GetStyle[].GetTransforms[BiScrollers.QuaBiScroller[gargoyleData.actionArea]].viewerToClient;
vec ← ImagerTransformation.Transform[viewerToClient, [x: viewerPoint.x, y: viewerPoint.y] ];
worldPoint ← [ vec.x, vec.y];
};
WorldToViewer: PUBLIC PROC [worldPoint: Point, gargoyleData: GargoyleData] RETURNS [viewerPoint: Point] = {
vec: Imager.VEC;
clientToViewer: Imager.Transformation ← BiScrollers.GetStyle[].GetTransforms[BiScrollers.QuaBiScroller[gargoyleData.actionArea]].clientToViewer;
vec ← ImagerTransformation.Transform[clientToViewer, [x: worldPoint.x, y: worldPoint.y] ];
viewerPoint ← [ vec.x, vec.y];
};
NewGGViewers: Commander.CommandProc = {
[cmd: Handle] RETURNS [result: REFNIL, msg: Rope.ROPENIL];
nameList, args: LIST OF Rope.ROPENIL;
argLength: NAT ← 0;
switchChar: CHAR = '-;
[list: args, length: argLength] ← CommandTool.ParseToList[cmd: cmd, starExpand: TRUE, switchChar: switchChar ! CommandTool.Failed => CONTINUE; ];
IF args = NIL OR argLength < 1 THEN { MakeGGViewer[fileName: NIL]; RETURN;};
FOR rl: LIST OF Rope.ROPE ← args, rl.rest UNTIL rl = NIL DO --open a GGViewer on each file
[] ← MakeGGViewer[fileName: FileNames.ResolveRelativePath[rl.first]];
ENDLOOP;
};
BuildActionArea: PRIVATE PROC [gargoyleData: GargoyleData] = {
Create an ActionArea which fills the bottom of the Gargoyle Container
bs: BiScrollers.BiScroller ← BiScrollers.GetStyle[].CreateBiScroller[
class: actionAreaClass,
info: [
parent: gargoyleData.outer,
wx: 0, wy: gargoyleData.height,
ww: gargoyleData.outer.ww,
wh: gargoyleData.outer.wh, -- only initial values for ww and wh. They are constrained below
data: gargoyleData,
border: FALSE,
scrollable: FALSE],
paint: FALSE
];
gargoyleData.actionArea ← bs.QuaViewer[inner: TRUE];
gargoyleData.biScroller ← bs;
GGContainer.ChildXBound[gargoyleData.outer, bs.QuaViewer[inner: FALSE]];
GGContainer.ChildYBound[gargoyleData.outer, bs.QuaViewer[inner: FALSE]];
gargoyleData.height ← gargoyleData.height + gargoyleData.actionArea.wh;
};
GGExtremaProc: PROC [clientData: REF ANY, direction: Geom2D.Vec] RETURNS [min, max: Geom2D.Vec] --BiScrollers.ExtremaProc-- = {
This proc is required by BiScrollers to return the extremes of the displayed data
area: Geom2D.Rect;
gargoyleData: GargoyleData ← NARROW[clientData];
bigBox: GGBoundBox.BoundBox ← GGBoundBox.BoundBoxOfBoxes[GGObjects.BoundBoxesInScene[gargoyleData.scene].list];
area ← IF bigBox#NIL THEN [x: bigBox.loX, y: bigBox.loY, w: bigBox.hiX-bigBox.loX, h: bigBox.hiY-bigBox.loY] ELSE [0.0, 0.0, 1.0, 1.0];
[min, max] ← Geom2D.ExtremaOfRect[r: area, n: direction];
};
NewCaretPos: PUBLIC PROC [gargoyleData: GargoyleData] = {
caret0, caret1, caret2Pos: Point;
distance, angle, slope, lineDist: REAL;
caret0 ← gargoyleData.measure.caret0;
caret1 ← gargoyleData.measure.caret1;
caret2Pos ← GGVector.Scale[GGCaret.GetPoint[gargoyleData.caret], 1.0/gargoyleData.hitTest.scaleUnit];
distance ← GGMeasure.DistanceBetweenPoints[caret1, caret2Pos]; -- distance in scaleUnits
angle ← GGMeasure.SmallestAngleOfPoints[caret0, caret1, caret2Pos];
slope ← GGMeasure.SlopeOfPoints[caret1, caret2Pos];
IF slope<0.0 THEN slope ← slope+180.0;
IF slope=360.0 THEN slope ← 0.0;
lineDist ← GGMeasure.DistanceFromPointToLine[caret2Pos, caret0, caret1]; -- line distance in scaleUnits
gargoyleData.measure.caret2Value ← caret2Pos;
GGViewerOps.SetPoint[gargoyleData.measure.caret2, caret2Pos];
gargoyleData.measure.slopeViewValue ← slope;
GGViewerOps.SetReal[gargoyleData.measure.slopeView, slope];
gargoyleData.measure.angleViewValue ← angle;
GGViewerOps.SetReal[gargoyleData.measure.angleView, angle];
gargoyleData.measure.radiusViewValue ← distance;
GGViewerOps.SetReal[gargoyleData.measure.radiusView, distance];
gargoyleData.measure.lineDistViewValue ← lineDist;
GGViewerOps.SetReal[gargoyleData.measure.lineDistView, lineDist];
};
SaveCaretPos: PUBLIC PROC [gargoyleData: GargoyleData] = {
caret2Pos: Point ← GGVector.Scale[GGCaret.GetPoint[gargoyleData.caret], 1.0/gargoyleData.hitTest.scaleUnit];
gargoyleData.measure.caret2Value ← caret2Pos;
GGViewerOps.SetPoint[gargoyleData.measure.caret2, caret2Pos];
gargoyleData.measure.caret0 ← gargoyleData.measure.caret1;
gargoyleData.measure.caret1 ← caret2Pos;
};
SetCursorLooks: PUBLIC PROC [type: GGInterfaceTypes.GravityType, gargoyleData: GargoyleData] = {
The following is a hack and is NOT the right way to do business. Unfortunately, the cursor data lives in a viewer CLASS rec instead of a viewer INSTANCE rec so their is no easy way to keep an instance-specific cursor.
newCursor: Cursors.CursorType;
mouseViewer: ViewerClasses.Viewer;
client: BOOL;
terminal: Terminal.Virtual ← Terminal.Current[];
mousePos: Terminal.Position ← Terminal.GetMousePosition[terminal]; -- mouse origin in upper left
tipScreenCoords: TIPUser.TIPScreenCoords ← NEW[TIPUser.TIPScreenCoordsRec ← [mouseX: mousePos.x, mouseY: mousePos.y, color: gargoyleData.actionArea.column=color] ];
tipScreenCoords.mouseY ← IF gargoyleData.actionArea.column=color THEN terminal.colorHeight-mousePos.y ELSE terminal.bwHeight-mousePos.y; -- move mouse origin to lower left
[mouseViewer, client] ← ViewerOps.MouseInViewer[tipScreenCoords];
gargoyleData.actionArea.class.cursor ← newCursor ← SELECT type FROM
innerCircle => pointsPreferredCursor,
strictDistance => strictDistanceCursor,
off => offCursor,
ENDCASE => ERROR;
change the cursor immediately if the mouse is in the action area
IF mouseViewer=gargoyleData.actionArea AND client THEN Cursors.SetCursor[newCursor];
};
BuildCursors: PROC [] = {
pointsPreferredArray: Cursors.CursorArray = [600B+1100B, 600B+1100B+2040B, 2040B+4020B, 4020B+10010B, 10010B+20004B, 20004B+40002B, 40002B+100001B, 40002B+100001B, 40002B+100001B, 40002B+100001B, 20004B+40002B, 10010B+20004B, 4020B+10010B, 2040B+4020B, 600B+1100B+2040B, 600B+1100B]; -- diamond
strictDistanceArray: Cursors.CursorArray = [100001B+40002B, 40002B+20004B, 20004B+10010B, 10010B+4020B, 4020B+2040B, 2040B, 0, 0, 0, 0, 2040B, 4020B+2040B, 10010B+4020B, 20004B+10010B, 40002B+20004B, 100001B+40002B]; -- folded diamond
offArray: Cursors.CursorArray = [177777B, 177777B, 140003B, 140003B, 140003B, 140003B, 140003B, 140003B, 140003B, 140003B, 140003B, 140003B, 140003B, 140003B, 177777B, 177777B]; -- square
pointsPreferredCursor ← Cursors.NewCursor[bits: pointsPreferredArray, hotX: -8, hotY: -6];
strictDistanceCursor ← Cursors.NewCursor[bits: strictDistanceArray, hotX: -8, hotY: -5];
offCursor ← Cursors.NewCursor[bits: offArray, hotX: -8, hotY: -6];
};
Gargoyle Viewer State
SetHeuristics: PUBLIC PROC [gargoyleData: GargoyleData, on: BOOL] = {
stateInfo: AtomButtons.TwoState ← gargoyleData.hitTest.heuristicsButton;
state: AtomButtons.StateType ← AtomButtons.GetButtonState[stateInfo];
IF state = on AND on OR state = off AND NOT on THEN RETURN;
AtomButtons.SwitchState[stateInfo];
RestoreScreenAndInvariants[paintAction: $PaintEntireViewer, gargoyleData: gargoyleData, remake: triggerBag, backgndOK: FALSE, edited: FALSE, okToClearFeedback: TRUE];
};
GetHeuristics: PUBLIC PROC [gargoyleData: GargoyleData] RETURNS [on: BOOL] = {
stateInfo: AtomButtons.TwoState ← gargoyleData.hitTest.heuristicsButton;
state: AtomButtons.StateType ← AtomButtons.GetButtonState[stateInfo];
on ← state = on;
};
SetGravityExtent: PUBLIC PROC [gargoyleData: GargoyleData, inches: REAL] = {
screenDots: REAL;
graphicsState: GGGraphicsButton.GraphicsState ← gargoyleData.hitTest.gravityExtentButton;
screenDots ← inches*72.0;
GGError.PutF[gargoyleData.feedback, oneLiner, "Gravity extent is now %g inches.", [real[inches]] ];
GGGraphicsButton.SetButtonValueAndPaint[graphicsState, screenDots];
gargoyleData.hitTest.tolerance ← screenDots;
gargoyleData.hitTest.criticalR ← screenDots;
gargoyleData.hitTest.innerR ← screenDots/2.0;
};
GetGravityExtent: PUBLIC PROC [gargoyleData: GargoyleData] RETURNS [inches: REAL] = {
screenDots: REAL;
graphicsState: GGGraphicsButton.GraphicsState ← gargoyleData.hitTest.gravityExtentButton;
screenDots ← GGGraphicsButton.GetValue[graphicsState];
inches ← screenDots/72.0;
};
Init: PROC = {
actionAreaClass ← BiScrollers.GetStyle[].NewBiScrollerClass[[
flavor: $ActionArea,
extrema: GGExtremaProc,
notify: GGUserInput.InputNotify,
paint: GGActionAreaPaint,
tipTable: TIPUser.InstantiateNewTIPTable["Gargoyle.TIP"],
mayStretch: FALSE, -- NOT OK to scale X and Y differently
offsetsMustBeIntegers: TRUE,
preferIntegerCoefficients: FALSE,
vanilla: GGBasicTransformProc, --proc which provides the vanilla transform for BiScrollers
preserve: [X: 0.5, Y: 0.5] --this specifies point that stays fixed when viewer size changes
]];
cleanIcon ← Icons.NewIconFromFile["Gargoyle.icons", 1]; -- done here so file will come from working directory into which Gargoyle was brought over, e.g. ///Commands/
dirtyIcon ← Icons.NewIconFromFile["Gargoyle.icons", 0]; -- done here so file will come from working directory into which Gargoyle was brought over, e.g. ///Commands/
originalWDir ← FileNames.CurrentWorkingDirectory[];
BuildCursors[];
Commander.Register[
key: "Gargoyle",
proc: NewGGViewers,
doc: "Create a Gargoyle Graphics Window",
clientData: NIL
];
};
actionAreaClass: BiScrollers.BiScrollerClass ← NIL; -- filled in by Init
cleanIcon: Icons.IconFlavor ← unInit; -- filled in by Init
dirtyIcon: Icons.IconFlavor ← unInit; -- filled in by Init
originalWDir: Rope.ROPENIL; -- filled in by Init
offCursor: Cursors.CursorType; -- filled in by BuildCursors
pointsPreferredCursor: Cursors.CursorType; -- filled in by BuildCursors
strictDistanceCursor: Cursors.CursorType; -- filled in by BuildCursors
Init[];
END.