Exemplo n.º 1
0
        /// <summary>
        /// Move selected shapes to new location.
        /// </summary>
        /// <param name="x">The X coordinate of point.</param>
        /// <param name="y">The Y coordinate of point.</param>
        private void MoveSelectionCacheTo(double x, double y)
        {
            double sx = _editor.Project.Options.SnapToGrid ? ProjectEditor.Snap(x, _editor.Project.Options.SnapX) : x;
            double sy = _editor.Project.Options.SnapToGrid ? ProjectEditor.Snap(y, _editor.Project.Options.SnapY) : y;

            double dx = sx - _startX;
            double dy = sy - _startY;

            _startX = sx;
            _startY = sy;

            if (_pointsCache != null)
            {
                ProjectEditor.MoveShapesBy(_pointsCache, dx, dy);
            }

            if (_shapesCache != null)
            {
                ProjectEditor.MoveShapesBy(_shapesCache, dx, dy);
            }
        }
Exemplo n.º 2
0
        /// <inheritdoc/>
        public override void LeftUp(double x, double y)
        {
            base.LeftUp(x, y);

            switch (_currentState)
            {
            case ToolState.None:
                break;

            case ToolState.One:
            {
                if (_editor.IsSelectionAvailable())
                {
                    double sx = _editor.Project.Options.SnapToGrid ? ProjectEditor.Snap(x, _editor.Project.Options.SnapX) : x;
                    double sy = _editor.Project.Options.SnapToGrid ? ProjectEditor.Snap(y, _editor.Project.Options.SnapY) : y;
                    if (_historyX != sx || _historyY != sy)
                    {
                        double dx = sx - _historyX;
                        double dy = sy - _historyY;

                        var previous = new
                        {
                            DeltaX = -dx,
                            DeltaY = -dy,
                            Points = _pointsCache,
                            Shapes = _shapesCache
                        };
                        var next = new
                        {
                            DeltaX = dx,
                            DeltaY = dy,
                            Points = _pointsCache,
                            Shapes = _shapesCache
                        };
                        _editor.Project?.History?.Snapshot(previous, next,
                                                           (state) =>
                            {
                                if (state.Points != null)
                                {
                                    ProjectEditor.MoveShapesBy(state.Points, state.DeltaX, state.DeltaY);
                                }

                                if (state.Shapes != null)
                                {
                                    ProjectEditor.MoveShapesBy(state.Shapes, state.DeltaX, state.DeltaY);
                                }
                            });
                    }

                    DisposeMoveSelectionCache();
                    _currentState           = ToolState.None;
                    _editor.CancelAvailable = false;
                    break;
                }

                if (_rectangle != null)
                {
                    _rectangle.BottomRight.X = x;
                    _rectangle.BottomRight.Y = y;
                    _editor.Project.CurrentContainer.WorkingLayer.Shapes = _editor.Project.CurrentContainer.WorkingLayer.Shapes.Remove(_rectangle);
                    _editor.Project.CurrentContainer.WorkingLayer.Invalidate();
                    _currentState = ToolState.None;
                    _editor.TryToSelectShapes(_editor.Project.CurrentContainer.CurrentLayer, _rectangle);
                    _editor.CancelAvailable = false;
                }
            }
            break;
            }
        }