Draw2d.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Bloomenthal, September 16, 1986 12:36:02 pm PDT
DIRECTORY Imager, Rope;
Draw2d: CEDAR DEFINITIONS
~ BEGIN
Type Declarations
Context:  TYPE ~ Imager.Context;
VEC:    TYPE ~ Imager.VEC;     -- RECORD [x, y: REAL]
DrawType: TYPE ~ {solid, dash, dot};
MarkType: TYPE ~ {cross, x, asterisk, dot, none};
PixelProc:  TYPE ~ PROC [x, y: INTEGER, data: REF ANYNIL];
General Utility Procedures
Clear: PROC [context: Context, width, height: INTEGER];
Clear a context to white; width and height refer to the context.
InitFont: PROC [context: Context];
Set the font for subsequent calls to Label.
Label: PROC [context: Context, vec: VEC, rope: Rope.ROPE];
Combines Imager.SetXY and Imager.ShowRope.
DoWithBuffer: PROC [context: Context, width, height: INTEGER, action: PROC];
Combine InitFont and ImagerOps.DoWithBuffer; width and height refer to the context.
Line Drawing Procedures
Line: PROC [context: Context, vec0, vec1: VEC, drawType: DrawType ← solid];
Draw a pixel wide line from vec0 to vec1 with Bresenham algorithm. If the Imager stroke
width is non-zero or the context expects anti-aliasing, then MaskVector is called.
Depending on the display mode, Line is two to six times faster than Imager.MaskVector.
DoWithLine: PUBLIC PROC [vec0, vec1: VEC, pixelProc: PixelProc];
Apply pixelProc to each pixel of the line; pixels are determined by the Bresenham algorithm.
Miscellaneous Procedures
Mark: PROC [context: Context, vec: VEC, markType: MarkType ← cross];
Draw a mark at vec.
Square: PROC [context: Context, vec: VEC, size: REAL];
Draw a solid square centered at vec with edges at +/- size.
Arrow: PROC [context: Context, tail, head: VEC, vary: BOOLTRUE];
Draw an arrow from tail to head; if vary, arrowhead size varies according to arrow length.
END.