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

    [ToolboxBitmap(typeof(Switch))]
    public class Switch : ButtonBase
    {
        private Color activeLedColor = Color.LightGreen;
        private int depth = 4;
        private FaceStyle faceStyle = InstrumentationControls.FaceStyle.RaisedNotch;
        private Color inactiveLedColor = Color.Green;

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

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

        private void DrawToggle(Graphics g)
        {
            Brush brush;
            Rectangle workRectangle = this.WorkRectangle;
            if (base.Pressed)
            {
                g.FillRectangle(Brushes.Silver, workRectangle.X, workRectangle.Y, workRectangle.Width, workRectangle.Height / 2);
                g.FillRectangle(Brushes.Gainsboro, workRectangle.X, workRectangle.Y + (workRectangle.Height / 2), workRectangle.Width, (workRectangle.Height / 2) - this.depth);
                g.FillRectangle(Brushes.Gray, workRectangle.X, (workRectangle.Y + workRectangle.Height) - this.depth, workRectangle.Width, this.depth);
            }
            else
            {
                g.FillRectangle(Brushes.Gainsboro, workRectangle.X, workRectangle.Y, workRectangle.Width, this.depth);
                g.FillRectangle(Brushes.DarkGray, workRectangle.X, workRectangle.Y + this.depth, workRectangle.Width, (workRectangle.Height / 2) - this.depth);
                g.FillRectangle(Brushes.Silver, workRectangle.X, workRectangle.Y + (workRectangle.Height / 2), workRectangle.Width, workRectangle.Height / 2);
            }
            if (base.Pressed)
            {
                brush = new SolidBrush(this.activeLedColor);
            }
            else
            {
                brush = new SolidBrush(this.inactiveLedColor);
            }
            Rectangle rect = new Rectangle(workRectangle.X + 3, (workRectangle.Y + this.depth) + 3, workRectangle.Width - 7, 4);
            if (base.Pressed)
            {
                rect.Y -= this.depth;
            }
            g.FillRectangle(brush, rect);
            if (this.faceStyle != InstrumentationControls.FaceStyle.Smooth)
            {
                int num = workRectangle.Height - 4;
                if (base.Pressed)
                {
                    num -= this.depth;
                }
                Pen pen = SystemPens.ControlLightLight;
                Pen pen2 = SystemPens.ControlDark;
                if (this.faceStyle == InstrumentationControls.FaceStyle.RaisedNotch)
                {
                    pen2 = SystemPens.ControlLightLight;
                    pen = SystemPens.ControlDark;
                }
                for (int i = (workRectangle.Y + (workRectangle.Height / 2)) + 2; i <= num; i += 3)
                {
                    g.DrawLine(pen2, workRectangle.X + 2, workRectangle.Y + i, (workRectangle.X + workRectangle.Width) - 4, workRectangle.Y + i);
                    g.DrawLine(pen, workRectangle.X + 2, (workRectangle.Y + i) + 1, (workRectangle.X + workRectangle.Width) - 4, (workRectangle.Y + i) + 1);
                }
            }
        }

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

        [DefaultValue(1)]
        public override ButtonBehaviour Behaviour
        {
            get
            {
                return base.Behaviour;
            }
            set
            {
                base.Behaviour = value;
            }
        }

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

        [Description("Press depth"), DefaultValue(4), Category("Appearance")]
        public int Depth
        {
            get
            {
                return this.depth;
            }
            set
            {
                if (this.depth != value)
                {
                    this.depth = value;
                    base.Invalidate();
                }
            }
        }

        [Description("Control face appearrance"), Category("Appearance"), DefaultValue(1)]
        public FaceStyle FaceStyle
        {
            get
            {
                return this.faceStyle;
            }
            set
            {
                if (this.faceStyle != value)
                {
                    this.faceStyle = value;
                    base.Invalidate();
                }
            }
        }

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