Example #1
0
        //Опередление положениее перемещаемой границы прямоугольника
        HitType BorderCheck(Shape shape, Point currentMousePosition)
        {
            Point[] corners     = GetCornersPosition(shape);
            Point   LeftTop     = corners[0];
            Point   LeftBottom  = corners[1];
            Point   RightTop    = corners[2];
            Point   RightBottom = corners[3];
            double  GAP         = thickness * 2;

            //Определяем границу, местоположение мыши на границе
            if (GraphicElements.CheckIntersection(LeftTop, LeftBottom, currentMousePosition, GAP, true))
            {
                // Left edge.
                if (GraphicElements.CheckIntersection(LeftTop, RightTop, currentMousePosition, GAP, true))
                {
                    return(HitType.UpperLeft);
                }
                if (GraphicElements.CheckIntersection(LeftBottom, RightBottom, currentMousePosition, GAP, true))
                {
                    return(HitType.LowerLeft);
                }
                return(HitType.Left);
            }
            if (GraphicElements.CheckIntersection(RightTop, RightBottom, currentMousePosition, GAP, true))
            {
                // Right edge.
                if (GraphicElements.CheckIntersection(LeftTop, RightTop, currentMousePosition, GAP, true))
                {
                    return(HitType.UpperRight);
                }
                if (GraphicElements.CheckIntersection(LeftBottom, RightBottom, currentMousePosition, GAP, true))
                {
                    return(HitType.LowerRight);
                }
                return(HitType.Right);
            }
            if (GraphicElements.CheckIntersection(LeftTop, RightTop, currentMousePosition, GAP, true))
            {
                return(HitType.Top);
            }
            if (GraphicElements.CheckIntersection(LeftBottom, RightBottom, currentMousePosition, GAP, true))
            {
                return(HitType.Bottom);
            }
            return(HitType.Body);
        }