--GraphicsToImager.tioga
--Maureen Stone December 16, 1983 3:48 pm
--Types
Path
Trajectory, Polygon, Outline
Context
Context
DeviceRef
FontRef
FONT
ImageRef
Color
Color
ConstantColor
Texture
Color
StrokeEnds: TYPE = {butt, square, round};
StrokeEnd: TYPE = {nil, square, butt, round};
Box: TYPE = RECORD[xmin,ymin,xmax,ymax: REAL]
Rectangle: TYPE = RECORD [x, y, w, h: REAL];
IntRectangle: TYPE = RECORD [x, y, w, h: INTEGER];
--eliminated
baseMark, Box, DeviceRef, Mark, nullMark, YMode, PaintMode
--new
PixelArray, Transformation, Visibility, Pair, RopeOrRefText, IntPair, IntRectangle
Contexts
NewContext: PROC[device: DeviceRef ← NIL] RETURNS[Context];
Create: PROC[deviceType: ATOM, data: REFNIL] RETURNS [Context];
CopyContext: PROC[self: Context] RETURNS[Context];
Gone
--Imager State
The imager state for a particular context is accessable through the class procedures IGet, IGetReal, and IGetInt.
Here are all the imager variables, with their types and initial values:
Persistent:
DCScpx, DCScpy: REAL ← 0
correctMX, correctMY: REAL ← 0
Non-persistent:
T: Transformation ← identityTransformation
priorityImportant: BOOLFALSE
mediumXSize, mediumYSize: REAL ← 0
fieldXMin, fieldYMin: REAL ← 0
fieldXMax, fieldYMax: REAL ← 0
showVec: Vector ← emptyVector
color: Color ← black
noImage: BOOLFALSE
strokeWidth: REAL ← 0
strokeEnd: StrokeEnd ← square
underlineStart: REAL ← 0
amplifySpace: REAL ← 1
correctPass: [0..2] ← 0
correctShrink: REAL ← 0.5
correctTX, correctTY: REAL ← 0
clipOutline: Outline ← FullField[]
Name: TYPE = {DCScpx, DCScpy, correctMX, correctMY, T, priorityImportant, mediumXSize, mediumYSize, fieldXMin, fieldYMin, fieldXMax, fieldYMax, showVec, color, noImage, strokeWidth, strokeEnd, underlineStart, amplifySpace, correctPass, correctShrink, correctTX, correctTY, clipOutline};
context: Imager.Context;
value: REF ← context.class.IGet[context: Context, n: Name]; --works for anything
real: REAL ← context.class.IGet[context: Context, n: Name]; --ie. n: DCScpx
int: INT ← context.class.IGet[context: Context, n: Name]; --ie. n:
Current position
GetCP: PROC[self: Context, rounded: BOOLEAN] RETURNS[x,y: REAL],
x ← self.class.IGetReal[self,DCScpx];
y ← self.class.IGetReal[self,DCScpy];
SetCP: PROC[self: Context, x,y: REAL, rel: BOOLEAN],
SetXY: PROC[context: Context, p: Pair];
IntegerSetXY: PROC[context: Context, x, y: INTEGER];
SetXYRel: PROC[context: Context, v: Pair];
IntegerSetXYRel: PROC[context: Context, x, y: INTEGER];
SetXRel: PROC[context: Context, x: REAL];
IntegerSetXRel: PROC[context: Context, x: INTEGER];
SetYRel: PROC[context: Context, y: REAL];
IntegerSetYRel: PROC[context: Context, y: INTEGER];
DrawTo: PROC[self: Context, x,y: REAL, rel: BOOLEAN],
MaskVector: PROC[context: Context, p1, p2: Pair,
strokeWidth: REAL ← defaultStrokeWidth, strokeEnd: StrokeEnd ← defaultStrokeEnd];
Path operators (now called Mask Operators). The semantics of paths have changed some. A Graphics.Path is equivalent to an Imager.Outline. An Imager.Outline is a list of Imager.Trajectory. An Imager.Trajectory is a single geometric trace or loop. Simple shapes are usually a single trajectory. You only need to create an outline if you have more than one trajectory in your shape (ie. a closed path with holes). All trajectory operations are of the form:
trajectory ← op[trajectory];
You start a Trajectory by doing a MoveTo, add to it by using LineTo, CurveTo, etc.
NewPath: PROC[size: INT ← 0] RETURNS[Path];
--part of MoveTo
LastPoint: PROC[self: Path] RETURNS[x, y: REAL];
LastPoint: PROC[t: Trajectory] RETURNS[Pair];
FlushPath: PROC[self: Path];
--gone
MoveTo: PROC[self: Path, x, y: REAL, flush: BOOLEANTRUE];
MoveTo: PROC[p: Pair] RETURNS[Trajectory];
LineTo: PROC[self: Path, x, y: REAL];
LineTo: PROC[t: Trajectory, p: Pair] RETURNS[Trajectory];
LineToX: PROC[t: Trajectory, x: REAL] RETURNS[Trajectory];
LineToY: PROC[t: Trajectory, y: REAL] RETURNS[Trajectory];
CurveTo: PROC[self: Path, x1, y1, x2, y2, x3, y3: REAL];
CurveTo: PROC[t: Trajectory, p1, p2, p3: Pair] RETURNS[Trajectory];
ConicTo: PROC[t: Trajectory, p1, p2: Pair, r: REAL] RETURNS[Trajectory];
ArcTo: PROC[t: Trajectory, p1, p2: Pair] RETURNS[Trajectory];
Rectangle: PROC[self: Path, x0, y0, x1, y1: REAL];
MaskRectangle: PROC[context: Context, x, y, w, h: REAL];
IntegerMaskRectangle: PROC[context: Context, x, y, w, h: INTEGER];
ClipRectangle: PROC[context: Context, x, y, w, h: REAL];
IntegerClipRectangle: PROC[context: Context, x, y, w, h: INTEGER];
IntegerExcludeRectangle: PROC[context: Context, x, y, w, h: INTEGER];
--new for the imager
MakeOutline: PROC[LIST OF Trajectory] RETURNS[Outline];
--drawing routines
DrawStroke: PROC[self: Context, path: Path, width: REAL, closed: BOOLEAN, ends: StrokeEnds],
MaskStroke: PROC[context: Context, t: Trajectory,
strokeWidth: REAL ← defaultStrokeWidth, strokeEnd: StrokeEnd ← defaultStrokeEnd];
MaskStrokeClosed: PROC[context: Context, t: Trajectory,
strokeWidth: REAL ← defaultStrokeWidth];
SetStrokeWidth: PROC[context: Context, strokeWidth: REAL];
SetStrokeEnd: PROC[context: Context, strokeEnd: StrokeEnd];
DrawArea: PROC[self: Context, path: Path, parityFill: BOOLEAN],
MaskFill: PROC[context: Context, outline: REF];
DrawBox: PROC[self: Context, box: Box],
MaskRectangle: PROC[context: Context, x, y, w, h: REAL];
IntegerMaskRectangle: PROC[context: Context, x, y, w, h: INTEGER];
--New for the imager
MaskPixel: PROC[context: Context, pa: PixelArray];
DrawImage: PROC[self: Context, image: ImageRef, raw: BOOLEAN],
--make sampled color, then MaskRectangle

