This time I cover the conversion of the numeric spinner input. It allows for a number to be chosen where the user does not enter it directly, but rather changes the value by pressing keys representing increment and decrement. It only allows for value between 0 and 250. Values above 250 are reserved for form control, such as ESC and TAB. I feel like this is fine since no one will want to cycle up/down into thousands or more, and most likely this will be used from 0 to 100. I contemplated a top limit of 100, but decided to allow up to 250. This was also the last gadget I wrote for my Action! library.
In the demo program, the user is allowed to change the Value field from 5 to 100. Once accepted, the new value is displayed below in the New field.
Here is the demo program showing how its called:
// ------------------------------------------------------------
// Program: gspin.c
// Desc...: A8 Library Window Menu Test
// Author.: Ripdubski
// Date...: 202208
// Notes..: cl65 -v [-O] -t atarixl gspin.c -o gspin.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 DoSpin(void)
// Desc...: Displays spinner demo
// ------------------------------------------------------------
void DoSpin(void)
{
byte bW, bC, bV;
unsigned char cL[4];
// Set default value
bV = 10;
// Open window
bW = WOpen(8, 7, 24, 9, WOFF);
WOrn(bW, WPTOP, WPLFT, "Spinner");
WPrint(bW, 2, 2, WOFF, "Value:");
WPrint(bW, 4, 4, WOFF, "New:");
// Display spinner and get returned value
// Min value=5, max value=100
bC = GSpin(bW, 8, 2, 5, 100, bV);
// What was returned?
if (bC == XESC)
{
GAlert(" Escaped Out! ");
}
else if (bC == XTAB)
{
GAlert(" Tabbed Out! ");
}
else
{
// Show the new value
sprintf(cL, "%3d", bC);
WPrint(bW, 8, 4, WOFF, cL);
}
// Wait for a key
WPrint(bW, WPCNT, 6, WOFF, "Press any key.");
WaitKCX(WOFF);
// Close window
WClose(bW);
}
// ------------------------------------------------------------
// Func...: void main(void)
// Desc...: Main routine
// ------------------------------------------------------------
void main(void)
{
// Variables
byte bW1, bW2, bC, bD;
unsigned char *pcM[8] =
{ " Alert ", " Progress ", " Buttons ", " Checkboxes ", " Radio Button ", " Spinner ", " 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, 11, 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, 7, 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: GAlert("Alert! menu option 5 selected!");
break;
case 6: DoSpin();
break;
case 7: bD = TRUE;
break;
}
}
// Wait for a keypress
while (! kbhit()) { };
// Close windows
WClose(bW2);
WClose(bW1);
// Exit
return;
}
Here is a screenshot of its use: