1010// a8libstr.pas
1111// a8libmisc.pas
1212// Revised:
13- // - Added MenuH to draw menu horizontally
13+ // - Merged MenuH and MenuV to single routine WMenu
1414// --------------------------------------------------
1515
1616unit a8libmenu;
@@ -27,131 +27,14 @@ interface
2727// --------------------------------------------------
2828// Function Prototypes
2929// --------------------------------------------------
30- function MenuV (bN, x, y, bI, bS, bC: Byte; pS: TStringArray): Byte;
31- function MenuH (bN, x, y, bI, bS, bC: Byte; pS: TStringArray): Byte;
30+ function WMenu (bN, x, y, bO, bI, bS, bC: Byte; pS: TStringArray): Byte;
3231
3332implementation
3433
3534uses
3635 a8libwin, a8libmisc;
3736
38- // ------------------------------------------------------------
39- // Func...: MenuV(bN, x, y, bI, bS, bC: Byte; pS: TStringArray): Byte
40- // Desc...: Vertical menu
41- // Param..: bN = Window handle number
42- // x = window column for cursor
43- // y = window row for cursor
44- // bI = Inverse flag (WON = leave on at selection)
45- // bS = Start item number
46- // bC = Number of menu items
47- // pS = pointer to array of menu item strings
48- // Return.: Selected item #, ESC (XESC), or TAB (XTAB)
49- // ------------------------------------------------------------
50- function MenuV (bN, x, y, bI, bS, bC: Byte; pS: TStringArray): Byte;
51- var
52- bF: Boolean;
53- bL, bK, tmp: Byte;
54- cL: string[39 ]; // 40 - 1
55- tmpStr: string[39 ];
56- begin
57- bF := false;
58-
59- // Set default return to start item #
60- Result := bS;
61-
62- // Continue until finished
63- while not bF do
64- begin
65- // Display each item
66- for bL := 0 to bC - 1 do
67- begin
68- tmpStr := pS[bL];
69- SetLength(cL, Length(tmpStr));
70- Move(@tmpStr[1 ], @cL[1 ], Length(cL));
71-
72- // Display item at row count - inverse if start item
73- if bL + 1 = Result then
74- begin
75- tmp := WON;
76- end
77- else begin
78- tmp := WOFF;
79- end ;
80- WPrint(bN, x, y + bL, tmp, cL);
81- end ;
82-
83- // Get key (no inverse key)
84- bK := WaitKCX(WOFF);
85-
86- // Process key
87- if (bK = KDOWN) or (bK = KEQUAL) or (bK = KRIGHT) or (bK = KASTER) then
88- begin
89- // Increment (move down list)
90- Inc(Result);
91-
92- // Check for overrun and roll to top
93- if Result > bC then
94- begin
95- Result := 1 ;
96- end ;
97- end
98- else if (bK = KUP) or (bK = KMINUS) or (bK = KLEFT) or (bK = KPLUS) then
99- begin
100- // Decrement (move up list)
101- Dec(Result);
102-
103- // Check for underrun and roll to bottom
104- if Result < 1 then
105- begin
106- Result := bC;
107- end ;
108- end ;
109-
110- // Set last selected item before checking for ESC/TAB/ENTER
111- bL := Result;
112-
113- // If ESC, set choice to XESC
114- if bK = KESC then
115- begin
116- Result := XESC;
117- bF := true;
118- end
119- // For TAB, set choice to XTAB
120- else if bK = KTAB then
121- begin
122- Result := XTAB;
123- bF := true;
124- end
125- // For enter, just exit
126- else if bK = KENTER then
127- begin
128- bF := true;
129- end ;
130- end ;
131-
132- // Uninverse last selection if needed
133- if bI = WOFF then
134- begin
135- tmpStr := pS[bL - 1 ];
136- SetLength(cL, Length(tmpStr));
137- Move(@tmpStr[1 ], @cL[1 ], Length(cL));
138- WPrint(bN, x, y + bL - 1 , WOFF, cL);
139- end ;
140- end ;
141-
142- // ------------------------------------------------------------
143- // Func...: MenuH(bN, x, y, bI, bS, bC: Byte; pS: TStringArray): Byte
144- // Desc...: Vertical menu
145- // Param..: bN = Window handle number
146- // x = window column for cursor
147- // y = window row for cursor
148- // bI = Inverse flag (WON = leave on at selection)
149- // bS = Start item number
150- // bC = Number of menu items
151- // pS = pointer to array of menu item strings
152- // Return.: Selected item #, ESC (XESC), or TAB (XTAB)
153- // ------------------------------------------------------------
154- function MenuH (bN, x, y, bI, bS, bC: Byte; pS: TStringArray): Byte;
37+ function WMenu (bN, x, y, bO, bI, bS, bC: Byte; pS: TStringArray): Byte;
15538var
15639 bF: Boolean;
15740 bL, bK, tmp, l, pos: Byte;
@@ -182,8 +65,14 @@ function MenuH(bN, x, y, bI, bS, bC: Byte; pS: TStringArray): Byte;
18265 else begin
18366 tmp := WOFF;
18467 end ;
185- WPrint(bN, pos + bL, y, tmp, cL);
186- pos:=pos + l;
68+ if bO = GHORZ then
69+ begin
70+ WPrint(bN, pos + bL, y, tmp, cL);
71+ pos:= pos + l;
72+ end
73+ else begin
74+ WPrint(bN, x, y + bL, tmp, cL);
75+ end ;
18776 end ;
18877
18978 // Get key (no inverse key)
@@ -241,7 +130,12 @@ function MenuH(bN, x, y, bI, bS, bC: Byte; pS: TStringArray): Byte;
241130 tmpStr := pS[bL - 1 ];
242131 SetLength(cL, Length(tmpStr));
243132 Move(@tmpStr[1 ], @cL[1 ], Length(cL));
244- WPrint(bN, pos + bL - 1 , y, WOFF, cL);
133+
134+ if bO = GHORZ then
135+ WPrint(bN, pos + bL - 1 , y, WOFF, cL)
136+ else
137+ WPrint(bN, x, y + bL - 1 , WOFF, cL);
245138 end ;
246139end ;
140+
247141end .
0 commit comments