TUI – Library

 

The idea behind the TUI library is have a set of C functions that speeds up the create of application user interfaces for computers that work CC65 C complier (Commodore 128, 64, Plus/4, Atari and AppleII* (* I haven’t found an easy way to run compiled programs in the WinApple emulator yet).

While these functions can be used in C programs my intent is that they are used to build C programs from a Visual Basic interface and code generation (Retro C IDE & Code Builder) that will create C code that can then be saved, compiled and run in an emulator (on retro hardware) on windows platform.

Even with the IDE it helps to understand the functions and related data structures.

CREATING/CLOSING WINDOWS

The core of each UI is the window and it is created with the function:

tgui_Window *newwindow(int x1, int y1, int x2, int y2, int color, unsigned parent, char* title);

The function draws a box on the screen with corners at x1, y1 and x2, y2 in the color specified, and a title if passed. Memory is dynamically allocated for a tgui_Window structure and  returns a pointer to the structure (see below).
The pointer is needed to pass to other functions that add menus and objects to the window.   The parent parameter (parent=0)  is used to determine if the part of the screen covered by this window needs to be saved and restored after the window is closed. The color parameter acts differently if it is Commodore or Atari.  For Commodore the color will become the default text color for the window.  For Atari it sets the background and text color for the application.

so a simple program to create a window would be :

#include <conio.h>
#include <tuilib.h>
void main () {
tgui_Window *winptr;

winptr = newwindow(0,0,39,24,COLOR_WHITE,0,”Hello World\0″);
cgetc();
closewindow(winptr);

} // end of main

resulting in :

tuilib01

void closewindow(tgui_Window* win);

Clears the screen where the window was drawn, redraws if the parent parameter was 0, and frees all the memory that was allocated to the window, including menus and objects.

ADDING OBJECTS

There are currently 5 kinds of objects that can be added to a window, Label, Text Box, Number Box (spinner), Button, Listbox.  They can each be created with a single call to the function :

void newobject(
int x, int y,                         // x, y position within and relative to current window
int width,                           // width of object, used in textbox, numbox and listbox
int height,                          // height of listbox, max value for number box
int color,                             // color of text for this object, not used for Atari
unsigned state,                 // index of selected item in list box, min value for number box
char *caption,                  // caption for button, label, listbox
char *data,                         // default data as string for any object
tgui_Object_type type,  // declares object type is enum for type below
tgui_Window *win,       // pointer to window that holds the object
void (*fp)(void *)           // pointer to a function that the object can call (button)
;
typedef enum {
label, button, checkbox, radiobutton, simpletext, multitext, numbox, listbox

} tgui_Object_type;

Note : Radiobutton, multitest checkbox are not yet implemented and may not be

Advertisements