--Transformations
Translate: PROC[self: Context, tx,ty: REAL, round: BOOLEAN],
TranslateT: PROC[context: Context, x, y: REAL];
Scale: PROC[self: Context, sx,sy: REAL]
ScaleT: PROC[context: Context, s: REAL];
Scale2T: PROC[context: Context, sx, sy: REAL];
Rotate: PROC[self: Context, angle: REAL];
RotateT: PROC[context: Context, a: REAL];
Concat: PROC[self: Context, m11,m12,m21,m22: REAL],
ConcatT: PROC[context: Context, m: Transformation];
--new to Imager
Move: PROC[context: Context];
Modify T so that the origin maps to the current position.
Trans: PROC[context: Context];
Modify T so that the origin maps to the rounded current position.
--Gone ??
Map: PROC[sc,dc: Context, sx,sy: REAL] RETURNS[dx,dy: REAL]
WorldToUser: PROC[self: Context, wx,wy: REAL] RETURNS[x,y: REAL],
UserToWorld: PROC[self: Context, x,y: REAL] RETURNS[wx,wy: REAL],
--Color.
--Color now includes flat colors and sampled colors (images)
SetColor: PROC[self: Context, color: Color],
SetColor: PROC[context: Context, color: Color];
GetColor: PROC[self: Context] RETURNS[Color],
--iget?
SetPaintMode: PROC[self: Context, mode: PaintMode] RETURNS[PaintMode],
invert: SetColor[context: Context, color: Imager.XOR];
opaque: standard
transparent: look at MaskPixel: PROC[context: Context, pa: PixelArray];
SetFat: PROC[self: Context, fat: BOOLEAN] RETURNS[BOOLEAN],
--gone?
--Fonts and Text. Font properties are defined in Font.mesa
MakeFont: PROC[name: Rope.ROPE] RETURNS[FontRef];
MakeFont: PROC[name: ROPE, size: REAL] RETURNS[FONT];
SetDefaultFont: PROC[self: Context, font: FontRef],
SetFont: PROC[context: Context, font: FONT];
GetDefaultFont: PROC[self: Context] RETURNS[FontRef],
--IGet?
DrawChar: PROC[self: Context, char: CHARACTER,font: FontRef ← NIL];
ShowChar: PROC[context: Context, char: CHAR, font: FONTNIL];
DrawRope: PROC[self: Context, rope: Rope.ROPE, start: INT ← 0, len: INT ← Rope.MaxLen, font: FontRef ← NIL];
ShowCharacters: PROC[context: Context, characters: RopeOrRefText, font: FONTNIL,
start: INT ← 0, length: INTLAST[INT]];
--From Font
RopeBox: PROC[font: FontRef, rope: Rope.ROPE, start: INT ← 0, len: INT ← Rope.MaxLen]
--gone?
RopeWidth: PROC[font: FontRef, rope: Rope.ROPE, start: INT ← 0, len: INT ← Rope.MaxLen]
TextWidth: PROC [font: FONT, text: RopeOrRefText] RETURNS [REAL];
CharBox: PROC[font: FontRef, char: CHARACTER] RETURNS[xmin,ymin,xmax,ymax: REAL];
Font.BoundingBox: PROC [font: FONT, char: CHAR] RETURNS [Box];
CharWidth: PROC[font: FontRef, char: CHARACTER] RETURNS[xw,yw: REAL];
Font.Width: PROC [font: FONT, char: CHAR] RETURNS [REAL];
FontBox: PROC[font: FontRef] RETURNS[xmin,ymin,xmax,ymax: REAL];
Font.FontBoundingBox: PROC [font: FONT] RETURNS [Box]
ClipArea: PROC[self: Context, path: Path, parityFill: BOOLEAN, exclude: BOOLEAN],
ClipOutline: PROC[context: Context, outline: REF];
ExcludeOutline: PROC[context: Context, outline: REF];
ClipBox: PROC[self: Context, box: Box, exclude: BOOLEAN],
ClipRectangle: PROC[context: Context, x, y, w, h: REAL];
ExcludeRectangle: PROC[context: Context, x, y, w, h: REAL];
IntegerClipRectangle: PROC[context: Context, x, y, w, h: INTEGER];
IntegerExcludeRectangle: PROC[context: Context, x, y, w, h: INTEGER];
--culling
IsPointVisible: PROC[self: Context, x,y: REAL] RETURNS[BOOLEAN],
IsRectangular: PROC[self: Context] RETURNS[BOOLEAN],
Visible: PROC[self: Context] RETURNS[BOOLEAN],
Visibility: TYPE = {visible, partlyVisible, invisible};
TestRectangle: PROC[context: Context, x, y, w, h: REAL] RETURNS[Visibility];
GetBounds: PROC[self: Context] RETURNS[Box],
GetSurfaceBounds: PROC[context: Context] RETURNS[IntRectangle];
For finding out where the usable parts of the Surface are. The results are in Surface coordinates.
GetViewBounds: PROC[context: Context] RETURNS[IntRectangle];
Yields the bounding box of the View clipper, in Surface coordinates.

