home *** CD-ROM | disk | FTP | other *** search
- {$S-,R-,I-,V-,B-}
-
- {*********************************************************}
- {* GXMENU.PAS 4.03 *}
- {* Copyright (c) Michael Day 1988 *}
- {* Portions copyright (c) TurboPower Software 1987. *}
- {* Portions copyright (c) Sunny Hill Software 1985, 1986 *}
- {* and used under license to TurboPower Software *}
- {* All rights reserved. *}
- {*********************************************************}
-
- unit GXMenu;
- {-Pulldown Graphic Extended Menu routines}
-
- interface
-
- uses
- tpcrt,
- graph;
-
- var GraphOn : boolean; {set to true when in graph mode}
-
- {------------------------------------------------------------------}
- {draw a string on the screen}
- procedure GTWrite(S:string; row,col,attr:byte);
-
- {------------------------------------------------------------------}
- {Restore screen contents and deallocate buffer space if requested}
- procedure GRestoreWindow(XL,YL,XH,YH:byte;
- Deallocate:Boolean;
- var Covers:Pointer);
-
- {------------------------------------------------------------------}
- {Allocate buffer space if requested and save window contents}
- function GSaveWindow(XL,YL,XH,YH:byte;
- Allocate:Boolean;
- var Covers:Pointer):Boolean;
-
- {------------------------------------------------------------------}
- {Clear a region with specified attribute}
- procedure GClearWindow(XL, YL, XH, YH, Attr : Byte);
-
- {------------------------------------------------------------------}
- {Draws a frame around specified area}
- {--- get a copy of FrameWindow from TPCRT.PAS and rename ---}
- {--- all its FastWrite calls to GTWrite to create this ---}
- {--- be sure to rename the procedure to GFWindow ---}
- procedure GFWindow(LeftCol, TopRow, RightCol, BotRow, FAttr, HAttr : Byte;
- Header : String);
-
-
- {==========================================================================}
-
- implementation
-
- type adsImage = Pointer;
- Rect = record
- Xmin, Ymin, Xmax, Ymax : Integer;
- end;
-
- Var CoversP : adsImage;
- BufBytes : LongInt;
- R : Rect;
-
- {++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
- {Convert row/col numbers to a graphic rectangle used as backdrop for text}
- Procedure ConvertToRect(var R : Rect; XL, YL, XH, YH : integer);
- begin
- With R do
- begin
- Xmin := pred(XL) * TextWidth('M'); {assumes row/col starts with 1,1}
- Ymin := pred(YL) * TextHeight('M');
- Xmax := pred( XH * TextWidth('M') ); {assumes row/col starts with 1,1}
- Ymax := pred( YH * TextHeight('M') );
- end;
- end;
-
- {++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
- {Convert row/col numbers to a graphic rectangle used to surround text}
- Procedure StringToRect(var R:Rect; S:String; col,row:Integer);
- begin
- With R do
- begin
- Xmin := pred(col) * TextWidth('M'); {assumes row/col starts with 1,1}
- Ymin := pred(row) * TextHeight('M');
- Xmax := pred( Xmin + TextWidth(S) );
- Ymax := pred( Ymin + TextHeight(S) );
- end;
- end;
-
- {*****************************************************************************}
- {display text string in graphics mode}
- procedure GTWrite(S:string; row,col,attr:byte);
- begin
- if S <> '' then
- begin
- if GraphOn then {graph screen write}
- begin
- StringToRect(R, S, col, row);
- SetFillStyle(1,attr shr 4);
- Bar(R.Xmin, R.Ymin, R.Xmax, R.Ymax);
- SetColor(attr and $0f);
- OutTextXY(R.Xmin, R.Ymin, S);
- end
- else
- FastWrite(S, row, col, attr); {text screen write}
- end;
- end;
-
- {*****************************************************************************}
- {Allocate buffer space if requested and save window contents}
- function GSaveWindow(XL, YL, XH, YH : byte;
- Allocate : Boolean;
- var Covers : Pointer) : Boolean;
-
- begin
- if GraphOn then {graph screen save}
- begin
- GSaveWindow := True; {assume success}
- CoversP := Covers;
- ConvertToRect(R, XL, YL, XH, YH); {convert to pixel data}
-
- if Allocate then {compute bytes needed for screen buffer}
- begin
- BufBytes := ImageSize(R.Xmin, R.Ymin, R.Xmax, R.Ymax);
- if MaxAvail < BufBytes then {make sure enough memory is available}
- begin
- GSaveWindow := False;
- Exit;
- end
- else
- Begin
- GetMem(CoversP, BufBytes); {allocate the screen buffer}
- Covers := CoversP;
- End;
- end;
-
- {save current contents to the screen buffer}
- GetImage(R.Xmin, R.Ymin, R.Xmax, R.Ymax, CoversP^);
- end
-
- else {text screen save}
- GSaveWindow := SaveWindow(XL, YL, XH, YH, Allocate, Covers);
- end;
-
- {*****************************************************************************}
- {Restore screen contents and deallocate buffer space if requested}
- procedure GRestoreWindow(XL, YL, XH, YH : byte;
- Deallocate : Boolean;
- var Covers : Pointer);
- begin
- if GraphOn then {graph screen restore}
- begin
- CoversP := Covers;
- ConvertToRect(R, XL, YL, XH, YH); {convert to pixel data}
-
- {Restore current contents to the screen buffer}
- PutImage(R.Xmin,R.Ymin,CoversP^,NormalPut);
-
- if Deallocate then {deallocate buffer space if requested}
- begin
- BufBytes := ImageSize(R.Xmin, R.Ymin, R.Xmax, R.Ymax);
- FreeMem(CoversP, BufBytes);
- Covers := nil;
- end;
- end
- else
- RestoreWindow(XL, YL, XH, YH, Deallocate, Covers); {text restore}
- end;
-
- {*****************************************************************************}
- {Clear a region with specified attribute}
- procedure GClearWindow(XL, YL, XH, YH, Attr : Byte);
- var
- WordsPerRow : Word;
- Row : Word;
- Span : string;
- begin
- if GraphOn then {graph mode clear}
- begin
- ConvertToRect(R, XL, YL, XH, YH); {convert to pixel data}
- SetFillStyle(1,attr shr 4);
- Bar(R.Xmin, R.Ymin, R.Xmax, R.Ymax);
- end
- else
- begin {text mode clear}
- WordsPerRow := Succ(XH-XL);
- Span[0] := Chr(WordsPerRow);
- FillChar(Span[1], WordsPerRow, ' ');
- for Row := YL to YH do
- GTWrite(Span, Row, XL, Attr);
- end;
- end;
- {$I MYSUBS.PAS}
- {*****************************************************************************}
- {Draws a frame around specified area}
- procedure GFWindow(LeftCol, TopRow, RightCol, BotRow, FAttr, HAttr : Byte;
- Header : String);
- var
- HeaderLen : Byte absolute Header;
- Row, Width, HeaderPos : Byte;
- Span : String[80];
- SpanLen : Byte absolute Span;
- begin
- {calculate width of window and position of header}
- SpanLen := Succ(RightCol-LeftCol);
- Width := SpanLen-2;
-
- {construct the upper border and draw it}
- FillChar(Span[2], Width, FrameChars[Horiz]);
- Span[1] := FrameChars[ULeft];
- Span[SpanLen] := FrameChars[URight];
- GTWrite(Span, TopRow, LeftCol, FAttr);
-
- {draw the vertical bars}
- for Row := Succ(TopRow) to Pred(BotRow) do begin
- GTWrite(FrameChars[Vert], Row, LeftCol, FAttr);
- GTWrite(FrameChars[Vert], Row, RightCol, FAttr);
- end;
-
- {draw the bottom border}
- Span[1] := FrameChars[LLeft];
- Span[SpanLen] := FrameChars[LRight];
- GTWrite(Span, BotRow, LeftCol, FAttr);
-
- if HeaderLen > 0 then begin
- if HeaderLen > Width then
- HeaderLen := Width;
- HeaderPos := (SpanLen-HeaderLen) shr 1;
- GTWrite(Header, TopRow, LeftCol+HeaderPos, HAttr);
- end;
- end;
-
- {******************************************************}
- {Initialization needed for the unit}
- begin
- GraphOn := false;
- end.
-