using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace UIControl
{
    public static class Common
    {
        public static void Draw_Arrow(Graphics g, RectangleF rect, eDirection dir, int arrowindex, int animstep, Color basecolor,Font f )
        {
            //컨베어 RUN 표시기 표시
            var paddingX = rect.Height * 0.15f;  //상하단에 이만큼의 여백을 준다
            var paddingY = rect.Height * 0.15f;
            var sigHeight = rect.Height - (paddingX * 2.0f);
            var sigWidth = rect.Width / animstep;

            if (dir == eDirection.BottomToTop || dir == eDirection.TopToBottom)
            {
                paddingX = rect.Width * 0.15f;
                paddingY = rect.Height / 10.0f;
                sigWidth = rect.Width - (paddingX * 2.0f);
                sigHeight = rect.Height / 4.5f;
            }
            List<PointF> pts = new List<PointF>();

            //사각영역을 표시해준다.
            //if (dir == eDirection.LeftToRight || dir == eDirection.RightToLeft)
            //{
            //    var rect2width = rect.Width / animstep;
            //    for (int i = 0; i < animstep; i++)
            //    {
            //        var rect2 = new RectangleF(rect.X + i * rect2width, rect.Y, rect2width, rect.Height);
            //        g.DrawRectangle(new Pen(Color.FromArgb(100, Color.Gray)), rect2.Left, rect2.Top, rect2.Width, rect2.Height);
            //        g.DrawString(i.ToString(), this.Font, Brushes.White, rect2.Left, rect2.Top);
            //    }
            //}
            //else
            //{
            //    var rect2width = rect.Height / animstep;
            //    for (int i = 0; i < animstep; i++)
            //    {
            //        var rect2 = new RectangleF(rect.X, rect.Y + i * rect2width, rect.Width, rect2width);
            //        g.DrawRectangle(new Pen(Color.FromArgb(100, Color.Gray)), rect2.Left, rect2.Top, rect2.Width, rect2.Height);
            //        g.DrawString(i.ToString(), this.Font, Brushes.White, rect2.Left, rect2.Top);
            //    }
            //}



            var bX = rect.X + paddingX;
            var bY = rect.Y + paddingY;

            if (dir == eDirection.LeftToRight)
            {
                var gridSize = rect.Width / animstep;
                pts.Add(new PointF(rect.X + paddingX + (arrowindex * sigWidth), rect.Y + paddingX));
                pts.Add(new PointF(rect.X + paddingX + (arrowindex * sigWidth) + sigWidth, rect.Y + paddingX));
                pts.Add(new PointF(rect.X + paddingX + (arrowindex * sigWidth) + sigWidth * 2.0f, rect.Y + paddingX + sigHeight / 2.0f));
                pts.Add(new PointF(rect.X + paddingX + (arrowindex * sigWidth) + sigWidth, rect.Y + paddingX + sigHeight));
                pts.Add(new PointF(rect.X + paddingX + (arrowindex * sigWidth), rect.Y + paddingX + sigHeight));
                pts.Add(new PointF(rect.X + paddingX + (arrowindex * sigWidth) + sigWidth, rect.Y + paddingX + sigHeight / 2.0f));
            }
            else if (dir == eDirection.RightToLeft)
            {
                var gridSize = rect.Width / animstep;
                paddingY = rect.Height * 0.1f;  //상,하 여백을 10%크기로 한다
                sigHeight = rect.Height - paddingY * 2.0f;

                bX = rect.X + ((animstep - 1) - arrowindex) * gridSize;
                bY = rect.Y + paddingY;

                pts.Add(new PointF(bX, bY));
                pts.Add(new PointF(bX - gridSize, bY + sigHeight / 2.0f));
                pts.Add(new PointF(bX, bY + sigHeight));
                pts.Add(new PointF(bX + gridSize, bY + sigHeight));
                pts.Add(new PointF(bX, bY + sigHeight / 2.0f));
                pts.Add(new PointF(bX + gridSize, bY));
            }
            else if (dir == eDirection.TopToBottom)
            {
                var gridSize = rect.Height / animstep;
                paddingX = rect.Width * 0.2f;  //상,하 여백을 10%크기로 한다
                sigWidth = rect.Width - paddingX * 2.0f;

                bX = rect.X + paddingX;
                bY = rect.Y + (arrowindex + 1) * gridSize;


                pts.Add(new PointF(bX, bY));
                pts.Add(new PointF(bX + (sigWidth / 2.0f), bY + gridSize));
                pts.Add(new PointF(bX + sigWidth, bY));
                pts.Add(new PointF(bX + sigWidth, bY - gridSize));
                pts.Add(new PointF(bX + (sigWidth / 2.0f), bY));
                pts.Add(new PointF(bX, bY - gridSize));

            }
            else if (dir == eDirection.BottomToTop)
            {
                var gridSize = rect.Height / animstep;
                paddingX = rect.Width * 0.2f;  //상,하 여백을 10%크기로 한다
                sigWidth = rect.Width - paddingX * 2.0f;

                bX = rect.X + paddingX;
                bY = rect.Y + ((animstep - 1) - arrowindex) * gridSize;


                pts.Add(new PointF(bX, bY));
                pts.Add(new PointF(bX + (sigWidth / 2.0f), bY - gridSize));
                pts.Add(new PointF(bX + sigWidth, bY));
                pts.Add(new PointF(bX + sigWidth, bY + gridSize));
                pts.Add(new PointF(bX + (sigWidth / 2.0f), bY));
                pts.Add(new PointF(bX, bY + gridSize));
            }
            if (pts.Count > 0)
            {
                g.FillPolygon(new SolidBrush(Color.FromArgb(10, basecolor)), pts.ToArray());
                g.DrawPolygon(new Pen(Color.FromArgb(100, basecolor)), pts.ToArray());
            }

            //g.DrawString(arrowindex.ToString(), f, Brushes.Yellow, rect.Left, rect.Top - 20);
        }

    }
}
