void SetValuesWidth(TwBar* bar, int32 width, bool32 fit) { if(fit) TwCall(TwSetParam(bar, nullptr, "valueswidth", TW_PARAM_CSTRING, 1, "fit")); else TwCall(TwSetParam(bar, nullptr, "valueswidth", TW_PARAM_INT32, 1, &width)); }
void SetAxisMapping(TwBar* bar, const char* varName, Axis xAxis, Axis yAxis, Axis zAxis) { static const char* AxisStrings[] = { "x", "-x", "y", "-y", "z", "-z" }; TwCall(TwSetParam(bar, varName, "axisx", TW_PARAM_CSTRING, 1, AxisStrings[uint64(xAxis)])); TwCall(TwSetParam(bar, varName, "axisy", TW_PARAM_CSTRING, 1, AxisStrings[uint64(yAxis)])); TwCall(TwSetParam(bar, varName, "axisz", TW_PARAM_CSTRING, 1, AxisStrings[uint64(zAxis)])); }
void SetUseArrowMode(TwBar* bar, const char* varName, bool32 useArrowMode, Float3 initialDirection) { if(useArrowMode) { std::string dirString = "'" + ToAnsiString(initialDirection.x) + " " + ToAnsiString(initialDirection.y) + " " + ToAnsiString(initialDirection.z) + "'"; TwCall(TwSetParam(bar, varName, "arrow", TW_PARAM_CSTRING, 1, dirString.c_str())); } else TwCall(TwSetParam(bar, varName, "arrow", TW_PARAM_CSTRING, 1, "0")); }
void SetColor(TwBar* bar, Float3 color) { int32 rgb[3] = { int32(Saturate(color.x) * 255.0f), int32(Saturate(color.y) * 255.0f), int32(Saturate(color.z) * 255.0f) }; TwCall(TwSetParam(bar, nullptr, "color", TW_PARAM_INT32, 3, rgb)); }
void SetArrowColor(TwBar* bar, const char* varName, Float3 color) { int32 rgb[3] = { int32(Saturate(color.x) * 255.0f), int32(Saturate(color.y) * 255.0f), int32(Saturate(color.z) * 255.0f) }; TwCall(TwSetParam(bar, varName, "arrowcolor", TW_PARAM_INT32, 3, rgb)); }
void Setting::Initialize(TwBar* tweakBar_, SettingType type_, void* data_, const char* name_, const char* group_, const char* label_, const char* helpText_, ETwType twType_) { tweakBar = tweakBar_; type = type_; data = data_; name = name_; group = group_; label = label_; helpText = helpText_; changed = false; static const ETwType twTypes[] = { TW_TYPE_FLOAT, TW_TYPE_INT32, TW_TYPE_BOOL32, TW_TYPE_UINT32, // not used TW_TYPE_DIR3F, TW_TYPE_QUAT4F, TW_TYPE_COLOR3F, }; StaticAssert_(_countof(twTypes) == uint64(SettingType::NumTypes)); const ETwType twType = twType_ == TW_TYPE_UNDEF ? twTypes[uint64(type)] : twType_; TwCall(TwAddVarRW(tweakBar, name.c_str(), twType, data, nullptr)); TwHelper::SetLabel(tweakBar, name.c_str(), label.c_str()); TwHelper::SetHelpText(tweakBar, name.c_str(), helpText.c_str()); TwHelper::SetGroup(tweakBar, name.c_str(), group.c_str()); }
void Button::Initialize(TwBar* tweakBar_, const char* name_, const char* group_, const char* label_, const char* helpText_) { tweakBar = tweakBar_; type = SettingType::Button; name = name_; group = group_; label = label_; helpText = helpText_; changed = false; TwCall(TwAddButton(tweakBar, name_, Button::Callback, this, "")); TwHelper::SetLabel(tweakBar, name.c_str(), label.c_str()); TwHelper::SetHelpText(tweakBar, name.c_str(), helpText.c_str()); TwHelper::SetGroup(tweakBar, name.c_str(), group.c_str()); }
void EnumSetting::Initialize(TwBar* tweakBar_, const char* name_, const char* group_, const char* label_, const char* helpText_, uint32 initialVal, uint32 numValues_, const char* const* valueLabels) { val = std::min(initialVal, numValues - 1); numValues = numValues_; // Register an enum type std::vector<TwEnumVal> enumValues(numValues); for(uint32 i = 0; i < numValues; ++i) { enumValues[i].Value = i; enumValues[i].Label = valueLabels[i]; } TwType twType = TwDefineEnum(name_, enumValues.data(), numValues); TwCall(twType); Setting::Initialize(tweakBar_, SettingType::Enum, &val, name_, group_, label_, helpText_, twType); }
void SetStep(TwBar* bar, const char* varName, float step) { TwCall(TwSetParam(bar, varName, "step", TW_PARAM_FLOAT, 1, &step)); }
void SetMinMax(TwBar* bar, const char* varName, int32 min, int32 max) { TwCall(TwSetParam(bar, varName, "min", TW_PARAM_INT32, 1, &min)); TwCall(TwSetParam(bar, varName, "max", TW_PARAM_INT32, 1, &max)); }
void SetMinMax(TwBar* bar, const char* varName, float min, float max) { TwCall(TwSetParam(bar, varName, "min", TW_PARAM_FLOAT, 1, &min)); TwCall(TwSetParam(bar, varName, "max", TW_PARAM_FLOAT, 1, &max)); }
void SetIconPosition(IconPosition position) { static const char* IconPositionStrings[] = { "topleft", "topright", "bottomleft", "bottomright" }; TwCall(TwSetParam(nullptr, nullptr, "iconpos", TW_PARAM_CSTRING, 1, IconPositionStrings[uint64(position)])); }
void SetUseAlphaChannel(TwBar* bar, const char* varName, bool32 useAlpha) { TwCall(TwSetParam(bar, varName, "coloralpha", TW_PARAM_INT32, 1, &useAlpha)); }
void SetFontScaling(float scale) { TwCall(TwSetParam(nullptr, nullptr, "fontscaling", TW_PARAM_FLOAT, 1, &scale)); }
void SetShortcutKeyDecrement(TwBar* bar, const char* varName, const char* shortcutKey) { TwCall(TwSetParam(bar, varName, "keydecr", TW_PARAM_CSTRING, 1, shortcutKey)); }
void SetFontStyle(FontStyle style) { static const char* FontStyleStrings[] = { "default", "fixed" }; TwCall(TwSetParam(nullptr, nullptr, "fontstyle", TW_PARAM_CSTRING, 1, FontStyleStrings[uint64(style)])); }
void SetFontResizable(bool32 resizable) { TwCall(TwSetParam(nullptr, nullptr, "fontresizable", TW_PARAM_INT32, 1, &resizable)); }
void SetFontSize(FontSize size) { int32 fontSize[1] = { int32(size) }; TwCall(TwSetParam(nullptr, nullptr, "fontsize", TW_PARAM_INT32, 1, fontSize)); }
void SetIconMargin(int32 marginX, int32 marginY) { int32 margins[2] = { marginX, marginY }; TwCall(TwSetParam(nullptr, nullptr, "iconmargin", TW_PARAM_INT32, 2, margins)); }
void SetIconAlignment(IconAlignment alignment) { static const char* IconAlignmentStrings[] = { "vertical", "horizontal" }; TwCall(TwSetParam(nullptr, nullptr, "iconalign", TW_PARAM_CSTRING, 1, IconAlignmentStrings[uint64(alignment)])); }
void SetPrecision(TwBar* bar, const char* varName, int32 precision) { TwCall(TwSetParam(bar, varName, "precision", TW_PARAM_INT32, 1, &precision)); }
// Group parameters void SetOpened(TwBar* bar, const char* groupName, bool32 opened) { TwCall(TwSetParam(bar, groupName, "opened", TW_PARAM_INT32, 1, &opened)); }
void SetHexidecimal(TwBar* bar, const char* varName, bool32 hex) { TwCall(TwSetParam(bar, varName, "hexa", TW_PARAM_INT32, 1, &hex)); }
void SetDrawOverlappedBars(bool32 drawOverlapped) { TwCall(TwSetParam(nullptr, nullptr, "overlap", TW_PARAM_INT32, 1, &drawOverlapped)); }
void SetBoolLabels(TwBar* bar, const char* varName, const char* falseLabel, const char* trueLabel) { TwCall(TwSetParam(bar, varName, "false", TW_PARAM_CSTRING, 1, falseLabel)); TwCall(TwSetParam(bar, varName, "true", TW_PARAM_CSTRING, 1, trueLabel)); }
void SetVisible(TwBar* bar, const char* varName, bool32 visible) { TwCall(TwSetParam(bar, varName, "visible", TW_PARAM_INT32, 1, &visible)); }
void SetColorOrder(TwBar* bar, const char* varName, ColorOrder order) { static const char* ColorOrderStrings[] = { "rgba", "bgra" }; TwCall(TwSetParam(bar, varName, "colororder", TW_PARAM_CSTRING, 1, ColorOrderStrings[uint64(order)])); }
void SetReadOnly(TwBar* bar, const char* varName, bool32 readOnly) { TwCall(TwSetParam(bar, varName, "readonly", TW_PARAM_INT32, 1, &readOnly)); }
void SetGroup(TwBar* bar, const char* varName, const char* group) { TwCall(TwSetParam(bar, varName, "group", TW_PARAM_CSTRING, 1, group)); }
void SetHelpText(TwBar* bar, const char* varName, const char* helpText) { TwCall(TwSetParam(bar, varName, "help", TW_PARAM_CSTRING, 1, helpText)); }