namespace PerpetuumSoft.Widgets
{
    using PerpetuumSoft.Widgets.Licensing;
    using System;
    using System.ComponentModel;
    using System.Drawing;

    [ToolboxBitmap(typeof(DigitalLED)), LicenseProvider(typeof(WidgetsLicenseProvider))]
    public class DigitalLED : InstrumentationControl
    {
        private DigitsDisplay digits = new DigitsDisplay();

        public DigitalLED()
        {
            this.BackColor = Color.Black;
            this.Text = "0123456789";
        }

        protected override void Draw(Graphics g, Rectangle r)
        {
            Rectangle workRectangle = this.WorkRectangle;
            base.Draw(g, r);
            Point point = new Point(workRectangle.Left + 5, (workRectangle.Top + (workRectangle.Height / 2)) - (this.digits.DigitHeight / 2));
            this.digits.PaintString(g, (PointF) point, this.Text);
        }

        protected override void OnTextChanged(EventArgs e)
        {
            base.Invalidate();
            base.OnTextChanged(e);
        }

        protected override Size DefaultSize
        {
            get
            {
                return new Size(0xa8, 0x30);
            }
        }

        [Category("Appearance"), Description("Segment digits"), DesignerSerializationVisibility(2)]
        public DigitsDisplay Digits
        {
            get
            {
                return this.digits;
            }
            set
            {
                if (this.digits != value)
                {
                    this.digits = value;
                    base.Invalidate();
                }
            }
        }
    }
}
