package Icarus.Graphics.Animation;

import System.Drawing.Graphics;
import System.Drawing.Color;
import System.Drawing.Size;
import System.Drawing.Font;
import System.Drawing.FontFamily;

/**
 * The abstract text class, which will allow us to render text in an efficient manner.
 */
public abstract class AbstractText extends AbstractRenderable
{
	public static final Graphics DefaultGraphics = Graphics.FromImage(new System.Drawing.Bitmap(1, 1));

	private String mText = null;
	private Color mColor = Color.get_Black();
	private Font mFont = null;

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

	public AbstractText(String text)
	{
		this(text, Color.get_Black());
	}

	public AbstractText(String text, Color c)
	{
		this(text, c, new Font(FontFamily.get_GenericSansSerif().get_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 Size GetSize()
	{
		System.Drawing.SizeF fsize = AbstractText.DefaultGraphics.MeasureString(this.GetText(), this.GetFont());
		return new Size((int) fsize.get_Width(), (int) fsize.get_Height());
	}

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