using System.Drawing;

namespace Icarus.Graphics.Animation
{
    public abstract class AbstractText 
		: AbstractRenderable
	{
		public static System.Drawing.Graphics DefaultGraphics = System.Drawing.Graphics.FromImage(new System.Drawing.Bitmap(1, 1));

		private string mText = null;
		private Color mColor = Color.Black;
		private Font mFont = null;

		public AbstractText()
			: this("")
		{ }

		public AbstractText(string text)
			: this(text, Color.Black)
        { }

		public AbstractText(string text, Color c)
			: this(text, c, new Font(FontFamily.GenericSansSerif.Name, 12))
        { }

		/**
		 * Creates a new instance of the abstract text.
		 */
		public AbstractText(string text, Color c, Font f)
		{
			mText = text;
			mColor = c;
			mFont = f;

			UpdateText();
		}

		public string GetText() { return mText; }
		public void SetText(string text) 
		{
			mText = text; 
			UpdateText();
		}

		public Color GetColor() { return mColor; }
		public void SetColor(Color color) 
		{
			mColor = color; 
			UpdateText();
		}

		public Font GetFont() { return mFont; }
		public void SetFont(Font font) 
		{
			mFont = font; 
			UpdateText();
		}

		/**
		 * Returns the size of the text in pixels.
		 */
		public override Size GetSize()
		{
			System.Drawing.SizeF fsize = AbstractText.DefaultGraphics.MeasureString(this.GetText(), this.GetFont());
			return new Size((int) fsize.Width, (int) fsize.Height);
		}

		/**
		 * Updates the text. This will be called any time the text itself, or the color or the font is changed.
		 */
		public abstract void UpdateText();
	}
}
