JunoGraphicsImpl.mesa
Coded July 1982 by Donna M. Auguste & Greg Nelson
Edited December 7, 1982 5:10 pm
Last Edited by: Gnelson, June 27, 1983 3:51 pm
Last Edited by: Stolfi, June 7, 1984 2:12:47 pm PDT
These are procedures which directly affect the Juno bitmap.
Imported by JunoTop and its submodules (JunoAlgebraImpl, JunoBody, JunoOldSolver...)
DIRECTORY
JunoGraphics,
Font USING [WidthVector],
JunoUserEvents USING[],
Real USING [RoundI],
Rope USING [ROPE, Cat, Map, ActionType, Equal],
Graphics USING [Context, Translate, Scale, SetCP, GetBounds,
SetColor, black, SetStipple, DrawBox],
GraphicsOps USING [BitmapRef, NewBitmap, DrawBitmap, NewContextFromBitmap],
Carets USING [StartCaret, StopCaret],
Imager USING [MakeFont, FONT, Trajectory, Context, XOR, black, white, MoveTo, LineTo,
LineToX, LineToY, Create, SpecialOp, Pair, SetXYRel, SetXY, Trans, ClipRectangle,
ScaleT, SetPriorityImportant, SetColor, MaskRectangle, MakeGray, SetStrokeEnd,
SetStrokeWidth, SetFont, DoSave, MaskFill, MaskStroke, MaskVector, CurveTo,
ShowCharacters, ShowChar, Reset],
ImagerPixelMaps USING [PixelMap, CreateFrameBuffer, Clear],
ImagerBasic USING [ColorRep],
ImagerPD USING [PDFileDescription, Raven, Puffin, PlateMaker];
- - - - GRAPHICS STATE
The variables below need not be protected by the monitor lock, since they are set and used only by the main process (JunoTop).
buf: REF ImMaps.PixelMap ← NIL; -- REF to Imager-style descriptor of buffer bitmap
bufCtx: Im.Context; -- A context that paints into buf. Origin at bottom left, 1 dot/unit
ctx: Im.Context ← NIL; -- Either bufCtx or a PD context (or NIL at first).
invert: PUBLIC Color ← Im.XOR;
black: PUBLIC Color ← Im.black;
white: PUBLIC Color ← Im.white;
currentColor: PUBLIC Color ← Im.black;
currentEnds: PUBLIC ATOM ← $round;
currentWidth: PUBLIC REAL ← 0;
currentFontName: PUBLIC ROPE ← "Helvetica";
currentFontSize: PUBLIC REAL ← 12;
currentFontFace: PUBLIC ATOM ← $regular;
currentJustification: PUBLIC ATOM ← $left;
currentFont: Im.FONT;
- - - - POINT HIGHLIGHTS (AFFECTS SCREEN IMAGE ONLY)
Trajectories for point highlights (Shouldn't we use a special symbol font instead?):
plusTraj: Im.Trajectory = Im.MoveTo[[-1, -1]].LineTo[[-5, -1]].LineTo[[-5, +1]]
.LineTo[[-1, +1]].LineTo[[-1, +5]].LineTo[[+1, +5]].LineTo[[+1, +1]]
.LineTo[[+5, +1]].LineTo[[+5, -1]].LineTo[[+1, -1]].LineTo[[+1, -5]]
.LineTo[[-1,-5]];
crossTraj: Im.Trajectory = Im.MoveTo[[-1, 0]].LineTo[[-4, +3]].LineTo[[-3, +4]]
.LineTo[[0, +1]].LineTo[[+3, +4]].LineTo[[+4, +3]].LineTo[[+1, 0]]
.LineTo[[+4, -3]].LineTo[[+3, -4]].LineTo[[0, -1]].LineTo[[-3, -4]]
.LineTo[[-4,-3]];
diam5Traj: Im.Trajectory = Im.MoveTo[[-5,0]].LineTo[[0,-5]].LineTo[[5, 0]].LineTo[[0,5]];
diam4Traj: Im.Trajectory = Im.MoveTo[[-4,0]].LineTo[[0,-4]].LineTo[[4, 0]].LineTo[[0,4]];
box4Traj: Im.Trajectory = Im.MoveTo[[-4,-4]].LineToX[+4].LineToY[+4].LineToX[-4];
box3Traj: Im.Trajectory = Im.MoveTo[[-3,-3]].LineToX[+3].LineToY[+3].LineToX[-3];
SetOrg:
PROC [ctx: Im.Context, coords: Coords] =
INLINE
Redefines origin at the given coordinates, rounded to the nearest pixel
{Im.SetXY[ctx, coords]; Im.Trans[ctx]};
Hilyte:
PUBLIC
PROC [coords: Coords, symbol: PointSymbol] =
BEGIN
DoShow:
PROC =
BEGIN
Im.SetColor[ctx, invert];
SetOrg[ctx, coords];
SELECT symbol
FROM
box =>
{Im.MaskRectangle[ctx, -4, -4, 8, 8];
Im.MaskRectangle[ctx, -3, -3, 6, 6]};
plus =>
{Im.MaskFill[ctx, plusTraj]};
cross =>
{Im.MaskFill[ctx, crossTraj]};
diamond =>
{Im.MaskFill[ctx, diam5Traj];
Im.MaskFill[ctx, diam4Traj]};
dot =>
{Im.MaskRectangle[ctx, -1, -1, 2, 2]};
bigDot =>
{Im.MaskRectangle[ctx, -2, -2, 4, 4]};
ENDCASE => ERROR;
END;
IF ctx # bufCtx THEN RETURN;
Im.DoSave[ctx, DoShow];
PicChanged[]
END;
- - - - LINES, STROKES, FILLED PATHS
DrawEdge:
PUBLIC
PROC [p, q: Coords, thin:
BOOL ←
TRUE] =
BEGIN
Im.MaskVector [context: ctx, p1: [p.x, p.y], p2: [q.x, q.y],
strokeWidth: IF thin THEN 0 ELSE currentWidth];
PicChanged[]
END;
DrawArc:
PUBLIC
PROC [p, r, s, q: Coords, thin:
BOOL ←
TRUE] =
BEGIN
Im.MaskStroke [context: ctx, t: Im.MoveTo[p].CurveTo[r, s, q],
strokeWidth: IF thin THEN 0 ELSE currentWidth];
PicChanged[]
END;
AppendEdge:
PUBLIC
PROC [t: Trajectory, p, q: Coords]
RETURNS [new: Trajectory] =
BEGIN
IF t = NIL THEN t ← Im.MoveTo[p];
new ← t.LineTo[q];
END;
AppendArc:
PUBLIC
PROC [t: Trajectory, p, r, s, q: Coords]
RETURNS [new: Trajectory] =
BEGIN
IF t = NIL THEN t ← Im.MoveTo[p];
new ← t.CurveTo[r, s, q];
END;
FillTrajectory:
PUBLIC
PROC [t: Trajectory] =
BEGIN
Im.MaskFill[ctx, t];
PicChanged[]
END;
StrokeTrajectory:
PUBLIC
PROC [t: Trajectory] =
BEGIN
Im.MaskStroke[ctx, t];
PicChanged[]
END;
GcTrajectory:
PUBLIC
PROC [t: Trajectory] =
BEGIN
END;
- - - - BITMAP BUFFER
The following data (except picChanged and the bits in the bitmap buffer) must be protected by the monitor lock, since they are altered by the main client process (JunoTop) and consulted by the bitmap-to-viewer dumping process (RefreshViewer).
currentPictureWidth: PUBLIC INTEGER ← 0; -- current picture dimensions (Juno units)
currentPictureHeight: PUBLIC INTEGER ← 0;
gbuf: GraphicsOps.BitmapRef ← NIL; -- REF to Graphics-style descriptor of buffer bitmap
bufferPos: IntCoords ← [0, 0]; -- position of origin of bitmap buffer wrt origin of viewer
picChanged:
PUBLIC
BOOLEAN ←
TRUE;
Signals that something (bits, buffer size, buffer offset, caret position) changed since last painting on viewer. Set by operations that paint on buf. Reset by PaintBuffer after dumping buf onto viewer.
bufferChanged:
BOOLEAN ←
TRUE;
Set by operations that change buffer size or position, reset by PaintProc after dumping buf onto viewer.
PicChanged: ENTRY PROC = INLINE {picChanged ← TRUE};
- - - - BLINKING CARET
The following data is also protected by the monitor lock:
caretReallyOn: BOOL ← FALSE; -- if TRUE, caret is currently on (set by PaintBuffer)
caretOn: PUBLIC BOOL ← FALSE; -- if TRUE, caret is being turned on (set by SetCaret)
caretPos: PUBLIC Coords; -- current caret position, in Juno coordinates
SetCaret:
PUBLIC
ENTRY
PROC [on:
BOOL ←
TRUE, coords: Coords←[0,0]] =
{caretOn ← on; caretPos ← coords;
picChanged ← TRUE};
- - - - VIEWER/JUNO COORDINATE MAPPING
ViewerToJuno:
PUBLIC ENTRY PROC
[viewer: Viewer, view: IntCoords]
RETURNS [coords: IntCoords] =
{coords.x ← view.x - bufferPos.x;
coords.y ← (viewer.ch - view.y) - bufferPos.y};
InternalJunoToViewer:
INTERNAL
PROC
[viewer: Viewer, coords: Coords]
RETURNS [view: IntCoords] =
INLINE
{view.x ← Real.RoundI[coords.x]+bufferPos.x;
view.y ← viewer.ch - (Real.RoundI[coords.y] + bufferPos.y)};
JunoToViewer:
PUBLIC ENTRY PROC
[viewer: Viewer, coords: Coords]
RETURNS [view: IntCoords] =
{RETURN [InternalJunoToViewer[viewer, coords]]};