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

namespace 试验版
{
    class muxian : element
    {

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

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




        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 = rect2.X + rect2.Width + (n + s) * 8;
            float ymax = rect2.Y + (e + w) * rect2.Height / 2 + (e + w) * 8 + (n + s) * rect2.Height;
            if ((p.X >= rect2.X + (n + s) * (rect2.Width - 8)) && (p.X <= xmax) && (p.Y >= rect2.Y + (e + w) * rect2.Height / 2 - (e + w) * 8) && (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 + (n + s) * rect2.Width + w * rect2.Width, rect2.Y + (e + w) * rect2.Height / 2 + n * rect2.Height);

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

            dian1.pos = p1;
            dian2.pos = center;

            

                

                g.DrawLine(mypen, center, p1);
                

            
        }
    }
}
