|
Contents
TwDefineEnum (function)
DescriptionThis function creates a new TwType corresponding to a C/C++ enum. Thus it could be used with TwAddVar* functions to control variables of type enum. ParametersnameSpecify a name for the enum type (must be unique). enumValuesAn array of structures of type TwEnumVal containing integer values and their associated labels (pointers to zero terminated strings) corresponding to the values. nbValuesNumber of elements of the enumValues array. Return values
Exampletypedef enum { SUMMER, FALL, WINTER, SPRING } Seasons; Seasons season = WINTER; TwEnumVal seasonsEV[] = { {SUMMER, "Summer"}, {FALL, "Fall"}, {WINTER, "Winter"}, {SPRING, "Spring"} }; TwType seasonType; // ... // Defining season enum type seasonType = TwDefineEnum("SeasonType", seasonsEV, 4); // Adding season to bar TwAddVarRW(bar, "Season", seasonType, &season, NULL); Note that enum values defintions can also be done through the val command of the def parameter of TwAddVar*. Like this: typedef enum { SUMMER, FALL, WINTER, SPRING } Seasons; Seasons season = WINTER; // ... // Defining an empty season enum type seasonType = TwDefineEnum("SeasonType", NULL, 0); // Adding season to bar and defining seasonType enum values TwAddVarRW(bar, "Season", seasonType, &season, " val='0 {Summer}, 1 {Fall}, 2 {Winter}, 3 {Spring}' "); // This will affect all variables that are of type seasonType. See also |