Meters
Volume Number: 7
Issue Number: 9
Column Tag: Pascal Forum
Related Info: Quickdraw
Meter Windows
By Walt Davis, Raleigh, NC
Note: Source code files accompanying article are located on MacTech CD-ROM or
source code disks.
[Walt is an electrical engineer who, until recently, worked for a NASA
contractor based in the Washington, DC area. He developed Mac software for NASA that
simulates the flow of high-speed data from space-based instruments and platforms
through various space- and ground-based networks to users on the ground. He
currently works for Alcatel Network Systems in Raleigh, North Carolina helping
Alcatel develop fiber-optic telecommunications systems that will someday bring fiber
into your home and to your Mac.]
Is the Meter Running?
No news is not necessarily good news. E specially when your application is
performing a time consuming task (e.g. lengthy I/O or number crunching) and you’ve
neglected to implement a mechanism to provide feedback on the task’s progress. As a
conscientious programmer you’ve changed the arrow cursor to the watch cursor or
maybe even harnessed the VBL interrupt to show a rotating watch cursor during these
lengthy pauses, but still it’s not enough. The user really has no idea how far into the
task the application has progressed or how much longer until the task is completed.
Forcing the user to rely on the familiar sound of the disk-drive access or the sight of
the disk-access light blinking during long pauses when such a rich graphical interface
is available is either laziness, sloppiness, or rudeness on the part of the programmer.
It is the programmer’s responsibility to see to it that the user always has a warm,
fuzzy feeling about what the application is doing at any particular time. It is the
programmer’s responsibility to create the illusion that the user is in control at all
times.
Actually, I’ve evolved to this position over time due to my experiences as a user
of my own software. I’ve written time consuming applications such as discrete- event
simulations and fast Fourier transforms where a simple watch cursor just won’t cut it.
And now that Apple has a full line of Macs with different processor and coprocessor
configurations, applications that take a few seconds on one Mac platform may take
several minutes on another Mac platform. With all this uncertainty, developers can be
certain of one thing: your software will be used in ways and in environments that
you’ve never considered (if you’re lucky!). You may not be able to test your software
in all these environments, but you can add some simple features to your software that
give it a consistent feel across these environments.
Meet the Meter
For these reasons, I’ve developed a set of procedures that support what I call the
Meter Window (MW). The MW functions as a visual feedback mechanism for the
progress of a task. The MW simply displays the title of the task and fills in a horizontal
box as the task is completed. It is easy to expand on this idea of visual feedback and
develop much more elaborate feedback graphics, but the primary goal of the MW is to
provide as much feedback as possible with the minimum increase in the completion
time of the task at hand. The MW is ideal for long repetitive loop processes but it can
be adapted for any long process that can be decomposed into steps. The MW is also
helpful during development and software testing to show how far into a task a problem
occurs. In a multi-step task, refreshing the MW at each step results in a crude form of
code profiler that shows the relative length of each step and helps identify which steps
are good targets for code optimization.
Meter Nuts and Bolts
The enclosed code, written in Think Pascal version 2.0, is a unit used to
initialize, display, update, and destroy the MW as well as code for a unit that creates a
simple example application that demonstrates the MW operation. The self-contained
MW unit provides full MW functionality for any Think Pascal project through five
simple procedure calls: mWindowInit, mWindowDraw, mWindowTitle,
mWindowUpdate, and mWindowKill. The mWindowInit procedure creates the MW data
structures and draws the empty window in the center of the screen. It works with
different size monitors because it uses the the QuickDraw global screenbits.bounds
rectangle to determine the size of the screen. The mWindowDraw procedure draws the
empty meter box with 5% graduations as well as the other meter box annotation (you