Amiga SuperMenus
Rick Du Chateau
Add new capabilities to Amiga Basic's MENU command with this powerful extension. Requires version 1.2 of Amiga Basic.
Amiga Basic may be the most powerful BASIC interpreter available. However, while it does a reasonable job of providing access to the system software built into the Amiga, Amiga Basic doesn't support the system software as completely as compiled languages like C, Pascal, and Modula II.
As an example, consider Amiga Basic's MENU command. With it, you can create custom menus and menu items, enable or disable the items, and place a checkmark next to a menu item. But this is only a small fraction of the menu features and capabilities provided by Intuition. (Intuition is the portion of the Amiga operating system that controls the user interface—the windows, menus, and alert boxes.) Amiga Basic's MENU command doesn't provide for sub-menus, command keys, alternate ways of highlighting a selected menu, and the ability to turn a checkmark on or off while excluding the other choices. For an example of how complex and useful menus can be, load Deluxe Paint II and wander through the menus and submenus.
Fortunately, the designers of Amiga Basic provided for these and future features by making Amiga Basic an extensible language through the use of subprograms and the LIBRARY command. By using LIBRARY, the Amiga Basic programmer has access to the multitude of the Amiga's operating system routines. And subprograms can actually add new commands to Amiga Basic.
"Amiga SuperMenus" illustrates the usefulness of subprograms by adding several menu-related commands to Amiga Basic. These new commands are INITIALIZE, SMENU, SUBMENU, and SMENUOFF. Adding SuperMenus to your own programs will give you access to the full power of the Amiga's menu system, and enable you to create more professional-looking programs. A short demonstration program is included that utilizes most of Supermenu's features.
Getting Started
Type in and save Program 1. This is the SuperMenus routine. You will want to be able to merge this routine into programs you write yourself, so you must save the program in ASCII (text) format. This is accomplished by adding ,A to the end of the SAVE command:
Add new power to Amiga Basic's menu handling with this clever utility.SAVE "SuperMenus" ,A
To learn how to use the routine, type in and save a copy of Program 2, SuperMenus.Demo. Now go to the BASIC command window and type LOAD "Super-Menus. Demo" and then type MERGE "SuperMenus" to add the SuperMenus routine to the demonstration program. Note that Program 2 will not work unless you merge SuperMenus with it. If you failed to save Program 1 as an ASCII file, you'll see the error message Bad file mode when you give the MERGE command.
Run the resulting program. After a few seconds, you'll hear a beep and see the message Super Menus Ready! Use the menu select button (the right mouse button) to view the various SuperMenu features. The demonstration will print any selections you make (when the right button is released). Select Quit to exit the program.
Available Flags
You may select as many of these flags as you like:
check% | puts a checkmark to the left of the item or subitem. |
text% | indicates that the item or subitem consists of text as opposed to a graphic image. |
command% | uses this flag if this item or subitem is to have a command-key associated with it. |
toggle% | uses this flag in conjunction with check% to toggle the checkmark on or off with selection. |
enabled% | indicates the item or subitem is enabled as opposed to ghosted (off). |
You must select one and only one of the following highlighting flags: | |
comp% | inverts the colors of an item or subitem during selection. |
box% | draws a box around the item or subitem during selection. |
selectimage% | uses a defined alternate image during selection. |
none% | indicates no highlighting. |
Follow these steps to incorporate SuperMenus into your own programs:
- After loading your Amiga Basic program, type MERGE "Super-Menus".
- Add the following lines to the beginning of your program:
DECLARE FUNCTION AllocMem&() LIBRARY INITIALIZE
See the demonstration program for an example of how this is done.
- Follow the format described below to create a menu.
- Call the SUBITEM subprogram to test for a subitem selection (returned in variable called Sub-Num%).
- At the end of your program call the SMENUOFF subprogram.
- Save your program.
- Before running your program, besure the files exec.bmap and graphics.bmap are in either your current directory or the Libs directory. These files can be found in the BasicDemos drawer on the Extras disk for version 1.2 of Amiga DOS.
The Commands
The first new command, INITIALIZE, should be used only once before the SMENU command. This subprogram initializes all of the variables used by SuperMenus and loads the necessary libraries from disk.
The SMENU command is the heart of SuperMenus. It is similar to Amiga Basic's MENU command. The format is
SMENU (Menu%, Item%, Submenu%, Flags%, MExclude&, CommandKey$, Text$, SelecText$)
The items in italics in the SMENU command have the following meanings:
- Menu% is the menu position, in the range 1-10 (as in Amiga Basic MENU).
- Item is the item position, in the range 1-19 (as in Amiga Basic MENU).
- SubItem% is the subitem position (no limit).
- Flags% is one or more of the flags listed in the table of flags.
- MExclude& is used in conjunction with the check% and toggle% flags in the table of flags. Choosing from Item 1& through Item 31& will exclude these items from selection when this item is active. For example, if you have a set of menu items 1, 2, and 3, and if you set MExclude&= Item2& + Item3& for the first menu item, then when item 1 is selected (and check marked), Intuition will erase any checkmarks on items 2 and 3. See the Amiga technical manuals for additional information.
- CommandKey$ is an alphanumeric character to be used with the right Amiga key to select this item.
- Text$ is the text to be used for this item.
- SelecText$ is the text to be substituted for Text$ when this item is selected if you use the selectimage% highlighting flag.
Amiga Basic's MENU(0) and MENU(1) functions return the values of the selected menu and menu item respectively. So, in order to check for a selected subitem, a new command—SUBITEM—had to be added. SUBITEM returns a selected subitem number in the variable SubNum%.
The final new command, SMENUOFF, should be used at the end of your program to free up the memory used by Supermenus.