|
Prisms Development Toolkit DocumentationSide Effects Software Inc. 1997 |
The result looks like this:
/* define SOP-specific constants and menus */
#define PLANE_XY 0
#define PLANE_YZ 1
#define PLANE_ZX 2
static MENU planeTypes[] = {
{ NULLMFUNC, "XY", (char *)PLANE_XY, },
{ NULLMFUNC, "YZ", (char *)PLANE_YZ, },
{ NULLMFUNC, "ZX", (char *)PLANE_ZX, },
{ NULL },
};
static void
sopDefaults(SOP *sop)
{
SOP_DATA *sb;
if (sop->special)
free(sop->special);
sb = (SOP_DATA *)Calloc(sizeof(SOP_DATA), "SOPCircleDefaults");
sop->special = (char *)sb;
/* if there were inputs, they would be defined here as
if (sop->sopin[0].type == SOURCE_NULL) // new sop
sop->sopin[0].type = SOURCE_PREV;
*/
sop->nsources = NSOURCES;
SopClearSources(sop, sop->nsources);
InitSopExpr(&sb->center[0], "0");
InitSopExpr(&sb->center[1], "0");
InitSopExpr(&sb->center[2], "0");
InitSopExpr(&sb->radius, "1");
InitSopExpr(&sb->ndivs, "10");
InitSopMenu(&sb->orient, planeTypes, PLANE_XY, "Orientations");
}
The user changes here involve the choice of Init routines, and the
values passed. The routine InitSopExpr() initializes an expression
value, and needs
to see the address of a sop value location, and a string containing
the default value. The preceeding example should be self-explanatory.
For menus, there is InitSopMenu(), which is defined thus:
void InitSopMenu(SOP_EXPR *sep, MENU *mp, int entry, char *title) where
sep is the entry in the SOP structure containing the menu mp is a pointer to a structure containing a list of menu entries
The first field is a pointer to a menu function - this will be NULL. The second is a menu string, and the third is the keyboard equivalent of that string. Usually, these are just ordered integers which distinguish one choice from the next.
entry is the number of the default entry. Number in this case means the integer just assigned to that entry.
title is the name which appears on the SOP to the left of the menu.
static int
getAvailableSops(SOP *sop, UI_STRING *sp, SOP_EXPR *sep)
{
SOP_DATA *sb;
UI_MENU *mp;
MENU *entry;
FILE *ifp;
int i;
char **sops;
char *file;
sb = (SOP_DATA *)sop->special;
file = SopExpandString(sop, sb->file.value.sval);
if (sb->saging && sb->oldFile && strcmp(file, sb->oldFile) != 0)
{
ACTsageStop(sb->saging);
sb->saging = 0;
}
if (!sb->saging)
{
if (sb->oldFile) free(sb->oldFile);
sb->saging = ACTsageStart(file);
sb->oldFile = strdup(file);
}
sops = ACTsageGetSops(sb->saging);
i = 0;
if( sops )
{
for (; sops[i]; i++)
{
GeneralBigMenu[i].func = NULLMFUNC;
GeneralBigMenu[i].menu = sops[i];
GeneralBigMenu[i].keyboard = (char *)0;
}
free(sops);
}
GeneralBigMenu[i].func = NOFUNC;
GeneralBigMenu[i].menu = NOSTRING;
mp = UI_InitMenu("Sage SOPs", GeneralBigMenu);
UI_SelectMenu(mp);
entry = UI_RenderMenu();
UI_CleanMenu(mp);
if (entry)
{
strreplace(&sep->value.sval, entry->menu);
UI_SETSTRING(sp, entry->menu);
}
for (i = 0; GeneralBigMenu[i].func != NOFUNC; i++)
free(GeneralBigMenu[i].menu);
return (entry) ? 1 : 0;
}