--The model for saving and restoring state has changed. Instead of a stack, the user must package sets of operations in procedures. The state is saved at the call and restored at the return.
DoSave and DoSaveAll differ in the amount of state that is saved.
Save: PROC[self: Context] RETURNS[Mark],
Restore: PROC[self: Context, mark: Mark],
DoSave: PROC[context: Context, body: PROC];
DoSaveAll: PROC[context: Context, body: PROC];
DrawBits: UNSAFE PROC[self: Context,
base: LONG POINTER, raster: CARDINAL, bitsPerPixel: [0..16),
x, y, w, h: CARDINAL, xorigin, yorigin: INTEGER],
DrawBitmap: PROC[context: Context, base: LONG POINTER, raster: CARDINAL, area: IntRectangle];
MaskPixel: PROC[context: Context, pa: PixelArray];
UserToDevice: PROC[self: Context, x, y: REAL, rel: BOOLEAN] RETURNS[tx, ty: REAL],
DeviceToUser: PROC[self: Context, tx, ty: REAL, rel: BOOLEAN] RETURNS[x, y: REAL],
GetYMode: PROC[self: Context] RETURNS[GraphicsBasic.YMode],
SetYMode: PROC[self: Context, mode: GraphicsBasic.YMode],
--Gone
DrawTexturedBox: PROC[self: Context, box: Box, texture: GraphicsBasic.Texture],
MakeStipple: PROC[CARDINAL] RETURNS[Color];
IntegerMaskRectangle: PROC[context: Context, x, y, w, h: INTEGER];
Disable: PROC[self: Context],
Gone?
MoveDeviceRectangle: PROC[self: Context, width, height, fromX, fromY, toX, toY: NAT]
MoveSurfaceRectangle: PROC [context: Context, source: IntRectangle, dest: IntPair];
];