Example #1
0
CVehicleColor CVehicleColors::GetRandomColor ( void )
{
    // Grab a random index
    unsigned int uiSize = CountColors ();
    if ( uiSize > 0 )
    {
        // Create a random index
        unsigned int uiRandomIndex = GetRandom ( 0, uiSize - 1 );

        // Grab the random color we got off the list
        unsigned int uiIndex = 0;
        list < CVehicleColor > ::iterator iter = m_Colors.begin ();
        for ( ; iter != m_Colors.end (); iter++ )
        {
            if ( uiIndex == uiRandomIndex )
            {
                return *iter;
            }

            ++uiIndex;
        }
    }

    // No items, return default color (black)
    return CVehicleColor ( 0, 0, 0, 0 );
}
// _MakeEmpty
void
Gradient::_MakeEmpty()
{
	int32 count = CountColors();
	for (int32 i = 0; i < count; i++)
		delete ColorAtFast(i);
	fColors.MakeEmpty();
}
// AddColor
int32
Gradient::AddColor(const rgb_color& color, float offset)
{
	// find the correct index (sorted by offset)
	BGradient::ColorStop* step = new BGradient::ColorStop(color, offset);
	int32 index = 0;
	int32 count = CountColors();
	for (; index < count; index++) {
		BGradient::ColorStop* s = ColorAtFast(index);
		if (s->offset > step->offset)
			break;
	}
	if (!fColors.AddItem((void*)step, index)) {
		delete step;
		return -1;
	}
	Notify();
	return index;
}
// ColorStepsAreEqual
bool
Gradient::ColorStepsAreEqual(const Gradient& other) const
{
	int32 count = CountColors();
	if (count == other.CountColors() &&
		fType == other.fType &&
		fInterpolation == other.fInterpolation &&
		fInheritTransformation == other.fInheritTransformation) {

		bool equal = true;
		for (int32 i = 0; i < count; i++) {
			BGradient::ColorStop* ourStep = ColorAtFast(i);
			BGradient::ColorStop* otherStep = other.ColorAtFast(i);
			if (*ourStep != *otherStep) {
				equal = false;
				break;
			}
		}
		return equal;
	}
	return false;
}