In this post I set out to convert the checkbox routine GCheck(). This displays a checkbox, and allows the user to check or uncheck it.
Here is the demo program showing how to call it:
// ------------------------------------------------------------
// Program: gcheck.c
// Desc...: A8 Library Gadget Checkbox Test
// Author.: Ripdubski
// Date...: 202208
// Notes..: cl65 -v [-O] -t atarixl gcheck.c -o gcheck.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 DoCheck(void)
// Desc...: Displays checkbox demo
// ------------------------------------------------------------
void DoCheck(void)
{
byte bW, bD, bF;
// Vars used for selections and previous selections
byte bca, bcb, bcc, bcap, bcbp, bccp;
// Set defaults for previous selections (initial item status)
bcap = GCOFF;
bcbp = GCOFF;
bccp = GCON;
// Open window
bW = WOpen(9, 10, 22, 6, WOFF);
WOrn(bW, WPTOP, WPLFT, "Checkboxes");
WPrint(bW, 1, 1, WOFF, "Select your weapons:");
WPrint(bW, 6, 2, WOFF, "Action!");
WPrint(bW, 6, 3, WOFF, "BASIC");
WPrint(bW, 6, 4, WOFF, "C");
// Display only with previous/default/initial value
bF = GCheck(bW, 2, 2, GDISP, bcap);
bF = GCheck(bW, 2, 3, GDISP, bcbp);
bF = GCheck(bW, 2, 4, GDISP, bccp);
GAlert(" Check all and TAB to quit. ");
// Continue until exited
bF = FALSE;
while (! bF)
{
// Stay on this check until ESC, TAB
bD = FALSE;
while (! bD)
{
// Call checkbox with edit and previous value
bca = GCheck(bW, 2, 2, GEDIT, bcap);
// Check returned value
if ((bca == XESC) || (bca == XTAB))
{
// Allow exit of loop for this checkbox
bD = TRUE;
}
else
{
// Set previous value to the current value
bcap = bca;
}
}
// Stay on this check until ESC, TAB
bD = FALSE;
while (! bD)
{
// Call checkbox with edit and previous value
bcb = GCheck(bW, 2, 3, GEDIT, bcbp);
// Check returned value
if ((bcb == XESC) || (bcb == XTAB))
{
// Allow exit of loop for this checkbox
bD = TRUE;
}
else
{
// Set previous value to the current value
bcbp = bcb;
}
}
// Stay on this check until ESC, TAB
bD = FALSE;
while (! bD)
{
// Call checkbox with edit and previous value
bcc = GCheck(bW, 2, 4, GEDIT, bccp);
// Check returned value
if ((bcc == XESC) || (bcc == XTAB))
{
// Allow exit of loop for this checkbox
bD = TRUE;
}
else
{
// Set previous value to the current value
bccp = bcc;
}
}
// Leave loop wonce all checked - DEMO
if ((bcap == GCON) && (bcbp == GCON) && (bccp == GCON))
{
bF = TRUE;
}
}
GAlert(" All options checked! ");
// Close window
WClose(bW);
return;
}
// ------------------------------------------------------------
// 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: DoCheck();
break;
case 5: GAlert("Alert! menu option 5 selected!");
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:
