//---------------------------
// Includes
//---------------------------
#include "StdAfx.h"
#include "resource.h"
#include "Bar.h"

#include "Painter.h"
#include "ResourceLoader.h"
#include "InputState.h"
#include "CollisionMesh.h"
#include "Image.h"
#include "TextFormat.h"
#include "Audio.h"

//---------------------------
// Defines
//---------------------------
//

//---------------------------
// Constructor & Destructor
//---------------------------
Bar::Bar(ResourceLoader* resourceLoaderPtr,const String& imagename, Point2D position, Point2D fillingPosition, int totalPoints, int height, int width, ColorRGBA color)
:m_ImagePtr(0)
,m_TotalPoints(totalPoints)
,m_Points(0)
,m_Position(position)
,m_Height(height)
,m_Width(width)
,m_Color(color)
,m_FillingPosition(fillingPosition)
{
	m_ImagePtr = resourceLoaderPtr->LoadImage(imagename);
	if(m_ImagePtr == 0)
	{
		cout << "The image was not loaded properly";
	}
	m_Scale = (double)m_Height / m_TotalPoints;
	m_MatWorld.SetAsTranslate(m_Position);
}

Bar::~Bar()
{
	SafeDelete(&m_ImagePtr);
}

void Bar::Paint(Painter *painterPtr)
{
	Matrix2D rectPosition;
	rectPosition.SetAsTranslate(m_FillingPosition);
	painterPtr->SetTransformMatrix(m_MatWorld * rectPosition);
	painterPtr->SetColor(m_Color);
	painterPtr->FillRect(m_Filling);
	painterPtr->SetTransformMatrix(m_MatWorld);
	painterPtr->DrawImage(m_ImagePtr,0,0);
}

void Bar::Tick(InputState *inputStatePtr)
{
	double pointHeight = m_Points * m_Scale;
	double drawY = m_Height - pointHeight;
	m_Filling.Set(0,drawY,m_Width,m_Height);
}

void Bar::setPoints(int points)
{
	m_Points = points;
}

void Bar::SetPosition(Point2D pt)
{
	m_Position = pt;
}