-- GraphicsOps.mesa
-- Last changed by Doug Wyatt, August 30, 1982 5:26 pm
-- Last changed by Paul Rovner, June 9, 1983 11:20 am

-- Low level or temporary interfaces to Cedar Graphics

DIRECTORY
Graphics USING [Context],
GraphicsBasic USING [Box, ClipperRef, FontRef, ImageRef, MapperRef, Texture, YMode],
FS USING [OpenFile],
Rope USING [ROPE];

GraphicsOps: CEDAR DEFINITIONS = {

Context: TYPE = Graphics.Context;
Box: TYPE = GraphicsBasic.Box;

------ Bitmaps ------


BitmapRef: TYPE = REF READONLY BitmapRep;
BitmapRep: TYPE = RECORD [
base: REF, -- pointer to bitmap bits
raster: CARDINAL, -- words per line
width: CARDINAL, -- width in bits
height: CARDINAL -- height in lines
];
-- (0,0) is at the upper left corner of the bitmap

NewBitmap: PROC[width,height: CARDINAL] RETURNS[BitmapRef];
-- Returns a new bitmap object of given width and height

NewContextFromBitmap: PROC[BitmapRef] RETURNS[Context];
-- Returns a display context which will draw into the given bitmap

SetTargetBitmap: PROC[self: Context, bitmap: BitmapRef];
-- After this call, the given context will draw into the given bitmap

DrawBitmap: PROC[self: Context, bitmap: BitmapRef,
w, h: CARDINAL, -- width and height of rectangle
x, y: CARDINAL ← 0, -- upper left corner of rectangle
xorigin, yorigin: INTEGER ← 0 -- point to be aligned with cp
];
-- Draws a rectangle from the given bitmap as an image in the given context

ScreenBitmap: PROC RETURNS[BitmapRef];
-- Returns a BitmapRef describing the default display. Caution: this has base=NIL,
-- by convention, since the display bitmap is not in counted storage.


------ Images ------

ImageRef: TYPE = GraphicsBasic.ImageRef;

NewAisImage: PROC[name: Rope.ROPE] RETURNS[ImageRef];
-- Create an Image object, given the name of an AIS file.
-- If the given name does not contain '., tries appending ".ais"
-- to obtain a file name for the image.

NewAisImageFromCapability: PROC[file: FS.OpenFile] RETURNS[ImageRef];
-- Create an Image object, given a capability for an AIS file.

ImageBox: PROC[image: ImageRef] RETURNS[xmin,ymin,xmax,ymax: REAL];
-- Return a box that bounds the given image.


------ Fonts and Text ------

FontRef: TYPE = GraphicsBasic.FontRef;

DefaultFont: PROC RETURNS[FontRef];

DrawTextFromProc: PROC[self: Context,
map: PROC[PROC[CHAR] RETURNS[BOOL]],
font: FontRef ← NIL];
-- Caution: 'map' may be called twice;
-- it must return the same string of characters both times!

-- DrawText, TextBox, and TextWidth, which take a REF READONLY TEXT, are
-- temporarily retained for compatibility, but they will go away soon.

maxLen: NAT = LAST[NAT];

DrawText: PROC[self: Context, text: REF READONLY TEXT,
start: NAT ← 0, len: NAT ← maxLen,
font: FontRef ← NIL];

TextBox: PROC[font: FontRef, text: REF READONLY TEXT,
start: NAT ← 0, len: NAT ← maxLen]
RETURNS[xmin,ymin,xmax,ymax: REAL];

TextWidth: PROC[font: FontRef, text: REF READONLY TEXT,
start: NAT ← 0, len: NAT ← maxLen]
RETURNS[xw,yw: REAL];


------ Transformations ------

UserToDevice: PROC[self: Context, x, y: REAL, rel: BOOLEANFALSE] RETURNS[tx, ty: REAL]
= INLINE { RETURN self.procs.UserToDevice[self, x, y, rel] };
DeviceToUser: PROC[self: Context, tx, ty: REAL, rel: BOOLEANFALSE] RETURNS[x, y: REAL]
= INLINE { RETURN self.procs.DeviceToUser[self, tx, ty, rel] };
-- Transform between user and device coordinates.
-- If rel is TRUE, transform as a relative displacement.


------ Mapper and Clipper operations ------

MapperRef: TYPE = GraphicsBasic.MapperRef;
ClipperRef: TYPE = GraphicsBasic.ClipperRef;

GetMapper: PROC[self: Context] RETURNS[MapperRef];
-- Create a copy of the context's current transformation.
-- This operation allocates new storage for the copied mapper.

SetMapper: PROC[self: Context, mapper: MapperRef];
-- Set the context's transformation to the specified value.
-- This operation does not allocate new storage (but it may cause
-- the context's old mapper to be saved if a Save is in effect).

GetClipper: PROC[self: Context] RETURNS[ClipperRef];
-- Create a copy of the context's current clipping region.
-- This operation allocates new storage for the copied clipper.

SetClipper: PROC[self: Context, clipper: ClipperRef];
-- Set the context's clipping region to the specified value.
-- This operation does not allocate new storage (but it may cause
-- the context's old clipper to be saved if a Save is in effect).

TestVisible: PROC[mapper: MapperRef, clipper: ClipperRef, x,y: REAL] RETURNS[BOOLEAN];
TestBounds: PROC[mapper: MapperRef, clipper: ClipperRef] RETURNS[Box];


------ Boxing ------

BeginBox: PROC[self: Context];
-- Begin maintaining a bounding box for all subsequently displayed objects.
EndBox: PROC[self: Context] RETURNS[Box];
-- Return the bounding box started by BeginBox, and stop boxing.


------ Y-direction mode ------

YMode: TYPE = GraphicsBasic.YMode;
-- {bottomUp, topDown}

GetYMode: PROC[self: Context] RETURNS[YMode]
= INLINE { RETURN self.procs.GetYMode[self] };
SetYMode: PROC[self: Context, mode: YMode]
= INLINE { self.procs.SetYMode[self, mode] };

------ Funny tiled textures ------

Texture: TYPE = GraphicsBasic.Texture;

DrawTexturedBox: PROC[self: Context, box: Box, texture: Texture]
= INLINE { self.procs.DrawTexturedBox[self, box, texture] };
-- Draw a box filled with the given texture.
-- The current color or texture in the context is unaffected.


-- -- -- Wizards only below here, please -- -- --

Disable: PROC[self: Context]
= INLINE { self.procs.Disable[self] };
-- Disable all display operations for this context.
-- After Disable is called, the context can no longer make visible
-- changes to the display, though its clients can't tell the difference.
-- This operation is irreversible (at least for now).

MoveDeviceRectangle: PROC[self: Context, width, height, fromX, fromY, toX, toY: NAT]
= INLINE { self.procs.MoveDeviceRectangle[self, width, height, fromX, fromY, toX, toY] };
-- Move a rectangular block on the display (e.g., for fast scrolling).
-- All numbers are in device coordinates:
-- width, height => size of the rectangle to be transferred
-- fromX, fromY => upper left corner of the source rectangle
-- toX, toY => upper left corner of the destination rectangle
-- Note: some devices may not implement this.

UnsafeNewFont: UNSAFE PROC[LONG POINTER] RETURNS[FontRef];
-- The long pointer must point to a mapped-in ks or strike font.

}.