#pragma once

#include "dllinterface.h"
#include "dxtexture.h"

class DeviceStateManager;

struct DXFUNCTIONS_API DXColor
{
	float r, g, b, a;

	DXColor() {}
    DXColor( unsigned argb);
	DXColor( const D3DCOLORVALUE& );
    DXColor( const float* );
    DXColor( const float r, const float g, const float b, const float a );

    // casting
    operator unsigned () const;

    operator float* ();
    operator const float* () const;

    // assignment operators
    DXColor& operator += ( const DXColor& );
    DXColor& operator -= ( const DXColor& );
    DXColor& operator *= ( const float );
    DXColor& operator /= ( const float );

    // unary operators
    DXColor operator + () const;
    DXColor operator - () const;

    // binary operators
    DXColor operator + ( const DXColor& ) const;
    DXColor operator - ( const DXColor& ) const;
    DXColor operator * ( const float ) const;
    DXColor operator / ( const float ) const;

    friend DXColor operator * ( const float, const DXColor& );

    bool operator == ( const DXColor& ) const;
    bool operator != ( const DXColor& ) const;

	DXVector3 ToRGB(void) const { return DXVector3(r, g, b); }
};

#include "DXColor.inl"

class DXFUNCTIONS_API DXMaterial
{
	D3DMATERIAL9 m_Material; //ambient,diffuse,specular,emissive,specpower
	DXTexture* m_Texture;
	XString		m_TextureFilename;
	
public:
	DXMaterial(void)
	{
		ZeroMemory(&m_Material,sizeof(D3DMATERIAL9));
		m_Texture = NULL;
	}
	~DXMaterial(void)
	{
		SAFERELEASE(m_Texture);
	}
	
	const D3DMATERIAL9& GetMaterial(void) const { return m_Material; }
	void SetMaterial(const D3DMATERIAL9 mat) { m_Material = mat; }

	D3DCOLORVALUE GetAmbient(void){return m_Material.Ambient;}
	void SetAmbient(D3DCOLORVALUE ambient){m_Material.Ambient = ambient;}

	D3DCOLORVALUE GetDiffuse(void){return m_Material.Diffuse;}
	void SetDiffuse(D3DCOLORVALUE diffuse){m_Material.Diffuse = diffuse;}

	D3DCOLORVALUE GetSpecular(void){return m_Material.Specular;}
	void SetSpecular(D3DCOLORVALUE specular){m_Material.Specular = specular;}

	D3DCOLORVALUE GetEmissive(void){return m_Material.Emissive;}
	void SetEmissive(D3DCOLORVALUE emissive){m_Material.Emissive = emissive;}

	float GetSpecularExponent(void){return m_Material.Power;}
	void SetSpecularExponent(float exponent){m_Material.Power = exponent;}

	const XString& GetTextureFilename(void) const { return m_TextureFilename; }

	bool LoadTexture(DeviceStateManager* const device);

	DXTexture* GetTexture(void){return m_Texture;}
	void SetTexture(DeviceStateManager*device,XString texture);

	void Setup(DeviceStateManager*device);
};

