Contents
TwAddVarCB (function)
Description
This function adds a new variable to a tweak bar by providing CallBack (CB) functions to access it. If the setCallback parameter is set to ParametersbarThe tweak bar to which adding a new variable. name
The name of the variable. It will be displayed in the tweak bar if no typeType of the variable. It must be one of the TwType constants or a user defined type created with TwDefineStruct or TwDefineEnum*. setCallbackThe callback function that will be called by AntTweakBar to change the variable’s value. You should define this callback function like this: void TW_CALL SetCallback(const void *value, void *clientData) { myVariable = *(const MyVariableType *)value; // for instance } getCallbackThe callback function that will be called by AntTweakBar to get the variable’s value. You should define this callback function like this: void TW_CALL GetCallback(void *value, void *clientData) { *(MyVariableType *)value = myVariable; // for instance } clientDataFor your convenience, this is a supplementary pointer that will be passed to the callback functions when they are called. For instance, if you set it to an object pointer, you can use it to access to the object’s members inside the callback functions. Here is an example: class Sphere { public: void SetRadius(float r); float GetRadius() const; // ... static void TW_CALL SetRadiusCallback(const void *value, void *clientData) { static_cast<Sphere *>(clientData)->SetRadius(*static_cast<const float *>(value)); } static void TW_CALL GetRadiusCallback(void *value, void *clientData) { *static_cast<float *>(value) = static_cast<const Sphere *>(clientData)->GetRadius(); } // ... }; int main() { Sphere s; // ... TwAddVarCB(bar, "s.Radius", TW_TYPE_FLOAT, Sphere::SetRadiusCallback, Sphere::GetRadiusCallback, &s, ""); // ... } def
An optional definition string used to modify the behavior of this new entry. This string must follow the variable parameters syntax, or set to Return value
See alsoTwAddVarRO, TwAddVarRW, TwAddButton, TwRemoveVar, TwAddSeparator, TwDefine, TwSetParam, TwGetParam, TwDefineStruct, TwDefineEnum |