This repository has been archived by the owner on Jun 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathasciitab.pas
322 lines (282 loc) · 10.1 KB
/
asciitab.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
{********[ SOURCE FILE OF GRAPHICAL FREE VISION ]**********}
{ }
{ System independent GRAPHICAL clone of ASCIITAB.PAS }
{ }
{ Interface Copyright (c) 1992 Borland International }
{ }
{ Copyright (c) 2002 by Pierre Muller }
{****************[ THIS CODE IS FREEWARE ]*****************}
{ }
{ This sourcecode is released for the purpose to }
{ promote the pascal language on all platforms. You may }
{ redistribute it and/or modify with the following }
{ DISCLAIMER. }
{ }
{ This SOURCE CODE is distributed "AS IS" WITHOUT }
{ WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR }
{ ANY OTHER WARRANTIES WHETHER EXPRESSED OR IMPLIED. }
{ }
{*****************[ SUPPORTED PLATFORMS ]******************}
{ 16 and 32 Bit compilers }
{ DPMI - FPC 0.9912+ (GO32V2) (32 Bit) }
{ WIN95/NT - FPC 0.9912+ (32 Bit) }
{ }
UNIT AsciiTab;
{<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
INTERFACE
{<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
{====Include file to sort compiler platform out =====================}
{$I platform.inc}
{====================================================================}
{==== Compiler directives ===========================================}
{$X+} { Extended syntax is ok }
{$R-} { Disable range checking }
{$S-} { Disable Stack Checking }
{$I-} { Disable IO Checking }
{$Q-} { Disable Overflow Checking }
{$V-} { Turn off strict VAR strings }
{====================================================================}
USES FVConsts, Objects, Drivers, Views, App; { Standard GFV units }
{***************************************************************************}
{ PUBLIC OBJECT DEFINITIONS }
{***************************************************************************}
{---------------------------------------------------------------------------}
{ TTABLE OBJECT - 32x32 matrix of all chars }
{---------------------------------------------------------------------------}
type
PTable = ^TTable;
TTable = object(TView)
procedure Draw; virtual;
procedure HandleEvent(var Event:TEvent); virtual;
private
procedure DrawCurPos(enable : boolean);
end;
{---------------------------------------------------------------------------}
{ TREPORT OBJECT - View with details of current char }
{---------------------------------------------------------------------------}
PReport = ^TReport;
TReport = object(TView)
ASCIIChar: LongInt;
constructor Load(var S: TStream);
procedure Draw; virtual;
procedure HandleEvent(var Event:TEvent); virtual;
procedure Store(var S: TStream);
end;
{---------------------------------------------------------------------------}
{ TASCIIChart OBJECT - the complete AsciiChar window }
{---------------------------------------------------------------------------}
PASCIIChart = ^TASCIIChart;
TASCIIChart = object(TWindow)
Report: PReport;
Table: PTable;
constructor Init;
constructor Load(var S: TStream);
procedure Store(var S: TStream);
procedure HandleEvent(var Event:TEvent); virtual;
end;
{---------------------------------------------------------------------------}
{ AsciiTableCommandBase }
{---------------------------------------------------------------------------}
const
AsciiTableCommandBase: Word = 910;
{---------------------------------------------------------------------------}
{ Registrations records }
{---------------------------------------------------------------------------}
RTable: TStreamRec = (
ObjType: idTable;
VmtLink: Ofs(TypeOf(TTable)^);
Load: @TTable.Load;
Store: @TTable.Store
);
RReport: TStreamRec = (
ObjType: idReport;
VmtLink: Ofs(TypeOf(TReport)^);
Load: @TReport.Load;
Store: @TReport.Store
);
RASCIIChart: TStreamRec = (
ObjType: idASCIIChart;
VmtLink: Ofs(TypeOf(TASCIIChart)^);
Load: @TASCIIChart.Load;
Store: @TASCIIChart.Store
);
{---------------------------------------------------------------------------}
{ Registration procedure }
{---------------------------------------------------------------------------}
procedure RegisterASCIITab;
{<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
IMPLEMENTATION
{<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
{***************************************************************************}
{ OBJECT METHODS }
{***************************************************************************}
{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
{ TTable OBJECT METHODS }
{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
procedure TTable.Draw;
var
NormColor : byte;
B : TDrawBuffer;
x,y : sw_integer;
begin
NormColor:=GetColor(1);
For y:=0 to size.Y-1 do begin
For x:=0 to size.X-1 do
B[x]:=(NormColor shl 8) or ((y*Size.X+x) and $ff);
WriteLine(0,Y,Size.X,1,B);
end;
DrawCurPos(true);
end;
procedure TTable.DrawCurPos(enable : boolean);
var
Color : byte;
B : word;
begin
Color:=GetColor(1);
{ add blinking if enable }
If Enable then
Color:=((Color and $F) shl 4) or (Color shr 4);
B:=(Color shl 8) or ((Cursor.Y*Size.X+Cursor.X) and $ff);
WriteLine(Cursor.X,Cursor.Y,1,1,B);
end;
procedure TTable.HandleEvent(var Event:TEvent);
var
CurrentPos : TPoint;
Handled : boolean;
procedure SetTo(xpos, ypos : sw_integer);
var
newchar : ptrint;
begin
newchar:=(ypos*size.X+xpos) and $ff;
DrawCurPos(false);
SetCursor(xpos,ypos);
Message(Owner,evCommand,AsciiTableCommandBase,
pointer(newchar));
DrawCurPos(true);
ClearEvent(Event);
end;
begin
case Event.What of
evMouseDown :
begin
If MouseInView(Event.Where) then
begin
MakeLocal(Event.Where, CurrentPos);
SetTo(CurrentPos.X, CurrentPos.Y);
exit;
end;
end;
evKeyDown :
begin
Handled:=true;
case Event.Keycode of
kbUp : if Cursor.Y>0 then
SetTo(Cursor.X,Cursor.Y-1);
kbDown : if Cursor.Y<Size.Y-1 then
SetTo(Cursor.X,Cursor.Y+1);
kbLeft : if Cursor.X>0 then
SetTo(Cursor.X-1,Cursor.Y);
kbRight: if Cursor.X<Size.X-1 then
SetTo(Cursor.X+1,Cursor.Y);
kbHome : SetTo(0,0);
kbEnd : SetTo(Size.X-1,Size.Y-1);
else
Handled:=false;
end;
if Handled then
exit;
end;
end;
inherited HandleEvent(Event);
end;
{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
{ TReport OBJECT METHODS }
{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
constructor TReport.Load(var S: TStream);
begin
Inherited Load(S);
S.Read(AsciiChar,Sizeof(AsciiChar));
end;
procedure TReport.Draw;
var
stHex,stDec : string[3];
s : string;
begin
Str(AsciiChar,StDec);
while length(stDec)<3 do
stDec:=' '+stDec;
stHex:=hexstr(AsciiChar,2);
s:='Char "'+chr(AsciiChar)+'" Decimal: '+
StDec+' Hex: $'+StHex+
' '; // //{!ss:fill gap. FormatStr function using be better}
WriteStr(0,0,S,1);
end;
procedure TReport.HandleEvent(var Event:TEvent);
begin
if (Event.what=evCommand) and
(Event.Command = AsciiTableCommandBase) then
begin
AsciiChar:=Event.InfoLong;
Draw;
ClearEvent(Event);
end
else inherited HandleEvent(Event);
end;
procedure TReport.Store(var S: TStream);
begin
Inherited Store(S);
S.Write(AsciiChar,Sizeof(AsciiChar));
end;
{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
{ TAsciiChart OBJECT METHODS }
{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
constructor TASCIIChart.Init;
var
R : Trect;
begin
R.Assign(0,0,34,12);
Inherited Init(R,'Ascii table',wnNoNumber);
Flags:=Flags and not (wfGrow or wfZoom);
Palette:=wpGrayWindow;
R.Assign(1,10,33,11);
New(Report,Init(R));
Report^.Options:=Report^.Options or ofFramed;
Insert(Report);
R.Assign(1,1,33,9);
New(Table,Init(R));
Table^.Options:=Table^.Options or (ofSelectable+ofTopSelect);
Insert(Table);
Table^.Select;
end;
constructor TASCIIChart.Load(var S: TStream);
begin
Inherited Load(S);
GetSubViewPtr(S,Table);
GetSubViewPtr(S,Report);
end;
procedure TASCIIChart.Store(var S: TStream);
begin
Inherited Store(S);
PutSubViewPtr(S,Table);
PutSubViewPtr(S,Report);
end;
procedure TASCIIChart.HandleEvent(var Event:TEvent);
begin
if (Event.what=evCommand) and
(Event.Command = AsciiTableCommandBase) then
begin
Report^.HandleEvent(Event);
end
else inherited HandleEvent(Event);
end;
{---------------------------------------------------------------------------}
{ Registration procedure }
{---------------------------------------------------------------------------}
procedure RegisterASCIITab;
begin
RegisterType(RTable);
RegisterType(RReport);
RegisterType(RAsciiChart);
end;
END.