/** 
 * \file Button.h
 * \brief Various buttons classes.
 * 
 * \author Petar Bajic, MPE (C) All Rights Reserved, Homepage: www.mystic-peanut.com
 * \date January, 16 2007.
 */

#include "d3dx9.h"
#include "MyDrawSprite.h"
#include "Sound.h"

/** 
* Button type enum.
* All kinds of buttons.
*/
enum MPE_BUTTON_TYPE{
	MPE_BUTTON_TYPE_PLAIN,    /**< button has no texture, just brush drawn rectangle and text*/
	MPE_BUTTON_TYPE_2DSTATIC, /**< button has one texture, no animation or texture switching*/
	MPE_BUTTON_TYPE_2DSWITCH, /**< button has two textures, it reacts onMouseOver by switching tex*/
	MPE_BUTTON_TYPE_2DANIM,   /**< button has two textures, it reacts onMOuseOver by softly blengind between textures*/
	MPE_BUTTON_TYPE_3DSTATIC, /**< button has static 3D model, no animation or reaction to onMouseOver.*/
	MPE_BUTTON_TYPE_3DANIM,	  /**< button has full model animation*/
};

/**
 * \brief This class is basic button class.
 *
 * All other button classes inherit functionality from this basic button class.
 *
 * \author Petar Bajic \date January, 16 2007.
 */
class CButton
{
public:
	CButton();
	~CButton();

	virtual bool Init(RECT box, bool visible, bool enabled, WCHAR* caption, RECT textBox, 
					  IDirectSound8* pDS, LPWSTR clickSoundFilename, LPWSTR focusSoundFilename, int type);
	virtual bool OnEvent( UINT uMsg, WPARAM wParam, LPARAM lParam );
	virtual BOOL ContainsPoint( POINT pt ) { return PtInRect( &m_rcBoundingBox, pt ); }
	virtual void OnRender(LPDIRECT3DDEVICE9 pd3dDevice);
	virtual void OnFrameMove(LPDIRECT3DDEVICE9 pd3dDevice, float fElapsedTime);

	bool CanHaveFocus() { return (m_bVisible && m_bEnabled); }
	void SetPosition(RECT box) {m_rcBoundingBox = box;}
	void SetFocus(bool focus);
	void SetVisible(bool visible) {m_bVisible = visible;}
	void SetEnable(bool enable) {m_bEnabled = enable;}
	bool GetFocus() {return m_focusIn;}
	void OnButtonPress();

	RECT m_rcBoundingBox;
	RECT m_rcTextBox;
	D3DCOLOR m_textColor;
	bool m_bEnabled;
	bool m_bVisible;
	WCHAR* m_caption;
	int m_buttonType;
	
protected:
	bool m_focusIn;
	bool m_bPressed;
	double m_localTime;

	CSound* m_clickSound;
	CSound* m_focusSound;

	D3DXVECTOR2 m_transOffset;
	D3DXVECTOR2 m_scaleOffset;
};

/**
 * \brief 2D Button class.
 *
 * Represents 2D buttons with textures.
 * \author Petar Bajic \date January, 16 2007.
 */
class C2DButton :  public CButton
{
public:
	C2DButton();

	bool Init(HWND hWnd, RECT box, bool visible, bool enabled, WCHAR* caption, RECT textBox, LPDIRECT3DTEXTURE9 tex, LPDIRECT3DTEXTURE9 texOver, 
				IDirectSound8* pDS, LPWSTR clickSoundFilename, LPWSTR focusSoundFilename, int type);
	bool OnEvent( UINT uMsg, WPARAM wParam, LPARAM lParam );
	void OnRender(LPDIRECT3DDEVICE9 pd3dDevice, LPD3DXSPRITE pSprite, LPD3DXFONT pFont, 
		           D3DXVECTOR2* scaling, D3DXVECTOR2* trans, D3DXVECTOR2* spriteCentre, float rotation);
	void OnFrameMove(LPDIRECT3DDEVICE9 pd3dDevice, float fElapsedTime);

	LPDIRECT3DTEXTURE9 m_buttonTexture;
	LPDIRECT3DTEXTURE9 m_buttonTextureOver;

};

/**
 * \brief 3D Button class.
 *
 * Represents 3D buttons with mesh models.
 * \author Petar Bajic \date January, 16 2007.
 */
class C3DButton :  public CButton
{

};