[comp.lang.pascal] Turbo 4.0 graphics problem

E8D@PSUVM.BITNET (04/24/88)

I seem to have run into a bug using the procedures OutText and OutTextXY
in Turbo 4.0 graphics mode.  They reset the CP to the upper left corner of
the character box.  OutText should only move CP if the horizontal justification
is Left and OutTextXY shouldn't ever change the Current Position.
   Does anyone know of a fix for this (aside from storing and retrieving CP)?
   Here's a little routine which shows the problem:

Program graphbug;{.PAS}
        {program to demonstrate how OutText and OutTextXY change the cp
         in graphics mode when they should not.}
uses
    Graph, CRT;
var
   graphDriver,GraphMode:           integer;
   symbol,ch:                          char;

Procedure OpenGraph;
begin
     GraphDriver := Detect;
     initgraph(GraphDriver,Graphmode, ''); {Put in your driverpath}
end;{OpenGraph}

Procedure Plot;
var
   Xpix, Ypix: integer;
begin
     xpix := 400;
     ypix := 150;
     SetTextStyle(Defaultfont,HorizDir,4);   {enlarge the symbol}
     SetTextJustify(CenterText,CenterText);
     Symbol := '0';
     MoveTo(xpix,ypix);
     OutTextXY(xpix,ypix,symbol);   {should not change cp}
     xpix := xpix - 100;
     lineto(xpix,ypix);
     Symbol := '1';
     OutText(symbol);               {should not change cp if text is centered}
     xpix := xpix + 100;
     ypix := ypix - 100;
     lineto(xpix,ypix);
     Symbol := '2';
     OutText(symbol);
     xpix := xpix + 100;
     lineto(xpix,ypix);
     Symbol := 'X';
     Outtext(symbol);
     MoveTo(xpix,ypix);              {fix to reset cp to proper position}
     xpix := 400;
     ypix := 150;
     lineto(xpix,ypix);
     MoveTo(0,0);
     SetTextStyle(Defaultfont,HorizDir,1);   {default text size}
     SetTextJustify(LeftText,TopText);
     OutText('Press any key');
end;{Plot}

begin {main}
     Opengraph;
     Plot;
     ch :=readkey;                       {Pause}
     closegraph;
end.{main}
------------------
Evan Dresel                               E8D at psuvm.bitnet
Dept. of Geochemistry
Penn State University
University Park PA  16802

"He is a man of splendid abilities but utterly corrupt.  He shines and stinks
like a rotten mackerel by moonlight."

lowey@sask.UUCP (Kevin Lowey) (05/03/88)

In article <40184E8D@PSUVM>, E8D@PSUVM.BITNET writes:
> I seem to have run into a bug using the procedures OutText and OutTextXY
> in Turbo 4.0 graphics mode.  They reset the CP to the upper left corner of
> the character box.  OutText should only move CP if the horizontal 
> justification
> is Left and OutTextXY shouldn't ever change the Current Position.
>    Does anyone know of a fix for this (aside from storing and retrieving CP)?

  I don't know if this is a bug, but there are two solutions (sort of).  One
is to write your own TEXTOUT routines, which save the CP, perform OutText,
then restores the CP.  

  The second works if you don't need to use the fancy text fonts.  I've found
that if you give the command 

  DIRECTVIDEO := FALSE;

then you can use the WRITE and WRITELN commands to display text (using the 
normal 8*8 box).  I haven't tested it, but I don't think the CP is changed when
you do this.

  The reason this works is TP 4.0 uses direct screen writes when DIRECTVIDEO is
TRUE.  This means any text drawn in graphics mode forms random dots because 
the text is being put directly into screen memory.  However, if DIRECTVIDEO is
FALSE, then TP 4.0 uses the BIOS calls to write to the screen.  These BIOS 
calls know about the graphics modes, and displays the text properly.


______________________________________________________________________________
| Kevin Lowey                    |The above is the personal opinion of Kevin |
| University of Saskatchewan     |Lowey.  It does not reflect the position of|
| Computing Services             |the University of Saskatchewan in any way. |
| SaskTel: (306) 966-4826        |                                           |
| Bitnet:LOWEY@SASK. (preferred) |I am in no way affiliated with any of the  |
| UUCP:    ihnp4!sask!lowey.uucp |above mentioned companies other than U of S|
|________________________________|___________________________________________|