home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1994 #1
/
monster.zip
/
monster
/
PROG_GEN
/
TVGRAPH.ZIP
/
TEXTVIEW.DOC
< prev
next >
Wrap
Text File
|
1993-12-23
|
8KB
|
233 lines
{*******************************************************}
{ }
{ Turbo Pascal Version 6.0,7.0 }
{ }
{ How To Modify TEXTVIEW unit source code }
{ to work with TVGraphic }
{ }
{ Richard P. Andresen October 5, 1993 }
{ }
{*******************************************************}
{ver 1.5}
The TEXTVIEW unit is not really useful except to derive
descendents from. Therefore the changes in the source code
to work with TVGraphic are shown here so that you may derive
your own descendents. This is good material to study the
differences between Turbo Vision text and TVGraphic graphic modes.
12/22/93
Version 1.5 NOTE: this unit now uses TVGraphic's intrinsic
blinking text cursor.
{------------------------------------}
To test your modified TEXTVIEW unit, create an instance
of the TTermW window below and insert it into the DeskTop
in the TVGraphic demo program. In general, you should size text
based windows with scrollbars using Charlen and Boxheight since the
standard TVGraphic scrollbars expect this.}
Example TVGraphic window that uses a TTerminal device
type
PTermW = ^TTermW;
TTermW = object(TWindow)
TermText: Text;
Terminal: PTerminal;
constructor Init;
procedure HandleEvent(var Event: TEvent); virtual;
end;
constructor TTermW.Init;
var
R: TRect;
HorScrollBar, VertScrollBar: PScrollBar;
begin
R.Assign(10*Charlen,5*Boxheight,60*Charlen,20*Boxheight);
{or R.Assign(10*Charlen,5*Boxheight,60*Charlen-1,20*Boxheight-1);
to avoid overlapping other windows}
TWindow.Init(R, 'Terminal Window', wnNoNumber);
HorScrollBar := StandardScrollBar(sbHorizontal or sbHandleKeyboard);
Insert(HorScrollBar);
VertScrollBar := StandardScrollBar(sbVertical or sbHandleKeyboard);
Insert(VertScrollBar);
GetMaxSubViewSize(R); {TVGraphic - returns size for views to just fill
a window. Takes scrollbars and titleblock into account}
New(Terminal, Init(R, HorScrollBar, VertScrollBar, 4096));
if Application^.ValidView(Terminal) <> nil then
begin
AssignDevice(TermText, Terminal);
Rewrite(TermText);
Insert(Terminal);
end;
end;
procedure TTermW.HandleEvent(var Event: TEvent);
begin
TWindow.HandleEvent(Event);
if Event.What and evKeyDown <> 0 then
if Event.KeyCode = kbEnter then Writeln(TermText) else
Write(TermText, Event.CharCode);
end;
{-----------------------------------}
TEXTVIEW Unit Changes
Changes are listed in order they will appear in your modified
TextView unit.
Rename the Unit "GTXTVIEW" and save it under this name
when you are done with the changes.
Interface
Replace existing "uses" statement with
uses MCursor2, MyGraph3, GObjects, GDrivers, GViews, Dos;
type
{ TTerminal Object }
Add these new fields after the Quefront,Queback fields:
OldLimit,OldDelta : TPoint; {used to limit redrawing}
PartialReDraw : boolean; {used to limit redrawing}
CurCount : byte; {used to blink the cursor}
Add these methods
procedure PartOfSetLimit(X, Y: Integer); virtual; {new with version 1.5}
{This is the same as used with TMyScroller in the demo program}
implementation
Add these constants to match those used in TTerminal.Draw
const
HSpacing = Charlen;
VSpacing = Boxheight;
{ TTerminal Object }
constructor TTerminal.Init(var Bounds:TRect; AHScrollBar,
AVScrollBar: PScrollBar; ABufSize: Word);
begin
Add two statements following the existing statements:
..
..
VFont := font8x14; {font text will appear in}
EventMask := EventMask or evTimerTick; {need to enable TimerTick
events so can flash cursor}
end;
procedure TTerminal.Draw;
{Note that these changes may leave a slim edge at the bottom
of the view that sometimes does not redraw if the view is not sized
vertically as a multiple of Boxheight.}
{The demo program shows a very different way of redrawing text
which makes sense when automatic upward scrolling isn't required.}
var
Add new variables
..
..
YSize,N,Color : integer;
Glob : TRect;
begin
----------
Add this group of statements Before existing statements:
MCur.Hide; {hide the mouse cursor}
GetVPRelCoords(Glob); {get viewport relative coords of
outline of this view}
Color := GetColor(1); {get color pair from palette}
SetFillStyle(solidfill,BackColor(Color)); {set background color}
SetColor(ForeColor(Color));
SetTextStyle(VFont, HorizDir, 1);
YSize := (Size.Y+1) div Boxheight;
-----------
In existing statements throughout Draw, change Every instance
of "Size.Y"
to YSize
of "Size.Y-1"
to YSize-1
(This converts graphic coords back to text mode based on the
TVGraphic constant Boxheight as the height of a text line.)
-----------
Replace (note - you may have just replaced Size.y-1 per step above - OK)
"for I := Limit.Y to Size.Y-1 do
WriteChar(0, I, ' ', 1, Size.X);"
with
Bar(Glob.A.x, Glob.A.y+(Limit.Y*Boxheight),
Glob.B.x, Glob.B.y);
(This erases area below last text line, if any.)
-----------
Need to prevent redrawing of previous lines when just adding
to the current line.
Find line "for I := I downto 0 do"
Add following If statement immediately before line above
if (not PartialReDraw) or
(Limit.y <> OldLimit.y) or (Delta.y <> OldDelta.y) then N := 0
else N := I;
modify line above to read
for I := I downto N do
------------
find line "else S := Copy(S, Delta.X+1, 255);"
Add following lines immediately after it
S := Copy(S,1,Size.x div Charlen); {limit width to window}
if (not PartialReDraw) or
(Limit.y <> OldLimit.y) or (Delta.y <> OldDelta.y) then
{erase line of text only if active line has changed}
Bar(Glob.A.x, Glob.A.y+(I*Boxheight),
Glob.B.x, Glob.A.y+((I+1)*Boxheight)-1);
{write line of text}
OutTextXY(Glob.A.x, Glob.A.y+(I*Boxheight) + BYOffset, S);
Delete next two lines
WriteStr(...
WriteChar(...
--------------
Add following statements immediately before the end statement of Draw.
OldLimit := Limit;
OldDelta := Delta;
PartialReDraw := false;
MCur.Show;
end. {of TTerminal.Draw}
procedure TTerminal. PartOfSetLimit(X, Y: Integer);
{new with version 1.5}
var
YSize,XSize : integer;
begin
XSize := (Size.x+1) div HSpacing;
YSize := (Size.y+1) div VSpacing;
Limit.X := X;
Limit.Y := Y;
if HScrollBar <> nil then
HScrollBar^.SetParams(HScrollBar^.Value, 0, X - XSize, XSize - 1,
HScrollBar^.ArStep);
if VScrollBar <> nil then
VScrollBar^.SetParams(VScrollBar^.Value, 0, Y - YSize, YSize - 1,
VScrollBar^.ArStep);
end;
procedure TTerminal.StrWrite(var S: TextBuf; Count: Byte);
begin
..
If you are working with TV1.0, TV2.0 casts QueFront to longint
when adding it to Count in a if >= BufSize statement. Reason is to avoid
arithmetic overflow since text buffer can be up to 65520 bytes long.
..
..
..
At end of StrWrite add new statement:
{new} PartialReDraw := true;
DrawView; {draws the line of text and the cursor}
end;