Пример #1
0
        /// <inheritdoc />
        public override void SetSelectPoint(PreviewPoint point = null)
        {
            if (point == null)
            {
                _p1Start = new PreviewPoint((int)Bounds.X, (int)Bounds.Y);
            }

            _selectionPoint = PointInDragPoints(point);
        }
Пример #2
0
        /// <inheritdoc />
        public override void MouseMove(int x, int y, int changeX, int changeY)
        {
            var rt    = new RotateTransform(-RotationAngle, _rotationCenter.X, _rotationCenter.Y);
            var point = rt.TransformPoint(x, y);

            //See if we're resizing
            if (_selectionPoint != null && (_selectionPoint.PointType == PreviewPoint.PointTypes.Size || _selectionPoint.PointType == PreviewPoint.PointTypes.Rotate))
            {
                //We are resizing, so figure our change and scale the points.
                if (_selectionPoint == _dragPoints[0])
                {
                    //Top Left
                    var newHeight = Bounds.Height + (Bounds.TopLeft.Y - point.Y);
                    var newWidth  = Bounds.Width + (Bounds.TopLeft.X - point.X);

                    var minSize = ClampSize();
                    var scaleY  = newHeight > minSize ? newHeight / Bounds.Height : 1;
                    var scaleX  = newWidth > minSize ? newWidth / Bounds.Width : 1;

                    if (Control.ModifierKeys == Keys.Shift)
                    {
                        scaleX = scaleY = MaxValue(scaleX, scaleY);
                    }
                    Layout();

                    Scale(scaleX, scaleY, ZoomCoordToOriginal(_dragPoints[2].X), ZoomCoordToOriginal(_dragPoints[2].Y));

                    _selectionPoint = _dragPoints[0];
                }
                else if (_selectionPoint == _dragPoints[1])
                {
                    //Top Right
                    var newHeight = Bounds.Height + (Bounds.TopRight.Y - point.Y);
                    var newWidth  = Bounds.Width + (point.X - Bounds.TopRight.X);

                    var minSize = ClampSize();
                    var scaleY  = newHeight > minSize ? newHeight / Bounds.Height : 1;
                    var scaleX  = newWidth > minSize ? newWidth / Bounds.Width : 1;

                    if (Control.ModifierKeys == Keys.Shift)
                    {
                        scaleX = scaleY = MaxValue(scaleX, scaleY);
                    }

                    Scale(scaleX, scaleY, ZoomCoordToOriginal(_dragPoints[3].X), ZoomCoordToOriginal(_dragPoints[3].Y));
                    Layout();

                    _selectionPoint = _dragPoints[1];
                }
                else if (_selectionPoint == _dragPoints[2])
                {
                    //Bottom Right
                    var newHeight = Bounds.Height + (point.Y - Bounds.BottomRight.Y);
                    var newWidth  = Bounds.Width + (point.X - Bounds.BottomRight.X);

                    var minSize = ClampSize();
                    var scaleY  = newHeight > minSize ? newHeight / Bounds.Height:1;
                    var scaleX  = newWidth > minSize ? newWidth / Bounds.Width:1;

                    if (Control.ModifierKeys == Keys.Shift)
                    {
                        scaleX = scaleY = MaxValue(scaleX, scaleY);
                    }

                    Scale(scaleX, scaleY, ZoomCoordToOriginal(_dragPoints[0].X), ZoomCoordToOriginal(_dragPoints[0].Y));
                    Layout();

                    _selectionPoint = _dragPoints[2];
                }
                else if (_selectionPoint == _dragPoints[3])
                {
                    //Bottom Left
                    var newHeight = Bounds.Height + (point.Y - Bounds.BottomLeft.Y);
                    var newWidth  = Bounds.Width + (Bounds.BottomLeft.X - point.X);

                    var minSize = ClampSize();
                    var scaleY  = newHeight > minSize ? newHeight / Bounds.Height : 1;
                    var scaleX  = newWidth > minSize ? newWidth / Bounds.Width : 1;

                    if (Control.ModifierKeys == Keys.Shift)
                    {
                        scaleX = scaleY = MaxValue(scaleX, scaleY);
                    }

                    Scale(scaleX, scaleY, ZoomCoordToOriginal(_dragPoints[1].X), ZoomCoordToOriginal(_dragPoints[1].Y));
                    Layout();

                    _selectionPoint = _dragPoints[3];
                }
                else if (_selectionPoint == _dragPoints[4])
                {
                    //We are rotating!
                    double angle = GetAngle(_rotationCenter, new Point(x, y));
                    RotationAngle   = (int)Math.Round(angle, MidpointRounding.AwayFromZero);
                    _selectionPoint = _dragPoints[4];
                }
            }
            else
            {
                var newX = _p1Start.X + changeX;
                var newY = _p1Start.Y + changeY;
                MoveTo(newX, newY);
            }
        }
Пример #3
0
 public override void Deselect()
 {
     Selected        = false;
     _selectionPoint = null;
     _dragPoints?.Clear();
 }
