Easy Menus in JForth

     The EZMenu system makes it quite easy to implement
     simple text based menus

     by Phil Burk
 
     Never Used Forth?

     If you have already programmed in Forth, skip ahead to the next section !

     I won't try to teach you Forth in this article. But hopefully I can explain enough so that the program listing makes some sense. In Forth, subroutine, or function is called a   "word" . The definition of a word is started with a colon,   ' : '  , followed by the name of the word. The definition is terminated with a semicolon,   ' ; ' .  A program called HI that prints out  "Hello World ! "  would be defined as follows :-

     :   HI   ."   Hello World !   "   ;

     This could be compiled interactively in any Forth in 1 or 2 seconds. Once compiled it is added to a dictionary of commands, any of which can be executed interactively or referenced in another program. Thus, Forth is both a compiler and an interactive environment.

     Forth code looks a little strange at first since it uses Reverse Polish Notation (RPN). In Forth, numbers and addresses are held on a stack. The Forth words operate on this stack in the order of their appearance in the code. The syntax is therefore very simple, being much like English. Here is some code that places two numbers on the stack, adds them together with  "plus" , then prints the answer using  "dot" .

     23   45   +   .

     The answer, 68, would be printed if you typed this into any Forth.

     Most of the common functions in Forth are standardized. However, the way in which Forth is interfaced to an operating system has not been standardized. Thus, this program, which uses Amiga Intuition Menus, will only compile under JForth from Delta Research. The EZMenu toolbox is unique to JForth, but almost every Forth on the Amiga allows you to access Intuition Menus in some way.

     Why Use Pull Down Menus?

     If you're like me, when you buy a new interactive program you want to try it out NOW !  You pop in the disk, click on some likely looking icon and you're in. Now what ?  While the manual sits unopened in the box you probably start exploring the pull down menus. If the user interface is well designed, you can get pretty far this way. After your initial frenzy subsides, and you get in deeper, you can always consult the manual to tell you what you've missed.

       If you are writing a program for others, providing a good set of menus is obviously important. Adding menus to your Amiga program, however, is no trivial matter. The Amiga menu system is so flexible, and has so many options, that it can take a lot of work even to do something simple. I am very grateful to the folks at Amiga for providing a very well thought out menu system that can handle almost anything. But when I was just writing a simple text menu, I used to wish for an easier way. For this reason, I wrote the EZMenu system and included it with the JForth compiler. The EZMenu system makes it quite easy to implement simple text based menus which are the most common type. If you choose to do something fancier, like including graphics in your menus, you will have to do a bit more work.

     [Note: JForth is a Forth '83 based compiler simlar to the MultiForth system described in previous Amazing Computing articles]

     Amiga Intuition Menus

     To understand how EZMenu system works, it helps to have some idea of how the Intuition Menu system works. Intuition Menus use several different structures linked together. (See Figure 1. for a diagram of this system .) The primary structure is the Menu structure. This structure determines where the menu appears on the menu bar, its name, and its size. The Menu structure points to a linked list of MenuItems.

     Each MenuItem has its own size and position, plus information on how to draw it. Each MenuItem points to either an IntuiText structure or an Image structure. Thus you can mix text and graphic images in a menu. MenuItems also have a number of flags that control whether it has a checkmark, how it is highlighted, whether it has a command key, etc. MenuItems may also have a pointer towards a list of SubItems.

     The IntuiText Structure has a pointer to the text, plus information on position, font, colors, etc. Multiple IntuiText structures can be linked together into lists. Image structures allow you to specify a bit mapped image, which bit planes to use for highlighting, size and position, etc. Images can also be linked together.

     The primary Menu structures can be linked together to form a Menu Strip which can be connected to a window. When you select a window, its menu strip is made available. When you pick from a menu, a MENUPICK event is sent to the window for use by your program.
 

 Continued