#include "hud.h"
#include "parsemsg.h"
#include "cl_util.h"
#include "vgui_TeamFortressViewport.h"
#include "vgui_meleetext.h"
using namespace std;
CMeleeTextPanel :: CMeleeTextPanel(string text, float flStartTime, float flEndTime, int iTrans, int iRemoveMe, int iStartX, int iStartY, int iEndX, int iEndY, int wide, int tall,int iStartR, int iStartG, int iStartB,int iEndR,int iEndG,int iEndB) : CMenuPanel(iTrans, iRemoveMe, iStartX,iStartY,wide,tall)
{	m_flStartTime = flStartTime;
	m_flEndTime = flEndTime;
	m_iStartX = iStartX;
	m_iStartY = iStartY;
	m_iEndX = iEndX;
	m_iEndY = iEndY;
	m_iStartR = iStartR;
	m_iStartG = iStartG;
	m_iStartB = iStartB;
	m_iEndR = iEndR;
	m_iEndG = iEndG;
	m_iEndB = iEndB;

	//schemes
	CSchemeManager *pSchemes = gViewPort->GetSchemeManager();
	SchemeHandle_t hStatsScheme = pSchemes->getSchemeHandle( "Melee Text" );

	Font *pFont = pSchemes->getFont(hStatsScheme);
	int iHeight = pFont->getTall();	
	setSize(ScreenWidth,iHeight+4);
	
	m_pMeleeTextLabel = new Label( "", 0, 0);
	m_pMeleeTextLabel->setSize(ScreenWidth/2,iHeight+2);
	m_pMeleeTextLabel->setParent(this);
	m_pMeleeTextLabel->setFont(pFont);
	m_pMeleeTextLabel->setFgColor( m_iStartR, m_iStartG, m_iStartB, 200 );
	m_pMeleeTextLabel->setText(text.c_str());
	
	int r,g,b,a; //standard bg colors
	pSchemes->getBgColor( hStatsScheme, r, g, b, a );
	m_pMeleeTextLabel->setBgColor( r, g, b, a );
	m_pMeleeTextLabel->setContentAlignment( vgui::Label::a_west );	
}

void CMeleeTextPanel::Update(float flTime)
{
	float flPercent = (flTime-m_flStartTime)/(m_flEndTime-m_flStartTime);
	
	//move
	int x = m_iStartX + flPercent * (m_iEndX - m_iStartX);
	int y = m_iStartY + flPercent * (m_iEndY - m_iStartY);

	// blend colors
	int r = m_iStartR + flPercent * (m_iEndR - m_iStartR);
	int g = m_iStartG + flPercent * (m_iEndB - m_iStartG);
	int b = m_iStartB + flPercent * (m_iEndB - m_iStartB);

	// set colors
	m_pMeleeTextLabel->setFgColor( r, g, b, flPercent * 256 );
	// set pos
	this->setPos(x,y);
}