Creating user friendly programs (5)
-----------------------------------
by Steven Flintham (15A)
------------------------
Interacting with the user (2)
-----------------------------
As mentioned in the last article, this time I want to cover step selection
menus.
The simplest type of step selection menu is the "one key to move, one to
select" type. Step1 is an example of this type. The program is fairly easy
to follow, with the possible exception of line 460.
This removes the teletext control codes from the start of the line,
therefore removing the highlight and adds one to choice%. The highlight is
then redisplayed the next time around the loop. Note that choice% is made to
automatically wrap around to zero when it reaches six by the MOD 6
statement. Note also that the CHR$(156) code at the end of the line is not
removed, as this only has an effect when the bar is displayed, when it is
overwritten by another CHR$(156) anyway. It could be considered a little
untidy doing this, but I feel it is neater as it avoids using another TAB
command to move the cursor to an appropriate place to remove the CHR$(156).
The only other point to note is that the values returned begin with 0, so
that the quit option, which is the sixth in the menu, returns 5. This is
done so that the MOD 6 technique mentioned above can be used easily.
This simple form of step selection has one main advantage. This is that only
two keys are required, so it is simple to use and it should be possible to
use this technique, modified for some other input device, with physically
handicapped people.
However, it has (to my mind) two disadvantages. The first is that it can be
tedious to have to move through the menu in just one direction -
particularly when you have missed the option you wanted and have to go all
the way round (just like setting most digital watches!)
The second is that, despite the simplicity of the method, it is difficult to
describe succintly and therefore a relatively long "prompt" is required.
Simply writing "Use SPACE to select and RETURN to choose" is confusing,
because it is not clear whether selecting is the action of moving through
the menu or the action of "choosing" an option (see what I mean!) (I suppose
you could use the word "step" to refer to stepping through the menu and
either "choose" or "select" to refer to making a choice, but I still feel
it's a bit confusing)
Two-way step selection avoids these problems - Step2 demonstrates this. This
is very similar to Step1 - the only real point of note as far as the program
is concerned is the use of *FX4,1 to allow the cursor keys to return ASCII
codes. Incidentally, although this also uses a long prompt, it would be
reasonable to just use "Use cursor keys and RETURN", which would all fit on
one line.
Step selection is possible in all modes, but the above examples work only in
mode 7. For completeness, Step3 is a version of Step2 written to work in
mode 4. Despite being basically the same, there are a few things worth
mentioning. Firstly, the double height routine is slightly non-standard. It
inserts a blank line at the top of the character and only uses "half" of the
last line of each character to compensate for this. This has the effect of
centering the text more effectively when used with reverse video, but
prevents descenders being displayed properly. As there are none in this
title, this is not a problem, but if you want to use this routine in your
own programs, try it first with a descender to see if you are happy with the
appearance. To see how "conventional" double height would appear, delete
line 800 and un-REM the following line.
Secondly, the bar is made from individual vertical lines because I can never
seem to get the "two-triangle" method of rectangle drawing to work in GCOL 4
mode. The two triangles always overlap and because they are plotted in the
inverse of whatever is on the screen, an inverse line appears across the
diagonal of the rectangle.
This method of rectangle plotting gives a partial "rolling bar" effect, as
mentioned by a member in issue 26, although this is just a side effect of
the method of drawing the bar, and varies depending on system speed. Step4
is a version of Step3 modified to give a better rolling bar effect which
appears regardless of system speed.
The program is fairly straightforward, but PROCdraw_bar is worthy of
examination. It selects inverse graphics with GCOL 4,1 and then works out
where to start and stop drawing the bar. start% is the y-coordinate at which
the bar begins and end% is the y-coordinate at which it ends. These are
initially assigned so that the bar is drawn from top to bottom, and then
swapped round in line 570 if the bar is to be drawn from bottom to top.
The expression after the STEP in the FOR command is just a convienient way
of setting the step value to 4 or -4 without using an IF-THEN command. It
could be replaced with:
IF end%>start% THEN step%=4 ELSE step%=-4
FOR y%=start% TO end% STEP step%
One line of the bar is then drawn, and if offset% has not been set to zero,
another line is drawn at y%+offset%. This is used to erase the old bar
line-by-line as the new one is being drawn, giving the flowing effect.
Finally, PROCdelay(2) provides a delay of two centiseconds between the
drawing of each line.
With the direct selection menus earlier in this series I gave a general
procedure which could be used to make implementing the menus easier. I have
not done this for these menus because there are so many variations that it
would not really be convienient. However, it should be relatively easy to
adapt any of the routines given here for your own programs and you are
welcome to do so, provided they are not used for profit.
In the next article I intend to cover step-and-direct selection menus, which
give the best of both worlds.