RangeData Manual

About

The RangeData stores data on ranges and on the current value within these ranges. It is typically used with the LodObject. The RangeData class is defined in the customgui_range.h header file. The ID is CUSTOMDATATYPE_RANGE.

Access

RangeData data is typically accessed from a LodObject. See LodObject Manual.

// This example reads the range data from the given LOD object.
GeData rangeData;
if (lodObject->GetParameter(LOD_BAR, rangeData, DESCFLAGS_GET_0))
{
RangeData* rangeCustomData = static_cast<RangeData*>(customData);
if (rangeCustomData)
{
const Float currentValue = rangeCustomData->GetCurrentValue();
GePrint("Value: " + String::FloatToString(currentValue));
}
}

Allocation/Deallocation

RangeData objects are created with the usual tools, see Entity Creation and Destruction Manual.

A RangeData object must be initialized:

// This example configures the given LOD object and defines the
// number of manual groups using the RangeData data.
// create custom data
AutoAlloc<RangeData> rangeCustomData;
if (rangeCustomData)
{
// configure LodObject
// configure range data
rangeCustomData->Init(10);
// store to LodObject
GeData rangeGeData;
rangeGeData.SetCustomDataType(CUSTOMDATATYPE_RANGE, rangeCustomData);
lodObject->SetParameter(LOD_BAR, rangeGeData, DESCFLAGS_SET_0);
}

Value

A RangeData stores a value between 0.0 and 1.0:

// This example sets the current, user defined value of the range slider.
// get range data
GeData rangeData;
lodObject->GetParameter(LOD_BAR, rangeData, DESCFLAGS_GET_0);
RangeData* rangeCustomData = static_cast<RangeData*>(customData);
if (!rangeCustomData)
return false;
// User LOD Value
// set value
rangeCustomData->SetCurrentValue(0.5);
lodObject->SetParameter(LOD_BAR, rangeData, DESCFLAGS_SET_0);

Knots

Multiple knots can be added to a RangeData object. These knots define the borders of the ranges.

// This example clears the given RangeData and
// adds two new knots.
// clear
rangeCustomData->Reset();
// add knots
rangeCustomData->AddValue(0.33);
rangeCustomData->AddValue(0.66);
// set selection
rangeCustomData->SetSelectedKnot(0);

A single knot can be selected:

// This example deletes the currently selected knot.
const Int knotIndex = rangeCustomData->GetSelectedKnot();
rangeCustomData->DeleteKnot(knotIndex);

Ranges

Value ranges are defined as the space confined by knots:

// This example sets the color of the range containing the current value.
// get current range
const Float currentValue = rangeCustomData->GetCurrentValue();
const Int currentRange = rangeCustomData->GetRangeIndex(currentValue);
// set color
const Vector color(1.0, 0.0, 0.0);
rangeCustomData->SetRangeColor(currentRange, color);

Color Modes

The ranges between knots can be colored in different ways:

// This example assigns a new color to each range.
// set mode
rangeCustomData->SetRandomColorMode(false);
rangeCustomData->SetColorMode(true);
// get number of ranges
const Int rangeCount = rangeCustomData->GetRangesCount();
const Float colorStep = 1.0 / Float(rangeCount);
// set color of each range
for (Int i = 0; i < rangeCount; ++i)
{
const Vector hsv = Vector(Float(i) * colorStep, 1.0, 1.0);
const Vector rgb = HSVToRGB(hsv);
rangeCustomData->SetRangeColor(i, rgb);
}

RangePair

The dimensions of a range are stored with a RangePair object:

The RangePair class includes:

// This example sets the current value to the center
// of the current range.
// get current value and range
const Float currentValue = rangeCustomData->GetCurrentValue();
const Int currentRange = rangeCustomData->GetRangeIndex(currentValue);
// get range center
RangePair rData = rangeCustomData->GetRange(currentRange);
const Float centerValue = rData.GetCenter();
// set value
rangeCustomData->SetCurrentValue(centerValue);

Further Reading