All the gadgets up until now have been mildly user interactive. In this post I finally tackle the biggest, and likely most useful, gadget – GInput(). This is the string input routine that allows type restricted (numeric, alphabetic, alpha-numeric, or any text) string input. The string editing size can be smaller than the string itself and the string will scroll left or right as the cursor is moved. There are some special keys tossed in to get to start of the string, end of the string, clearing the string, inserting and deleting characters. At the time of this writing, the C version hasn’t been fully tested for the last three cases mentioned, but will be by the time the library is published.
The code for GInput() is quite large in relation to the other gadgets, but it does quite a bit.
Here is a demo program showing how the gadget is called:
// ------------------------------------------------------------
// Program: ginput.c
// Desc...: A8 Library Input Test
// Author.: Ripdubski
// Date...: 202208
// Notes..: cl65 -v [-O] -t atarixl ginput.c -o ginput.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 DoInput(void)
// Desc...: Displays input demo
// ------------------------------------------------------------
void DoInput(void)
{
byte bW;
unsigned char cA[41], cB[41], cC[41], cD[41];
// Assign default string values
strcpy(cA, "-100.00 ");
strcpy(cB, "This string has something to edit in it!");
strcpy(cC, " ");
sprintf(cD, "%cAny character string!%c ", CHBALL, CHBALL);
// Open window & draw form
bW = WOpen(2, 6, 36, 10, WOFF);
WOrn(bW, WPTOP, WPLFT, "Input Test");
WPrint(bW, 1, 1, WOFF, "Data Fields");
WPrint(bW, 2, 3, WOFF, "Numer:");
WPrint(bW, 2, 4, WOFF, "Alpha:");
WPrint(bW, 2, 5, WOFF, "AlNum:");
WPrint(bW, 2, 6, WOFF, "Any..:");
// Display fields as is
// WPrint will truncate what doesn't fit (27 chars for this window).
WPrint(bW, 8, 3, WOFF, cA);
WPrint(bW, 8, 4, WOFF, cB);
WPrint(bW, 8, 5, WOFF, cC);
WPrint(bW, 8, 6, WOFF, cD);
// Input each in succession
// 27 is the maximum width to display of the 40 lengths
GInput(bW, 8, 3, GNUMER, 27, cA);
GInput(bW, 8, 4, GALPHA, 27, cB);
GInput(bW, 8, 5, GALNUM, 27, cC);
GInput(bW, 8, 6, GANY, 27, cD);
// Wait for a key
WPrint(bW, WPCNT, 8, 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[9] =
{ " Alert ", " Progress ", " Buttons ", " Checkboxes ", " Radio Button ", " Spinner ", " Input ", " 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, 12, 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, 8, 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: GAlert("Alert! menu option 6 selected!");
break;
case 7: DoInput();
break;
case 8: 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 (the cursor is active on the s in the word has of the Alpha field):
