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

namespace 试验版
{
    class erby:element
    {



        public erby(Graphics gra):base(gra)
        {
            sbname = "er";
            dian1 = new dian(this, gra);
            dian2 = new dian(this, gra);
            Point = new Point();
            
        }

        public override void Resize(float scale)
        {
            float Scale = 1.0f;
            Scale *= scale;//放大缩小
            rect5.Width *= scale;
            rect5.Height *= scale;
        }




        public override bool ispickpoint(Point p)
        {

            int n = 0;
            int s = 0;
            int w = 0;
            int e = 0;
            float rr = rect.Width / 8;

            if (direction % 4 == 0)
            {
                e = 1; s = 0; n = 0; w = 0;
            }
            else if (direction % 4 == 1)
            {
                e = 0; s = 0; n = 1; w = 0;
            }
            else if (direction % 4 == 2)
            {
                e = 0; s = 0; n = 0; w = 1;
            }
            else
            {
                e = 0; s = 1; n = 0; w = 0;
            }

            PointF p1 = new PointF(rect5.X - e * 2 * rect5.Width + (n + s) * rect5.Width / 2 + w * 4 * rect5.Width, rect5.Y + (e + w) * rect5.Height / 2 + n * 4 * rect5.Height - s * 2 * rect5.Height);

            float xmax = p1.X - e * rr - (n + s) * rr / 2 + rr;
            float ymax = p1.Y - (e + w) * rr / 2 - s * rr + rr;

            if ((p.X >= p1.X - e * rr - (n + s) * rr / 2) && (p.X <= xmax) && (p.Y >= p1.Y - (e + w) * rr / 2 - s * rr) && (p.Y <= ymax))
            {
                return true;
            }
            else
            {
                return false;
            }

        }




        public override bool ispickpoint2(Point p)
        {

            int n = 0;
            int s = 0;
            int w = 0;
            int e = 0;
            float rr = rect.Width / 8;

            if (direction % 4 == 0)
            {
                e = 1; s = 0; n = 0; w = 0;
            }
            else if (direction % 4 == 1)
            {
                e = 0; s = 0; n = 1; w = 0;
            }
            else if (direction % 4 == 2)
            {
                e = 0; s = 0; n = 0; w = 1;
            }
            else
            {
                e = 0; s = 1; n = 0; w = 0;
            }
            PointF p4 = new PointF(rect5.X + e * 3 * rect5.Width + (n + s) * rect5.Width / 2 - w * rect5.Width, rect5.Y + (e + w) * rect5.Height / 2 + s * 3 * rect5.Height - n * rect5.Height);

            float xmax = p4.X - (n + s) * rr / 2 - w * rr + rr;
            float ymax = p4.Y - (e + w) * rr / 2 - n * rr + rr;
            if ((p.X >= p4.X - (n + s) * rr / 2 - w * rr) && (p.X <= xmax) && (p.Y >= p4.Y - (e + w) * rr / 2 - n * rr) && (p.Y <= ymax))
            {
                return true;
            }
            else
            {
                return false;
            }

        }






        public override bool ispick(Point p)
        {
            int n = 0;
            int s = 0;
            int w = 0;
            int e = 0;

            if (direction % 4 == 0)
            {
                e = 1; s = 0; n = 0; w = 0;
            }
            else if (direction % 4 == 1)
            {
                e = 0; s = 0; n = 1; w = 0;
            }
            else if (direction % 4 == 2)
            {
                e = 0; s = 0; n = 0; w = 1;
            }
            else
            {
                e = 0; s = 1; n = 0; w = 0;
            }

            float xmax = rect5.X + 2 * e * rect5.Width + (n + s) * rect5.Width + 3 * w * rect5.Width;
            float ymax = rect5.Y + (e + w) * rect5.Height + n * 3 * rect5.Height + 2 * s * rect5.Height;
            if ((p.X >= rect5.X - e * rect5.Width) && (p.X <= xmax) && (p.Y >= rect5.Y - s * rect5.Height) && (p.Y <= ymax))
            {
                return true;
            }
            else
            {
                return false;
            }

        }


        public override void draw(Graphics g, Pen mypen, float scale)
        {
            rect5.Width = rect5.Width * scale;
            rect5.Height = rect5.Height * scale;


            int n = 0;
            int s = 0;
            int w = 0;
            int e = 0;

            if (direction % 4 == 0)
            {
                e = 1; s = 0; n = 0; w = 0;
            }
            else if (direction % 4 == 1)
            {
                e = 0; s = 0; n = 1; w = 0;
            }
            else if (direction % 4 == 2)
            {
                e = 0; s = 0; n = 0; w = 1;
            }
            else
            {
                e = 0; s = 1; n = 0; w = 0;
            }

            // 在矩形内部绘制图案
            //鼠标位置
            PointF center = new PointF(rect2.X + rect2.Width, rect2.Y + rect2.Height / 2);
            PointF center2 = new PointF(rect2.X, rect2.Y + rect2.Height / 2);
            float radius = Math.Min(rect2.Width, rect2.Height) / 2;
            float rr = rect.Height / 8;


            PointF p1 = new PointF(rect5.X - e * 2 * rect5.Width + (n + s) * rect5.Width / 2 + w * 4 * rect5.Width, rect5.Y + (e + w) * rect5.Height / 2 + n * 4 * rect5.Height - s * 2 * rect5.Height);
            PointF p2 = new PointF(rect5.X - e * rect5.Width + (n + s) * rect5.Width / 2 + w * 3 * rect5.Width, rect5.Y + (e + w) * rect5.Height / 2 + n * 3 * rect5.Height - s * rect5.Height);

            PointF p3 = new PointF(rect5.X + e * 2 * rect5.Width + (n + s) * rect5.Width / 2, rect5.Y + (e + w) * rect5.Height / 2 + s * 2 * rect5.Height);
            PointF p4 = new PointF(rect5.X + e * 3 * rect5.Width + (n + s) * rect5.Width / 2 - w * rect5.Width, rect5.Y + (e + w) * rect5.Height / 2 + s * 3 * rect5.Height - n * rect5.Height);

            dian1.pos = p1;
            dian2.pos = p4;


            
                g.DrawEllipse(mypen, rect5.X - e * rect5.Width + w * rect5.Width, rect5.Y + n * rect5.Height - s * rect5.Height, (e + w + 2 * n + 2 * s) * rect5.Height, (2 * e + 2 * w + n + s) * rect5.Width);
                g.DrawEllipse(mypen, rect5.X, rect5.Y, (e + w + 2 * n + 2 * s) * rect5.Height, (2 * e + 2 * w + n + s) * rect5.Width);

                g.DrawLine(mypen, p1, p2);
                g.DrawLine(mypen, p3, p4);

                g.DrawEllipse(mypen, p1.X - e * rr - (n + s) * rr / 2, p1.Y - (e + w) * rr / 2 - s * rr, rr, rr);
                g.DrawEllipse(mypen, p4.X - (n + s) * rr / 2 - w * rr, p4.Y - (e + w) * rr / 2 - n * rr, rr, rr);


            
        }
    }
}
