/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2009.
     ssss    gggg x   x         Steven Goodwin. All Rights Reserved.
    
This version has been released under the GNU Public License v2.0.

Please see the license files for details.

File: sgx/include/domains/graphics/color/colortypes.hpp

*/

#ifndef SGX_DOMAIN_GRAPHICS_COLORTYPES_HPP
#define SGX_DOMAIN_GRAPHICS_COLORTYPES_HPP		1

#include "sgx/core/math/math.hpp"

tUINT32  sgxGetRGB32(const tREAL32 r, const tREAL32 g, const tREAL32 b);
tUINT32  sgxGetRGBA32(const tREAL32 r, const tREAL32 g, const tREAL32 b, const tREAL32 a);

class sgxColorRGB;
class sgxColorRGBA;

class sgxColorHSV
{
public:
	sgxColorHSV();
	sgxColorHSV(const tREAL32 vh, const tREAL32 vs, const tREAL32 vv);
	sgxColorHSV(const tREAL32 vh, const tREAL32 vs, const tREAL32 vv, const tREAL32 va);

	sgxColorRGB rgb() const;

	tREAL32 h,s,v;
};

class sgxColorRGB
{
public:
	sgxColorRGB();
	sgxColorRGB(const sgxColorRGBA &col);
	sgxColorRGB(const tREAL32 vr, const tREAL32 vg, const tREAL32 vb);
	sgxColorRGB(const tREAL32 vr, const tREAL32 vg, const tREAL32 vb, const tREAL32 va);

	sgxColorHSV hsv() const;
	
			void	asHex(sgxString &str) const;
			tUINT32	asInt() const;
			void	fromInt(const tUINT32 col);

	static	tBOOL	fromName(sgxColorRGB &col, const sgxString &str);
	static	tBOOL	fromName(sgxColorRGB &col, const char *pName);

	SGX_INLINE	bool	operator!=(const sgxColorRGB &rhs) const { return (r!=rhs.r || g!=rhs.g || b!=rhs.b)?TRUE:FALSE; }


				void	darken(const tREAL32 pc=10);
				void	lighten(const tREAL32 pc=10);

	static const sgxColorRGB	White;
	static const sgxColorRGB	LtGrey;
	static const sgxColorRGB	DkGrey;
	static const sgxColorRGB	Black;
	static const sgxColorRGB	Red;
	static const sgxColorRGB	Green;
	static const sgxColorRGB	Blue;
	static const sgxColorRGB	Yellow;
	static const sgxColorRGB	Magenta;
	static const sgxColorRGB	Cyan;

	tREAL32 r,g,b;
};

class sgxColorRGBA
{
public:
	sgxColorRGBA();
	sgxColorRGBA(const sgxColorRGB &col);
	sgxColorRGBA(const tREAL32 vr, const tREAL32 vg, const tREAL32 vb);
	sgxColorRGBA(const tREAL32 vr, const tREAL32 vg, const tREAL32 vb, const tREAL32 va);

	sgxColorRGB rgb() const {
		return sgxColorRGB(r,g,b);
	}

			void	asHex(sgxString &str) const;
			tUINT32	asInt() const;
			void	fromInt(const tUINT32 col);

	static	tBOOL	fromName(sgxColorRGBA &col, const sgxString &str);
	static	tBOOL	fromName(sgxColorRGBA &col, const char *pName);

	static	sgxColorRGBA	fromHexString(const char *pName);

	SGX_INLINE	bool operator!=(const sgxColorRGBA &rhs) const 
	{ 
		return (r!=rhs.r || g!=rhs.g || b!=rhs.b || a!=rhs.a)?TRUE:FALSE; 
	}

	SGX_INLINE sgxColorRGBA approach(const sgxColorRGBA &approaching, const tREAL32 max_delta=0.1f)
	{
		sgxColorRGBA result;

		result.r = sgxApproach(r, approaching.r, max_delta);
		result.g = sgxApproach(g, approaching.g, max_delta);
		result.b = sgxApproach(b, approaching.b, max_delta);
		result.a = sgxApproach(a, approaching.a, max_delta);

		return result;			
	}

	SGX_INLINE sgxColorRGBA lerp(const sgxColorRGBA &target, const tREAL32 t)
	{
		sgxColorRGBA result;

		result.r = r + (target.r-r)*t;
		result.g = g + (target.g-g)*t;
		result.b = b + (target.b-b)*t;
		result.a = a + (target.a-a)*t;

		return result;			
	}

	static const sgxColorRGBA	White;
	static const sgxColorRGBA	LtGrey;
	static const sgxColorRGBA	DkGrey;
	static const sgxColorRGBA	Black;
	static const sgxColorRGBA	Red;
	static const sgxColorRGBA	Green;
	static const sgxColorRGBA	Blue;
	static const sgxColorRGBA	Yellow;
	static const sgxColorRGBA	Magenta;
	static const sgxColorRGBA	Cyan;

	tREAL32 r,g,b,a;
};

#endif /* SGX_DOMAIN_GRAPHICS_COLORTYPES_HPP */
