예제 #1
0
        private void HandleArrowKey(KeyEventArgs e, Keys modifierKeys)
        {
            IEnumerable <IDrawable> selectedShapes = _canvas.Drawables.SelectedShapes;

            if (selectedShapes.Any())
            {
                MovementType movementType;
                switch (e.KeyCode)
                {
                case Keys.Up:
                    movementType = MovementType.Up;
                    break;

                case Keys.Down:
                    movementType = MovementType.Down;
                    break;

                case Keys.Left:
                    movementType = MovementType.Left;
                    break;

                case Keys.Right:
                    movementType = MovementType.Right;
                    break;

                default:
                    throw new Exception("Unexpected movement type.");
                }

                // If the Control key was held, then we make the unit of movement smaller, for more precise movement.
                if (modifierKeys.HasFlag(Keys.Control))
                {
                    movementType |= MovementType.SingleUnit;
                }

                foreach (IDrawable selectedShape in selectedShapes)
                {
                    _canvas.MoveShape(selectedShape, movementType);
                }
            }
        }