#ifndef SPRITE_H
#define SPRITE_H

#include "texture.h"

#include <string>

#include "mesh.h"

namespace CBK
{
	namespace Shapes
	{
		class Sprite : public Mesh
		{
		public:
			typedef kLibrary::Factory<Texture, IDirect3DDevice9*> textureFactory;

			Sprite(const MeshParam& params, const std::string& image = "");
			~Sprite(void);

			virtual item& load(const std::string& name, const MeshParam& params);

			virtual void draw(const DWORD& = 0);
			virtual void apply(void);

			Sprite& setColor(const D3DCOLOR& color);
			Sprite& setColor(const float& r, const float& g, const float& b, const float& a = 1.0f);
			const D3DCOLOR& getColor(void) const;

			Sprite& setCenter(const D3DXVECTOR3& center);
			Sprite& setCenter(const float& x, const float& y, const float& z);
			const D3DXVECTOR3& getCenter(void) const;

			Sprite& setImageArea(const RECT& imageArea);
			Sprite& setImageArea(const long& left, const long& top, const long& right, const long& bottom);
			Sprite& clearImageArea(void);
			const RECT* const getImageArea(void) const;

			Sprite& setImage(const std::string& image);
			Texture* getImage(void) const;

			Sprite& setTextureLoader(textureFactory* textureLoader);

			const ID3DXSprite* const getSprite(void) const;

			Sprite& enableWorldSpace(const bool enabled = true);
			Sprite& disableWorldSpace(void);
			const bool getIsWorldSpace(void) const;

			Sprite& enableBillBoard(const bool enabled = true);
			Sprite& disableBillBoard(void);
			const bool getIsBillBoard(void) const;

			Sprite& setPosition(const float& x, const float& y, const float& z);
			Sprite& setPosition(const D3DXVECTOR3& position);
			Sprite& clearPosition(void);
			const D3DXVECTOR3* const getPosition(void) const;

			Sprite& setTransform(const D3DXMATRIX& transform);

		protected:

		private:
			DWORD _flags;

			ID3DXSprite* _sprite;

			Texture* _image;
			RECT* _imageArea;

			D3DXVECTOR3 _center;
			D3DXVECTOR3* _position;
			D3DCOLOR _color;

			D3DXMATRIX _transform;

			//Disallow copying
			Sprite(Sprite&);
			Sprite& operator=(Sprite& other);
		};
	}
}

#endif //SPRITE_H