namespace InstrumentationControls
{
	using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Drawing.Drawing2D;

    [ToolboxBitmap(typeof(PowerSwitch))]
    public class PowerSwitch : ButtonBase
    {
        private Color activeLedColor = Color.LightGreen;
        private Color inactiveLedColor = Color.Green;

        public PowerSwitch()
        {
            this.Behaviour = ButtonBehaviour.CheckBox;
        }

        protected override void Draw(Graphics g, Rectangle r)
        {
            base.Draw(g, r);
            this.DrawToggle(g);
        }

        private void DrawToggle(Graphics g)
        {
            int num4;
            Brush brush2;
            Brush brush3;
            g.SmoothingMode = (SmoothingMode)4;
            Rectangle workRectangle = this.WorkRectangle;
            Point point = new Point(workRectangle.X + (workRectangle.Width / 2), workRectangle.Y + (workRectangle.Height / 2));
            int num = Math.Min((int) ((workRectangle.Width / 2) - 2), (int) ((workRectangle.Height / 6) - 2));
            int num2 = (int) (((float) num) / 1.5f);
            int num3 = (int) (((float) num) / 2.3f);
            if (base.Pressed)
            {
                num4 = point.Y - (num * 2);
            }
            else
            {
                num4 = point.Y + (num * 2);
            }
            Rectangle rect = new Rectangle(point.X - num2, point.Y - num2, num2 * 2, num2 * 2);
            Brush brush = new LinearGradientBrush(rect, Color.Gainsboro, Color.Gray, 45f);
            g.FillEllipse(brush, rect);
            brush.Dispose();
            if (base.Pressed)
            {
                brush2 = new SolidBrush(Color.DarkGray);
            }
            else
            {
                brush2 = new SolidBrush(Color.Gainsboro);
            }
            Point[] points = new Point[] { new Point(point.X - num3, point.Y), new Point(point.X + num3, point.Y), new Point(point.X + num, num4), new Point(point.X - num, num4) };
            Rectangle rectangle3 = new Rectangle(point.X - num3, point.Y - num3, num3 * 2, num3 * 2);
            g.FillEllipse(brush2, rectangle3);
            g.FillPolygon(brush2, points);
            if (!base.Pressed)
            {
                brush3 = new SolidBrush(Color.DarkGray);
            }
            else
            {
                brush3 = new SolidBrush(Color.Gainsboro);
            }
            Rectangle rectangle4 = new Rectangle(point.X - num, num4 - num, num * 2, num * 2);
            g.FillEllipse(brush3, rectangle4);
            g.SmoothingMode=(System.Drawing.Drawing2D.SmoothingMode)0;
        }

        [Category("Appearance"), DefaultValue(typeof(Color), "LightGreen"), Description("Active led color")]
        public Color ActiveLedColor
        {
            get
            {
                return this.activeLedColor;
            }
            set
            {
                if (value != this.activeLedColor)
                {
                    this.activeLedColor = value;
                    base.Invalidate();
                }
            }
        }

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

        [DefaultValue(typeof(Color), "Green"), Category("Appearance"), Description("Inactive led color")]
        public Color InactiveLedColor
        {
            get
            {
                return this.inactiveLedColor;
            }
            set
            {
                if (value != this.inactiveLedColor)
                {
                    this.inactiveLedColor = value;
                    base.Invalidate();
                }
            }
        }
    }
}
