enum TwType |
---|
Constants used to declare the type of variables added to a tweak bar. Used by functions TwAddVarRW, TwAddVarRO and TwAddVarCB.
A C++ boolean. C++ only .
Example:
bool b = true; // ... TwAddVarRW(bar, "b", TW_TYPE_BOOLCPP, &b, "");
A byte (8 bits) which represents a boolean value.
Example:
char mipmap = 0; // ... TwAddVarRW(bar, "MIP-map", TW_TYPE_BOOL8, &mipmap, " true=Enabled false=Disabled ");
A 16 bits variable which represents a boolean value.
Example:
short modeIsLinear = 1; // ... TwAddVarRW(bar, "InterpMode", TW_TYPE_BOOL16, &modeIsLinear, " label='Interpolation mode' true=Linear false=Point ");
A 32 bits variable which represents a boolean value.
Example:
int antialias = 0; // ... TwAddVarRW(bar, "Antialiasing", TW_TYPE_BOOL32, &antialias, " key=ALT+a ");
A character (8 bits).
Example:
char letter = 'A'; // ... TwAddVarRW(bar, "Letter", TW_TYPE_CHAR, &letter, " min=65 max=90 "); // 65 and 90 correspond to 'A' and 'Z' ASCII codes
A 8 bits signed integer.
Example:
signed char i8 = 0; // ... TwAddVarRW(bar, "int8", TW_TYPE_INT8, &i8, " keyIncr=i keyDecr=I ");
A 8 bits unsigned integer.
Example:
unsigned char ui8 = 0; // ... TwAddVarRW(bar, "uint8", TW_TYPE_UINT8, &ui8, "");
A 16 bits signed integer.
Example:
short i16 = 0; // ... TwAddVarRW(bar, "int16", TW_TYPE_INT16, &i16, "");
A 16 bits unsigned integer.
Example:
unsigned short ui16 = 0; // ... TwAddVarRW(bar, "uint16", TW_TYPE_UINT16, &ui16, "");
A 32 bits signed integer.
Example:
int z = 20; // ... TwAddVarRW(bar, "Z", TW_TYPE_INT32, &z, " min=-1000 max=1000 keyIncr=z keyDecr=Z ");
A 32 bits unsigned integer.
Example:
unsigned int cost = 2000; // ... TwAddVarRW(bar, "Cost", TW_TYPE_UINT32, &cost, " max=100000 step=100 ");
A 32 bits floating point value (float).
Example:
float seconds = 5.0f; // ... TwAddVarRW(bar, "DeltaTime", TW_TYPE_FLOAT, &seconds, " min=0 max=60 step=0.1 ");
A 64 bits floating point value (double).
Example:
double tmpt = 30.0; // ... TwAddVarRW(bar, "Temperature", TW_TYPE_DOUBLE, &tmpt, " precision=3 ");
A color represented by a 32 bits integer. Order is RGBA if the graphic API is OpenGL or Direct3D10, and inversed if the graphic API is Direct3D9. R, G, B and A are respectively the Red, Green, Blue and Alpha channels. The alpha channel can be made editable by specifying alpha
in the definition string of the variable. The order can be modified by specifying colorOrder=...
in the definition string of the variable.
Example:
unsigned int color; // ... TwAddVarRW(bar, "Color", TW_TYPE_COLOR32, &color, " coloralpha=true ");
A color represented by 3 floats in the range [0,1] and corresponding to the Red, Green and Blue color channels (in that order).
Example:
float submarineColor[3] = {1, 1, 0}; // yellow // ... TwAddVarRW(bar, "Submarine", TW_TYPE_COLOR3F, &submarineColor, " colormode=hls ");
A color with transparency represented by 4 floats in the range [0,1] and corresponding to the Red, Green, Blue and Alpha channels (in that order).
Example:
float glassColor[4] = {0, 1, 1, 0.2f}; // transparent cyan // ... TwAddVarRW(bar, "Glass", TW_TYPE_COLOR4F, &glassColor, "");
A C-Static sized null-terminated String. Here ‘static’ means that the maximum size of the string is fixed and the string pointer is also fixed (the string memory block will not be moved).
maxsize
is the maximum size of the string (including the null termination character).
Example:
char s1[64] = "a static string"; // ... TwAddVarRW(bar, "s1", TW_TYPE_CSSTRING(sizeof(s1)), s1, ""); // here, sizeof(s1) is 64 // also works with TwAddVarRO and TwAddVarCB
Note that you don’t need to pass a pointer tos1
buts1
itself which is already a pointer (and will remain fixed).
An example using TwAddVarCB:
char s1[64] = "a static string"; // ... void TW_CALL SetMyCSStringCB(const void *value, void * /*clientData*/) { const char *src = (const char *)value; strncpy(s1, src, sizeof(s1)); s1[sizeof(s1)-1] = '\0'; // ensure that it is always null-terminated } void TW_CALL GetMyCSStringCB(void *value, void * /*clientData*/) { char *dest = (char *)value; strncpy(dest, s1, sizeof(s1)); dest[sizeof(s1)-1] = '\0'; // ensure that it is always null-terminated } // ... TwAddVarCB(bar, "s1", TW_TYPE_CSSTRING(sizeof(s1)), SetMyCSStringCB, GetMyCSStringCB, NULL, "");
A C-Dynamic null-terminated String. This null-terminated string can be allocated and reallocated dynamically (eg. by calling malloc
/realloc
/strdup
...). So its pointer can change.
Example:
// TwCopyCDStringToClientFunc must have been called before (see explanation below) char *s2 = strdup("a string allocated dynamically"); // ... TwAddVarRW(bar, "s2", TW_TYPE_CDSTRING, &s2, ""); // also works with TwAddVarRO and TwAddVarCB // ... free(s2);
Note that you should pass a pointer to the pointers2
(contrary tos1
inTW_TYPE_CSSTRING
above) becauses2
is not static and thus can change.
In order to correctly handle memory allocations between your client application and the AntTweakBar library, you must also provide a function that will be called by AntTweakBar to copy the content of a C-Dynamic String. If this function is not provided, the variable will remain read-only. See TwCopyCDStringToClientFunc for more details.
In the other way, if your application needs to copy a C-Dynamic String to AntTweakBar (for instance if you use callbacks to handle the variable via TwAddVarCB), use the function TwCopyCDStringToLibrary. See TwCopyCDStringToLibrary for an example of how to use TwAddVarCB
with a variable of type TW_TYPE_CDSTRING
.
See also this recap of how to handle the different string variable types.
A C++ String. It corresponds to an object of type std::string
, which is the standard string class provided by the STL library.
Example:
// TwCopyStdStringToClientFunc must have been called before (see explanation below) std::string s3 = "a STL string"; // ... TwAddVarRW(bar, "s3", TW_TYPE_STDSTRING, &s3, ""); // also works with TwAddVarRO and TwAddVarCB
In order to correctly handle memory allocations between your client application and the AntTweakBar library, you must also provide a function that will be called by AntTweakBar to copy the content of a std::string
. If this function is not provided, the variable will remain read-only. See TwCopyStdStringToClientFunc for more details.
In the other way, if your application needs to copy a std::string
to AntTweakBar (for instance if you use callback to handle the variable via TwAddVarCB), you must copy it by calling TwCopyStdStringToLibrary. See TwCopyStdStringToLibrary for an example of how to use TwAddVarCB
with a variable of type TW_TYPE_STDSTRING
.
See also this recap of how to handle the different string variable types.
A rotation represented by a unit quaternion coded with 4 floats or 4 doubles.
See the following page for a description of quaternions:
http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation
Quaternion values are stored in the following order:
q[0] = sin( a / 2 ) * vx
q[1] = sin( a / 2 ) * vy
q[2] = sin( a / 2 ) * vz
q[3] = cos( a / 2 )
where a is the rotation angle (in radian) and {vx,vy,vz} is the normalized rotation axis.
Example:
float quat[4] = {0, 0, 0, 1}; // null rotation // ... TwAddVarRW(bar, "Rotation", TW_TYPE_QUAT4F, &quat, "");
See example TwSimpleGLUT for a more complete use of quaternions and directions.
A direction represented by a 3D vector coded with 3 floats or 3 doubles.
Example:
double dir[3] = {1, 1, 0}; // direction pointing to +x and +y // ... TwAddVarRW(bar, "LightDir", TW_TYPE_DIR3D, &dir, "");
See example TwSimpleGLUT for a more complete use of quaternions and directions.