/*
* FX Editor Misc Classes
* @version 7-09-06
* @author Joseph 'Pcjoe' Florencio
*/

#pragma warning (disable:4786)
#pragma warning (disable:4530)

#ifndef FXEDITORMISC_H
#define FXEDITORMISC_H
#include <VGUI_Panel.h>
#include <VGUI_TablePanel.h>
#include <VGUI_HeaderPanel.h>
#include <VGUI_TextGrid.h>
#include <VGUI_Label.h>
#include <string>
#include <map>
using namespace std;

// Tile Directions for CImagePanel
enum TILE_DIR
{	PANELTILE_NONE,
	PANELTILE_HORIZONTAL,
	PANELTILE_VERTICAL,
	PANELTILE_ALL
};

// Get Image Pointer
BitmapTGA *getImageVGUIBTGA( string strPath );
Image *getImageVGUI( string strPath );

/*
* Tooltip Manager Class
*/
class CTooltipManager
{
public:
	/*
	* Constructor
	*/
	CTooltipManager( void );

	// Paint tooltip (only paint if needed)
	void doPaint(vgui::Panel *panel);

	// Add tooltip, get text from titles.txt, use strKey to find
	void addTooltip( string strKey );

	// Enable Tip
	void enableTip( string strKey );

	// Disable Tip
	void disableTip( void );

	// Should/Is a tip currently being displayed?
	bool isEnabled( void );

	/*
	* Accessors / Mutators
	*/
	void setCurrentTip( string strTip ) { m_strCurrentTip = strTip; }
	string getCurrentTip( void ) { return m_strCurrentTip; }

	void setTipTime( float flTime ) { m_flStartTipTime = flTime; }
	float getTipTime( void ) { return m_flStartTipTime; }

	void setTextImage( TextImage *pImage ) { m_pText = pImage; }
	TextImage *getTextImage( void ) { return m_pText; }

	void setPanel( Panel *pPanel ) { m_pPanel = pPanel; }
	Panel *getPanel( void ) { return m_pPanel; }

	void setWide( int iWide ) { m_iWide = iWide; }
	int getWide( void ) { return m_iWide; }

	void setTall( int iTall ) { m_iTall = iTall; }
	int getTall( void ) { return m_iTall; }
protected:
	map<string,string>	m_Tooltips;
	string m_strCurrentTip;
	float m_flStartTipTime;
	TextImage *m_pText;
	Panel *m_pPanel;
	int m_iWide;
	int m_iTall;
};

/*
* Tooltip Panel
*/
class CTooltipPanel : public CTransparentPanel
{
public:
	/*
	* Constructor
	*/
	CTooltipPanel( int x, int y, int wide, int tall ) : CTransparentPanel(192,x,y,wide,tall) { }

	// Paint
	virtual void paintBackground();
};

/*
* Mouse Over Tooltip Enabler
*/
class CHandler_TooltipButtonOver : public InputSignal
{
private:
	string m_strTooltip;
public:
	CHandler_TooltipButtonOver( string strTooltip );
		
	void cursorEntered(Panel *panel);
	void cursorExited(Panel* panel);

	void cursorMoved(int x,int y,Panel* panel) {};
	void mousePressed(MouseCode code,Panel* panel) {};
	void mouseReleased(MouseCode code,Panel* panel) {};
	void mouseDoublePressed(MouseCode code,Panel* panel) {};
	void mouseWheeled(int delta,Panel* panel) {};
	void keyPressed(KeyCode code,Panel* panel) {};
	void keyTyped(KeyCode code,Panel* panel) {};
	void keyReleased(KeyCode code,Panel* panel) {};
	void keyFocusTicked(Panel* panel) {};
};

/*
* Image Panel Class, generates tiled images in the background
*/
class CImagePanel : public CTransparentPanel
{
public:
	/*
	* Constructors
	*/
	CImagePanel( string strImage, TILE_DIR tile_dir=PANELTILE_NONE, int x=0, int y=0, int wide=0, int tall=0 );
	CImagePanel( Image *pImage, TILE_DIR tile_dir=PANELTILE_NONE, int x=0, int y=0, int wide=0, int tall=0 );

	// Paint Background
	virtual void paintBackground();

	/*
	* Mutators/Accessors
	*/
	void setImage(Image* image) { _image = image; }
	Image *getImage( void ) { return _image; }

	void setTile(TILE_DIR tileDir) { _tile = tileDir; }
	TILE_DIR getTile( void ) { return _tile; }

	void setTransparency(int transparency) { _transparency = transparency; }
	int getTransparency( void ) { return _transparency; }
protected:
	Image* _image;
	TILE_DIR _tile;
	int _transparency;
};

/*
* Image Button Class, fades in mouse over
*/
class CFadeImageButton : public Button
{
public:
	/*
	* Constructor
	*/
	// By default, fade in 1/3rd of a second
	CFadeImageButton( int x,int y,int wide,int tall, BitmapTGA *image, BitmapTGA *image_mo, const char *text=NULL, BitmapTGA *image_click=NULL, float faderate=765.0 );

	// Resize Width to Text (padding is x2, applied to left and right)
	virtual void resizeWidthToText( int iPadding );

	// Paint Background
	virtual void paintBackground();

	// Paint
	virtual void paint();

	/*
	* Accessors/Mutators
	*/
	void setFadeRate( float flRate ) { m_flFadeRate = flRate; }
	float getFadeRate( void ) { return m_flFadeRate; }

	void setFading( bool fade ) { m_bFading = fade; }
	bool isFading( void ) { return m_bFading; }

	void setSelected( bool select ) { m_bSelected = select; }
	bool isSelected( void ) { return m_bSelected; }

	void setAlpha( float alpha ) { m_flAlpha = alpha; }
	float getAlpha( void ) { return m_flAlpha; }

	void setTextImage( TextImage *pImage ) { m_pText = pImage; }
	TextImage *getTextImage( void ) { return m_pText; }

	void setImage( BitmapTGA *pImg ) { m_pImage = pImg; }
	BitmapTGA *getImage() { return m_pImage; }

	void setImageArmed( BitmapTGA *pImg ) { m_pImageArmed = pImg; }
	BitmapTGA *getImageArmed() { return m_pImageArmed; }

	void setImageClick( BitmapTGA *pImg ) { m_pImageClick = pImg; }
	BitmapTGA *getImageClick() { return m_pImageClick; }

protected:
	BitmapTGA	*m_pImage;
	BitmapTGA	*m_pImageArmed;
	BitmapTGA	*m_pImageClick;
	TextImage	*m_pText;
	bool		m_bFading;
	bool		m_bSelected;
	float		m_flFadeRate;
	float		m_flAlpha;
};
#endif