home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
database
/
optmen.zip
/
OPT.PRG
< prev
next >
Wrap
Text File
|
1987-02-22
|
9KB
|
271 lines
*
*
* Opt - Display menu of choices (maximum of 8) (VERSION 1.0)
*
* by Anthony T. DeHart - GENIE (ATDEHART)
*
*
* Requires: choice - Array of menu selection descriptions
* maxopt - Number of options to be displayed in menu (not including
* the quit option (element 9 but displayed as 0)
* pntr - selection number of the option to highlight initially
* (allows you to keep the last option selected highlighted
* if you have to redraw the menu again)
* answer - the selection number of the choice made by the user
*
* Assumes: Global variables reverse, highlight, and normal are setup
* see OPTSETUP
* Does not clear the screen so you must do that if you want it done
* MaxOpt <= 8 (no more than 8 menu items, can be modified for more
* but if you need more then you should probably break down
* your menus a little more)
*
* Action: Draws a double column menu with up to 8 selections (not including
* option 0 which should be exit or return to calling menu) and
* centers it on the screen with boxes, etc. Selection is done using
* a light bar with the cursor keys and the return key. Used in
* conjuction with lscrtop (see demo prg's included with arc file)
* creates a very professional looking menu. My only complaint is
* that on a regular PC is that it is not instantaneous
* when displayed. This is the first version and it probably could
* use some improvement.
*
* Usage: I'm not to concerned with what is done with this routine but if
* you do modify it and want to repost it please notify me first
* via GENIE or DARWIN BBS. Also, I expect that you will also give
* credit where credit is due and leave my name and Genie ID here
* in the prg also. Have fun and take a look at some of the other
* files that go along with the demo prg. LSCRTOP, ASK_YN, PLAC_MSG
* are neat little programs and LSCRTOP looks nice when used with
* this routine.
* Anthony T. DeHart
* ATD Software
* 189 S. Keystone Ave.
* Sayre, PA 18840
* 717-888-7439
* GENIE (ATDEHART)
*
*
Parameters choice, maxopt, pntr, answer
***** Declare arrays
private X_Cursor, Y_Cursor
declare X_Cursor[9]
declare Y_Cursor[9]
***** Pad menu strings with spaces up to max length of longest choice
maxLen = len(alltrim(choice[9]))
for counter = 1 to maxopt
if len(alltrim(choice[counter])) > maxLen
maxLen = len(alltrim(choice[counter]))
endif
next
if maxLen + 9 > 40
maxLen = maxLen - ((maxLen + 9) - 40)
endif
Y_Base = 9 && Y location of center of menu
L_Column = 20 - int((maxLen + 8) / 2) && Left column position
R_Column = 60 - int((maxLen + 8) / 2) && Right column position
Top_Bar = '┌'+replicate('─',3)+'┬'+replicate('─',maxLen+2)+'┐'
Mid_Bar = '├'+replicate('─',3)+'┼'+replicate('─',maxLen+2)+'┤'
Bot_Bar = '└'+replicate('─',3)+'┴'+replicate('─',maxLen+2)+'┘'
* Find X and Y locations for the options and stick in array
cutoff = int((maxopt/2)+.5) && Last menu item in left column
Y_Base = Y_Base + (4 - cutoff) && Center meny on screen
***** Assign X and Y location in array for each menu item and Draw Menu
***** Left Column
for counter = 1 to cutoff
X_Cursor[counter] = L_Column
Y_Cursor[counter] = Y_Base + ((counter - 1) * 2)
Choice[counter] = left(choice[counter]+space(maxLen+2),maxLen)
if counter = 1
@ Y_Cursor[counter]-1,X_Cursor[counter] say Top_Bar
else
@ Y_Cursor[counter]-1,X_Cursor[counter] say Mid_Bar
endif
@ Y_Cursor[counter],X_Cursor[counter] say '│ '+alltrim(str(counter,1))+' │ '+choice[counter]+' │'
if counter = cutoff
@ Y_Cursor[counter]+1,X_Cursor[counter] say Bot_Bar
endif
next
***** Right Column
for counter = cutoff+1 to maxopt
X_Cursor[counter] = R_Column
Y_Cursor[counter] = Y_Base + ((counter - (cutoff+1)) * 2)
Choice[counter] = left(choice[counter]+space(maxLen+2),maxLen)
if counter = cutoff+1
@ Y_Cursor[counter]-1,X_Cursor[counter] say Top_Bar
else
@ Y_Cursor[counter]-1,X_Cursor[counter] say Mid_Bar
endif
@ Y_Cursor[counter],X_Cursor[counter] say '│ '+alltrim(str(counter,1))+' │ '+choice[counter]+' │'
if counter = maxopt
@ Y_Cursor[counter]+1,X_Cursor[counter] say Bot_Bar
endif
next
***** Menu selection 0 Location and Draw It
X_Cursor[9] = L_Column + int((R_Column - L_Column)/2)
Y_Cursor[9] = Y_Base + 1 + (cutoff*2)
Choice[9] = left(choice[9]+space(maxLen+2),maxLen)
@ Y_Cursor[9]-1,X_Cursor[9] say Top_Bar
@ Y_Cursor[9],X_Cursor[9] say '│ 0 │ '+choice[9]+' │'
@ Y_Cursor[9]+1,X_Cursor[9] say Bot_Bar
***** Draw Instructions
store 'Move cursor ' + chr(25) + ' ' + chr(24) + ' ' + chr(27) + ' ' + chr(26) + ' to highlight choice and press ' + chr(17) + chr(217) to message1
store 'or press number of selection and ' + chr(17) + chr(217) + ' to select menu option' to message2
@ 21,0 to 24,79 double
@ 22,(80 - len(message1))/2 say message1
@ 23,(80 - len(message2))/2 say message2
answer = 0 && Selection number when return is pressed
oldpntr = 0 && Menu item highlighted before cursor is moved
if pntr = 0 && Menu item to be highlighted on screen (current cursor pos)
pntr = 1
endif
if pntr = 9
pntr = 0
oldpntr = 1
endif
curspntr = pntr && Actual pntr to cursor selection
LastColumn = 0 && Last Column that cursor was in
do while .T.
if oldpntr # curspntr && If cursor moved then update position
if oldpntr = 0
oldpntr = 9
endif
if curspntr = 0
curspntr = 9
endif
***** Unhighlight old position
set color to &normal
@ Y_Cursor[oldpntr],X_Cursor[oldpntr]+6 say choice[oldpntr]
***** Highlight new position
set color to &reverse
@ Y_Cursor[curspntr],X_Cursor[curspntr]+6 say choice[curspntr]
set color to &normal
@ Y_Cursor[curspntr],X_Cursor[curspntr]+2 say ''
if curspntr = 9
curspntr = 0
endif
if oldpntr # 9
LastColumn = X_Cursor[oldpntr]
endif
oldpntr = curspntr
endif
***** Get keypress and update time on screen
KeyCode = 0
do while Keycode = 0
Keycode = inkey(1)
stime = time()
@ 2,71 say stime
if curspntr # 0
@ Y_Cursor[curspntr],X_Cursor[curspntr]+2 say ''
else
@ Y_Cursor[9],X_Cursor[9]+2 say ''
endif
enddo
do case
case Keycode = 13 && Return
answer = curspntr
exit
***** Movement routines are a little more complex than usual
***** Rather than describe it, run the program and move the cursor around
***** using the up and down arrows and you'll see why all the if statements
***** and case checking.
case Keycode = 5 && Up Arrow
if curspntr = 0
do case
case LastColumn = L_Column
curspntr = maxopt
loop
case LastColumn = R_Column
curspntr = cutoff
loop
endcase
endif
if curspntr = cutoff + 1
curspntr = 0
loop
endif
curspntr = curspntr - 1
loop
case Keycode = 24 && Down Arrow
if curspntr = 0 .and. LastColumn = L_Column
curspntr = cutoff + 1
loop
endif
if (curspntr = maxopt) .or. (curspntr = cutoff)
curspntr = 0
loop
endif
curspntr = curspntr + 1
loop
case Keycode = 4 && Right Arrow
if curspntr # 0
if curspntr <= cutoff
curspntr = curspntr + cutoff
endif
if curspntr > maxopt
curspntr = maxopt
endif
else
curspntr = maxopt
endif
case Keycode = 19 && Left Arrow
if curspntr # 0
if curspntr > cutoff
curspntr = curspntr - cutoff
endif
else
curspntr = cutoff
endif
***** Can also select by using the number of the routine and hitting return
case chr(Keycode) >= '0' .and. chr(Keycode) <= alltrim(str(maxopt,1))
curspntr = val(chr(Keycode))
endcase
enddo
if answer = 0
answer = 9
endif
***** Unhighlight description and highlight actual number of description
set color to &reverse
if answer # 9
@ Y_Cursor[answer], X_Cursor[answer]+2 say alltrim(str(answer,1))
else
@ Y_Cursor[answer], X_Cursor[answer]+2 say '0'
endif
set color to &normal
@ Y_Cursor[answer], X_Cursor[answer]+6 say choice[answer]
return