Beispiel #1
0
        //Определение новых размеров прямоугольника
        private Rect GetNewSize(Shape currentFigure, Point currentMousePosition)
        {
            Rect   rect       = GraphicElements.GetPosition(currentFigure);
            double new_x      = rect.X;
            double new_y      = rect.Y;
            double new_width  = rect.Width;
            double new_height = rect.Height;
            double offset_x   = currentMousePosition.X - mousePosition.X;
            double offset_y   = currentMousePosition.Y - mousePosition.Y;

            switch (hitType)
            {
            case HitType.UpperLeft:
                new_x      += offset_x;
                new_y      += offset_y;
                new_width  -= offset_x;
                new_height -= offset_y;
                break;

            case HitType.UpperRight:
                new_y      += offset_y;
                new_width  += offset_x;
                new_height -= offset_y;
                break;

            case HitType.LowerRight:
                new_width  += offset_x;
                new_height += offset_y;
                break;

            case HitType.LowerLeft:
                new_x      += offset_x;
                new_width  -= offset_x;
                new_height += offset_y;
                break;

            case HitType.Left:
                new_x     += offset_x;
                new_width -= offset_x;
                break;

            case HitType.Right:
                new_width += offset_x;
                break;

            case HitType.Bottom:
                new_height += offset_y;
                break;

            case HitType.Top:
                new_y      += offset_y;
                new_height -= offset_y;
                break;
            }
            return(new Rect(new_x, new_y, new_width, new_height));
        }
Beispiel #2
0
        //Опередление точные координаты границ прямоугольника
        private Point[] GetCornersPosition(Shape shape)
        {
            Point [] corners = new Point[4];
            double   angle   = GraphicElements.GetRotationAngle(shape);
            Rect     rect    = GraphicElements.GetPosition(shape);
            Point    Center  = GraphicElements.GetCenter(rect);
            //Определяем координаты углов прямоугольника без учёта угла поворота
            Point           LeftTop         = new(rect.X, rect.Y);
            Point           LeftBottom      = new(rect.X, rect.Y + rect.Height);
            Point           RightTop        = new(rect.X + rect.Width, LeftTop.Y);
            Point           RightBottom     = new(rect.X + rect.Width, LeftTop.Y + rect.Height);
            RotateTransform rotateTransform = new(angle, Center.X, Center.Y);

            //Определяем координаты углов прямоугольника с учётом угла поворота
            corners[0] = rotateTransform.Transform(LeftTop);
            corners[1] = rotateTransform.Transform(LeftBottom);
            corners[2] = rotateTransform.Transform(RightTop);
            corners[3] = rotateTransform.Transform(RightBottom);
            return(corners);
        }