#include "Button.h"

Button::Button(MenuManager*manager,DWORD id) : GUIElement(manager,id)
{
	m_Image = new Panel(GetManager(),0);
	AddChild(m_Image);
	m_Caption = new Label(GetManager(),0);
	m_Caption->SetTextAlign(AL_CENTER);
	m_NColor = 0xffffffff;
	m_IColor = 0xffc0c0c0;
	m_AColor = 0xffffff00;
	AddChild(m_Caption);

	m_Image->SetEventHandler(GE_BUTTONCLICK, OnFwdEvent);
	m_Caption->SetEventHandler(GE_BUTTONCLICK, OnFwdEvent);
}

Button::~Button(void)
{
}

void Button::OnUpdate(void)
{
	if(IsEnable())
	{
		if(IsMouseOver() || m_Image->IsMouseOver() || m_Caption->IsMouseOver())
			m_Caption->SetColor(m_AColor);
		else
			m_Caption->SetColor(m_NColor);

		if(GetMouseButton(MBTN_LEFT) || m_Image->GetMouseButton(MBTN_LEFT) || m_Caption->GetMouseButton(MBTN_LEFT))
		{
			m_Caption->SetPosition(1,1);
			m_Image->SetPosition(1,1);
		}
		else
		{
			m_Caption->SetPosition(0,0);
			m_Image->SetPosition(0,0);
		}
	}
	else
	{
		m_Caption->SetColor(m_IColor);
	}
}

void Button::SetSize(const float xl, const float yl)
{
	GUIElement::SetSize(xl,yl);

	m_Image->SetSize(GetXl(),GetYl());
	m_Caption->SetSize(GetXl(),GetYl());
}

void Button::SetTexture(DXTexture*tex)
{
	m_Image->SetTexture(tex);
}

void Button::SetCaption(const XString&cap)
{
	m_Caption->SetText(cap);
}

void Button::SetFont(Font*fnt)
{
	m_Caption->SetFont(fnt);
}

/*void Button::SetBorder(float b,float tb)
{
	m_Image->SetBorder(b,tb);
}*/

void Button::SetAlphaBlend(bool ab)
{
	m_Image->SetAlphaBlend(ab);
}