-
Notifications
You must be signed in to change notification settings - Fork 1
/
aedcho2.pas
560 lines (526 loc) · 16.5 KB
/
aedcho2.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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
(*
Unit to handle selection menus with dynamic variables.
Compatible to be used with Unit VIDE
Last Modified: 22/08/2016.
Coded by Velorek.
*)
Unit AEDCho2;
INTERFACE
Uses Video,Vidutil,Keyboard;
Type
tmNodo = ^tmenulist;
tMenulist = record
nChoice :string; {New choice}
nListCount :integer; {# elements}
mBackColor : integer; {Background color}
mForeColor : integer; {Foreground color}
mSBackColor : integer; {BC when selected}
mSForeColor : integer; {FC when selected}
xWhere : integer;
yWhere : integer;
mNext : tmNodo; {Move forward}
mBack : tmNodo; {move backward}
end;
Var
ErrorCode : integer; { errorcode standard Int}
kglobal : char; {monitors key strokes }
mfirst,mLast,mCurrent : tmNodo; {Shorcut pointers to list}
b2,f2,bs2,fs2 : integer;
daIndex : integer; { List's Cardinal}
firsttime : Boolean; { To control whether an opt. was selected for the first time}
Procedure cMenu(var mHandler: tmNodo;b1,f1,bs1,fs1:integer);
Procedure Add_item(var mHandler : tmNodo;nItem:string;x,y:integer);
Procedure Update(var mHandler : tmNodo;nItem:string;num:integer);
Procedure Start_vMenu(var mHandler:tmNodo);
Procedure Start_hMenu(var mHandler: tmNodo);
procedure vscroll(var menu1:tmnodo;x1,y1:integer;list1:array of string;show_index,b1,f1,bs1,fs1:integer);
Procedure Fondo(num : integer);
Procedure Fondo2(b1,c1 : integer;fillch:char);
Procedure ChartoInt(ch:char;var i:byte);
Procedure Start_Table(mHandler: tmNodo;var mdata:string; cols : integer; vertical:boolean);
Procedure gotoP(var mHandler:tmNodo;po:integer);
Procedure Crumble(mHandler : tmNodo);
Procedure lSquare(x1,y1,x2,y2,bcolor,fcolor : integer;single:boolean);
Procedure dline(x1,y1,x2,bcolor,fcolor : integer);
Procedure mDisplay;
IMPLEMENTATION
Procedure ChartoInt(ch:char;var i:byte);
{Alternatively use ORD}
var j:byte;
begin
for j:=0 to 255 do
begin
if chr(j) = ch then i:=j;
end;
End;
Procedure dline(x1,y1,x2,bcolor,fcolor : integer);
(* Draws a HLine *)
var i : integer;
Begin
for i:=x1 to x2 do
esc(i,y1,chr(196),bcolor,fcolor,false);
updatescreen(true);
End;
Procedure lSquare(x1,y1,x2,y2,bcolor,fcolor : integer;single:boolean);
(* Draws a square *)
var i,j : integer;
Begin
if single then begin
{sides}
for i:=x1 to x2 do begin
esc(i,y1,chr(196),bcolor,fcolor,false);
esc(i,y2,chr(196),bcolor,fcolor,false);
end;
for j:=y1 to y2 do begin
esc(x1,j,chr(179),bcolor,fcolor,false);
esc(x2,j,chr(179),bcolor,fcolor,false);
end;
{corners}
esc(x1,y1,chr(218),bcolor,fcolor,false);
esc(x2,y1,chr(191),bcolor,fcolor,false);
esc(x1,y2,chr(192),bcolor,fcolor,false);
esc(x2,y2,chr(217),bcolor,fcolor,false);
end
else begin
{sides}
for i:=x1 to x2 do begin
esc(i,y1,chr(205),bcolor,fcolor,false);
esc(i,y2,chr(205),bcolor,fcolor,false);
end;
for j:=y1 to y2 do begin
esc(x1,j,chr(186),bcolor,fcolor,false);
esc(x2,j,chr(186),bcolor,fcolor,false);
end;
{corners}
esc(x1,y1,chr(201),bcolor,fcolor,false);
esc(x2,y1,chr(187),bcolor,fcolor,false);
esc(x1,y2,chr(200),bcolor,fcolor,false);
esc(x2,y2,chr(188),bcolor,fcolor,false);
end;
updatescreen(true);
end;
Procedure Fondo(num : integer);
var i,j : integer;
Begin
for j:=1 to screenheight do
for i:=1 to screenwidth do
esc(i,j,chr(32),num,num,false);
setcursorpos(0,0);
updatescreen(true);
end;
Procedure Fondo2(b1,c1 : integer;fillch:char);
var i,j : integer;
Begin
for j:=1 to screenheight do
for i:=1 to screenwidth do
esc(i,j,fillch,b1,c1,false);
setcursorpos(0,0);
updatescreen(true);
end;
Procedure Crumble(mHandler : tmNodo);
{ Disposes the memory}
var aux,aux2 : tmNodo;
Begin
aux:=mLast;
{ if aux=mFirst then dispose(aux);}
while aux <> mFirst do
Begin
aux2:=aux;
dispose(aux2);
aux:=aux^.mback;
End;
End;
Procedure mDisplay;
var
aux:tmNodo;
Begin
aux:=mFirst;
while aux <> mFirst^.mBack do begin
esc(aux^.xwhere,aux^.ywhere,aux^.nChoice,aux^.mBackcolor,aux^.mForecolor,false);
aux:=aux^.mNext;
end;
esc(aux^.xwhere,aux^.ywhere,aux^.nChoice,aux^.mBackcolor,aux^.mForecolor,false);
aux:=aux^.mNext;
end;
Procedure cMenu(var mHandler:tmNodo;b1,f1,bs1,fs1:integer);
(* Creates the group associated to the menu array
mHandler => Dyanamic List.
MID => Group's name identifier.
b1,f1 => back & fore ground colors ; bs1,fs1 => colors when selected
*)
Begin
daIndex:=1;
mFirst := nil;
mCurrent := nil;
{mcurrent^.nlistcount:=0;}
// firsttime:=true;
mHandler := nil; {initiate the dynamic list}
b2:=b1;
f2:=f1;
bs2:=bs1;
fs2:=fs1;
End;
Procedure Add_item(var mHandler:tmNodo;nItem:string;x,y:integer);
(**)
var current,other,former:tmNodo;
Begin
If ((mHandler=nil) and (mFirst = nil)) then begin
new(mHandler);
with mHandler^ do begin
mback := nil;
nListCount := daIndex;
nChoice := nItem;
mBackColor := b2;
mForeColor := f2;
mSBackColor := bs2;
mSForeColor := fs2;
xWhere := x;
yWhere := y;
mFirst := mHandler; {Always points to #1 item }
Former:=mFirst;
current:=former;
mBack:=nil;
mFirst^.mNext := mFirst;
mFirst^.mBack := mFirst;
mLast:=mFirst;
end;
End
Else Begin
Former:=Current;
new(other);
former^.mNext := other;
other^.mBack := former;
mLast := other; {Always points to latest item}
mFirst^.mBack := mLast; {we close the circular list}
other^.mNext := mFirst;
daIndex := daIndex +1;
with other^ do Begin
nListCount := daIndex;
nChoice := nItem;
mBackColor := b2;
mForeColor := f2;
mSBackColor := bs2;
mSForeColor := fs2;
xWhere := x;
yWhere := y;
mLast^.mNext := mFirst;
end;
Current := other;
{mhandler^.nlistCount := other^.nListCount;
mhandler^.nchoice := other^.nchoice;}
End;
End;
Procedure Move_down(var auxx:tmNodo);
Begin
{former item}
esc(auxx^.xwhere,auxx^.ywhere,auxx^.nChoice,auxx^.mBackcolor,auxx^.mForecolor,false);
auxx:=auxx^.mNext;
{next item}
esc(auxx^.xwhere,auxx^.ywhere,auxx^.nChoice,auxx^.mSBackcolor,auxx^.mSForecolor,false);
End;
Procedure Move_up(var auxx:tmNodo);
Begin
{former item}
esc(auxx^.xwhere,auxx^.ywhere,auxx^.nChoice,auxx^.mBackcolor,auxx^.mForecolor,false);
{next item}
esc(auxx^.mBack^.xwhere,auxx^.mBack^.ywhere,auxx^.mBack^.nChoice,auxx^.mBack^.mSBackcolor,auxx^.mBack^.mSForecolor,false);
auxx:=auxx^.mBack;
End;
Procedure move_tleft(var auxx : tmNodo;cols:integer);
var fcol : integer;
Begin
{former item}
esc(auxx^.xwhere,auxx^.ywhere,auxx^.nChoice,auxx^.mBackcolor,auxx^.mForecolor,false);
{locate item}
fCol:=auxx^.nListCount;
while auxx^.nListCount < (cols + fcol) do begin
if (cols + fCol) <= daIndex then
auxx:=auxx^.mNext
else
Begin
{If overflow in search is produced}
auxx:=mLast;
break;
end;
end;
{next item}
esc(auxx^.xwhere,auxx^.ywhere,auxx^.nChoice,auxx^.mSBackcolor,auxx^.mSForecolor,false);
End; { move_tleft }
Procedure move_tright(var auxx : tmNodo;cols:integer);
var fcol : integer;
Begin
{former item}
esc(auxx^.xwhere,auxx^.ywhere,auxx^.nChoice,auxx^.mBackcolor,auxx^.mForecolor,false);
{locate item}
fCol:=auxx^.nListCount;
while auxx^.nListCount > (fcol-cols) do begin
if (fcol-cols) > 1 then
auxx:=auxx^.mBack
else
Begin
{If overflow in search is produced}
auxx:=mFirst;
break;
end;
end;
{next item}
esc(auxx^.xwhere,auxx^.ywhere,auxx^.nChoice,auxx^.mSBackcolor,auxx^.mSForecolor,false);
End;
Procedure Start_vMenu(var mHandler : tmNodo);
var aux:tmNodo;
ch:tkeyevent;
Begin
mDisplay;
if mFirst = nil then Begin
ErrorCode:=1;
{ Writeln('Error ',ErrorCode,': no items found');}
end
Else Begin
aux:=mFirst;
esc(aux^.xwhere,aux^.ywhere,aux^.nChoice,aux^.mSBackcolor,aux^.mSForecolor,true);
InitKeyboard;
Repeat
updatescreen(true);
ch:=TranslateKeyEvent(GetKeyEvent);
kglobal:=GetKeyEventChar(ch);
Case GetKeyEventCode(ch) of
kbdDown : move_down(aux);
kbdUp : move_up(aux);
kbdleft : begin kglobal:=#75; break; end;
kbdright: begin kglobal:=#77; break; end;
End;
until (kglobal=chr(27)) or (kglobal=chr(13));
mCurrent:=aux;
mCurrent^.nChoice := Aux^.nChoice;
mCurrent^.nListCount := Aux^.nListCount;
mHandler:=aux;
mHandler^.nChoice := Aux^.nChoice;
firsttime:=false;
End;
End;
Procedure Start_hMenu(var mHandler : tmNodo);
var aux:tmNodo;
ch:tkeyevent;
Begin
mDisplay;
if mFirst = nil then Begin
ErrorCode:=1;
{ Writeln('Error ',ErrorCode,': no items found');}
end
Else Begin
aux:=mFirst;
esc(aux^.xwhere,aux^.ywhere,aux^.nChoice,aux^.mSBackcolor,aux^.mSForecolor,true);
InitKeyboard;
Repeat
updatescreen(true);
ch:=TranslateKeyEvent(GetKeyEvent);
kglobal:=GetKeyEventChar(ch);
Case GetKeyEventCode(ch) of
kbdright : move_down(aux);
kbdleft : move_up(aux);
End;
until (kglobal=chr(27)) or (kglobal=chr(13));
mCurrent:=aux;
mCurrent^.nChoice := Aux^.nChoice;
mCurrent^.nListCount := Aux^.nListCount;
mHandler:=aux;
mHandler^.nChoice := Aux^.nChoice;
firsttime:=false;
kglobal:=GetKeyEventChar(ch);
End;
End;
Procedure gotoP(var mHandler:tmNodo; po : integer);
{go to selected item}
var aux:tmNodo;
upperbound,b:integer;
Begin
aux:=mLast;
mHandler:=aux;
upperbound:=aux^.nlistcount;
b:=0;
if upperbound >= po then
Begin
b:=upperbound;
while b <> po do begin
esc(aux^.xwhere,aux^.ywhere,aux^.nChoice,aux^.mBackcolor,aux^.mForecolor,false);
b:=b-1;
aux:=aux^.mBack;
end;
esc(aux^.xwhere,aux^.ywhere,aux^.nChoice,aux^.mSBackColor,aux^.mSForecolor,false);
mhandler:=aux;
End;
End;
Procedure Update(var mHandler: tmNodo;nItem:string;num:integer);
var aux:tmnodo;
Begin
aux:=mCurrent;
mHandler:=mCurrent;
{ textcolor(mHandler^.mForecolor);
textbackground(mHandler^.mBackcolor);}
mhandler^.nListcount:=aux^.nListcount;
mhandler^.nChoice:=nItem;
End;
Procedure Start_Table(mHandler:tmnodo;var mdata:string; cols : integer; vertical:boolean);
var aux : tmNodo;
ch : tkeyevent;
Begin
mdisplay;
if firsttime=true then
begin
aux:=mFirst;
esc(aux^.xwhere,aux^.ywhere,aux^.nChoice,aux^.mSBackColor,aux^.mSForecolor,true);
end
else
begin
gotoP(aux,mCurrent^.nlistcount);
SetCursorPos(mCurrent^.xwhere,mCurrent^.ywhere);
end;
move_down(aux);
move_up(aux);
Initkeyboard;
Repeat
updatescreen(true);
ch:=TranslateKeyEvent(GetKeyEvent);
kglobal:=GetKeyEventChar(ch);
if vertical=false then begin
Case GetKeyEventCode(ch) of
kbddown : move_down(aux);
kbdup : move_up(aux);
kbdright : move_tleft(aux,cols);
kbdleft : move_tright(aux,cols);
{else }
//kglobal:=chr(0);
end; { case }
end
else begin
Case GetKeyEventCode(ch) of
kbdleft : move_down(aux);
kbdright : move_up(aux);
kbddown : move_tleft(aux,cols);
kbdup : move_tright(aux,cols);
end;
end;
until (KGLOBAL=chr(27)) or (KGLOBAL=chr(13)) or (kglobal='q');
kglobal:=GetKeyEventChar(ch);
mCurrent:=aux;
mCurrent^.nChoice := Aux^.nChoice;
mCurrent^.nListCount := Aux^.nListCount;
{mCurrent^.xwhere := wherex;
mCurrent^.ywhere := wherey; }
mdata:=aux^.nChoice;
firsttime:=false;
End;
procedure vscroll(var menu1:tmnodo;x1,y1:integer;list1:array of string;show_index,b1,f1,bs1,fs1:integer);
var
aux:tmNodo;
inumber,factor:integer;
pointer,pointix:integer;
dir,endx:boolean;
// notscroll:boolean;
Procedure Start_vList(var mHandler:tmNodo;displaynum:integer);
var ch:tkeyevent;
Begin
mDisplay;
if mFirst = nil then Begin
ErrorCode:=1;
{ Writeln('Error ',ErrorCode,': no items found');}
end
Else Begin
{ aux:=mFirst; }
gotop(aux,displaynum);
esc(aux^.xwhere,aux^.ywhere,aux^.nChoice,aux^.mSBackcolor,aux^.mSForecolor,true);
InitKeyboard;
Repeat
updatescreen(true);
ch:=TranslateKeyEvent(GetKeyEvent);
if aux^.nlistcount=1 then begin dir:=false; endx:=false; end;
if aux^.nlistcount>1 then dir:=true;
if aux^.nlistcount+pointer=inumber then endx:=true; {Samll correction for last items}
kglobal:=GetKeyEventChar(ch);
if GetKeyEventCode(ch) = kbddown then kglobal:=#80;
if GetKeyEventCode(ch) = kbdup then kglobal:=#72;
if (kglobal=#80) and (aux=mlast) then break;
if (kglobal=#72) and (aux=mfirst) then break;
Case GetKeyEventCode(ch) of
kbddown : begin move_down(aux); end;
kbdup : begin move_up(aux); end;
End;
// kglobal:=GetKeyEventChar(ch);
until (KGLOBAL=chr(27)) or (KGLOBAL=chr(13));
//pointer:=pointer+1;
mCurrent:=aux;
mCurrent^.nChoice := Aux^.nChoice;
mCurrent^.nListCount := Aux^.nListCount;
mHandler:=aux;
firsttime:=false;
End;
End;
procedure loadlist(pointer:integer);
var
y,line:integer;
begin
line:=1;
inumber:=length(list1);
if inumber>=show_index then begin
factor:=inumber - (show_index-1); {Last item in which all items can be displayed without scroll}
if pointer<inumber then begin
for y:=pointer to pointer+show_index-1 do begin
add_item(menu1,list1[y],x1,y1+line);
line:=line+1;
end;
end;
end;
if inumber<show_index then begin
{no scroll needed}
for y:=0 to inumber-1 do begin
add_item(menu1,list1[y],x1,y1+line);
line:=line+1;
end;
end;
end;
BEGIN
inumber:=length(list1); {Total number of elements in array}
if inumber<=show_index then begin
{without scroll}
cMenu(menu1,b1,f1,bs1,fs1);
loadlist(0);
// notscroll:=true;
end;
if inumber>=show_index then begin
cMenu(menu1,b1,f1,bs1,fs1);
pointer:=0; {Counter of items}
pointix:=1; {Pointer to the item in the list}
loadlist(0);
endx:=false;
repeat
if pointer < inumber then begin
if (pointer<factor-1) and (pointer>=0) then begin
start_vlist(menu1,pointix);
if kglobal=#80 then begin
pointer:=pointer+1;
pointix:=show_index;
end;
end;
if (pointer>0) and (kglobal=#72) then begin
pointer:=pointer-1;
pointix:=1;
end;
end;
if pointer < inumber then begin
crumble(menu1);
cMenu(menu1,b1,f1,bs1,fs1);
loadlist(pointer);
end;
if pointer=factor-1 then begin
start_vlist(menu1,pointix);
end;
until (kglobal=#27) or (kglobal=#13);
if dir=true then gotop(menu1,aux^.nlistcount+1);
if (dir=false) or (endx=true) then gotop(menu1,aux^.nlistcount);
end
else
{ writeln('List is shorter than display');}
//loadlist(1);
start_vmenu(menu1);
END;
End.