// ------------------------------------------------------------------------------------ //
//																						//
//	File: Asura_GUIMenu_Element_Image.h													//
//																						//
//	Description: image element class													//
//																						//
//	Created: Steve Keen - 9/11/06														//
//																						//
//	Copyright (C) 2006 Rebellion (Derby), All Rights Reserved.							//
// ------------------------------------------------------------------------------------ //

#ifndef __ASURA_GUIMENU_ELEMENT_IMAGE_H__
#define __ASURA_GUIMENU_ELEMENT_IMAGE_H__

#ifdef ASURA_USE_PRAGMA_ONCE
#pragma once
#endif

#ifdef ASURA_USE_GUI_MENU_SYSTEM
#include "Rendering/Asura_Overlay_Quad.h"
#include "Asura_GUIMenu_Element_Base.h"
// -- Typedef -------------------------------------------------------------------------

// -- Enums ---------------------------------------------------------------------------

// -- Defines -------------------------------------------------------------------------
#define	ASURA_GUIMENU_MAX_UVLIST_SIZE 2

#define ASURA_GUIMENU_ELEMENT_IMAGE_LOCAL_FLAG_START	16

// -- Data Chunk Version --
// Versions: ASURA_CHUNK_ELEMENT_IMAGE_VERSION
// 0:	Initial data
// 1:	Added Tile data
// 2:	Added rotation value - SK 14.11.07
// 3:	Moved tile hash out of Tools - NDB 050808
#define ASURA_CHUNK_ELEMENT_IMAGE_VERSION 3

// -- Structures ----------------------------------------------------------------------

class Asura_GUIMenu_Element_Image : public Asura_GUIMenu_Element_Base
{
protected:
	typedef Asura_GUIMenu_Element_Base PARENT;

public:
	enum Asura_GUIMenu_Inherit_Flag_Element_Image_Type
	{
		ASURA_GUIMENU_ELEMENT_IMAGE_LOCAL_FLAG_TEXTURE				= (1<<(ASURA_GUIMENU_ELEMENT_IMAGE_LOCAL_FLAG_START+0)),
		ASURA_GUIMENU_ELEMENT_IMAGE_LOCAL_FLAG_UVS					= (1<<(ASURA_GUIMENU_ELEMENT_IMAGE_LOCAL_FLAG_START+1)),
		ASURA_GUIMENU_ELEMENT_IMAGE_LOCAL_FLAG_ROTATION				= (1<<(ASURA_GUIMENU_ELEMENT_IMAGE_LOCAL_FLAG_START+2)),
		ASURA_GUIMENU_ELEMENT_IMAGE_LOCAL_FLAG_SCALETOORIGIN		= (1<<(ASURA_GUIMENU_ELEMENT_IMAGE_LOCAL_FLAG_START+3)),
		ASURA_GUIMENU_ELEMENT_IMAGE_LOCAL_FLAG_INVERT_X				= (1<<(ASURA_GUIMENU_ELEMENT_IMAGE_LOCAL_FLAG_START+4)),
		ASURA_GUIMENU_ELEMENT_IMAGE_LOCAL_FLAG_INVERT_Y				= (1<<(ASURA_GUIMENU_ELEMENT_IMAGE_LOCAL_FLAG_START+5)),
		ASURA_GUIMENU_ELEMENT_IMAGE_LOCAL_FLAG_POST_ROTATE_SCALE	= (1<<(ASURA_GUIMENU_ELEMENT_IMAGE_LOCAL_FLAG_START+6)),
		ASURA_GUIMENU_ELEMENT_IMAGE_LOCAL_FLAG_TILE			 		= (1<<(ASURA_GUIMENU_ELEMENT_IMAGE_LOCAL_FLAG_START+7)),
		ASURA_GUIMENU_ELEMENT_IMAGE_LOCAL_FLAG_IGNORETILEUV	 		= (1<<(ASURA_GUIMENU_ELEMENT_IMAGE_LOCAL_FLAG_START+8)),
		//ASURA_GUIMENU_ELEMENT_IMAGE_OVERIDE_MAX is here to stop another programmer adding past bit flag 31
		ASURA_GUIMENU_ELEMENT_IMAGE_LOCAL_FLAG_MAX					= (1<<(ASURA_GUIMENU_ELEMENT_IMAGE_LOCAL_FLAG_START+15))
	};

	Asura_GUIMenu_Element_Image( void);
	virtual ~Asura_GUIMenu_Element_Image( void);

