示例#1
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;
            }
        }