//
// Tools_GUIMenu_Element_Image.h
//
// Created by Richard Rice - 05/12/2006
// 
// Copyright (C) 2006 Rebellion, All Rights Reserved.
//


#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif


#ifndef _TOOLS_GUIMENU_ELEMENT_IMAGE_H_
#define _TOOLS_GUIMENU_ELEMENT_IMAGE_H_
#ifdef ASURA_USE_GUI_MENU_SYSTEM

#include "GUIMenu/Tools_GUIMenu_Element_Base.h"


class Asura_GUIMenu_Element_Image;
class Tools_UV_Editor;

class Tools_GUIMenu_Element_Image : public Tools_GUIMenu_Element_Base
{
    typedef Tools_GUIMenu_Element_Base PARENT;
public :
	Tools_GUIMenu_Element_Image(Asura_GUIMenu_Element_Image* pxAsuraImage,Tools_GUIMenu_Root* pxToolsParent);
	~Tools_GUIMenu_Element_Image();

	virtual void Update();
	virtual void RenderUI();
	virtual void OnDeselection();
	virtual bool IsUsingKey(int iKey);
	virtual void Copy(const Tools_GUIMenu_Root* pxSource);

	virtual bool UsesTexture(int iTexture) const;


	//Asks user to select a texture , with the display limited to those already used by menus
	static int SelectTexture(int iInitialTexture, const char* szTitle = 0);
	static int SelectTiledTexture(int iInitialTile);

	//callback for texture selection
	static bool IsMenuTexture(int iTextureIndex,void* pList);
	static void ListTexturesCallback(int iTextureIndex,void* pList);

	virtual bool Verify();

protected :
	virtual void SetRectangle(const Asura_Bounding_Rectangle& xRect);
	virtual void AddOverlayControls(Asura_Overlay* pxOverlay,Asura_Vector_2& xOffset);
	virtual void UpdateOverlayControls(Asura_Overlay* pxOverlay);
	virtual const char* GetLocalDataFlagName(u_int uFlagValue) const;
	virtual bool IsModifierTypeSupported( ASURA_GUIMENU_MODIFY_TYPE eType ) const;
	virtual void AddModifierOverlayControls(Asura_GUIMenu_Modifier* pxModifier, Asura_Vector_2& xOffset);
	virtual void InitialiseModifier(Asura_GUIMenu_Modifier* pxModifier);
	virtual void CleanupModifierEditing();

	virtual void CopyToAsura();
	virtual void CopyFromAsura();

#define OVERLAY_VOID_CALLBACK(__FnName)\
	static void __FnName(int iThis){((Tools_GUIMenu_Element_Image*)iThis)->__FnName();}\
	void __FnName();
#define OVERLAY_BOOL_CALLBACK(__FnName)\
	static bool __FnName(int iThis){return ((Tools_GUIMenu_Element_Image*)iThis)->__FnName();}\
	bool __FnName();

	OVERLAY_VOID_CALLBACK(SelectTextureCallback)
	OVERLAY_VOID_CALLBACK(SelectTiledTextureCallback)
	OVERLAY_VOID_CALLBACK(SelectModifierTexture)
	OVERLAY_VOID_CALLBACK(ToggleUVEdit)
	OVERLAY_VOID_CALLBACK(ToggleModifierUVEdit)

	OVERLAY_BOOL_CALLBACK(CanEditTexture)
	OVERLAY_BOOL_CALLBACK(CanEditUVs)
	OVERLAY_BOOL_CALLBACK(CanLockUVToDims)
	OVERLAY_BOOL_CALLBACK(CanEditRotation)
	OVERLAY_BOOL_CALLBACK(CanFlipTile)
	OVERLAY_BOOL_CALLBACK(IsTile)
	OVERLAY_BOOL_CALLBACK(IsTexture)

	#undef OVERLAY_VOID_CALLBACK
	#undef OVERLAY_BOOL_CALLBACK
		
protected:

	Asura_GUIMenu_Element_Image* m_pxAsuraImage;
	Asura_GUIMenu_UV_Set m_xUV;

	int m_iTextureWidth;
	int m_iTextureHeight;
	bool m_bTextureSizeValid;

	Tools_UV_Editor* m_pxUVEdit;
	Asura_GUIMenu_UV_Set* m_pxUVEditUVs;//set of UVs being edted by UV window in bottom right
	bool m_bEditingModifierUV;

	float m_fRotation;
	bool  m_bRotationChanged;

	static bool s_bShowInPixels;
	static bool s_bShowInPixelsChanged;

private :
		
	void StartUVEdit(Asura_GUIMenu_UV_Set* pxUVs,bool bModifierUV);
	void FinishUVEdit();
	void UpdateUVEdit();
	void RenderUVEdit();

	void UpdateTextureSize();
	void UpdateFromTile();

	bool  m_bAtemptedTileFileLoad;
};




#endif //ASURA_USE_GUI_MENU_SYSTEM
#endif //_TOOLS_GUIMENU_ELEMENT_IMAGE_H_
