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

    internal class ShapeGenerator
    {
        private ShapeGenerator()
        {
        }

        private static PointF[] Arrow(Rectangle rectangle, ShapeKinds shape)
        {
            float num;
            float num2;
            RectangleF ef = rectangle;
            switch (shape)
            {
                case ShapeKinds.UpArrow:
                    num = ef.Width * 0.3f;
                    num2 = Math.Min((float) (ef.Height / 2f), (float) (ef.Width / 2f));
                    return new PointF[] { new PointF(ef.X + num, ef.Y + ef.Height), new PointF((ef.X + ef.Width) - num, ef.Y + ef.Height), new PointF((ef.X + ef.Width) - num, ef.Y + num2), new PointF(ef.X + ef.Width, ef.Y + num2), new PointF(ef.X + (ef.Width / 2f), ef.Y), new PointF(ef.X, ef.Y + num2), new PointF(ef.X + num, ef.Y + num2) };

                case ShapeKinds.DownArrow:
                    num = ef.Width * 0.3f;
                    num2 = Math.Min((float) (ef.Height / 2f), (float) (ef.Width / 2f));
                    return new PointF[] { new PointF(ef.X + num, ef.Y), new PointF((ef.X + ef.Width) - num, ef.Y), new PointF((ef.X + ef.Width) - num, (ef.Y + ef.Height) - num2), new PointF(ef.X + ef.Width, (ef.Y + ef.Height) - num2), new PointF(ef.X + (ef.Width / 2f), ef.Y + ef.Height), new PointF(ef.X, (ef.Y + ef.Height) - num2), new PointF(ef.X + num, (ef.Y + ef.Height) - num2) };

                case ShapeKinds.LeftArrow:
                    num = ef.Height * 0.3f;
                    num2 = Math.Min((float) (ef.Height / 2f), (float) (ef.Width / 2f));
                    return new PointF[] { new PointF(ef.X + ef.Width, ef.Y + num), new PointF(ef.X + ef.Width, (ef.Y + ef.Height) - num), new PointF(ef.X + num2, (ef.Y + ef.Height) - num), new PointF(ef.X + num2, ef.Y + ef.Height), new PointF(ef.X, ef.Y + (ef.Height / 2f)), new PointF(ef.X + num2, ef.Y), new PointF(ef.X + num2, ef.Y + num) };

                case ShapeKinds.RightArrow:
                    num = ef.Height * 0.3f;
                    num2 = Math.Min((float) (ef.Height / 2f), (float) (ef.Width / 2f));
                    return new PointF[] { new PointF(ef.X, ef.Y + num), new PointF(ef.X, (ef.Y + ef.Height) - num), new PointF((ef.X + ef.Width) - num2, (ef.Y + ef.Height) - num), new PointF((ef.X + ef.Width) - num2, ef.Y + ef.Height), new PointF(ef.X + ef.Width, ef.Y + (ef.Height / 2f)), new PointF((ef.X + ef.Width) - num2, ef.Y), new PointF((ef.X + ef.Width) - num2, ef.Y + num) };
            }
            return new PointF[0];
        }

        public static GraphicsPath GenerateShape(ShapeKinds shape, Rectangle rectangle)
        {
            float num;
            PointF[] tfArray;
            RectangleF ef = rectangle;
            GraphicsPath path = new GraphicsPath();
            switch (shape)
            {
                case ShapeKinds.Rectangle:
                    path.AddRectangle(rectangle);
                    return path;

                case ShapeKinds.RoundedRectangle:
                    num = Math.Min((float) (ef.Height / 5f), (float) (ef.Width / 5f));
                    path.StartFigure();
                    path.AddLine(ef.Left + num, ef.Top, ef.Right - num, ef.Top);
                    path.AddArc(ef.Right - (2f * num), ef.Top, 2f * num, 2f * num, -90f, 90f);
                    path.AddLine(ef.Right, ef.Top + num, ef.Right, ef.Bottom - num);
                    path.AddArc(ef.Right - (2f * num), ef.Bottom - (2f * num), 2f * num, 2f * num, 0f, 90f);
                    path.AddLine(ef.Right - num, ef.Bottom, ef.Left + num, ef.Bottom);
                    path.AddArc(ef.Left, ef.Bottom - (2f * num), 2f * num, 2f * num, 90f, 90f);
                    path.AddLine(ef.Left, ef.Bottom - num, ef.Left, ef.Top + num);
                    path.AddArc(ef.Left, ef.Top, 2f * num, 2f * num, 180f, 90f);
                    path.CloseFigure();
                    return path;

                case ShapeKinds.Ellipse:
                    path.AddEllipse(rectangle);
                    return path;

                case ShapeKinds.Diamond:
                    path.StartFigure();
                    tfArray = new PointF[] { new PointF(ef.X + (ef.Width / 2f), ef.Y), new PointF(ef.X, ef.Y + (ef.Height / 2f)), new PointF(ef.X + (ef.Width / 2f), ef.Y + ef.Height), new PointF(ef.X + ef.Width, ef.Y + (ef.Height / 2f)) };
                    path.AddLines(tfArray);
                    path.CloseFigure();
                    return path;

                case ShapeKinds.UpArrow:
                    path.StartFigure();
                    path.AddLines(Arrow(rectangle, shape));
                    path.CloseFigure();
                    return path;

                case ShapeKinds.DownArrow:
                    path.StartFigure();
                    path.AddLines(Arrow(rectangle, shape));
                    path.CloseFigure();
                    return path;

                case ShapeKinds.LeftArrow:
                    path.StartFigure();
                    path.AddLines(Arrow(rectangle, shape));
                    path.CloseFigure();
                    return path;

                case ShapeKinds.RightArrow:
                    path.StartFigure();
                    path.AddLines(Arrow(rectangle, shape));
                    path.CloseFigure();
                    return path;

                case ShapeKinds.UpRectArrow:
                    path.StartFigure();
                    path.AddLines(RectArrow(rectangle, shape));
                    path.CloseFigure();
                    return path;

                case ShapeKinds.DownRectArrow:
                    path.StartFigure();
                    path.AddLines(RectArrow(rectangle, shape));
                    path.CloseFigure();
                    return path;

                case ShapeKinds.LeftRectArrow:
                    path.StartFigure();
                    path.AddLines(RectArrow(rectangle, shape));
                    path.CloseFigure();
                    return path;

                case ShapeKinds.RightRectArrow:
                    path.StartFigure();
                    path.AddLines(RectArrow(rectangle, shape));
                    path.CloseFigure();
                    return path;

                case ShapeKinds.UpTriangle:
                    path.StartFigure();
                    tfArray = new PointF[] { new PointF(ef.X, ef.Y + ef.Height), new PointF(ef.X + ef.Width, ef.Y + ef.Height), new PointF(ef.X + (ef.Width / 2f), ef.Y) };
                    path.AddLines(tfArray);
                    path.CloseFigure();
                    return path;

                case ShapeKinds.DownTriangle:
                    path.StartFigure();
                    tfArray = new PointF[] { new PointF(ef.X, ef.Y), new PointF(ef.X + ef.Width, ef.Y), new PointF(ef.X + (ef.Width / 2f), ef.Y + ef.Height) };
                    path.AddLines(tfArray);
                    path.CloseFigure();
                    return path;

                case ShapeKinds.LeftTriangle:
                    path.StartFigure();
                    tfArray = new PointF[] { new PointF(ef.X + ef.Width, ef.Y), new PointF(ef.X + ef.Width, ef.Y + ef.Height), new PointF(ef.X, ef.Y + (ef.Height / 2f)) };
                    path.AddLines(tfArray);
                    path.CloseFigure();
                    return path;

                case ShapeKinds.RightTriangle:
                    path.StartFigure();
                    tfArray = new PointF[] { new PointF(ef.X, ef.Y), new PointF(ef.X, ef.Y + ef.Height), new PointF(ef.X + ef.Width, ef.Y + (ef.Height / 2f)) };
                    path.AddLines(tfArray);
                    path.CloseFigure();
                    return path;

                case ShapeKinds.Octagon:
                {
                    float num2 = 0.3f;
                    float num3 = 1f - num2;
                    path.StartFigure();
                    tfArray = new PointF[] { new PointF(ef.X + (ef.Width * num2), ef.Y), new PointF(ef.X + (ef.Width * num3), ef.Y), new PointF(ef.X + ef.Width, ef.Y + (ef.Height * num2)), new PointF(ef.X + ef.Width, ef.Y + (ef.Height * num3)), new PointF(ef.X + (ef.Width * num3), ef.Y + ef.Height), new PointF(ef.X + (ef.Width * num2), ef.Y + ef.Height), new PointF(ef.X, ef.Y + (ef.Height * num3)), new PointF(ef.X, ef.Y + (ef.Height * num2)) };
                    path.AddLines(tfArray);
                    path.CloseFigure();
                    return path;
                }
                case ShapeKinds.Parallelogram:
                    num = Math.Min((float) (ef.Height / 3f), (float) (ef.Width / 3f));
                    path.StartFigure();
                    tfArray = new PointF[] { new PointF(ef.Left + num, ef.Top), new PointF(ef.Right, ef.Top), new PointF(ef.Right - num, ef.Bottom), new PointF(ef.Left, ef.Bottom) };
                    path.AddLines(tfArray);
                    path.CloseFigure();
                    return path;
            }
            return path;
        }

        private static PointF[] RectArrow(Rectangle rectangle, ShapeKinds shape)
        {
            float num;
            RectangleF ef = rectangle;
            switch (shape)
            {
                case ShapeKinds.UpRectArrow:
                    num = Math.Min((float) (ef.Height / 2f), (float) (ef.Width / 2f));
                    return new PointF[] { new PointF(ef.X, ef.Y + ef.Height), new PointF(ef.X + ef.Width, ef.Y + ef.Height), new PointF(ef.X + ef.Width, ef.Y + num), new PointF(ef.X + (ef.Width / 2f), ef.Y), new PointF(ef.X, ef.Y + num) };

                case ShapeKinds.DownRectArrow:
                    num = Math.Min((float) (ef.Height / 2f), (float) (ef.Width / 2f));
                    return new PointF[] { new PointF(ef.X, ef.Y), new PointF(ef.X + ef.Width, ef.Y), new PointF(ef.X + ef.Width, (ef.Y + ef.Height) - num), new PointF(ef.X + (ef.Width / 2f), ef.Y + ef.Height), new PointF(ef.X, (ef.Y + ef.Height) - num) };

                case ShapeKinds.LeftRectArrow:
                    num = Math.Min((float) (ef.Height / 2f), (float) (ef.Width / 2f));
                    return new PointF[] { new PointF(ef.X + ef.Width, ef.Y), new PointF(ef.X + ef.Width, ef.Y + ef.Height), new PointF(ef.X + num, ef.Y + ef.Height), new PointF(ef.X, ef.Y + (ef.Height / 2f)), new PointF(ef.X + num, ef.Y) };

                case ShapeKinds.RightRectArrow:
                    num = Math.Min((float) (ef.Height / 2f), (float) (ef.Width / 2f));
                    return new PointF[] { new PointF(ef.X, ef.Y), new PointF(ef.X, ef.Y + ef.Height), new PointF((ef.X + ef.Width) - num, ef.Y + ef.Height), new PointF(ef.X + ef.Width, ef.Y + (ef.Height / 2f)), new PointF((ef.X + ef.Width) - num, ef.Y) };
            }
            return null;
        }
    }
}
