#include "Salamander.h"
#include "Sprite.h"

namespace Salamander
{

Sprite::Sprite() : Entity(), Visual()
{
	// Create a blank 2D square with default properties.
	Stream& vertices = *(new Stream(StreamVertex::TypeId));
	vertices.add(*(new StreamVertex(-0.5f, -0.5f)));
	vertices.add(*(new StreamVertex(-0.5f,  0.5f)));
	vertices.add(*(new StreamVertex( 0.5f, -0.5f)));
	vertices.add(*(new StreamVertex( 0.5f,  0.5f)));
	addStream(vertices);

	//Stream coordinates = Stream(StreamCoordinates::TypeId);
	//addStream(coordinates);

}

Sprite::~Sprite()
{

}

bool Sprite::onAdded(Node& parent)
{
	visual().preCache(*this);

	return Entity::onAdded(parent);
}

bool Sprite::onRemoved(Node& parent)
{
	visual().postCache(*this);

	return Entity::onRemoved(parent);
}

void Sprite::propogate()
{
	// First update the base class properties.
	Entity::propogate();

	// Then update our geometry transform.
	Visual::setTransform(world_);
}

}