-- Compiler GriffinInput/n
-- Tiberi December 11, 1979  4:25 PM

DIRECTORY
	GriffinInputDefs: FROM "GriffinInputDefs",
	StreamDefs: FROM "StreamDefs"
		USING [KeyboardHandle,GetDefaultKey],
	PointDefs: FROM "PointDefs" USING [ScrPt],
	CursorDefs: FROM "CursorDefs" USING [CursorPosition],
	ProcessDefs: FROM "ProcessDefs" USING [Yield],
	KeyDefs: FROM "KeyDefs";

GriffinInput: PROGRAM IMPORTS StreamDefs, CursorDefs, ProcessDefs
	EXPORTS GriffinInputDefs = 
BEGIN OPEN GriffinInputDefs;

Input: PUBLIC PROCEDURE [handler: InputEventProc] =
BEGIN
oldMouseButton: KeyDefs.MouseButton ← KeyDefs.Mouse.buttons;
keys: StreamDefs.KeyboardHandle = StreamDefs.GetDefaultKey[];
oldPoint: PointDefs.ScrPt ← [0,0];
point: PointDefs.ScrPt;
shifted: BOOLEAN;

	DO  --forever
	ProcessDefs.Yield;
	point ← CursorDefs.CursorPosition[];
	shifted ← KeyDefs.Keys.LeftShift = down
		OR KeyDefs.Keys.RightShift = down;
	IF KeyDefs.Mouse.buttons # oldMouseButton THEN
		BEGIN
		oldMouseButton ← KeyDefs.Mouse.buttons;
		SELECT oldMouseButton FROM
		   Red => handler[[red,,point,shifted]];
		   Yellow => handler[[yellow,,point,shifted]];
		   Blue => handler[[blue,,point,shifted]];
		   None => handler[[up,,point,shifted]];
		   ENDCASE => handler[[multiple,,point,shifted]];
		END
	ELSE IF ~ keys.endof[keys]
	   THEN handler[[keyStroke, keys.get[keys], point, FALSE]]
	ELSE IF oldPoint # point
	   THEN handler[[newPosition, , point, shifted]];
	oldPoint ← point
	ENDLOOP
END;

END.