using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Xml;
using ImageBlockz.Api;
using ImageBlockz.Core;

namespace ImageBlockz.Operations.Edit
{
    class TextToImage : AbstractOperation
    {
        public static readonly string OperationName = typeof(TextToImage).FullName;

        public TextToImage()
            : base(OperationType.Filter)
        {
            
        }

        public TextToImage(string text)
            : this()
        {
            Text = text;
        }

        public string Text
        {
            set;
            get;
        }

        public override Bitmap Do(Bitmap bmp)            
        {
            Graphics graphic = Graphics.FromImage(bmp);
            SolidBrush brush = new SolidBrush(Color.Black);
            Pen pen          = new Pen(Color.White);

            graphic.FillRectangle(brush, 5, 5, bmp.Width - 10, 35);
            graphic.DrawRectangle(pen, 5, 5, bmp.Width - 10, 35);
            graphic.DrawString(Text, new Font("Tahoma", 25), Brushes.White, new Point(8,4));
            graphic.Dispose();

            return bmp;
        }

        public override XmlNode ToXml(XmlDocument xmlDoc)
        {
            XmlElement textToImage = xmlDoc.CreateElement(OperationName);

            XmlElement text = XmlOperation.StringToXml("text", Text, xmlDoc);

            textToImage.AppendChild(text);

            return textToImage;
        }

        public override void FromXml(XmlNode node)
        {
            Text = XmlOperation.StringFromXml(node["text"]);
        }

        public override string GetFormattedName()
        {
            return "Text to Image";
        }


        public override string GetInfo()
        {
            return "String: " + Text;
        }

    }
}
