In the previous post I converted the non-interactive gadget GProc(). In this post I move to the most basic of user interaction: buttons (like OK, Cancel) via function GButton(). The button labels and quantity are up to you, as well as the default button selection.
The programmer is required to specify any ornaments for the buttons, if so desired. As the user moves between buttons, the active one is displayed in inverse video. The implementation in C is actually quite simpler than an Action! due to C’s advanced handling of arrays of strings. The source code will be released once the entire library has been converted – at that point you can compare if you are so inclined.
Here is a program demonstrating its use:
// ------------------------------------------------------------
// Program: gbutton.c
// Desc...: A8 Library Gadget Button Test
// Author.: Ripdubski
// Date...: 202208
// Notes..: cl65 -v [-O] -t atarixl gbutton.c -o gbutton.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 DoButt(void)
// Desc...: Displays button demo
// ------------------------------------------------------------
void DoButt(void)
{
byte bC, bW;
unsigned char *cS[3] = { "[ Ok ]", "[ Cancel ]" };
// Open window
bW = WOpen(9, 10, 22, 6, WOFF);
WOrn(bW, WPTOP, WPLFT, "Buttons");
WPrint(bW, 2, 2, WOFF, "Select a button:");
// Call the button handler with all buttons defined
bC = GButton(bW, 5, 4, 2, 2, cS);
// 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: DoButt();
break;
case 4: GAlert("Alert! menu option 4 selected!");
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 running:
