home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Education
/
collectionofeducationcarat1997.iso
/
COMPUSCI
/
TOT11.ZIP
/
TOTDOC11.ZIP
/
CHAPT5.TXT
< prev
next >
Wrap
Text File
|
1991-02-11
|
48KB
|
1,188 lines
Writing
to the
Screen
"Some of the newer computer-related equipment is of considerable
help... Among the most useful tools is the cathode-ray-tube console, a
computer-connected instrument resembling a television set, which can
display on its screen textual information from the computer's memory in
easily readable form."
The American Heritage Dictionary, 1981
Most programs need to write output to the display, and usually this
needs to be done very quickly! The totFAST unit includes a variety of
objects for writing to the screen.
The main object ScreenOBJ is capable of writing to the physical screen
as well as virtual screens. A virtual screen is a screen that is not
visible but provides all the facilities of the physical screen. A vir-
tual screen can be used to keep a snapshot copy of the physical screen
so that it may be restored at some later date. Virtual screens can also
be used to prepare full screen displays "off line", which, when
required, can be pushed onto the visible screen using a variety of
effects.
The ScreenOBJ object provides methods for writing to the screen using
varied justification, as well as methods to draw lines and boxes, read
information from the screen, move blocks of text around the screen, and
control cursor location and appearance.
The totFAST unit also includes objects for controlling the appearance
of scroll bars and window shadows. Note: remember that the display
colors are always specified as the composite foreground and background
attribute (refer to page 3.11 for more information).
The Writing Engine
Before plunging into the totFAST unit, you ought to be aware of an
important Toolkit feature.
At the heart of the ScreenOBJ object is another object called WriteOBJ
(yes, an object within an object). This object is the screen writing
engine, and performs all of the primary screen manipulation tasks.
There are methods for writing text, controlling the cursor, and for
making direct video memory moves.
You should never need to access the WriteOBJ methods; when you make
calls to the ScreenOBJ methods, the Toolkit makes calls to the WriteOBJ
engine. Ordinarily, therefore, you don't even need to be aware that
WriteOBJ exists. However, if you want to use some different routines
for accessing the display (e.g. you want to run programs on non-
5-2 User's Guide
--------------------------------------------------------------------------------
standard hardware, or you want to run in graphics mode), then all you
have to do is create your own WriteOBJ-type object, and instruct the
Toolkit to use it. This "back door" gives you complete control of the
Toolkit's engine. This feature allows you to modify the Toolkit display
engine without making a single change to the Toolkit source code.
This whole subject is discussed in detail in Part 2: Extending the
Toolkit.
Managing the Visible Screen
One of the few parts of the Toolkit written in Assembler is the screen
writing code. The reason? Speed. The totFAST unit provides very high
performance screen writing, especially in CGA systems, which are noto-
rious for "snow" and slow speeds.
The Toolkit can write to all PC monitor types ranging from monochrome
to VGA. For performance reasons, totFAST bypasses DOS screen writing
services (BIOS) and writes directly to the video area of memory.
The Toolkit automatically switches off the mouse cursor during screen
writes.
Using SCREEN
totFAST includes a global object SCREEN of type ScreenOBJ. SCREEN is
automatically initialized when you use the totFAST unit. All direct
screen writing should be performed using the SCREEN instance. For exam-
ple, to write "Hello World" at the current cursor position, you would
call the method Write as follows:
Screen.Write("Hello World");
Most of the other screen writing methods must be passed the X and Y
coordinates where the string is to be written. Like Turbo Pascal, the
Toolkit uses a one-based system where the top left of the screen is at
coordinates (1,1) and the bottom right of the screen is normally
(80,25). Some routines, like the box drawing methods, need to be passed
a pair of coordinates. Pass the upper-left and lower-right coordinates,
respectively.
Basic Screen Writing
This section explains how to use the methods for writing strings using
varied justification methods, how to clear all or part of the screen,
how to change the display attributes and how to draw lines and boxes.
Writing to the Screen 5-3
--------------------------------------------------------------------------------
Note: unfortunately, Turbo Pascal provides no facility for writing
procedures or functions which can be passed different parameter
types or varying numbers of parameters. For this reason, the Tool-
kit is incapable of providing the ultra-flexible facilities similar
to Turbo Pascal's own Write and WriteLn procedures.
The Toolkit therefore expects a single string to be passed to its
main screen writing methods. If you need to write a non-string
item, you can use one of the string conversion functions in the
totSTR unit. For example, to display the value of a real variable
REALVAL, use the following statement:
SCREEN.Write(RealToStr(REALVAL));
For plain screen writing, feel free to use Turbo Pascal's proce-
dures Write and WriteLn, e.g. Write(REALVAL);, but remember to hide
the mouse first.
Writing Strings
The following eleven methods simplify the tasks of writing strings to
the screen:
Write(Str:string);
Writes a string at the current cursor position using the default dis-
play attributes. The display attributes are set with Turbo Pascal's CRT
procedures TextColor and TextBackground. The cursor is automatically
moved to the position following the last character of the string.
WriteLn(Str:string);
This method is the same as Write, except that the cursor is moved to
the beginning of the next line. If the string is written to the last
line of the display (or the last line of a window - discussed later),
the display scrolls up one line.
WriteAT(X,Y,Attr:byte; Str:string);
Writes a string at the specified X and Y coordinates using the display
attribute Attr. The cursor is not moved.
WriteHi(X,Y,AttrHi,Attr:byte; Str:string);
5-4 User's Guide
--------------------------------------------------------------------------------
This method is used to write a string with a combination of color
attributes. Some parts of the string may be written in attribute
AttrHi, and other parts in Attr. A special character must be embedded
into the string to indicate when to change attributes. By default, this