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

    [LicenseProvider(typeof(WidgetsLicenseProvider)), ToolboxBitmap(typeof(Light))]
    public class Light : ValuePresenter
    {
        private LightStyle style = LightStyle.Square;

        public Light()
        {
            this.BackColor = Color.Black;
            this.ForeColor = Color.Lime;
        }

        protected override void Draw(Graphics g, Rectangle r)
        {
            base.Draw(g, r);
            Rectangle workRectangle = this.WorkRectangle;
            GraphicsPath path = new GraphicsPath();
            if (this.style == LightStyle.Round)
            {
                path.AddEllipse(workRectangle);
            }
            else
            {
                path.AddRectangle(workRectangle);
            }
            PathGradientBrush brush = new PathGradientBrush(path);
            float num = 0.5f + (0.5f * (((float) (base.Value - this.Minimum)) / (this.Maximum - this.Minimum)));
            brush.set_CenterColor(Color.FromArgb(0xff, (int) (this.ForeColor.R * num), (int) (this.ForeColor.G * num), (int) (this.ForeColor.B * num)));
            Color[] colorArray = new Color[] { this.BackColor };
            brush.set_SurroundColors(colorArray);
            g.FillEllipse(brush, workRectangle);
        }

        [DefaultValue(typeof(Color), "Black")]
        public override Color BackColor
        {
            get
            {
                return base.BackColor;
            }
            set
            {
                base.BackColor = value;
            }
        }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override Image BackgroundImage
        {
            get
            {
                return base.get_BackgroundImage();
            }
            set
            {
                base.set_BackgroundImage(value);
            }
        }

        private Point Center
        {
            get
            {
                Rectangle workRectangle = this.WorkRectangle;
                return new Point((workRectangle.Left + workRectangle.Right) / 2, (workRectangle.Bottom + workRectangle.Top) / 2);
            }
        }

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

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override System.Drawing.Font Font
        {
            get
            {
                return base.Font;
            }
            set
            {
                base.Font = value;
            }
        }

        [DefaultValue(typeof(Color), "Lime")]
        public override Color ForeColor
        {
            get
            {
                return base.ForeColor;
            }
            set
            {
                base.ForeColor = value;
            }
        }

        private int Radius
        {
            get
            {
                Rectangle workRectangle = this.WorkRectangle;
                if (workRectangle.Width < workRectangle.Height)
                {
                    return (workRectangle.Width / 2);
                }
                return (workRectangle.Height / 2);
            }
        }

        [DefaultValue(0), Category("Appearance"), Description("Style of light appearance")]
        public LightStyle Style
        {
            get
            {
                return this.style;
            }
            set
            {
                if (this.style != value)
                {
                    this.style = value;
                    base.Invalidate();
                }
            }
        }

        [EditorBrowsable(EditorBrowsableState.Never), Browsable(false)]
        public override string Text
        {
            get
            {
                return base.Text;
            }
            set
            {
                base.Text = value;
            }
        }
    }
}
