Windows

Introduction

BBC BASIC (Z80) writes text to the text window and graphics to the graphics window, rectangular regions that form part (or all) of the screen. An alternative name for a window is a viewport. The text and graphics windows can overlap. By default, the text and graphics windows are as close to the full size of the screen as possible, but the size and position of the windows may be changed.

The text and graphics windows may be restored to their default state with the VDU 26 command.

The CLS command clears the text window to the current text background colour. The CLG command clears the graphics window to the current graphics background colour with the current graphics background plotting action (set by GCOL). If the text and graphics windows overlap, the background colour of the overlapping area will be set by the last clear command issued.

Text Window

The text origin is the top left-hand corner of the current text window. The reference point for defining a text window is also the top left-hand corner of the screen.

Define Text Window

The VDU 28 command defines a text window. The four bytes following the command define the X & Y coordinates of the top-left corner of the window and the X & Y coordinates of the bottom-right corner of the window, in that order. The coordinates are with respect to the screen text origin and are measured in 'character positions'.

If the text cursor is outside the new window, it is moved to the new home position (top left of the window). If it is inside the new window, it is not moved.

If any of the edges of the new text window would be off the screen, they are clipped.

The following example defines a text window with the top-left corner at (0,3) (X across, Y down) and the bottom-right corner at (20,6) (X across, Y down).

VDU 28,0,3,20,6

Clear Text Window

The CLS (or VDU 12) command clears the text window to the current text background colour. If you subsequently change the text background colour, the background of each character cell will be set to the new background colour as the character is printed on the screen. When the screen scrolls, the 'empty' line scrolled onto the screen will have the new background colour.

Graphics Window

The graphics origin is initially the top-left hand corner of the screen. A graphics window is defined with reference to the current graphics origin. The graphics origin may be set with the VDU 29 command as described later.

Define Graphics Window

In the graphics modes, the VDU 24 command defines a graphics window. The four words (pairs of bytes) following the command are the X & Y coordinates of the top-left corner of the window and the X & Y coordinates of the bottom-right corner of the window, in that order. The coordinates are with respect to the current graphics origin.

If any of the edges of the new graphics window would be off the screen, they are clipped. It is particularly easy to select invalid window limits if the graphics origin has been moved. It is advisable, therefore, to precede a VDU 24 command with a VDU 26 command to reset the windows and the graphics origin.

The following example defines a graphics window with the top-left corner at (20,10) (X,Y) and the bottom-right corner at (80,60) (X,Y).

VDU 24,20;10;80;60;

Note the use of semicolons in this VDU command. Their significance is explained under the VDU keyword.

Clear Graphics Window

The CLG (or VDU 16) command clears the graphics window to the current graphics background colour using the current background plotting action (set by GCOL). If you change the graphics background colour, you will probably not notice a change in the graphics background colour until you next clear the graphics window. However, some of the PLOT modes use the current background colour.

Changing the Graphics Origin

In the graphics modes, VDU 29 moves the graphics origin to the coordinates specified by the following two words (pairs of bytes). The first word specifies the X coordinate of the new origin and the second specifies the Y coordinate. Subsequent graphics commands operate with respect to this origin.

The following example sets the graphics origin to the centre of the screen, assuming a width of 96 pixels and a height of 64 pixels:

VDU 29,48;32;

Note the use of semicolons in this VDU command. Their significance is explained under the VDU keyword.

Resetting Text and Graphics Windows

VDU 26 resets the text and graphics windows to their default positions (filling the whole screen), homes the text cursor to the top left of the screen (0,0), resets the graphics origin to the bottom left of the screen (0,0) and homes the graphics cursor to the graphics origin.

Positioning The Cursor

Text Cursor

The text cursor may be positioned within the text window with the TAB(X,Y) command. For example;

PRINT TAB(2,3)"Fred"

will print the word 'Fred' starting at column 2 of row 3. The top left hand corner of the text window is (0,0).

Graphics Cursor

Within the graphics window, the graphics cursor is positioned by the MOVE, DRAW or PLOT commands.

When printing characters at the graphics cursor position, the top left-hand corner of the character cell is positioned at the graphics cursor position.

Homing The Cursor

In VDU 4 mode, VDU 30 homes the text cursor to the top left corner of the text window. In VDU 5 mode, VDU 30 homes the graphics cursor to the top left corner of the graphics window.