示例#1
0
        public void Undo()
        {
            if (_recodes.Count == 0)
            {
                return;
            }
            ConstructRecode r = _recodes.Last();

            switch (r.type)
            {
            case RecodeType.CREATE:
                foreach (var s in r.targetshapes)
                {
                    _shapes.Remove(s);
                }
                break;

            case RecodeType.DELETE:
                foreach (var s in r.targetshapes)
                {
                    AddShape(s);
                }
                break;

            case RecodeType.MOVE:
                foreach (Shape s in r.targetshapes)
                {
                    s.Move(r.moveRecode);
                }
                break;
            }
            _recodes.RemoveAt(_recodes.Count - 1);
        }
示例#2
0
        private void UpdateDrag()
        {
            if (_drawState == DrawState.NONE)
            {
                if (_selectedShapes.Count == 0)
                {
                    return;
                }
                if (Scene.CurrentScene.IsLeftMouseDown && _selectedShapes.Any(s => s.IsEnoughClose(_pos)))
                {
                    _readyForDrag = true;
                }
                if (_readyForDrag && Scene.CurrentScene.IsMouseMoved)
                {
                    _readyForDrag = false;
                    ConstructRecode r = new ConstructRecode(RecodeType.MOVE, _selectedShapes);
                    _recodes.Add(r);
                    _lastpos = samplepoint.Coord;
                    if (Scene.CurrentScene.IsLeftMouseClicking)
                    {
                        _isDragging = true;
                    }
                }

                if (_isDragging || Scene.CurrentScene.IsLeftMouseClicking && Scene.CurrentScene.IsMouseMoved)
                {
                    var diff = Scene.CurrentScene.MousePosition - Scene.CurrentScene.LastMousePosition;
                    if (_isDragging || _selectedShapes.Any(s => s.IsEnoughClose(_pos)))
                    {
                        if (!_isDragging)
                        {
                            _isDragging = true;
                        }
                        _selectedShapes.ForEach(s => { s.UnSelect = false; s.Move(diff.ToVector2()); });
                        samplepoint.Move(diff.ToVector2());
                    }
                    if (Scene.CurrentScene.IsLeftMouseUp)
                    {
                        _isDragging = false;
                        _recodes.Last().WriteMoveRecode(samplepoint.Coord - _lastpos);
                        return;
                    }
                }
            }
        }