HiMenus, Color Notes
Volume Number: 4
Issue Number: 6
Column Tag: Basic School
Hierarchical Menus & Color Notes 
By Dave Kelly, MacTutor Editorial Board
Hierarchical Menus in ZBasic
Hierarchical menus (also known as submenus) are possible in ZBasic with a
small amount of sweat. Hierarchical menu items have the small filled black triangle
pointing to the right in many of the newer application programs that are coming out
now. This month I will show you how you can implement them in your own ZBasic
source code.
There are a few standard guidelines for using submenus which you can find in The
Macintosh User Interface Guidelines found in Vol. 5 of Inside Macintosh. In the
pull-down menu structure of the Macintosh, it was originally intended that the user
could quickly scan through all of the menus and know the function of all the menu
items. Therefore, it is strongly recommended that submenus only be used for lists of
related items. You should try to only use one level of hierarchical menus although it is
possible to go several levels.
The concepts of submenu programming is fairly simple and easy to implement.
However, implementing submenus in ZBasic without some understanding of how things
work will probably frustrate some of the average Basic programmers out there. The
first thing we have to do is throw away the ZBasic event loop and event handling
statements and set up our own GETNEXTEVENT loop. This sounds difficult to some of
you, but actually it solves some of the problems inherent in ZBasic that I’ve been
pulling my hair out over for the past year or so. In this month’s sample program I
even went a step further by defining some of the menus and the main window using
MENU and WIND resources. You can refer back to my GETNEXTEVENT ZBasic shell
program in September 1987 MacTutor. This will give you the program shell to start
with.
First create the window resource. Any window type will do for this example. I
chose the rDocProc type window which has a ProcID number 16. To create the WIND
resource, open ResEdit and select New from the File menu and type in the WIND
resource type. Then select New to create a resource and type the following parameters
into your window (as shown in the ResEdit Window in figure 2):
boundsRect 54 78 280 325
procID 16
visible True
goAway False
refCon 0
title Hierarchical Menu Sample
Change the WIND ID to 29414 (or any other unique number) by selecting Get
Info from the File menu. Now the WIND resource is created. This window will be used
by the program to output confirmation that everything works.
Fig. 1 Our hierarchical menu example in ZBasic
The menus are just as simple to create with ResEdit as the WIND resource was.
The parameters for each of the menus is shown in the window dumped from ResEdit
which are included here. Two menus are created with ZBasic Menu statements which
are not included as resources. Actually, it would probably be better to use all toolbox
calls instead of ZBasic Menu statements because we could be in complete control of all
the menus. MENU id 255 is the Apple menu created with the APPLE MENU statement in
ZBasic, but it is very automatic and you have to have desk accessories whether you like
it or not. If you created your own, you could exclude any part you didn’t want, but you
would have to control every little thing that happens. MENU ID 2 is created with the
ZBasic EDIT MENU statement. This is the easiest way to make an Edit menu. MENU ID
134 is the File menu. It contains only one menu item, “Quit”.
MENU ID 135 is the Format menu which is the main menu which the submenus
will be attached. The Format menu contains two items, “Style” and “Font” which will
each have submenus. Now comes the fun part. To attach a menu we first set the “key
equiv” for the menu item to $1B. This will put the black filled triangle in the menu.
A $1B is ASCII character 27, the ESCAPE key. If you have an Extended keyboard you
will have no trouble producing this character by typing “esc”. Typing CTRL-[ will
also produce the ESC character. However, I haven’t found a good way to produce ESC
using the MacPlus or earlier keyboards; anybody know how??. Next the ID of the
submenu is put in the mark Char field. Actually, you enter the character which has
the ASCII value of the ID of the submenu. In the Style menu the ASCII value of “à” is
136. This character is entered by using the “option-`” then “a”. The Font menu has
submenu with ID=137 so the mark Char is “â” which is entered by typing “option-i”
and the “a”. You should examine the ResEdit windows shown here if you need more
help understanding this.
Fig. 2 ResEdit version of the Window Resource
Fig. 3 Menu Resource
After the MENU and WIND resources are complete, the program can be compiled.
You will need to compile the program as an application and install the MENU and WIND
resources before running the program or unexpected results will occur. Remember
that the program needs to have the resources in order to work properly. Be sure that
the resources are installed by running ResEdit immediately after compiling. It would
be nice if ZBasic would install a resource file for you as in “real” development
languages. Maybe they will add this capability someday.
The program really doesn’t do anything except respond to the menu and print to
the window which menu was selected. There are a few left over functions that were
originally part of the GETNEXTEVENT shell program. The shell could be expanded to
work with other applications you may like to do.
An alternative to using ResEdit is to create your resources with RMaker, as
shown in the program listing. Once the resources are compiled, ResEdit can be used to
move the resources from the RMaker output file into the ZBasic compiled file.
Sorry State of Mac Basics
Thus far, the Mac II has been out over a year and as of the date of this writing,
there is still no Basic released which fully supports all the new ROM capabilities.
Even the method I’ve shown here is a work around because of the way that ResEdit has
to be used. It still holds true, however, that ZBasic has the most features and is faster
than any of the competitors. Microsoft still has no new updates of MS Basic. And with
all the bugs in the compiler, Absoft doesn’t want to add any new features till the old
ones are fixed. Somebody is walking around with blinders on and doesn’t even know it.
From the response I’ve seen, most people are dissatisfied with all the Basic products
that are currently released. There are still some possibilities coming up True Basic
2.01 was released this week. We will be taking a good hard look at the new True Basic
in upcoming issues. The grapevine says that Microsoft is readying a new release for
sometime? All I can say is that I hope they are listening to all of us and what we are
screaming for. [Note that True Basic 2.0 was found to be defective shortly after
shipment, and the company has upgraded immediately to 2.01. It seems that a memory
management bug exists in 2.0 that is actually hidden by the presence of the Macsbug
debugger, which nearly all their beta testors were using. When they tried the product
without Macsbug installed, a problem was found that seems to prevent True Basic from
picking up on mouse and keyboard events properly during program execution. We
discovered it when we noticed the demos would not stop without powering down the Mac.
So be sure to check that your upgrade disk is version 2.01, and a word of warning to
other developers, that the presence of a debugger may be altering or hiding potential
memory manager bugs. -Ed]
By the way, my daughter helped to discover a undocumented feature of ZBasic.
She was quietly invading my Mac II (when I wasn’t looking) while I had ZBasic running
and happened to press the arrow keys. Well it turns out that the down arrow key
lists the next sequential program line. The up arrow key prints the previous line.
Right arrow lists the last line and Left arrow lists the first line. Interesting, but I
prefer to do all my editing using an editor. I’d like to say I like using the built in
editor the best, but it still doesn’t quite work right.
True Basic 2.01 & Color Models
One of the neat features of the new True Basic 2.01 is that it supports Macintosh
II color including palette animation. In fact, the palette animation article we did last
month in MacTutor can be done in just a few lines in True Basic! And a neat Mac touch
they have added is that the output window for True Basic is saved and refreshed and can
be written to disk as a PICT2 resource, unlike MS Basic, which “forgets” how to
update the output window after a program runs. To help us get up to speed on color
processing on the Mac, here are some notes on color types.
Along with color and the Mac II there also comes new terminology. I’m sure there
are many of you that either haven’t wanted to or have had no opportunity till now to
know about the various color models that exist. Most of us have heard of RGB, some for
the first time when they bought their Mac II with RGB monitor. RGB is yet only one of
several color models being used in the computer graphics industry. Some other color
models include: CMY, YIQ, LAB, HSL, HSV, and HSI Color Models.
I will attempt to explain them from the few things that I have read on the subject.
Each model has its advantages and disadvantages. In general the color models have been
formed to assist the user in selecting one of the 16 million colors.
RGB
RGB is directly related to the hardware involved in color displays. Most of us are
familiar with this from using the Color Picker package to select colors on the Mac II.
The Red, Green, and Blue values are represented as long integers, which are converted
into signals driving each of the color guns in the CRT (one for each color). The RGB
model is easier for the programmer to implement because it is directly related to the
hardware. But it may not be the easiest for the user to use unless he/she understands
the RGB model. The other color models are always converted to RGB then the hardware
uses a Color LookUp Table (CLUT) to determine which color to display. Also notable
about the RGB model, when the values of RGB are equal ( R = G = B) the CRT phosphor
chromaticities are balanced so that gray is the result. The brightness or darkness of
grey is determined by the amplitude of the RGB components as they effect the color
guns of the CRT.
HSV
HSV stands for Hue, Saturation and Value. The Hue associates the color with a
value in the color spectrum, Saturation represents the vividness of the color with
pure colors (such as red, green, and yellow) being called fully saturated colors and
grays being called desaturated colors, the Value represents the lightness or darkness of
a color. The Brightness field of the Macintosh Color Picker dialog is the equivalent of
the HSV value. The Color Picker primarily works using the HSV model. The RGB
values are shown also, but only users that understand both color systems will
understand how to the HSV and RGB values relate. The RGB system is given so that the