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

namespace 试验版
{
    class dbreak:element

    {
       

        public dbreak(Graphics gra):base(gra)
        {
            dian1 = new dian(this, gra);
            dian2 = new dian(this, gra);
            sbname = "bbr";
        }

        public override void Resize(float scale)
        {
            float Scale = 1.0f;
            Scale *= scale;//放大缩小
            rect2.Width *= scale;
            rect2.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 center = new PointF(rect2.X + (e + w) * rect2.Width + (n + s) * rect2.Width / 2, rect2.Y + (e + w) * rect2.Height / 2);
            PointF center2 = new PointF(rect2.X - (e + w) * rect2.Width + (n + s) * rect2.Width / 2, rect2.Y + (e + w) * rect2.Height / 2 + 2 * (n + s) * rect2.Height);
            PointF p1 = new PointF(rect2.X + (e + w) * 2 * rect2.Width + (n + s) * rect2.Width / 2, rect2.Y + (e + w) * rect2.Height / 2 - (n + s) * rect2.Height);
            PointF p2 = new PointF(rect2.X + (n + s) * rect2.Width / 2, rect2.Y + (e + w) * rect2.Height / 2 + (n + s) * rect2.Height);

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

            if ((p.X >= center2.X - (e + w) * rr - (n + s) * rr / 2) && (p.X <= xmax) && (p.Y >= center2.Y - (e + w) * rr / 2) && (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 p1 = new PointF(rect2.X + (e + w) * 2 * rect2.Width + (n + s) * rect2.Width / 2, rect2.Y + (e + w) * rect2.Height / 2 - (n + s) * rect2.Height);

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

        }







        public override void draw(Graphics g, Pen mypen, float scale)
        {
            rect2.Width = rect2.Width * scale;
            rect2.Height = rect2.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 + (e + w) * rect2.Width + (n + s) * rect2.Width / 2, rect2.Y + (e + w) * rect2.Height / 2);
            PointF center2 = new PointF(rect2.X - (e + w) * rect2.Width + (n + s) * rect2.Width / 2, rect2.Y + (e + w) * rect2.Height / 2 + 2 * (n + s) * rect2.Height);
            float radius = Math.Min(rect2.Width, rect2.Height) / 2;
            float rr = rect.Width / 8;

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

            dian1.pos = p1;
            dian2.pos = center2;

            if(edgesRemoved == false)
            {
                g.DrawLine(mypen, center, p1);
                g.DrawLine(mypen, p2, center2);

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

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

                g.DrawLine(mypen, p2, center);
            }
            else
            {
                g.DrawLine(mypen, center, p1);
                g.DrawLine(mypen, p2, center2);

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

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

                g.DrawLine(mypen, p4, p3);

            }


            

            
        }
    }
}
