Пример #1
0
        //
        // Layer Image Released mouse event handler
        //
        private void OnLayerImageReleased(object sender, MouseEventArgs mouseEventArgs)
        {
            // Get the index of the control being dragged
            var control = sender as LayerControl;

            if (control == null)
            {
                return;
            }

            // Open context menu
            if (mouseEventArgs.Button == MouseButtons.Right)
            {
                // If no controls are selected, select the control that was pressed
                if (SelectedControls.Length == 0)
                {
                    control.Selected = true;
                }

                ShowLayersContextMenu();

                return;
            }

            // Select layers
            if (!_movingControls)
            {
                if (ModifierKeys.HasFlag(Keys.Shift))
                {
                    ClearSelection();

                    // Select all layers from the current active layer to the selected control layer
                    for (int i = Math.Min(ActiveLayerControl.Layer.Index, control.Layer.Index); i <= Math.Max(ActiveLayerControl.Layer.Index, control.Layer.Index); i++)
                    {
                        _layerControls[i].Selected = true;
                    }

                    return;
                }
                if (ModifierKeys.HasFlag(Keys.Control))
                {
                    // Select the control
                    control.Selected = !control.Selected;

                    return;
                }
            }

            ClearSelection();

            // Move layers
            if (!_movingControls)
            {
                return;
            }

            _movingControls = false;

            int index    = control.Layer.Index;
            int newIndex = _layerControls.IndexOf(control);

            if (index == newIndex)
            {
                return;
            }

            // Reset the layer control index
            SwapLayerControls(index, newIndex);

            if (newIndex >= 0 && newIndex < _controller.LayerCount)
            {
                _controller.MoveLayer(index, newIndex);
            }
        }