home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_GEN / TVGRAPH.ZIP / TEXTVIEW.DOC < prev    next >
Text File  |  1993-12-23  |  8KB  |  233 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Turbo Pascal Version 6.0,7.0                    }
  5. {                                                       }
  6. {       How To Modify TEXTVIEW unit source code         }
  7. {           to  work with TVGraphic                     }
  8. {                                                       }
  9. {      Richard P. Andresen   October 5, 1993            }
  10. {                                                       }
  11. {*******************************************************}
  12. {ver 1.5}
  13.  
  14. The TEXTVIEW unit is not really useful except to derive
  15. descendents from. Therefore the changes in the source code
  16. to work with TVGraphic are shown here so that you may derive
  17. your own descendents. This is good material to study the
  18. differences between Turbo Vision text and TVGraphic graphic modes.
  19.  
  20. 12/22/93
  21. Version 1.5 NOTE: this unit now uses TVGraphic's intrinsic
  22.                   blinking text cursor.
  23.  
  24. {------------------------------------}
  25.  
  26. To test your modified TEXTVIEW unit, create an instance
  27. of the TTermW window below and insert it into the DeskTop
  28. in the TVGraphic demo program. In general, you should size text
  29. based windows with scrollbars using Charlen and Boxheight since the
  30. standard TVGraphic scrollbars expect this.}
  31.  
  32. Example TVGraphic window that uses a TTerminal device
  33. type
  34.   PTermW = ^TTermW;
  35.   TTermW = object(TWindow)
  36.     TermText: Text;
  37.     Terminal: PTerminal;
  38.     constructor Init;
  39.     procedure HandleEvent(var Event: TEvent); virtual;
  40.   end;
  41.  
  42. constructor TTermW.Init;
  43. var
  44.   R: TRect;
  45.   HorScrollBar, VertScrollBar: PScrollBar;
  46. begin
  47.   R.Assign(10*Charlen,5*Boxheight,60*Charlen,20*Boxheight);
  48.   {or  R.Assign(10*Charlen,5*Boxheight,60*Charlen-1,20*Boxheight-1);
  49.      to avoid overlapping other windows}
  50.   TWindow.Init(R, 'Terminal Window', wnNoNumber);
  51.   HorScrollBar := StandardScrollBar(sbHorizontal or sbHandleKeyboard);
  52.   Insert(HorScrollBar);
  53.   VertScrollBar := StandardScrollBar(sbVertical or sbHandleKeyboard);
  54.   Insert(VertScrollBar);
  55.   GetMaxSubViewSize(R);   {TVGraphic - returns size for views to just fill
  56.            a window. Takes scrollbars and titleblock into account}
  57.   New(Terminal, Init(R, HorScrollBar, VertScrollBar, 4096));
  58.   if Application^.ValidView(Terminal) <> nil then
  59.   begin
  60.     AssignDevice(TermText, Terminal);
  61.     Rewrite(TermText);
  62.     Insert(Terminal);
  63.   end;
  64. end;
  65.  
  66. procedure TTermW.HandleEvent(var Event: TEvent);
  67. begin
  68.   TWindow.HandleEvent(Event);
  69.   if Event.What and evKeyDown <> 0 then
  70.     if Event.KeyCode = kbEnter then Writeln(TermText) else
  71.       Write(TermText, Event.CharCode);
  72. end;
  73. {-----------------------------------}
  74.  
  75. TEXTVIEW Unit Changes
  76.  
  77. Changes are listed in order they will appear in your modified
  78. TextView unit.
  79.  
  80. Rename the Unit "GTXTVIEW" and save it under this name
  81. when you are done with the changes.
  82.  
  83. Interface
  84.  
  85. Replace existing "uses" statement with
  86.   uses MCursor2, MyGraph3, GObjects, GDrivers, GViews, Dos;
  87.  
  88. type
  89.   { TTerminal Object }
  90.  Add these new fields after the Quefront,Queback fields:
  91.     OldLimit,OldDelta : TPoint;  {used to limit redrawing}
  92.     PartialReDraw : boolean;     {used to limit redrawing}
  93.     CurCount : byte;             {used to blink the cursor}
  94.  
  95.  Add these methods
  96.     procedure PartOfSetLimit(X, Y: Integer); virtual; {new with version 1.5}
  97.        {This is the same as used with TMyScroller in the demo program}
  98.  
  99. implementation
  100.  
  101.  Add these constants to match those used in TTerminal.Draw
  102. const
  103.   HSpacing = Charlen;
  104.   VSpacing = Boxheight;
  105.  
  106.  
  107. { TTerminal Object }
  108.  
  109. constructor TTerminal.Init(var Bounds:TRect; AHScrollBar,
  110.   AVScrollBar: PScrollBar; ABufSize: Word);
  111. begin
  112.   Add two statements following the existing statements:
  113.   ..
  114.   ..
  115.   VFont := font8x14;                      {font text will appear in}
  116.   EventMask := EventMask or evTimerTick;  {need to enable TimerTick
  117.                                            events so can flash cursor}
  118. end;
  119.  
  120. procedure TTerminal.Draw;
  121.   {Note that these changes may leave a slim edge at the bottom
  122.   of the view that sometimes does not redraw if the view is not sized
  123.   vertically as a multiple of Boxheight.}
  124.  
  125.   {The demo program shows a very different way of redrawing text
  126.   which makes sense when automatic upward scrolling isn't required.}
  127. var
  128.   Add new variables
  129.   ..
  130.   ..
  131.   YSize,N,Color : integer;
  132.   Glob : TRect;
  133. begin
  134. ----------
  135.  Add this group of statements Before existing statements:
  136.   MCur.Hide;                          {hide the mouse cursor}
  137.   GetVPRelCoords(Glob);               {get viewport relative coords of
  138.                                        outline of this view}
  139.   Color := GetColor(1);                      {get color pair from palette}
  140.   SetFillStyle(solidfill,BackColor(Color));  {set background color}
  141.   SetColor(ForeColor(Color));
  142.  
  143.   SetTextStyle(VFont, HorizDir, 1);
  144.   YSize := (Size.Y+1) div Boxheight;
  145. -----------
  146. In existing statements throughout Draw, change Every instance
  147.   of "Size.Y"
  148.     to YSize
  149.   of "Size.Y-1"
  150.     to YSize-1
  151. (This converts graphic coords back to text mode based on the
  152. TVGraphic constant Boxheight as the height of a text line.)
  153. -----------
  154. Replace   (note - you may have just replaced Size.y-1 per step above - OK)
  155.     "for I := Limit.Y to Size.Y-1 do
  156.       WriteChar(0, I, ' ', 1, Size.X);"
  157.     with
  158.       Bar(Glob.A.x, Glob.A.y+(Limit.Y*Boxheight),
  159.           Glob.B.x, Glob.B.y);
  160. (This erases area below last text line, if any.)
  161. -----------
  162. Need to prevent redrawing of previous lines when just adding
  163. to the current line.
  164.  
  165. Find line "for I := I downto 0 do"
  166.  
  167. Add following If statement immediately before line above
  168.   if (not PartialReDraw) or
  169.      (Limit.y <> OldLimit.y) or (Delta.y <> OldDelta.y) then N := 0
  170.   else N := I;
  171.  
  172. modify line above to read
  173.   for I := I downto N do
  174. ------------
  175. find line  "else S := Copy(S, Delta.X+1, 255);"
  176.  
  177. Add following lines immediately after it
  178.   S := Copy(S,1,Size.x div Charlen); {limit width to window}
  179.   if (not PartialReDraw) or
  180.      (Limit.y <> OldLimit.y) or (Delta.y <> OldDelta.y) then
  181.       {erase line of text only if active line has changed}
  182.     Bar(Glob.A.x, Glob.A.y+(I*Boxheight),
  183.         Glob.B.x, Glob.A.y+((I+1)*Boxheight)-1);
  184.       {write line of text}
  185.     OutTextXY(Glob.A.x, Glob.A.y+(I*Boxheight) + BYOffset, S);
  186.  
  187. Delete next two lines
  188.     WriteStr(...
  189.     WriteChar(...
  190. --------------
  191. Add following statements immediately before the end statement of Draw.
  192.   OldLimit := Limit;
  193.   OldDelta := Delta;
  194.   PartialReDraw := false;
  195.   MCur.Show;
  196. end.      {of TTerminal.Draw}
  197.  
  198.  
  199.  
  200. procedure TTerminal. PartOfSetLimit(X, Y: Integer);
  201. {new with version 1.5}
  202. var
  203.   YSize,XSize : integer;
  204. begin
  205.   XSize := (Size.x+1) div HSpacing;
  206.   YSize := (Size.y+1) div VSpacing;
  207.   Limit.X := X;
  208.   Limit.Y := Y;
  209.   if HScrollBar <> nil then
  210.     HScrollBar^.SetParams(HScrollBar^.Value, 0, X - XSize, XSize - 1,
  211.       HScrollBar^.ArStep);
  212.   if VScrollBar <> nil then
  213.     VScrollBar^.SetParams(VScrollBar^.Value, 0, Y - YSize, YSize - 1,
  214.       VScrollBar^.ArStep);
  215. end;
  216.  
  217.  
  218. procedure TTerminal.StrWrite(var S: TextBuf; Count: Byte);
  219. begin
  220.   ..
  221. If you are working with TV1.0, TV2.0 casts QueFront to longint
  222.   when adding it to Count in a if >= BufSize statement. Reason is to avoid
  223.   arithmetic overflow since text buffer can be up to 65520 bytes long.
  224.   ..
  225.   ..
  226.   ..
  227. At end of StrWrite add new statement:
  228.  
  229. {new} PartialReDraw := true;
  230.     DrawView;                      {draws the line of text and the cursor}
  231. end;
  232.  
  233.