We can then override these defaults to customize our window. In the next two lines, we can give it our own title by storing the absolute address of a string in the title field of the NewWindow structure. The example in section (8) used a pointer to a structure. Here we use the structure directly. Note also that we use "0" since the Amiga uses zero terminated strings instead of Forth style strings. The word ..! is the opposite of ..@ as it is used to store values in a structure.

We need to change a few of the flags to make menus work with this application. We set the IDCMP flags to give us menu picks and closewindow events using the line :-

CLOSEWINDOW MENUPICK I

MY-WINDOW ..I nw_IDCMPFlags

The equivalent code in 'C' would be :-

rny_window.IDCMPFlags = CLOSEWINDOW I MENUPICK;

By also setting the ACTIVATE flag, we don't have to click in the window to active when it opens. This flag is ORed with the existing flags. We now open the window and associate our menu with it using SetMenuStrip( ) .

The Termination word clears the menu strip, closes the window, then frees any memory associated with the EZMenu. The last word EZWALKER ties everything together. Finally I print a message that tells me how to run the program immediately after compiling.

Conclusion

I hope this article will encourage you to use menus in your application (if you are not already doing so) . To get the most out of Amiga's menus you should read the Intuition manual. Menus can make your programs easier to use and help give them a professional look.

I will try to upload this program onto most bulletin boards so you don't have to type it in. It shouldn't take too long to download. The source code is 5215 bytes. The executable image is 9324 bytes and the small image size is because of CLONE : an optimizing target compiler to be released in late 1988.

If you can't find EZWalker on a BBS you can send $5.00 to: Delta Research, P.O. Box 1051, San Rafael, CA 94915

We will send you a public domain disk containing this program and others. The $5.00 can be applied toward the price of JForth when purchased from Delta Research. More extensive examples are included with the JForth compiler that demonstrate multiple menus, enabling menu items, etc. If you have questions about this program, call me at (415) 485-6867.

Listing One .................................................................

\ Demonstrate the use of JForth's EZMenu system.

\ Use pull down menus in a simple graphics application.

\

\ Author : Phil Burk

\ Delta Research, Box 1051, San Rafael, CA, 94915

\ (415) 485-6867

\ July 8, 1988

\

\ This code is hereby placed in the Public Domain

\ and may be freely distributed.

\ (1) Conditionally compile support code not already
\ loaded

include? newwindow.setup Ju:amiga_graph
include? ev.getclass Ju:amiga_events
include? ezmenu Ju:amiga_menus
include? choose Ju:random

\ Forget this code if already loaded.

ANEW TASK-EZWALKER.F

\ (2} Declare an EZMenu structure.

EZMENU MY-MENU

\ (3) Variables used to control application.

variable DRAW-MODE ( lines or boxes )
0 constant USE_LINES
1 constant USE_BOXES

variable QUIT-NOW ( time to stop ? )
variable LAST-X
variable LAST-Y

\ Define words (functions) to call when menu item picked.

: USE.LINES ( -- , set application drawing mode to lines)
use_lines draw-mode !
last-x @ last-y @ gr.move
;

: USE.BOXES ( -- , now draw boxes )
use_boxes draw-mode !
;

\ (4) Call any Amiga Library routine by name
\ using the JForth CALL facility.

: CLEAR.WINDOW ( -- , set rastport to color 0 )
gr-currport @ ( get absolute addr of window rastport)
0 ( background color )

Continued