-
Notifications
You must be signed in to change notification settings - Fork 8
/
WIN.PAS
130 lines (98 loc) · 2.96 KB
/
WIN.PAS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
{*******************************************************}
{ }
{ Turbo Pascal Version 6.0 }
{ Window Interface Unit }
{ }
{ Copyright (C) 1989,90 Borland International }
{ }
{*******************************************************}
unit Win;
{$D-,S-}
interface
uses Crt;
type
{ Window title string }
TitleStr = string[63];
{ Window frame characters }
FrameChars = array[1..8] of Char;
{ Window state record }
WinState = record
WindMin, WindMax: Word;
WhereX, WhereY: Byte;
TextAttr: Byte;
end;
const
{ Standard frame character sets }
SingleFrame: FrameChars = 'ÚÄ¿³³ÀÄÙ';
DoubleFrame: FrameChars = 'ÉÍ»ººÈͼ';
{ Direct write routines }
procedure WriteStr(X, Y: Byte; S: String; Attr: Byte);
procedure WriteChar(X, Y, Count: Byte; Ch: Char; Attr: Byte);
{ Window handling routines }
procedure FillWin(Ch: Char; Attr: Byte);
procedure ReadWin(var Buf);
procedure WriteWin(var Buf);
function WinSize: Word;
procedure SaveWin(var W: WinState);
procedure RestoreWin(var W: WinState);
procedure FrameWin(Title: TitleStr; var Frame: FrameChars;
TitleAttr, FrameAttr: Byte);
procedure UnFrameWin;
implementation
{$L WIN}
procedure WriteStr(X, Y: Byte; S: String; Attr: Byte);
external {WIN};
procedure WriteChar(X, Y, Count: Byte; Ch: Char; Attr: Byte);
external {WIN};
procedure FillWin(Ch: Char; Attr: Byte);
external {WIN};
procedure WriteWin(var Buf);
external {WIN};
procedure ReadWin(var Buf);
external {WIN};
function WinSize: Word;
external {WIN};
procedure SaveWin(var W: WinState);
begin
W.WindMin := WindMin;
W.WindMax := WindMax;
W.WhereX := WhereX;
W.WhereY := WhereY;
W.TextAttr := TextAttr;
end;
procedure RestoreWin(var W: WinState);
begin
WindMin := W.WindMin;
WindMax := W.WindMax;
GotoXY(W.WhereX, W.WhereY);
TextAttr := W.TextAttr;
end;
procedure FrameWin(Title: TitleStr; var Frame: FrameChars;
TitleAttr, FrameAttr: Byte);
var
W, H, Y: Word;
begin
W := Lo(WindMax) - Lo(WindMin) + 1;
H := Hi(WindMax) - Hi(WindMin) + 1;
WriteChar(1, 1, 1, Frame[1], FrameAttr);
WriteChar(2, 1, W - 2, Frame[2], FrameAttr);
WriteChar(W, 1, 1, Frame[3], FrameAttr);
if Length(Title) > W - 2 then Title[0] := Chr(W - 2);
WriteStr((W - Length(Title)) shr 1 + 1, 1, Title, TitleAttr);
for Y := 2 to H - 1 do
begin
WriteChar(1, Y, 1, Frame[4], FrameAttr);
WriteChar(W, Y, 1, Frame[5], FrameAttr);
end;
WriteChar(1, H, 1, Frame[6], FrameAttr);
WriteChar(2, H, W - 2, Frame[7], FrameAttr);
WriteChar(W, H, 1, Frame[8], FrameAttr);
Inc(WindMin, $0101);
Dec(WindMax, $0101);
end;
procedure UnFrameWin;
begin
Dec(WindMin, $0101);
Inc(WindMax, $0101);
end;
end.