Esempio n. 1
0
        //Отпускание фигуры
        /// <summary>
        /// Обработчик отпускания фигур
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="e"></param>
        private void MouseUpFigure(object obj, MouseEventArgs e)
        {
            MouseMoveDelegate += MouseMoveSelecting;
            MouseMoveDelegate -= MouseMoveFigure;
            MouseUpDelegate   -= MouseUpFigure;

            if (_reallyMoved)
            {
                var newState = new Dictionary <int, BaseFigure>();
                foreach (var figure in SelectedFigures)
                {
                    if (!_presenter.GetFigures().ContainsKey(figure.Key))
                    {
                        continue;
                    }
                    var index = figure.Key;
                    newState.Add(index, FigureFactory.CreateCopy(figure.Value));
                }

                OnFiguresMoved(newState);
                _reallyMoved = false;
            }

            Canvas.Refresh();
        }
Esempio n. 2
0
        /// <summary>
        /// Обработчик события изменения параметров фигур(ы)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _view_ParametersChanged(object sender, FigureParameters e)
        {
            var beforeState = new Dictionary <int, BaseFigure>();

            if (_currentHandler.GetType() == typeof(CursorHandler))
            {
                var handler = _currentHandler as CursorHandler;
                if (handler != null)
                {
                    foreach (var figure in handler.SelectedFigures)
                    {
                        if (!_model.GetFigureList().ContainsKey(figure.Key))
                        {
                            continue;
                        }
                        var index = figure.Key;
                        beforeState.Add(index, FigureFactory.CreateCopy(figure.Value));
                    }
                }
            }
            else
            {
                var handler = _currentHandler as FigureCreatingHandler;
                if (handler != null)
                {
                    handler.FigureParameters = e;
                }
                //_currentHandler.FigureParameters = e;
            }

            var cmd = new ChangeParametersCommand(_model, beforeState, e);

            _undoRedoStack.Do(cmd);
            _view.Canvas.Invalidate();
        }
Esempio n. 3
0
        /// <inheritdoc />
        /// <summary>
        /// Копирование объекта
        /// </summary>
        /// <param name="index">Индек фигуры</param>
        /// <param name="figure">Копируемая фигура</param>
        public void CopyFigure(int index, BaseFigure figure)
        {
            var addingFigure = FigureFactory.CreateCopy(figure, FigureFactory.CopyType.CopyWithOffset);

            CurrentIndex += 1;
            _figures.Add(CurrentIndex, addingFigure);
            NotifyObservers();
        }
Esempio n. 4
0
 /// <summary>
 /// Копирование словарей
 /// </summary>
 /// <param name="fromDictionary">Из словаря</param>
 /// <param name="toDictionary">В словарь</param>
 private static void CopyToDictionary(Dictionary <int, BaseFigure> fromDictionary,
                                      Dictionary <int, BaseFigure> toDictionary)
 {
     foreach (var entry in fromDictionary)
     {
         var index = entry.Key;
         toDictionary.Add(index, FigureFactory.CreateCopy(entry.Value));
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Конструктор класса команды движения фигур
        /// </summary>
        /// <param name="model"></param>
        /// <param name="beforeState"></param>
        /// <param name="newState"></param>
        public MoveFigureCommand(IModel model,
                                 Dictionary <int, BaseFigure> beforeState,
                                 Dictionary <int, BaseFigure> newState)
        {
            Model        = model;
            _beforeState = new Dictionary <int, BaseFigure>();
            _newState    = new Dictionary <int, BaseFigure>();

            foreach (var entry in beforeState)
            {
                var index = entry.Key;
                _beforeState.Add(index, FigureFactory.CreateCopy(entry.Value));
            }
            foreach (var entry in newState)
            {
                var index = entry.Key;
                _newState.Add(index, FigureFactory.CreateCopy(entry.Value));
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Обработчик отпускания маркера
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="e"></param>
        private void MouseUpMarker(object obj, MouseEventArgs e)
        {
            MouseMoveDelegate += MouseMoveSelecting;
            MouseMoveDelegate -= MouseMoveMarker;
            MouseUpDelegate   -= MouseUpMarker;

            var newPointState = new Dictionary <int, BaseFigure>();

            if (_isPointMoved)
            {
                newPointState.Add(_pickedFigureIndex,
                                  FigureFactory.CreateCopy(
                                      SelectedFigures[_pickedFigureIndex]));

                OnPointMoved(newPointState);

                _isPointMoved = false;
            }

            Canvas.Refresh();
        }
Esempio n. 7
0
        //Мышка нажата
        /// <summary>
        /// Обработчик события нажатия мышки
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (_isFigurePicked &&
                    SelectedFigures != null)
                {
                    if (IsPointOnFigure(e.Location))
                    {
                        if ((SelectedFigures != null) &&
                            SelectedFigures.ContainsKey(GetFigurePointOn(e.Location)))
                        {
                            _selectedFigure = _presenter.GetFigures()
                                              [GetFigurePointOn(e.Location)];

                            //Сохраняем предыдущее состояние
                            BeforeState?.Clear();

                            foreach (var figure in SelectedFigures)
                            {
                                if (!_presenter.GetFigures().Contains(figure))
                                {
                                    continue;
                                }
                                var index = figure.Key;
                                BeforeState?.Add(index, FigureFactory.CreateCopy(figure.Value));
                            }

                            MouseMoveDelegate -= MouseMoveSelecting;
                            MouseMoveDelegate += MouseMoveFigure;
                            MouseUpDelegate   += MouseUpFigure;

                            _offsetX = _selectedFigure.Points.GetPoints()[0].X - e.X;
                            _offsetY = _selectedFigure.Points.GetPoints()[0].Y - e.Y;
                        }
                    }
                    else if (IsPointOnMarker(e.Location, out _pickedPoint))
                    {
                        MouseMoveDelegate -= MouseMoveSelecting;
                        MouseMoveDelegate += MouseMoveMarker;
                        MouseUpDelegate   += MouseUpMarker;

                        BeforePointState?.Clear();

                        foreach (var figure in _presenter.GetFigures())
                        {
                            if (figure.Key != _pickedFigureIndex)
                            {
                                continue;
                            }
                            _oldFigureIndex = figure.Key;
                            BeforePointState?.Add(_oldFigureIndex,
                                                  FigureFactory.CreateCopy(figure.Value));
                        }

                        _offsetX = _pickedPoint.X - e.X;
                        _offsetY = _pickedPoint.Y - e.Y;
                    }
                    else
                    {
                        _isMouseDown = true;
                    }
                }
                else
                {
                    _isMouseDown = true;
                }
                _originalMouseDownPoint = e.Location;
            }
        }