81: How do I
format graphics output like in textmode writeln?
A: In the graphics mode
the positioned text output procedure is
OutTextXY (X ,Y : integer; TextString : string); It does not have
the same output formatting capabilities as the write procedure. It
only accepts the one TextString. Therefore all the output formatting
must be done previously on the string. The Str procedure has such
capabilities. The example below gives the rudiments.
uses Crt, Graph;
var grDriver : integer;
grMode : integer;
ErrCode : integer;
s, s1 : string;
v1 : real;
begin
grDriver := Detect;
InitGraph (grDriver, grMode, ' ');
ErrCode := GraphResult;
if ErrCode <> grOk then begin
Writeln ('Graphics error:', GraphErrorMsg(ErrCode)); halt; end;
ClearDevice;
{}
{ Writing text in the graphics mode }
{ Set the drawing color }
SetColor (Yellow);
{ Set the current background color }
SetBkColor (Black);
{ Set style for text output in graphics mode }
SetTextStyle (DefaultFont, HorizDir, 2);
{ Preprocess the text }
v1 := 2.345;
Str (v1 : 10:2, s1);
s := 'The first value is' + s1 + '.';
{ Output the text }
OutTextXY (100, 30, s);
OutTextXY (100, 50, 'Press any key');
{}
repeat until KeyPressed;
{}
RestoreCrtMode;
writeln ('That''s all folks');
CloseGraph;
end.
Besides not having the same output formatting capabilities
OutTextXY
and OutText procedures do not scroll the screen. If you wish to
achieve such an effect, you will have to code it yourself step by
step. You can see the effect in
111673 Oct 8 1993 ftp://garbo.uwasa.fi/pc/ts/tsdemo16.zip
tsdemo16.zip Assorted graphics demonstrations of functions etc
Coding the scrolling is a straight-forward but a laborious task.
Hence it is beyond this FAQ. The outline, however, is that you must
keep track where on the screen you are. When you come to the
bottom
of your window you have to move the above region upwards
before you
output new text. You can move graphics regions using the
ImageSize,
GetImage and PutImage procedures.
As for readln-type input in a graphics mode, that is a complicated
issue. You will have to build the input routine reading a character
at a time with ReadKey. The rudiments of using ReadKey are
shown in
the first question of FAQPAS.TXT. The demo, referred to a few
lines
back, will show the effect.