Example #1
0
        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (_moving != null)
                {
                    MoveCommand moveCommand = new MoveCommand(_shapeList, _moving.Shape, _moving.StartMoveMousePoint,
                        e.Location);
                    //moveCommand.Do();
                    _commandStack.Push(moveCommand);
                    _undoneCommands.Clear();
                    UpdateControls();
                    Invalidate();
                    Capture = false;
                    _moving = null;
                }
                if (_resizing != null)
                {
                    ResizeCommand resizeCommand = new ResizeCommand(_resizing.Shape, _mouseDownLocation, e.Location);
                    //moveCommand.Do();
                    _commandStack.Push(resizeCommand);
                    _undoneCommands.Clear();
                    UpdateControls();
                    Capture = false;
                    _resizing = null;
                }

                switch (_activemode)
                {
                    case Mode.Controller:
                        RefreshShapeSelection(e.Location);
                        break;
                    case Mode.Rectangle:
                        if (_startLocation.X != e.X && _startLocation.Y != e.Y)
                        {
                            DrawCommand rectangleCommand = new DrawCommand(_shapeList,
                                new DrawRectangle(_startLocation.X, _startLocation.Y, e.X, e.Y));
                            rectangleCommand.Do();
                            _commandStack.Push(rectangleCommand);
                            _undoneCommands.Clear();
                        }

                        UpdateControls();
                        Invalidate();
                        break;
                    case Mode.Ellipse:
                        if (_startLocation.X != e.X && _startLocation.Y != e.Y)
                        {
                            DrawCommand ellipseCommand = new DrawCommand(_shapeList,
                                new DrawEllipse(_startLocation.X, _startLocation.Y, e.X, e.Y));
                            ellipseCommand.Do();
                            _commandStack.Push(ellipseCommand);
                            _undoneCommands.Clear();
                        }

                        UpdateControls();
                        Invalidate();
                        break;
                } //end mode switch
            } //end leftclick
            else if (e.Button == MouseButtons.Right)
            {
                if (_activemode == Mode.Controller)
                {
                    SetupRightClickmenu();
                }
            }
        }
Example #2
0
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            if (_activemode == Mode.Controller)
            {
                _mouseDownLocation = e.Location;
                if (_selected != null && _moving == null)
                {
                    for (int i = 1; i <= 4; i++)
                    {
                        if (GetHandleRectangle(i, _selected).Contains(e.Location))
                        {
                            _resizing = new ResizeInfo
                            {
                                Shape = _selected,
                                StartResizePoint = _selected.StartPoint,
                                HandleNumber = i
                            };
                            break;
                        }
                        Capture = true;

                        _moving = new MoveInfo
                        {
                            Shape = _selected,
                            StartShapePoint = _selected.StartPoint,
                            EndShapePoint = _selected.EndPoint,
                            StartMoveMousePoint = e.Location
                        };
                    }
                    //Capture = true;
                    //_moving = new MoveInfo
                    //{
                    //    Shape = _selected,
                    //    StartShapePoint = _selected.StartPoint,
                    //    EndShapePoint = _selected.EndPoint,
                    //    StartMoveMousePoint = e.Location
                    //};
                }
                RefreshShapeSelection(e.Location);
            }
            else if (_activemode == Mode.Rectangle)
            {
                _startLocation = e.Location;
            }

            else if (_activemode == Mode.Ellipse)
            {
                _startLocation = e.Location;
            }
        }