Пример #4
0
        /// <inheritdoc />
        public override void MouseMove(int x, int y, int changeX, int changeY)
        {
            var rt    = new RotateTransform(-RotationAngle, _rotationCenter.X, _rotationCenter.Y);
            var point = rt.TransformPoint(x, y);

            //See if we're resizing
            if (_selectionPoint != null && (_selectionPoint.PointType == PreviewPoint.PointTypes.Size || _selectionPoint.PointType == PreviewPoint.PointTypes.Rotate))
            {
                //We are resizing, so figure our change and scale the points.
                if (_selectionPoint == _dragPoints[0])
                {
                    //Top Left
                    var newHeight = Bounds.Height + (Bounds.TopLeft.Y - point.Y);
                    var newWidth  = Bounds.Width + (Bounds.TopLeft.X - point.X);

                    var minSize = ClampSize();
                    var scaleY  = newHeight > minSize ? newHeight / Bounds.Height : 1;
                    var scaleX  = newWidth > minSize ? newWidth / Bounds.Width : 1;

                    if (Control.ModifierKeys == Keys.Shift)
                    {
                        scaleX = scaleY = MaxValue(scaleX, scaleY);
                    }
                    Layout();

                    Scale(scaleX, scaleY, ZoomCoordToOriginal(_dragPoints[2].X), ZoomCoordToOriginal(_dragPoints[2].Y));

                    _selectionPoint = _dragPoints[0];
                }
                else if (_selectionPoint == _dragPoints[1])
                {
                    //Top Right
                    var newHeight = Bounds.Height + (Bounds.TopRight.Y - point.Y);
                    var newWidth  = Bounds.Width + (point.X - Bounds.TopRight.X);

                    var minSize = ClampSize();
                    var scaleY  = newHeight > minSize ? newHeight / Bounds.Height : 1;
                    var scaleX  = newWidth > minSize ? newWidth / Bounds.Width : 1;

                    if (Control.ModifierKeys == Keys.Shift)
                    {
                        scaleX = scaleY = MaxValue(scaleX, scaleY);
                    }

                    Scale(scaleX, scaleY, ZoomCoordToOriginal(_dragPoints[3].X), ZoomCoordToOriginal(_dragPoints[3].Y));
                    Layout();

                    _selectionPoint = _dragPoints[1];
                }
                else if (_selectionPoint == _dragPoints[2])
                {
                    //Bottom Right
                    var newHeight = Bounds.Height + (point.Y - Bounds.BottomRight.Y);
                    var newWidth  = Bounds.Width + (point.X - Bounds.BottomRight.X);

                    var minSize = ClampSize();
                    var scaleY  = newHeight > minSize ? newHeight / Bounds.Height:1;
                    var scaleX  = newWidth > minSize ? newWidth / Bounds.Width:1;

                    if (Control.ModifierKeys == Keys.Shift)
                    {
                        scaleX = scaleY = MaxValue(scaleX, scaleY);
                    }

                    Scale(scaleX, scaleY, ZoomCoordToOriginal(_dragPoints[0].X), ZoomCoordToOriginal(_dragPoints[0].Y));
                    Layout();

                    _selectionPoint = _dragPoints[2];
                }
                else if (_selectionPoint == _dragPoints[3])
                {
                    //Bottom Left
                    var newHeight = Bounds.Height + (point.Y - Bounds.BottomLeft.Y);
                    var newWidth  = Bounds.Width + (Bounds.BottomLeft.X - point.X);

                    var minSize = ClampSize();
                    var scaleY  = newHeight > minSize ? newHeight / Bounds.Height : 1;
                    var scaleX  = newWidth > minSize ? newWidth / Bounds.Width : 1;

                    if (Control.ModifierKeys == Keys.Shift)
                    {
                        scaleX = scaleY = MaxValue(scaleX, scaleY);
                    }

                    Scale(scaleX, scaleY, ZoomCoordToOriginal(_dragPoints[1].X), ZoomCoordToOriginal(_dragPoints[1].Y));
                    Layout();

                    _selectionPoint = _dragPoints[3];
                }
                else if (_selectionPoint == _dragPoints[4])
                {
                    //We are rotating!
                    double angle = GetAngle(_rotationCenter, new Point(x, y));

                    // Use Detents of 0, 45, 90, 135, 180, 225, 270 and 315 when holding the Shift modifier key down.
                    if (Control.ModifierKeys == Keys.Control)
                    {
                        if (angle >= 22.5 && angle < 67.5)
                        {
                            angle = 45;
                        }
                        else if (angle >= 67.5 && angle < 112.5)
                        {
                            angle = 90;
                        }
                        else if (angle >= 112.5 && angle < 157.5)
                        {
                            angle = 135;
                        }
                        else if (angle >= 157.5 && angle < 202.5)
                        {
                            angle = 180;
                        }
                        else if (angle >= 202.5 && angle < 247.5)
                        {
                            angle = 225;
                        }
                        else if (angle >= 247.5 && angle < 292.5)
                        {
                            angle = 270;
                        }
                        else if (angle >= 292.5 && angle < 337.5)
                        {
                            angle = 315;
                        }
                        else if (angle >= 337.5 || angle < 22.5)
                        {
                            angle = 0;
                        }
                    }

                    RotationAngle   = (int)Math.Round(angle, MidpointRounding.AwayFromZero);
                    _selectionPoint = _dragPoints[4];
                }
            }
            else
            {
                var newX = _p1Start.X + changeX;
                var newY = _p1Start.Y + changeY;
                MoveTo(newX, newY);
            }
        }