Library obnc

DEFINITION XYplane;
(*Basic facilities for graphics programming

Implements the basic library module from "The Oakwood Guidelines for Oberon-2 Compiler Developers". The drawing plane is repainted when Key is invoked. Fullscreen mode is toggled with Ctrl-f; it can also be exited with Esc.*)

	CONST
		(*drawing modes*)
		draw = 1;
		erase = 0;

	VAR
		X, Y: INTEGER; (*X = 0 and Y = 0. Included for compatibility with The Oakwood Guidelines.*)
		W, H: INTEGER; (*width and height of the drawing plane in pixels*)

	PROCEDURE Open;
(*initializes the drawing plane*)

	PROCEDURE Clear;
(*erases all pixels in the drawing plane*)

	PROCEDURE Dot(x, y, mode: INTEGER);
(*Dot(x, y, m) draws or erases the pixel at the coordinates (x, y) relative to the lower left corner of the plane. If m = draw the pixel is drawn, if m = erase the pixel is erased.*)

	PROCEDURE IsDot(x, y: INTEGER): BOOLEAN;
(*returns TRUE if the pixel at the coordinates (x, y) relative to the lower left corner of the screen is drawn, otherwise it returns FALSE*)

	PROCEDURE Key(): CHAR;
(*reads the keyboard. If a key was pressed prior to invocation, its character value is returned, otherwise the result is 0X.*)

(*Example:

	MODULE fpstest;
		(*draw dots and print the number of displayed frames per second*)

		IMPORT Input, Out, XYplane;
	
		VAR
			n, t, x, y: INTEGER;

	BEGIN
		XYplane.Open;
		n := -1;
		t := Input.Time();
		REPEAT
			INC(n);
			IF Input.Time() - t >= Input.TimeUnit THEN
				Out.String("fps: ");
				Out.Int(n, 0);
				Out.Ln;
				n := 0;
				t := Input.Time()
			END;
			x := Input.Time() MOD XYplane.W;
			y := Input.Time() MOD XYplane.H;
			XYplane.Dot(x, y, XYplane.draw)
		UNTIL XYplane.Key() = "q"
	END fpstest.
*)

END XYplane.