home *** CD-ROM | disk | FTP | other *** search
- unit TPW60;
-
- interface
-
- uses
- crt;
-
- const
- maxitem = 10; {Maximum items in a menu list}
- mw = 30; {Maximum windows open at one time}
- hidecursor : integer = 8192;
-
- type
- str80 = string[80];
- BytePtr = ^Byte;
- TPWrec = Record
- wrow,wrows,wcol,wcols,wattr,wshdw:integer;wlastx,wlasty:byte;
- end;
- ItemList= array [1..MaxItem] of string[40];
- menurec = record
- item:itemlist;
- itemcount,startpos,curntpos,hlattr,flattr,bartype:integer;
- flon:boolean;
- end;
-
- var
- TPWstat : array [0..mw] of TPWrec;
- TPWptr : array [1..mw] of BytePtr;
- oldcursor: integer;
- IDX : byte;
-
- procedure TPWprint(row,col:integer;strdat:str80;tattr:integer);
- procedure TPWfill (row,col,rows,cols:integer;ch:char;tattr:integer);
- procedure TPWattr (row,col,rows,cols,tattr:integer);
- procedure TPWprintc(row,colL,colR:integer;strdat:str80;tattr:integer);
- procedure TPWborder(colornum:integer);
- procedure TPWbox(col,row,col1,row1,wattr,wbattr,brdrsel,zoom,sattr,shadow:integer;TPWptr:byteptr);
- procedure TPWrbox(row,col,rows,cols,shadow:integer;TPWptr:byteptr);
- procedure TPWtitle(loc,row,col,rows,cols:integer;strdat:str80;tattr:integer);
- procedure MakeWindow(row,col,rows,cols,wtattr,wbtattr,brdrsel,stattr,shadow,zoom:integer);
- procedure MakeBox(row,col,rows,cols,wtattr,wbtattr,brdrsel,stattr,shadow,zoom:integer);
- procedure TitleWindow(dir,tattr:integer;title:str80);
- procedure RemoveWindow;
- procedure ClearWindow;
- procedure PrtWindow(row,col:integer;strdat:str80);
- procedure PrtCWindow(row:integer;strdat:str80);
- procedure CursorChange(new:integer;var old:integer);
- procedure MakeMenu(var menu:menurec);
- procedure VideoOn;
- procedure VideoOff;
- procedure EGA43;
- function Attr (fore,back:integer):integer;
-
- implementation
-
- {$L TPW60}
- procedure TPWprint; external;
- procedure TPWprintc; external;
- procedure TPWfill; external;
- procedure TPWattr; external;
- procedure TPWborder; external;
- procedure TPWbox; external;
- procedure TPWrbox; external;
- procedure TPWtitle; external;
- procedure VideoOff; external;
- procedure VideoOn; external;
- procedure EGA43; external;
-
- function attr;
- var temp:byte;
- begin
- temp := (back*16)+fore;
- if fore>15 then temp := temp+112;
- attr := temp
- end;
-
- procedure makewindow;
- var
- wsize:integer;
- begin
- if IDX>=mw then writeln('Too many windows!')
- else
- begin
- if shadow <1 then wsize:=(cols*rows*2) else wsize:=((rows+1)*(cols+2)*2);
- if (0<memavail) and (memavail<=(wsize shr 4)) then
- writeln('No memory available!')
- else
- begin
- TPWstat[IDX].wlastx := wherex;
- TPWstat[IDX].wlasty := wherey;
- IDX:= IDX+1;
- with TPWstat[IDX] do
- begin
- wrow := row; wcol := col; wrows := rows;
- wcols := cols;wattr := wtattr;wshdw := shadow;
- end;
- getmem(TPWptr[IDX],wsize);
- TPWbox(col-1,row-1,col+cols-2,row+rows-2,wtattr,wbtattr,brdrsel,zoom,stattr,shadow,TPWptr[IDX]);
- window(col+1,row+1,col+cols-2,row+rows-2);
- textattr := wtattr;
- gotoxy(1,1);
- end
- end;
- end;
-
- procedure titlewindow;
- begin
- with tpwstat[IDX] do
- begin
- TPWtitle(dir,wrow,wcol,wrows,wcols,title,tattr);
- end;
- end;
-
- procedure removewindow;
- var
- wsize:integer;
- begin
- if IDX=0 then writeln('No windows left!')
- else
- begin
- with TPWstat[IDX] do
- begin
- if wshdw < 1 then wsize:=(wcols*wrows*2) else wsize:=((wrows+1)*(wcols+2)*2);
- TPWrbox(wrow,wcol,wrows,wcols,wshdw,TPWptr[IDX]);
- freemem(TPWptr[IDX],wsize);
- end;
- IDX:=IDX-1;
- with TPWstat[IDX] do
- begin
- if IDX=0 then window(1,1,80,25) else window(wcol+1,wrow+1,wcol+wcols-2,wrow+wrows-2);
- textattr:=wattr;
- gotoxy(wlastx,wlasty);
- end;
- end;
- end;
-
- procedure clearwindow;
- begin
- with TPWstat[IDX] do
- begin
- TPWfill(wrow+1,wcol+1,wrows-2,wcols-2,' ',wattr);
- end;
- end;
-
- procedure prtwindow;
- begin
- with TPWstat[IDX] do
- begin
- TPWprint(wrow+row,wcol+col,strdat,wattr);
- end;
- end;
-
- procedure prtcwindow;
- begin
- with TPWstat[IDX] do
- begin
- TPWprintc(wrow+row,wcol,wcol+wcols,strdat,wattr);
- end;
- end;
-
- procedure makebox;
- begin
- TPWbox(col-1,row-1,col+cols-2,row+rows-2,wtattr,wbtattr,brdrsel,zoom,stattr,shadow,NIL);
- end;
-
- procedure cursorchange;
- begin
- inline($31/$C0/$8E/$C0/$26/$A1/$60/$04/$C4/$7E/<OLD/$AB/
- $B4/$01/$8B/$4E/<NEW/$CD/$10);
- end;
-
- procedure makemenu;
- var
- done:boolean;
- mloop : integer;
- ch : char;
- ch1 : char;
- begin
- done := false;
- with TPWstat[IDX],menu do
- begin
- for mloop := 1 to itemcount do
- begin
- TPWprint(wrow+mloop,wcol+(wcols shr 1)-length(item[mloop]) shr 1,item[mloop],wattr);
- if flon then TPWprint(wrow+mloop,wcol+(wcols shr 1)-length(item[mloop]) shr 1,item[mloop][1],FLattr);
- end;
- if curntpos = 0 then if startpos = 0 then curntpos:=1 else curntpos := startpos;
- repeat
- case bartype of
- 1 : TPWattr(wrow+curntpos,wcol+1,1,wcols-2,hlattr);
- 2 : TPWattr(wrow+curntpos,wcol+(wcols shr 1) - (length(item[curntpos]) shr 1)-1,1,
- length(item[curntpos]) + 2,hlattr);
- 3 : TPWprint(wrow+curntpos,wcol+(wcols shr 1)-length(item[curntpos]) shr 1-2,'═',hlattr);
- end;
- ch:=readkey;
- if ch=#0 then ch1:=readkey;
- case bartype of
- 3 : TPWprint(wrow+curntpos,wcol+(wcols shr 1)-length(item[curntpos]) shr 1-2,' ',wattr)
- else
- TPWattr(wrow+curntpos,wcol+1,1,wcols-2,wattr);
- TPWprint(wrow+curntpos,wcol+(wcols shr 1)-length(item[curntpos]) shr 1,item[curntpos],wattr);
- if flon then TPWprint(wrow+curntpos,wcol+(wcols shr 1)-length(item[curntpos]) shr 1,item[curntpos][1],FLattr);
- end;
- if (bartype<>0) and (ch=#0) then
- case ord(ch1) of
- 72,75,45,56,52 : curntpos := pred(curntpos);
- 80,77,43,50,54 : curntpos := succ(curntpos);
- end;
- if flon then
- for mloop := 1 to itemcount do
- begin
- if upcase(ch) = upcase(item[mloop][1]) then
- begin
- curntpos := mloop;
- done := true;
- end;
- end;
- if (not flon) or (bartype <> 0) then if ch = #13 then done := true;
- if ch = #27 then
- begin
- curntpos := 0;
- done := true;
- end;
- if curntpos > itemcount then curntpos := 1;
- if curntpos < 1 then curntpos := itemcount;
- until done;
- end;
- end;
-
- begin
- IDX := 0;
- with TPWstat[IDX] do
- begin
- Wrow := 1;
- Wcol := 1;
- Wrows := 25;
- Wcols := 80;
- Wattr := attr(7,0);
- Wlastx := WhereX;
- Wlasty := WhereY;
- TPWfill ( 1, 1,25,80,' ',Wattr);
- end;
- end.
-