Draw2d.mesa
Copyright Ó 1985, 1991, 1992 by Xerox Corporation. All rights reserved.
Bloomenthal, July 17, 1992 2:08 pm PDT
DIRECTORY Imager, Rope, SF, ViewerClasses;
Draw2d: CEDAR DEFINITIONS
IMPORTS Imager
~ BEGIN
Types
VEC:    TYPE ~ Imager.VEC;
Context:  TYPE ~ Imager.Context;
ROPE:   TYPE ~ Rope.ROPE;
Viewer:  TYPE ~ ViewerClasses.Viewer;
DrawType: TYPE ~ {solid, dashed, dotted};
MarkType: TYPE ~ {cross, x, asterisk, dot, none};
DrawProc: TYPE ~ PROC [
context:    Context,         -- Imager context
clientData:   REF ANY ¬ NIL,       -- client supplied data
whatChanged:  REF ANY ¬ NIL,       -- as in ViewerOps
viewer:    Viewer ¬ NIL       -- NIL if for Interpress master
];
PixelProc:  TYPE ~ PROC [x, y: INTEGER] RETURNS [continue: BOOL ¬ TRUE];
IntegerBox: TYPE ~ RECORD [x, y, w, h: INTEGER];
Zip:   TYPE ~ REF ZipRep;
ZipRep:  TYPE ~ RECORD [
box:     SF.Box,
rasterDevice:   BOOL ¬ FALSE,
transform:   Imager.Transformation
];
General Utility Procedures
BoxFromContext: PROC [context: Context] RETURNS [IntegerBox];
Return the box in integer device coordinates that corresponds to the Imager context.
ScreenScale: PROC [viewer: Viewer, aspectRatio: REAL ¬ 4.0/3.0] RETURNS [REAL];
Return the width (in pixels) of the largest rectangle with the given aspect ratio
that fits inside the viewer.
Clear: PROC [context: Context, color: Imager.Color ¬ Imager.white];
Clear the context to the given color.
Label: PROC [context: Context, position: VEC, rope: ROPE];
Combines AssureFont, Imager.SetXY and Imager.ShowRope..
AssureFont: PROC [context: Context];
If context has no font, initialize it to helvetica10; prevents certain Imager errors.
DoWithBuffer: PROC [context: Context, action: PROC, clear: BOOL ¬ TRUE];
Perform double buffered action; if clear, first clear to white.
Zip is obtained and placed on context property list during action.
IPOut: PROC [fileName: ROPE, drawProc: DrawProc, clientData: REF ANY ¬ NIL];
Perform drawProc while writing to an interpress file. clientData is passed to drawProc.
whatChanged argument to drawProc is $IPOut, and viewer argument is NIL.
Accelerator
GetZip: PROC [context: Context, zip: Zip ¬ NIL] RETURNS [Zip];
Return an accelerator for subsequent calls to Line[].
NIL is returned if the Imager strokeWIdth is non-zero, if the context
is not a raster device, or if the size of the context is zero.
A new Zip is needed after any change to context's size, transformation, or display device.
ReleaseZip: PROC [zip: Zip];
Companion to GetZip; releases zip.transform.
Line Drawing Procedures
Line: PROC [context: Context, vec0, vec1: VEC, drawType: DrawType ¬ solid, zip: Zip ¬ NIL];
If Imager stroke width # 0 or context expects anti-aliasing, then MaskVector is called.
Otherwise a pixel wide line from vec0 to vec1 is drawn with Bresenham's algorithm.
This is faster than Imager.MaskVector, but slower than ImagerCG6Context.LineCG6.
This procedure will work for gray or stippled lines.
DoWithLine: PUBLIC PROC [vec0, vec1: VEC, pixelProc: PixelProc];
Apply pixelProc to each pixel of the line, as determined by the Bresenham algorithm.
Miscellaneous Marking Procedures
Mark: PROC [context: Context, position: VEC, markType: MarkType ¬ cross, zip: Zip ¬ NIL];
Draw a mark at position.
Square: PROC [context: Context, center: VEC, size: REAL];
Draw a solid square centered at center with edges at +/- size.
Circle: PROC [context: Context, center: VEC, radius: REAL, fill: BOOL ¬ FALSE];
Draw a circle at the given center with the given radius.
Arrow: PROC [
context: Context,
tail, head: VEC,
drawType: DrawType ¬ solid,
vary: BOOL ¬ TRUE,
zip: Zip ¬ NIL];
Draw an arrow from tail to head; if vary, arrowhead size varies according to arrow length.
END.