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

    [TypeConverter(typeof(BevelConverter))]
    public class Bevel
    {
        private bool innerBorder = false;
        private bool outterBorder = false;
        private BevelStyle style;

        public Bevel(BevelStyle style, bool outterBorder, bool innerBorder)
        {
            this.style = style;
            this.innerBorder = innerBorder;
            this.outterBorder = outterBorder;
        }

        public void Draw(Graphics g, Rectangle r)
        {
            if (this.style != BevelStyle.None)
            {
                Point location = r.Location;
                Point point2 = r.Location + r.Size;
                if (this.outterBorder)
                {
                    g.DrawRectangle(Pens.Black, r);
                    location.X++;
                    location.Y++;
                    point2.X--;
                    point2.Y--;
                }
                Pen pen = SystemPens.ControlLightLight;
                Pen pen2 = SystemPens.ControlDark;
                Pen pen3 = Pens.Black;
                Pen pen4 = Pens.Black;
                switch (this.style)
                {
                    case BevelStyle.Flat:
                        pen3 = pen2;
                        pen4 = pen2;
                        break;

                    case BevelStyle.Single:
                        pen3 = Pens.Black;
                        pen4 = Pens.Black;
                        break;

                    case BevelStyle.Double:
                        pen3 = Pens.Black;
                		pen4 = Pens.Black;
                        break;

                    case BevelStyle.Raised:
                        pen3 = pen;
                        pen4 = pen2;
                        break;

                    case BevelStyle.Lowered:
                        pen3 = pen2;
                        pen4 = pen;
                        break;

                    case BevelStyle.DoubleRaised:
                        pen3 = pen;
                        pen4 = pen2;
                        break;

                    case BevelStyle.DoubleLowered:
                        pen3 = pen2;
                        pen4 = pen;
                        break;

                    case BevelStyle.FrameRaised:
                        pen3 = pen;
                        pen4 = pen2;
                        break;

                    case BevelStyle.FrameLowered:
                        pen3 = pen2;
                        pen4 = pen;
                        break;
                }
                g.DrawLine(pen3, location.X, location.Y, location.X, point2.Y);
                g.DrawLine(pen3, location.X, location.Y, point2.X, location.Y);
                g.DrawLine(pen4, location.X, point2.Y, point2.X, point2.Y);
                g.DrawLine(pen4, point2.X, location.Y, point2.X, point2.Y);
                if (((this.style == BevelStyle.Double) || (this.style == BevelStyle.DoubleRaised)) || (((this.style == BevelStyle.DoubleLowered) || (this.style == BevelStyle.FrameLowered)) || (this.style == BevelStyle.FrameRaised)))
                {
                    if ((this.style == BevelStyle.FrameLowered) || (this.style == BevelStyle.FrameRaised))
                    {
                        Pen pen5 = pen3;
                        pen3 = pen4;
                        pen4 = pen5;
                    }
                    location.X++;
                    location.Y++;
                    point2.X--;
                    point2.Y--;
                    g.DrawLine(pen3, location.X, location.Y, location.X, point2.Y);
                    g.DrawLine(pen3, location.X, location.Y, point2.X, location.Y);
                    g.DrawLine(pen4, location.X, point2.Y, point2.X, point2.Y);
                    g.DrawLine(pen4, point2.X, location.Y, point2.X, point2.Y);
                }
                if (this.innerBorder)
                {
                    Rectangle rect = new Rectangle(location.X + 1, location.Y + 1, (point2.X - location.X) - 2, (point2.Y - location.Y) - 2);
                    g.DrawRectangle(Pens.Black, rect);
                }
            }
        }

        public int GetMargin()
        {
            int num = 0;
            if (this.style == BevelStyle.None)
            {
                num = 0;
            }
            else if (((this.style == BevelStyle.Flat) || (this.style == BevelStyle.Single)) || ((this.style == BevelStyle.Raised) || (this.style == BevelStyle.Lowered)))
            {
                num = 1;
            }
            else
            {
                num = 2;
            }
            if (this.outterBorder)
            {
                num++;
            }
            if (this.innerBorder)
            {
                num++;
            }
            return num;
        }

        [DefaultValue(false), NotifyParentProperty(true), Category("Appearance"), Description("Indicate whether the inner border should be drawn")]
        public bool InnerBorder
        {
            get
            {
                return this.innerBorder;
            }
            set
            {
                this.innerBorder = value;
            }
        }

        [DefaultValue(false), Category("Appearance"), NotifyParentProperty(true), Description("Indicate whether the outter border should be drawn")]
        public bool OutterBorder
        {
            get
            {
                return this.outterBorder;
            }
            set
            {
                this.outterBorder = value;
            }
        }

        [NotifyParentProperty(true), Category("Appearance"), Description("Style of control's bevel")]
        public BevelStyle Style
        {
            get
            {
                return this.style;
            }
            set
            {
                this.style = value;
            }
        }
    }
}
