#ifndef TEXT_H
#define TEXT_H

#include <string>
#include "d3dUtility.h"

namespace CBK
{
	class Text
	{
	public:
		typedef unsigned int byte;

		enum VerticalAlignment
		{
			VOFF_Bottom = DT_BOTTOM,
			VOFF_Top = DT_TOP,
			VOFF_Center = DT_VCENTER
		};
		enum HorizontalAlignment
		{
			HOFF_Left = DT_LEFT,
			HOFF_Right = DT_RIGHT,
			HOFF_Center = DT_CENTER
		};

		Text(IDirect3DDevice9* device, const std::string& facename, const std::string& text, const int height = 24, const unsigned int width = 16, const unsigned int weight = 0, const bool italic = false);
		~Text(void);

		Text& setText(const std::string& text);
		const std::string& getText(void) const;

		Text& setPoint1(const long x, const long y);
		Text& setPoint2(const long x, const long y);
		Text& setSize(const long width, const long height);
		void getPoint1(long* x, long* y) const;
		void getPoint2(long* x, long* y) const;
		void getSize(long* width, long* height) const;

		Text& enableAutoSize(const bool enabled = true);
		Text& disableAutoSize(void);
		const bool getIsAutoSized(void) const;

		Text& setAlignmentVertical(const VerticalAlignment& vAlignment = VOFF_Top);
		Text& setAlignmentHorizontal(const HorizontalAlignment& hAlignment = HOFF_Left);
		const VerticalAlignment getAlignmentVertical(void);
		const HorizontalAlignment getAlignmentHorizontal(void);

		Text& enableForceSingleLine(const bool enabled = true);
		Text& disableForceSingleLine(void);
		const bool getIsForcedSingleLine(void);

		Text& setColor(const D3DCOLOR& color);
		Text& setColor(const float& r, const float& g, const float& b, const float& a);
		Text& setColor(const byte r, const byte g, const byte b, const byte a);
		const D3DCOLOR& getColor(void) const;

		virtual const bool draw(void) const;

	protected:
		void updateSize(void) const;

	private:
		IDirect3DDevice9* _device;
		ID3DXFont* _font;
		ID3DXSprite* _sprite;

		std::string _text;
		DWORD _format;
		mutable RECT _rect;
		bool _autoSize;
		D3DCOLOR _color;

		Text(const Text&);
		Text& operator=(const Text&);
	};
}

#endif //TEXT_H