CDVScale.mesa (Viewer definitions for Chipndale)
Copyright © 1983, 1984 by Xerox Corporation. All rights reserved.
by Christian Jacobi July 15, 1983 11:16 am
complete redesigned by Christian Jacobi August 28, 1984 8:44:31 am PDT
last edited by Christian Jacobi August 28, 1984 9:01:55 am PDT
DIRECTORY
CD USING [Number, DesignNumber, Position, DesignPosition, Rect, DesignRect];
CDVScale: CEDAR DEFINITIONS =
BEGIN
-- Non public chipndale interface to scaling of viewers.
--
-- Scaling must be real fast, therefore the crazyness.
-- Design -> Viewer is the most speed critical operation done, used for drawing every rectangle...
-- Viewer -> Design is speed critical for cursor tracking
-- This interface is thought as an implementation module and freely recompiled to improve the
-- inline procedures. Do never copy code from this module, because this module changes to
-- often, but if new need for scaling appears, include it here.
-- Analyzing compiler generated code showed that it is feasible to have a full record as
-- parameter, since the optimization will get rid of copiing the record.
scaleNum: CARDINAL = 19;
ScaleRange: TYPE = [0..scaleNum);
--A type describing scales; increasing a scale number means viewing a bigger part of the
--chip in a viewer; (more overview, less detail).
ScaleRec: TYPE = RECORD [
--data in this record must be gridded correctly, such that the origin of
--the viewer lies on a grid point; otherwise the gridding would
--require more complex and slower arithmetic.
off: CD.DesignPosition,
xx: PRIVATE INT,
useMultiply: PRIVATE BOOL,
sA, sB, sC, sD: PRIVATE CARDINAL,
grid: INTEGER, --in DesignCoordinates
nscale: INTEGER
];
DesignToViewerFactor: PROC [scale: ScaleRec] RETURNS [f: REAL] ~ INLINE {
--without translation
IF scale.useMultiply THEN f ← scale.xx ELSE f ← 1.0/scale.xx;
};
DesignToViewerScalar: PROC [scale: ScaleRec, n: CD.DesignNumber]
RETURNS [CD.Number] ~ INLINE {
--without translation
RETURN [IF scale.useMultiply THEN n*scale.xx ELSE n/scale.xx];
};
DesignToViewerPosition: PROC[scale: ScaleRec, designPos: CD.DesignPosition]
RETURNS [viewerPos: CD.Position] ~ INLINE {
--including translation to viewer origin
RETURN[
IF scale.useMultiply THEN CD.Position[
(designPos.x-scale.off.x)*scale.xx,
(designPos.y-scale.off.y)*scale.xx
]
ELSE CD.Position[
(designPos.x-scale.off.x)/scale.xx,
(designPos.y-scale.off.y)/scale.xx
]
]
};
DesignToViewerRect: PROC[scale: ScaleRec, designRect: CD.DesignRect]
RETURNS [CD.Rect] ~ INLINE {
--including translation to viewer origin
RETURN[
IF scale.useMultiply THEN CD.Rect[
x1: (designRect.x1-scale.off.x)*scale.xx,
y1: (designRect.y1-scale.off.y)*scale.xx,
x2: (designRect.x2-scale.off.x)*scale.xx,
y2: (designRect.y2-scale.off.y)*scale.xx
]
ELSE CD.Rect[
x1: (designRect.x1-scale.off.x)/scale.xx,
y1: (designRect.y1-scale.off.y)/scale.xx,
x2: (designRect.x2-scale.off.x)/scale.xx,
y2: (designRect.y2-scale.off.y)/scale.xx
]
]
};
ViewerToDesignScalar: PROC [scale: ScaleRec, v: LONG CARDINAL] RETURNS [CD.DesignNumber] = INLINE {
--without translation, but gridded to the current grid
RETURN [LOOPHOLE[(v*scale.sA+scale.sB)/scale.sC*scale.sD, CD.DesignNumber]]
};
UngriddedViewerToDesignScalar: PROC [scale: ScaleRec, v: LONG CARDINAL] RETURNS [CD.DesignNumber] = INLINE {
--without translation, without grid
IF scale.useMultiply THEN
RETURN [LOOPHOLE[(v*scale.sA+scale.xx-1)/scale.xx, CD.DesignNumber]]
ELSE
RETURN [LOOPHOLE[(v*scale.sA), CD.DesignNumber]]
};
ViewerToDesignPosition: PROC[scale: ScaleRec, viewerPos: CD.Position] RETURNS [designPos: CD.DesignPosition] = INLINE {
--with offset and grid
RETURN[CD.DesignPosition[
ViewerToDesignScalar[scale, viewerPos.x]+scale.off.x,
ViewerToDesignScalar[scale, viewerPos.y]+scale.off.y]
]
};
MakeScale: PROC [off: CD.DesignPosition←[0, 0], nscale: ScaleRange𡤄, grid: INTEGER←-1] RETURNS [ScaleRec];
--given the grid, offset and nscale; makes a correctly gridded and initialized ScaleRec
GetClipRecord: PROC[scale: ScaleRec, highX, highY: CARDINAL] RETURNS [CD.DesignRect];
--given the index of the (high-most) pixel in the viewer, compute an outside clipping
--rectangle in design coordinates; (such that all outside the clipping area is invisible).
END.