	virtual void 				Render( u_int uState);
	virtual void				Render( u_int uState, const Asura_Bounding_Rectangle& xBounds);
	virtual void				Copy( const Asura_GUIMenu_Root* pxSource );

	const Asura_GUIMenu_UV		GetUV( u_int uIndex) const;

	void						SetUV( u_int uIndex, float fU, float fV);
	void						SetUV( u_int uIndex, const Asura_GUIMenu_UV& xUV);
	void						SetUV( u_int uIndex, const Asura_GUIMenu_UV* pxUV);

	void						SetTexture( const Asura_String& xTextureName, bool bFromASR = false);
	void						SetTexture( int iTextureID) {m_iTextureID = iTextureID;}
	void						SetTextureNameHash( Asura_Hash_ID uHash) {m_uHashTextureName = uHash;}

	int							GetTexture( void) const { return m_iTextureID; }

#ifdef ASURA_GUIMENU_STORE_NAMES
	const Asura_String&			GetTextureName( void) const { return m_xTextureName; }
#endif
	Asura_Hash_ID				GetTextureNameHash( void) const { return m_uHashTextureName; }

	float						GetRotation( void) const			{ return m_fRotation;	}
	void						SetRotation( const float fRotation)	{ m_fRotation = fRotation;	}

	void						SetTile( const Asura_Hash_ID uHash );
	Asura_Hash_ID				GetTileHash() const					{ return m_uTileHash; }

#ifdef ASURA_TOOLS
	virtual void				UpdateLocalDataFromStyle( void);

	virtual	void				TraverseUsedTextures(void (*pfnCallback)(int iTextureID, void* pUserData), void* pUserData);
	virtual	void				AddFilesToExportList();
	virtual void				WriteToChunkStream( Asura_Chunk_Stream& xStream) const;
	virtual void				ExportToXML(Tools_GUIMenu_XMLExporter* pxExporter) const;

	virtual const Asura_String& GetTileFileName()	 const { return m_xTileFileName; }
	virtual const Asura_String& GetTextureFileName() const { return m_xTextureName; }

	virtual void SetTileFileName( const Asura_String& xName )   { m_xTileFileName = xName; }
	virtual void SetTextureFileName(const Asura_String& xName ) { m_xTextureName = xName; }

	static const Asura_String StripProjectPathFromGraphicsFileName( const Asura_String& xFileName );
#endif // ASURA_TOOLS

	virtual void				ReadFromChunkStream( Asura_Chunk_Stream& xStream, Asura_GUIMenu_Root* pxParentObject, u_int uChunkVersion);

	//Gets the default flags that are applied to texturs used by image elements
	static int					GetDefaultTextureFlags() {return s_iDefaultTextureFlags;}

protected:
	void						ApplyModifierChanges( u_int uStateToMatch, float& fPosX, float& fPosY, float& fWidth, float& fHeight, Asura_RGBA& xColour, ASURA_TRANSLUCENCY_MODE& eTranslucencyMode, int& iTextureID, Asura_GUIMenu_UV& xUV0, Asura_GUIMenu_UV& xUV1, float& fRotation);
	void						ApplyAnimatorChanges( Asura_GUIMenu_Animator* pxAnim, u_int uStateToMatch, float& fPosX, float& fPosY, float& fWidth, float& fHeight, Asura_RGBA& xColour, ASURA_TRANSLUCENCY_MODE& eTranslucencyMode, int& iTextureID, Asura_GUIMenu_UV& xUV0, Asura_GUIMenu_UV& xUV1, float& fRotation);

	void						SetTileHash( const Asura_Hash_ID uTileHash )	{ m_uTileHash = uTileHash; }

	// -- Variables -------------------------------------------------------------------
	int							m_iTextureID;
	
	Asura_Hash_ID				m_uHashTextureName;
	Asura_Hash_ID				m_uTileHash;

#ifdef ASURA_GUIMENU_STORE_NAMES
	Asura_String				m_xTextureName;
	Asura_String				m_xTileFileName;
#endif

	Asura_GUIMenu_UV			m_axUV[ASURA_GUIMENU_MAX_UVLIST_SIZE];

	float						m_fRotation;

	static const int			s_iDefaultTextureFlags;

	// --------------------------------------------------------------------------------
};
#endif // ASURA_USE_GUI_MENU_SYSTEM
#endif // __ASURA_UI_ELEMENT_IMAGE_H__
