Sounds like someone's been programming too much Perl again, or
Lisp, or something.
Been too long for either of them. Thanks to both (quick) responders.
This is to be help screens for an embedded system. I want to define a
hierarchical set of structures that define each screen, including buttons
with multiple representations (being pressed, e.g.), and a function
associated with each button.
It wasn't the code for manipulating it, I just couldn't get everything
declared. Fortunately, that part of my stupidity has cleared. Here's
what I came up with in case anybody's interested.
-------8<-------
#ifndef _BUTTON_H_
#define _BUTTON_H_
typedef unsigned char uchar;
typedef enum
{ SC_EXIT, SC_Main, SC_Wireless, SC_DotQuad, SC_ESSID } SCREEN;
// Button defines size and which, of possibly 4, image to display
typedef struct
{
size_t cols, rows; // Pixels
int current; // If more than one set of images, which?
int active; // Use active rather than idle
uchar *idle[ 2 ]; // Primary & alternate idle view
uchar *actv[ 2 ]; // Primary & alternate active view
} Button;
// ButtonOp defines the operation of a given button: where it is on
// screen, its active touch values, the function to be called, and the
// images to use for it.
typedef struct _ButtonOp
{
int tp, lp; // Top left pixel
int tt, lt, bt, rt; // Top left, bottom right touch
SCREEN (*touchFunc)(struct _ButtonOp *, int, int, int);
Button *button;
} ButtonOp;
// MenuScreen defines the entire screen.
typedef struct
{
SCREEN theScreen;
int bcolor;
int tf, tb;
void (*initFunc)(void);
int buttons;
ButtonOp *button[ 20 ];
} MenuScreen;
extern MenuScreen MainScreen;
#endif
---->8----
And here's a stripped-down version of a screen definition:
----8<----
#include <stdio.h>
#include <stdlib.h>
#include "button.h"
static void sc1_initFunc( void );
static SCREEN sc1_bf1( ButtonOp *theBop, int ht, int vt, int up );
extern uchar sc1_b1i[], sc1_b1a[];
static Button sc1_b1 = { 100, 40, 0, 0, {sc1_b1i}, {sc1_b1a}};
static ButtonOp SC1_BB1 = { 20, 20, 1, 1, 2, 5, sc1_bf1, &sc1_b1 };
MenuScreen MainScreen =
{
SC_Main, 0, 0, 0, sc1_initFunc, 1, { &SC1_BB1 }
};
static void sc1_initFunc( void )
{
return;
}
static SCREEN sc1_bf1( ButtonOp *theBop, int ht, int vt, int up )
{
(void)theBop;(void)ht;(void)vt;(void)up;
return SC_DotQuad;
}
// In the real world, these are not strings, but raw bitmaps.
static uchar sc1_b1i[] = "sc1_b1i";
static uchar sc1_b1a[] = "sc1_b1a";
---->8----