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

    [LicenseProvider(typeof(WidgetsLicenseProvider)), ToolboxBitmap(typeof(ProgressBar)), DefaultProperty("Value")]
    public class ProgressBar : ValuePresenter
    {
        private Color endColor = Color.LightBlue;
        private bool smooth = false;
        private Color startColor = Color.DarkBlue;

        protected override void Draw(Graphics g, Rectangle r)
        {
            base.Draw(g, r);
            Rectangle workRectangle = this.WorkRectangle;
            float num = (base.Value - this.Minimum) / (this.Maximum - this.Minimum);
            int num2 = (int) (num * workRectangle.Width);
            int width = workRectangle.Width;
            g.FillRectangle(Brushes.get_Black(), workRectangle);
            Rectangle rectangle2 = this.WorkRectangle;
            rectangle2.Inflate(1, 1);
            Brush brush = new LinearGradientBrush(rectangle2, this.startColor, this.endColor, 0);
            if (this.smooth)
            {
                if (base.Value > this.Minimum)
                {
                    Rectangle rect = workRectangle;
                    rect.Width = num2;
                    g.FillRectangle(brush, rect);
                }
            }
            else
            {
                int num3 = workRectangle.Height - 1;
                for (int i = 0; (i + ((num3 + 1) / 2)) <= num2; i += num3 + 1)
                {
                    int num5 = i + num3;
                    if (num5 > workRectangle.Width)
                    {
                        num5 = workRectangle.Width;
                    }
                    Rectangle rectangle4 = new Rectangle(workRectangle.Left + i, workRectangle.Top, num3, workRectangle.Height);
                    g.FillRectangle(brush, rectangle4);
                }
            }
            g.Flush();
        }

        [EditorBrowsable(EditorBrowsableState.Never), Browsable(false)]
        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);
            }
        }

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

        [Category("Appearance"), Description("End gradient color"), DefaultValue(typeof(Color), "DarkBlue")]
        public Color EndColor
        {
            get
            {
                return this.endColor;
            }
            set
            {
                if (this.endColor != value)
                {
                    this.endColor = value;
                    base.Invalidate();
                }
            }
        }

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

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

        [Description("Smooth indicator visualization style."), Category("Appearance"), DefaultValue(false)]
        public bool Smooth
        {
            get
            {
                return this.smooth;
            }
            set
            {
                if (this.smooth != value)
                {
                    this.smooth = value;
                    base.Invalidate();
                }
            }
        }

        [Category("Appearance"), DefaultValue(typeof(Color), "DarkBlue"), Description("Start gradient color")]
        public Color StartColor
        {
            get
            {
                return this.startColor;
            }
            set
            {
                if (this.startColor != value)
                {
                    this.startColor = value;
                    base.Invalidate();
                }
            }
        }

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