Example #1
0
        private void TheImage_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            // Get the hue index ( zero based )
            SelectedColor = GetHueIndex(e.X, e.Y);

            // Handle selection of hues

            if (!(ShiftPressed() || ControlPressed()))
            {
                if ((SelectedHues.Count == 1) && (SelectedHues.Contains(SelectedColor)))
                {
                    SelectedHues.Clear();
                    DrawSelectionChart();
                    return;
                }
                // No modifier keys pressed. Clear selection and add current item
                SelectedHues.Clear();
                SelectedHues.Add(SelectedColor);
                PreviousSelectedColor = SelectedColor;
                DrawSelectionChart();
                return;
            }

            if (SelectedHues.Contains(SelectedColor))
            {
                // Clicking the same just deselects it
                SelectedHues.Remove(SelectedColor);

                if (ShiftPressed())
                {
                    // Go down
                    if (SelectedHues.Contains((SelectedColor + 1)))
                    {
                        for (int i = (SelectedColor + 1); i <= PreviousSelectedColor; i++)
                        {
                            if (SelectedHues.Contains(i))
                            {
                                SelectedHues.Remove(i);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                PreviousSelectedColor = (SelectedColor - 1);
                DrawSelectionChart();
                return;
            }

            if (ControlPressed())
            {
                // Add a single item to the list
                SelectedHues.Add(SelectedColor);
                PreviousSelectedColor = SelectedColor;
                DrawSelectionChart();
                return;
            }

            if (ShiftPressed())
            {
                // Add a selection of items
                if (PreviousSelectedColor < SelectedColor)
                {
                    // Moving backwards
                    for (int i = SelectedColor; i > PreviousSelectedColor; i--)
                    {
                        if (!SelectedHues.Contains(i))
                        {
                            SelectedHues.Add(i);
                        }
                    }
                }
                if (PreviousSelectedColor > SelectedColor)
                {
                    // Moving forward
                    for (int i = SelectedColor; i < PreviousSelectedColor; i++)
                    {
                        if (!SelectedHues.Contains(i))                             // Avoid duplicates
                        {
                            SelectedHues.Add(i);
                        }
                    }
                }

                PreviousSelectedColor = SelectedColor;
                DrawSelectionChart();
                return;
            }
        }
Example #2
0
 public void ClearSelection()
 {
     SelectedHues.Clear();
     SelectionChart = (Bitmap)Chart.Clone();
     TheImage.Image = Chart;
 }