home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Zodiac Super OZ
/
MEDIADEPOT.ISO
/
FILES
/
13
/
N_B_V203.ZIP
/
MENUS.TXT
< prev
next >
Wrap
Text File
|
1996-07-04
|
11KB
|
208 lines
$if 0
┌──────────────────────────╖ PowerBASIC v3.20
┌──┤ DASoft ╟──────────────────────┬──────────────────╖
│ ├──────────────────────────╢ Copyright 1995 │ DATE: 1995-10-01 ╟─╖
│ │ FILE NAME MENUS .TXT ║ by ╘════════════════─ ║ ║
│ │ ║ Don Schullian, Jr. ║ ║
│ ╘══════════════════════════╝ ║ ║
│ A license is hereby granted to the holder to use this source code in ║ ║
│ any program, commercial or otherwise, without receiving the express ║ ║
│ permission of the copyright holder and without paying any royalties, ║ ║
│ as long as this code is not distributed in any compilable format. ║ ║
│ IE: source code files, PowerBASIC Unit files, and printed listings ║ ║
╘═╤═════════════════════════════════════════════════════════════════════╝ ║
│ .................................... ║
╘═══════════════════════════════════════════════════════════════════════╝
$endif
'.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°
' ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° °
These functions and routines for menus are, I think, just a bit past the
point where I wanted to develop this package. As menus are so important
to program/user interface I generally like to design them separately for
each program. Not so much on how they work ( that's pretty constant ) but
in how they look and feel. I think it best if you have a look around this
suite of functions then raid them for ideas and code. You can, of course
use them as they are but they are somewhat complicated.
─────────────────────────────────────────────────────────────────────────
Menus are, still, an important part of any program. In graphics the items
are, now-a-days, icons but in text mode they are words. Because of this
they can be, for a typist, easier to handle; that is if you've got them
set-up like the drop-down menu in PowerBASIC where the selections all can
be chosen by a single letter. Remember, a typist does not want to remove
his/her hands from the keyboard.
The items of a menu can come from an array of known values you have given
the program during production or can be read from an index file, DOS, or
a data file you have allowed the user to modify. Regardless of where they
come from, or their numbers, they all have to be displayed in an orderly
manner that is easily accessible to the user. PowerBASIC's drop-down menu
and file menu are two good examples of how menus should be presented.
Each item of a menu can have one of several values:
Non-existent drawn as a separating line "├──────────────┤"
Inactive shown but not selectable
Active selectable
Selected under the bar : this is also know as "HOT"
Not selected
Hot keys can be used differently also:
0) not used - the user is forced to move the bar and press <ENTER>
1) automatic selection: assumes that this item was moved to and selected
2) move only to the next/first item bearing this first letter
3) a variation is where letter keys are collected into a string and
the menu searches for the first match for the string
ie: user inputs "P" "O" and "W"
"P" finds the first item starting with "P"
"PO" skips forward to the first item starting with "PO"
"POW" skips forward to the first item starting with "POW"
this style is extremely handy when faced with hundreds or thousands
of items such as would be found in customer indexes, product lists,
etc.
Browsing is just another form a menu can take. It usually displays only a
single item with extended information and is popular when searching for
customer records, etc.
Item selection can also be interpreted differently also:
1) <ENTER> selects the single item and exits the function
2) <SPACE> toggles an ON/OFF variable and displays a mark for
the selected items
<ENTER> ends multiple selections
ie: the program presents a list of files found in a directory
the user selects those files to be deleted
when <ENTER> is pressed the hot items are acted upon
Menus can either wrap or not. Wrap is where the bar moves to the 1st item
when it passes the last item on it's way down and moves to the last item
when it passes the 1st item on it's way up.
Menus can consist of one column of items or several columns. If there is
more than one column the selections can be displayed vertically ordered or
horizontally ordered. (PB uses this style for the file menu) If the menu
has to scroll to display all the items then horizontal order is, by and far
the best of the two possibilities. If, on the other hand, the menu doesn't
scroll then vertical is the more user friendly as it is more common to find
columnized lists in vertical order (see any dictionary or index).
If the menu is going to scroll then it may be advantageous to display a
slider button to indicate where, approximately, in the list the user is. This
is most common in graphics but can be done quite effectively in text mode
also. This style also allows a visual area for the mouse to be used to
indicate "UP" and "DOWN". In fact the whole row above and below the item
list can be used for these purposes but that may not be readily apparent
to the user.
And, finally, we come to the hard part! What are these things supposed to
look like? No one answer comes to mind, here, as each program has it's own
look and feel that is, in part, effected by the menu design. Herein lies
the difficult part of building a write once-use many menu routine. What
follows is the architecture of how I handle the situation. It's not
particularly easy to use while developing a program but sure cuts down on
code when compiled, allows for a quick language change of the whole program,
and has just about everything one could ask for.
────────────────────────────────────────────────────────────────────────────
──────── fTmenuHOT% ─────────
────────────────────────────────────────────────────────────────────────────
Each menu has 4 arrays sent to it:
I$() = the items to be used
H$() = a one line message displayed as each item comes under the bar
O?() = an ON/OFF flag
T%() = > 0 if item has been "tagged" or not
Each array is dimmed starting with element ZERO. In this manner if your
menu will not be using the Help strings you can:
I$(0) carries the 20 bytes of TMenuTYPE and the menu title in bytes 21+.
H$() if DIMmed to ZERO will bypass the help feature
O?() must be dimmed out to it's full length as the menu routine uses it
to store hot-key info if the item is "ON" when it came in.
T%() can also be DIMmed to ZERO if no tagging is to take place or
up to the number of items you wish to be tagged or
one element for each item
HUGH?
Ok. Your menu has 100 items. You want your user to select up to
any 5 of them: DIM T%(5) and when the 5th item is tagged the menu
returns. Or, DIM T%(100) and the user can run around tagging all
the items.
There is one menu call to get all this happening: fTMenuHOT%
but I've put a group of small intermediate calls so you can get to any
or none of the "special" features without putting extra code into your
programs. The presence or absence of "H", "O", and/or "T" tells what
each routine expects or sets up for you.
fTmenu% ( I$(), LastI%, H$, Exet$, SelNo% )
the H$ here is a one-time help line or NULL if you don't want it
H$(), O?() and T%() are all taken care of for you
fTmenuH% ( I$(), LastI%, H$(), Exet$, SelNo% )
here you have requested a menu with a help line for each item.
O?() and T%() are taken care of for you
fTmenuHO% ( I$(), LastI%, H$(), O?(), Exet$, SelNo% )
here only the T%() is omitted so each item has it's own help and can
be either On or Off
fTmenuHT% ( I$(), LastI%, H$(), T%(), Exet$, SelNo% )
all items are ON, each has a help line and Tagging is implemented
fTmenuO% ( I$(), LastI%, H$, O?(), Exet$, SelNo% )
a one-time help line or NULL for H$ and items can be ON/OFF but
no tagging allowed
fTmenuOT% ( I$(), LastI%, H$, O?(), T%(), Exet$, SelNo% )
once again a 1 time help line, items can be ON/OFF and ON items can
be Tagged
(This one really doesn't make much sense! I don't know what kind of
logic it would take to find oneself in this situation but.... )
fTmenuT% ( I$(), LastI%, H$, T%(), Exet$, SelNo% )
a one-time help line, all item are ON, and tagging is in effect
fTmenuHOT% ( I$(), LastI%, H$(), O?(), T%(), Exet$, SelNo% )
EVERYTHING......
once again, I don't know <HOW> you could do this but this is the main
driver for all the others so it's gotta' big job to do.
Now that you know what, let's move on to "HOW".
I$() is a list of the menu items but I$(0) carries some special info into
the function. I$(0) is the data for TMenuTYPE and the title for the menu.
eg: I$(0) = tM + "Main Menu"
or.....
LSET tM = I$(0) : Title$ = MID$( I$(0), 23 )
' ┌───────────────────┐
'┌┤ GENERAL MENU TYPE ├───────────────────────────
TYPE TmenuTYPE '│└───────────────────┘
SetUp AS BYTE '│ if 0 then TmenuSETUP will be called
Row AS BYTE '│ starting row ( box border if .Brdr > 0 )
Col AS BYTE '│ starting col ( box border if .Brdr > 0 )
Iwide AS BYTE '│ MAX item width
IRows AS BYTE '│ N° if item rows 1, 2, 3, 4 etc
ICols AS BYTE '│ N° of item columns 1, 2, 3, 4 etc
Vert AS BYTE '│ Vertical YES/NO
Wrap AS BYTE '│ Wrap ON/OFF
HKs AS BYTE '│ 0 = NONE : 1 = ALPHA : 2 = HOT-KEY : >2 = TAG
'─────────────────────────┤
AttrN AS BYTE '│ Normal
AttrL AS BYTE '│ Letter HI-light or Tagged Item
AttrB AS BYTE '│ select Bar
AttrO AS BYTE '│ "OFF" item
'─────────────────────────┤
Srow AS BYTE '│ all 3 of these are computed by fTmenuBox$ when
Scol AS BYTE '│ .Srow > 0 else if .Srow = 0 then ignored
Srows AS BYTE '│ values used by fTmenuHOT% if .Srow > 0
Aattr AS BYTE '│ arrow attribute if > 0 else Battr used
'─────────────────────────┤
Brdr AS BYTE '│ Border style SEE: TBoxDRAW
Battr AS BYTE '│ Border attribute
Shdo AS BYTE '│ Shadow style SEE: DrawTShadow
Sattr AS BYTE '│ Shadow attribute
Tpos AS BYTE '│ Title Position
END TYPE '└──────────────┤ 22 bytes ├──────────────────────