Draw2d.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Bloomenthal, September 20, 1986 3:27:15 pm PDT
DIRECTORY Imager, Rope;
Type Declarations
ROPE: TYPE ~ Rope.ROPE;
Context: TYPE ~ Imager.Context;
VEC: TYPE ~ Imager.VEC; -- RECORD [x, y: REAL]
DrawType: TYPE ~ {solid, dashed, dotted};
MarkType: TYPE ~ {cross, x, asterisk, dot, none};
PixelProc: TYPE ~ PROC [x, y: INTEGER, data: REF ANY ← NIL]
RETURNS [continue: BOOL ← TRUE];
General Utility Procedures
Clear:
PROC [context: Context];
Clear context to white.
Label:
PROC [context: Context, vec:
VEC, rope:
ROPE];
Combines Imager.SetXY and Imager.ShowRope. Font, if unitialized, is set to helvetica10.
DoWithBuffer:
PROC [context: Context, action:
PROC, clear:
BOOL ←
TRUE];
Set stroke width to zero and perform action while double buffering.
If clear, the buffer is first cleared to white.
Line Drawing Procedures
Line:
PROC [context: Context, vec0, vec1:
VEC, drawType: DrawType ← solid];
If the Imager stroke width is non-zero or the context expects anti-aliasing, then MaskVector
is called; otherwise a pixel wide line from vec0 to vec1 is drawn with Bresenham algorithm.
Depending on the display mode, this 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, as 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.
Circle:
PUBLIC
PROC [context: Context, vec:
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];
Draw an arrow from tail to head; if vary, arrowhead size varies according to arrow length.