With a basic button set now working, I set my sights on converting my Action! library radio button routine. This is the GRadio() function. It displays a set of radio buttons either horizontally or vertically. I made a minor alteration in how navigation/selection is handled in the C version. In the Action! version, space would establish a button as selected but not exit until Enter was pressed. After using it a bit and never having been completely satisfied, I chose to have Space select and exit. Navigation feels smoother with this minor change.
To enable form drawing before activating any controls, it is necessary to call the function with a flag telling it to only display the choices and exit. You call it again with an edit flag when it is ready to be activated. After a radio button is edited, it should be called again with the display only flag to clean up – meaning to revert the selection if ESC was pressed, or show the new selection. There is no difference here in how it worked in my Action! library.
It’s noteworthy to mention that each of the interactive gadgets will return special values if ESC or TAB are pressed. This enables you to write a looping routing to process different input gadget elements as a form and allow the user to TAB through each control – much like modern GUI’s. In the demo program here you can see the handling of these keys which prevent the exit of the loop/form until both sets of radio buttons have the 3rd option selected.
Here is the demo program showing how the function is called for both orientations.
// ------------------------------------------------------------
// Program: gradio.c
// Desc...: A8 Library Gadget Radio Button Test
// Author.: Ripdubski
// Date...: 202208
// Notes..: cl65 -v [-O] -t atarixl gradio.c -o gradio.xex
// ------------------------------------------------------------
// Pull in include files
#include <stdio.h>
#include <conio.h>
#include <unistd.h>
#include <string.h>
#include <atari.h>
#include "a8defines.h"
#include "a8defwin.h"
#include "a8libmisc.c"
#include "a8libstr.c"
#include "a8libwin.c"
#include "a8libgadg.c"
#include "a8libmenu.c"
// ------------------------------------------------------------
// Func...: void DoRadio(void)
// Desc...: Displays radio button demo
// ------------------------------------------------------------
void DoRadio(void)
{
byte bW, bra, brb, brap, brbp;
unsigned char *rA[4] = { "One", "Two", "Three" };
unsigned char *rB[4] = { "Choice A", "Choice B", "Choice C" };
// Set defaults for selection and previous selection
bra = 1;
brb = 1;
brap = bra;
brbp = brb;
// Open window
bW = WOpen(2, 5, 36, 12, WOFF);
WOrn(bW, WPTOP, WPLFT, "Radio Button Test");
// Show horizontal buttons
WPrint(bW, 1, 2, WOFF, "Radio Buttons (horiz)");
GRadio(bW, 2, 3, GHORZ, GDISP, brap, 3, rA);
// Show veritcal buttons
WPrint(bW, 1, 5, WOFF, "Radio Buttons (vert)");
GRadio(bW, 2, 6, GVERT, GDISP, brbp, 3, rB);
WPrint(bW, 1, 10, WOFF, "Pick 3rd choices to exit.");
// Loop until accepted or cancelled
while ((bra != 3) || (brb != 3))
{
// Display horiz buttons and get choice
bra = GRadio(bW, 2, 3, GHORZ, GEDIT, brap, 3, rA);
// If not bypass, set previous selected value
if ((bra != XESC) && (bra != XTAB))
{
brap = bra;
}
// Redisplay buttons
GRadio(bW, 2, 3, GHORZ, GDISP, brap, 3, rA);
// Display vert buttons and get choice
brb = GRadio(bW, 2, 6, GVERT, GEDIT, brbp, 3, rB);
// If not bypass, set previous selected value
if ((brb != XESC) && (brb != XTAB))
{
brbp = brb;
}
// Redisplay buttons
GRadio(bW, 2, 6, GVERT, GDISP, brbp, 3, rB);
}
// Close window
WClose(bW);
}
// ------------------------------------------------------------
// Func...: void main(void)
// Desc...: Main routine
// ------------------------------------------------------------
void main(void)
{
// Variables
byte bW1, bW2, bC, bD;
unsigned char *pcM[7] = { " Alert ", " Progress ", " Buttons ", " Checkboxes ", " Radio Button ", " Quit " };
// Setup screen
WInit();
WBack(14);
// Open windows
bW1 = WOpen(0, 0, 40, 3, WON);
WPrint(bW1, WPCNT, 1, WOFF, "CC65 A8 Library Test");
bW2 = WOpen(12, 6, 16, 10, WOFF);
WOrn(bW2, WPTOP, WPCNT, "Menu");
// Set done to false
bD = FALSE;
// Loop until done (Quit selected)
while (! bD) {
// Call menu
bC = MenuV(bW2, 1, 2, WON, 1, 6, pcM);
// Process choice
switch (bC)
{
case 1: GAlert("Alert! menu option 1 selected!");
break;
case 2: GAlert("Alert! menu option 2 selected!");
break;
case 3: GAlert("Alert! menu option 3 selected!");
break;
case 4: GAlert("Alert! menu option 4 selected!");
break;
case 5: DoRadio();
break;
case 6: bD = TRUE;
break;
}
}
// Wait for a keypress
while (! kbhit()) { };
// Close windows
WClose(bW2);
WClose(bW1);
// Exit
return;
}
Here is a screenshot of it in use:
