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

namespace 试验版
{
    class Break:element
    {
        


        public Break(Graphics gra):base(gra)
        {                                                                                     
            rect2 = new RectangleF(60,60,50,25);
            
            Point = new Point(); 
            sbname = "br";
            


        }

        public override bool ispick(Point p)
        {

            float xmax = rect2.X + rect2.Width;
            float ymax = rect2.Y + rect2.Height;
            if ((p.X >= rect2.X) && (p.X <= xmax) && (p.Y >= rect2.Y) && (p.Y <= ymax))
            {
                return true;
            }
            else
            {
                return false;
            }

        }

        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 * rect2.Width + (n + s) * rect2.Width / 2, rect2.Y + (e + w) * rect2.Height / 2 + s * rect2.Height);
            PointF center2 = new PointF(rect2.X - e * rect2.Width + w * 2 * rect2.Width + (n + s) * rect2.Width / 2, rect2.Y + (e + w) * rect2.Height / 2 + 2 * n * rect2.Height - s * rect2.Height);
            float radius = Math.Min(rect2.Width, rect2.Height) / 2;
            float rr = rect.Width / 8;

            PointF p1 = new PointF(rect2.X + e * 2 * rect2.Width - w * rect2.Width + (n + s) * rect2.Width / 2, rect2.Y + (e + w) * rect2.Height / 2 - n * rect2.Height + 2 * s * rect2.Height);
            PointF p2 = new PointF(rect2.X + (n + s) * rect2.Width / 2 + w * rect2.Width, rect2.Y + (e + w) * rect2.Height / 2 + n * rect2.Height); 
            
            dian1.pos = center2;
            dian2.pos = p1;

            
            if (edgesRemoved == false)
            {
                g.DrawRectangle(mypen, rect2.X, rect2.Y, rect2.Width, rect2.Height);

                g.DrawLine(mypen, p2, center2);//left
                g.DrawLine(mypen, center, p1);//right
                g.DrawLine(mypen, p2, center);//middle

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

            }
            else
            {
                g.DrawRectangle(mypen, rect2.X, rect2.Y, rect2.Width, rect2.Height);

                g.DrawLine(mypen, p2, center2);//left
                g.DrawLine(mypen, center, p1);//right

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



            


        }
    }
}
