-- Device.mesa
-- Last changed by Doug Wyatt, September 15, 1980 5:39 PM

DIRECTORY
Style USING [Data],
Area USING [Handle],
Pipe USING [Handle],
Mapper USING [Handle],
Font USING [Id],
Vector USING [Matrix],
OpaqueDevice USING [TextHandle];

Device: DEFINITIONS = {

Handle: TYPE = LONG POINTER TO Object;

-- Client interface for a Device object

-- returns a Pipe for drawing areas in the given style
NewPipe: PROCEDURE[self: Handle, style: Style.Data]
RETURNS[Pipe.Handle] = INLINE {
RETURN[self.procs.NewPipe[self,@style]]
};
-- returns a Text object for drawing characters in the given font
NewText: PROCEDURE[self: Handle,
id: Font.Id, size: REAL, m: Vector.Matrix, style: Style.Data]
RETURNS[OpaqueDevice.TextHandle] = INLINE {
RETURN[self.procs.NewText[self,id,size,@m,@style]]
};
ApplyBaseTransform: PROCEDURE[self: Handle, mapper: Mapper.Handle] = INLINE {
self.procs.ApplyBaseTransform[self,mapper]
};
Boundary: PROCEDURE[self: Handle] RETURNS[Area.Handle] = INLINE {
RETURN[self.procs.Boundary[self]]
};
Ref: PROCEDURE[self: Handle] RETURNS[Handle] = INLINE {
self.refs←self.refs+1; RETURN[self]
};
Free: PROCEDURE[selfPtr: LONG POINTER TO Handle] = INLINE {
self: Handle=selfPtr↑; selfPtr↑←NIL;
IF (self.refs←self.refs-1)=0 THEN self.procs.Free[self]
};

-- Actual representation for a Device interface

Object: TYPE = RECORD [
procs: LONG POINTER TO READONLY Procs,
data: LONG POINTER TO Data,
refs: CARDINAL←1
];

Procs: PRIVATE TYPE = RECORD [
NewPipe: PROCEDURE[self: Handle, style: POINTER TO Style.Data]
RETURNS[Pipe.Handle],
NewText: PROCEDURE[self: Handle, id: Font.Id, size: REAL,
pm: POINTER TO READONLY Vector.Matrix,
style: POINTER TO READONLY Style.Data]
RETURNS[OpaqueDevice.TextHandle],
ApplyBaseTransform: PROCEDURE[self: Handle, mapper: Mapper.Handle],
Boundary: PROCEDURE[self: Handle] RETURNS[Area.Handle],
Free: PROCEDURE[self: Handle]
];

Data: PRIVATE TYPE;

}.