--	File TestCIFUtilities.Mesa
--	Last changed: 14-Jul-81 16:27:49

DIRECTORY

CIFUtilitiesDefs USING [DisplayContext, InitCedarGraphics, SetDisplayContext, GetDisplayContext, GetBaseContext, SetClipRectangle, GetClipRectangle, GetBaseClipRectangle, DrawClipRectangle, ClearClipRectangle, DrawRectangleOutline, MoveTo, DrawTo, EnableClipping, DisableClipping, SetUniformView, ScreenParams, TrackBox, MoveCursorTo],

JaMFnsDefs USING [Register, PushReal, GetReal, PushLongInteger, PushInteger];

CIFUtilities: PROGRAM
IMPORTS CIFUtilitiesDefs, JaMFnsDefs =
BEGIN OPEN CIFUtilitiesDefs, JaMFnsDefs;

dc: DisplayContext ← NIL;

CallInitCedarGraphics: PROCEDURE =
	BEGIN
	InitCedarGraphics[];
	END;

CallSetDisplayContext: PROCEDURE =
	BEGIN
	SetDisplayContext[dc];
	END;

CallGetDisplayContext: PROCEDURE =
	BEGIN
	dc ← GetDisplayContext[];
	END;

CallGetBaseContext: PROCEDURE =
	BEGIN
	dc ← GetBaseContext[];
	END;

CallSetClipRectangle: PROCEDURE =
--set clip rectangle in current context
	BEGIN
	t: REAL ← GetReal[];
	r: REAL ← GetReal[];
	b: REAL ← GetReal[];
	l: REAL ← GetReal[];
	SetClipRectangle[[l,b,r,t]];
	END;

CallGetClipRectangle: PROCEDURE =
	BEGIN
	l,b,r,t: REAL;
	[[l,b,r,t]] ← GetClipRectangle[];
	PushReal[l];
	PushReal[b];
	PushReal[r];
	PushReal[t];
	END;

CallGetBaseClipRectangle: PROCEDURE =
	BEGIN
	l,b,r,t: REAL;
	[[l,b,r,t]] ← GetBaseClipRectangle[];
	PushReal[l];
	PushReal[b];
	PushReal[r];
	PushReal[t];
	END;

CallDrawClipRectangle: PROCEDURE =
	BEGIN
	DrawClipRectangle[];
	END;

CallClearClipRectangle: PROCEDURE =
	BEGIN
	ClearClipRectangle[];
	END;

CallDrawRectangleOutline: PROCEDURE =
	BEGIN
	t: REAL ← GetReal[];
	r: REAL ← GetReal[];
	b: REAL ← GetReal[];
	l: REAL ← GetReal[];
	DrawRectangleOutline[[l,b,r,t]];
	END;

CallMoveTo: PROCEDURE =
	BEGIN
	y: REAL ← GetReal[];
	x: REAL ← GetReal[];
	MoveTo[x,y];
	END;

CallDrawTo: PROCEDURE =
	BEGIN
	y: REAL ← GetReal[];
	x: REAL ← GetReal[];
	DrawTo[x,y];
	END;

CallEnableClipping: PROCEDURE =
	BEGIN
	EnableClipping[];
	END;

CallDisableClipping: PROCEDURE =
	BEGIN
	DisableClipping[];
	END;

CallSetUniformView: PROCEDURE =
--Set up transform to map rectangles, but without introducing differential scaling
--Minimum scale factor is used, and centers will correspond
	BEGIN
	tot: REAL ← GetReal[];
	tor: REAL ← GetReal[];
	tob: REAL ← GetReal[];
	tol: REAL ← GetReal[];
	fromt: REAL ← GetReal[];
	fromr: REAL ← GetReal[];
	fromb: REAL ← GetReal[];
	froml: REAL ← GetReal[];
	SetUniformView[[froml,fromb,fromr,fromt],[tol,tob,tor,tot]];
	END;

CallScreenParams: PROCEDURE =
	BEGIN
	base: LONG POINTER;
	raster: CARDINAL;
	height: CARDINAL;
	[base,raster,height] ← ScreenParams[];
	PushLongInteger[LOOPHOLE[base]];
	PushInteger[raster];
	PushInteger[height];
	END;

CallTrackBox: PROCEDURE =
	BEGIN
	y: REAL ← GetReal[];
	x: REAL ← GetReal[];
	TrackBox[x,y,Red];
	END;

CallMoveCursorTo: PROCEDURE =
	BEGIN
	y: REAL ← GetReal[];
	x: REAL ← GetReal[];
	MoveCursorTo[x,y];
	END;
	
Register["init"L,CallInitCedarGraphics];
Register["setdc"L,CallSetDisplayContext];
Register["getdc"L,CallGetDisplayContext];
Register["getbasedc"L,CallGetBaseContext];
Register["setclip"L,CallSetClipRectangle];
Register["getclip"L,CallGetClipRectangle];
Register["getbaseclip"L,CallGetBaseClipRectangle];
Register["drawclip"L,CallDrawClipRectangle];
Register["clearclip"L,CallClearClipRectangle];
Register["drawrect"L,CallDrawRectangleOutline];
Register["moveto"L,CallMoveTo];
Register["drawto"L,CallDrawTo];
Register["enableclip"L,CallEnableClipping];
Register["disableclip"L,CallDisableClipping];
Register["setuniform"L,CallSetUniformView];
Register["screenparams"L,CallScreenParams];
Register["trackbox"L,CallTrackBox];
Register["movecursor"L,CallMoveCursorTo];


END.