/****************************************************************************************************

		MCColorRGBAIndex.h
		Copyright: (c) 2001 Eovia Corp. All rights reserved.

		Author:	Julien
		Date:	10/11/2002

****************************************************************************************************/

#ifndef __MCColorRGBAIndex__
#define __MCColorRGBAIndex__

#if CP_PRAGMA_ONCE
#pragma once
#endif

#include "MCColorRGBA.h"

/// \addtogroup MCCore
/// \{

/// <P>TMCColorRGBAIndex is a TMCColorRGBA with an associated index It can be used as a pMap parameter and be animated. <BR>
/// ::kColorRGBAIndexParamType is its paramType value. <BR>
/// ::kColorRGBAIndexValueType is its valueType value. </P>
///
/// It is used by TMCGradient
///
class TMCColorRGBAIndex : public TMCObject1
{
	public:
		// ****************************************************************************
		//								TMCColorRGBAIndex
		// 
		// -Description:
		//		constructors.
		// -Parameters:
		//		color and index, or rr,gg,bb.aa.ii : a value for the TMCColorRGBAIndex
		inline TMCColorRGBAIndex		(void);
		inline TMCColorRGBAIndex		(const TMCColorRGBA& color, const real32 index);
		inline TMCColorRGBAIndex		(const real32 rr, const real32 gg, const real32 bb, const real32 aa, const real32 ii);
				
		// ****************************************************************************
		//								Set
		// 
		// -Description:
		//		setters.
		// -Parameters:
		//		color and index, or rr,gg,bb.aa.ii : a value for the TMCColorRGBAIndex
		inline void Set					(const real32 rr, const real32 gg, const real32 bb, const real32 aa, const real32 ii);
		inline void Set					(const TMCColorRGBA& color, const real32 index);

		// ****************************************************************************
		//								
		// 
		// -Description:
		//		equality test
		// -Parameters:
		//		rhs: the other TMCColorRGBAIndex
		//		epsilon: a tolerance.
		// -Returns:
		//		return true if equal ( same color and same index ).
		boolean IsEqual					(const TMCColorRGBAIndex& rhs, const real32 epsilon = 0.0) const;		
		
		// ****************************************************************************
		//								Interpolate
		// 
		// -Description:
		//		linear interpolation
		//		valid for constant alpha and pre-mul alpha interp
		// -Parameters:
		//		from: first TMCColorRGBAIndex.
		//		to: second TMCColorRGBAIndex.
		//		interpolant: interpolation value (should be beetween 0 and 1).
		void		Interpolate			(const TMCColorRGBAIndex& from, const TMCColorRGBAIndex& to, const real32 interpolant);

		// ****************************************************************************
		//								Interpolate
		// 
		// -Description:
		//		linear interpolation
		//		valid for constant alpha and pre-mul alpha interp
		// -Parameters:
		//		interpolants: interpolation values ( x [left/right], y [lower/upper])
		//		lowerLeft, lowerRight, upperLeft, upperRight: the 4 TMCColorRGBAIndex
		void		Interpolate			(const TVector2& interpolants, // x [left/right], y [lower/upper]
										 const TMCColorRGBAIndex& lowerLeft,
										 const TMCColorRGBAIndex& lowerRight,
										 const TMCColorRGBAIndex& upperLeft,
										 const TMCColorRGBAIndex& upperRight);
		
		// ****************************************************************************
		//								operator==
		// 
		// -Description:
		//		same as IsEqual
		inline boolean		 operator==	(const TMCColorRGBAIndex& rhs) const;

		// ****************************************************************************
		//								operator!=
		// 
		// -Description:
		//		same as !IsEqual
		inline boolean		 operator!=	(const TMCColorRGBAIndex& rhs) const;
		
		// ****************************************************************************
		//								operator=
		// 
		// -Description:
		//		copy the contant of c to the left side gradient
		// -Parameters:
		//		grad: the TMCColorRGBAIndex to be copy
		inline TMCColorRGBAIndex& operator=	(const TMCColorRGBAIndex& c);

		// ****************************************************************************
		//								TMCColorRGBAIndex
		// 
		// -Description:
		// Used to initialiase the color
		//
		// -Parameters:
		// i		: should always be equal to 0 !
		//
		inline TMCColorRGBAIndex& operator= (const int32 i) { fIndex=0; fColor=i; return *this; }

	public:
		TMCColorRGBA fColor;
		real32 fIndex;
};

/// \}

inline TMCColorRGBAIndex::TMCColorRGBAIndex(void)
	: fIndex( 0.0 )
	{ }

inline TMCColorRGBAIndex::TMCColorRGBAIndex(const TMCColorRGBA& color, const real32 index)
	: fColor(color), fIndex( index )
	{ MCAssert(index>=0.0 && index<=1.0); }

inline TMCColorRGBAIndex::TMCColorRGBAIndex(const real32 rr,const real32 gg,const real32 bb,const real32 aa, const real32 ii )
	: fColor(rr,gg,bb,aa), fIndex( ii )
	{ MCAssert(ii>=0.0 && ii<=1.0); }

inline void TMCColorRGBAIndex::Set(const real32 rr, const real32 gg, const real32 bb, const real32 aa, const real32 ii )
	{  MCAssert(ii>=0.0 && ii<=1.0); fColor.Set( rr, gg, bb, aa ); fIndex=ii; }

inline void TMCColorRGBAIndex::Set(const TMCColorRGBA& color, const real32 index)
	{  MCAssert(index>=0.0 && index<=1.0); fColor=color; fIndex=index; }

inline boolean TMCColorRGBAIndex::operator== (const TMCColorRGBAIndex& rhs) const 
	{ return IsEqual( rhs ); }

inline boolean TMCColorRGBAIndex::operator!= (const TMCColorRGBAIndex& rhs) const 
	{ return !IsEqual( rhs ); }

inline TMCColorRGBAIndex &TMCColorRGBAIndex::operator= (const TMCColorRGBAIndex &rhs)
{
	fColor=rhs.fColor;
	fIndex=rhs.fIndex;

	return *this;
}








#endif
