Icon Creations
Volume Number: 1
Issue Number: 2
Column Tag: Macintosh and Resources
Create your own icons
By David E. Smith
In last month’s column, we presented a complete program shell for creating a
Mac application from assembly language. We did not cover menus or menu bars, which
we will save for next time. Also, we did not cover resources. This month, we begin
examining resources and in particular, icons, including how to install an icon on the
desktop. If you’ve wanted to know how to create your own icons for your applications,
then read on for a complete cook-book approach to this most unfamilar of Mac topics.
Macintosh and Resources
Resources have to be the most frustrating aspect of learning how to program the
Macintosh. It has been said the only reason they exist at all is to get around limitations
of Lisa Pascal; a statement made by a programmer no doubt. But they do serve a useful
purpose once the program design is completed in that they allow text oriented program
aspects like menus and dialogues to be seperated from the code to facilitate translation
into foreign languages. Apple is the first company to design into it’s product a
universal market appeal. To date few developer’s have taken advantage of this feature,
but it’s there.
The main problem of resources facing new developer’s is that the concept is
unique to the Macintosh, and almost totally undocumented. “Inside Macintosh”, the
only offical Mac documentation from Apple, mentions only resource compi- lation on
the Lisa using the Resource Compiler. It also mentions a “Resource Editor”, but says it
doesn’t exist yet. What about the Mac environment? For the most part, that has to be
dug out by hacking to translate Lisa resource formats into one of the Macintosh formats
shown in figure 1. Both the Apple assembler/ linker and the RMaker utility can
compile resources ON the Mac, FOR the Mac. The problem is, the formats are different
than those described in the IM manuals for Lisa’s Resource Compiler.
In addition to RMaker or the assembler system, other utilites are needed as
shown in figure 2. Both icons and fonts are complicated enough to require their own
editors for creating them. These utilities are available with the Software Supplement
on Macintosh disks, or can be found in many public domain libraries. The remainder of
this column will assume you have access to at least the icon editor and the Apple
assembler/editor written by Bill Duvall of Consulair Corp.
ICONS ON THE DESKTOP
The first thing most people want to do with resources is to create a unique icon on
the desktop for their application program. Like a logo, an icon is often created before
the first line of code is written! Creating an icon is easy. Getting it onto the desktop is
not. The desktop file exhibits many peculiar properties when it comes to icons. If you
move a file from one disk to another, you may be surprised to find the icon changes.
This is because the Finder keeps a list of icons and the creator tags that go with each
icon. If the desktop file already has an icon for a creator tag, it uses it, ignoring the
icon resource in the application file. If it has never seen that creator tag before, it
reads the file’s resource to match the new icon with that creator type.
DESKTOP FILE NEVER FORGETS!
The key to icons is the fact that the desktop file never forgets icon/creator tag
combinations even if the file or applciation has been trashed. The only way to make it
forget is to destroy the desktop file and force the Finder to re-create it from the
resources in each application file. This is most easily done by booting up with the
option/command key held down. This forces a new desktop file to be created, but throws
everything out of the folders onto the desktop.
CREATOR BYTES MUST BE UNIQUE
If a file is moved to a disk where it never existed, but the creator tag has existed,
the file will come up with the icon previously associated with that creator. This is why
Apple requires icons and creator tags to be registered with them. The four byte creator
tag must be unique or the whole Macintosh Icon scheme will be frustrated as
applications and documents lose track of each other.The TYPE and CREATOR tags tell the
Finder which applications should be launched for which documents, and the icons are
the visual indication of that linkage. Changing the creator tag of a resource file to
something unique that the desktop file for that disk has never seen, will cause the new
icon to appear without trashing the desktop file. Let’s see how we go about creating new
icons for our applications.
ICON EDITOR
The icon editor utility is used to create the new icon by using a “fat bits” mode to
click in the icon form. A small window shows the acutal icon proportions. An additional
window displays the hex code format for the icon. Figure 3 shows the icon editor output
as seen on the screen. The hex code for the icon, shown in figure 4, is saved to disk,
with an appropriate name such as “WIND.ICON”. The problem is, this binary
information represents the graphic bit pattern of the icon and is incompatable with all
our other resource tools. What is needed is a simple utility to read each byte of our
icon file and re-write it in text format that either the assembler or RMaker can read.
ICON CONVERTER UTILITY
The icon converter utility is written in MS/Basic 1.0 and is shown in the listing
in figure 10. The output and set-up for the program is shown in figure 5. Icon
Converter reads the icon file created by the icon editor and produces either a text file
in assembly source code format for use by the assembler, or a text file in resource
format for use by RMaker, the resource compiler on the Macintosh. As the questions in
figure 5 indicate, the user can specify assembly or resource format for the output.
Also, the program can generate an icon mask or read in a second icon file created by the
icon editor for the mask.
ICON MASK
The icon mask is used when the icon is clicked. The mask icon is XOR’d with the
icon to produce a black outline of the icon when it is selected. If the automatic mask
option is selected with icon converter, then a mask of $FFFF will be generated, which
will result in the black outline shown for the icon in figure 6A. This produces a black
square with the icon in white. To get the mask limited to the outline of the icon, a
second icon must be created with the icon editor by filling an outline of the icon with
solid black. This second icon can be saved as “WIND.ICON.MASK” for example, and
loaded by the icon converter by selecting the load mask option. The icon shown in figure
6B was created with a second icon for it’s mask. In either case, the program writes a
text file of both the icon and it’s mask (either the automatic mask or the mask icon) to
disk and names it with the “.ASM” or “.R” suffix, depending on if the assembler
output or resource output is selected. The resulting output file can then be
“INCLUDED” by the assembler in the assembly resource file, or merged with a
resource file for compilation by RMaker.
PUTTING IT ALL TOGETHER