Exemple #1
0
        public override Object ShowDialog(PropertyItem propertyItem, Object propertyValue, IInputElement commandSource)
        {
            HashSet <Color> discreteColors = GetDiscreteColors(propertyItem.Component);

            Color colorValue;

            if (propertyValue != null)
            {
                colorValue = (Color)propertyValue;
            }
            else
            {
                colorValue = discreteColors.Any() ? discreteColors.First() : Color.White;
            }
            DialogResult result;

            if (discreteColors.Any())
            {
                using (DiscreteColorPicker dcp = new DiscreteColorPicker())
                {
                    dcp.ValidColors     = discreteColors;
                    dcp.SingleColorOnly = true;
                    dcp.SelectedColors  = new List <Color> {
                        colorValue
                    };
                    dcp.Text = propertyItem.DisplayName;
                    result   = dcp.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        propertyValue = !dcp.SelectedColors.Any() ? discreteColors.First() : dcp.SelectedColors.First();
                    }
                }
            }
            else
            {
                using (ColorPicker cp = new ColorPicker())
                {
                    cp.LockValue_V = true;
                    cp.Color       = XYZ.FromRGB(colorValue);
                    cp.Text        = propertyItem.DisplayName;
                    result         = cp.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        propertyValue = cp.Color.ToRGB().ToArgb();
                    }
                }
            }

            return(propertyValue);
        }
Exemple #2
0
        private Tuple <DialogResult, System.Drawing.Color> ChooseColor(List <ElementNode> selectedNodes, System.Drawing.Color color)
        {
            var          returnColor = color;
            var          colors      = ValidDiscreteColors(selectedNodes);
            DialogResult result      = DialogResult.Abort;

            if (colors.Any())
            {
                using (DiscreteColorPicker dcp = new DiscreteColorPicker())
                {
                    dcp.ValidColors     = colors;
                    dcp.SingleColorOnly = true;
                    dcp.SelectedColors  = new List <System.Drawing.Color> {
                        color
                    };
                    result = dcp.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        if (!dcp.SelectedColors.Any())
                        {
                            returnColor = System.Drawing.Color.White;
                        }
                        else
                        {
                            returnColor = dcp.SelectedColors.First();
                        }
                    }
                }
            }
            else
            {
                using (ColorPicker cp = new ColorPicker())
                {
                    cp.LockValue_V = false;
                    cp.Color       = XYZ.FromRGB(color);
                    result         = cp.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        returnColor = cp.Color.ToRGB();
                    }
                }
            }

            return(new Tuple <DialogResult, System.Drawing.Color>(result, returnColor));
        }
Exemple #3
0
 private void panelColor_Click(object sender, EventArgs e)
 {
     if (_discreteColors)
     {
         using (DiscreteColorPicker dcp = new DiscreteColorPicker())
         {
             dcp.ValidColors     = _validDiscreteColors;
             dcp.SingleColorOnly = true;
             dcp.SelectedColors  = new List <Color> {
                 Color
             };
             DialogResult result = dcp.ShowDialog();
             if (result == DialogResult.OK)
             {
                 if (dcp.SelectedColors.Count() == 0)
                 {
                     Color = Color.White;
                 }
                 else
                 {
                     RGBColor = dcp.SelectedColors.First();
                 }
             }
         }
     }
     else
     {
         using (ColorPicker cp = new ColorPicker())
         {
             cp.LockValue_V = true;
             cp.Color       = XYZ.FromRGB(Color);
             DialogResult result = cp.ShowDialog();
             if (result == DialogResult.OK)
             {
                 RGBColor = cp.Color.ToRGB();
             }
         }
     }
 }
        private void ShowColorPicker()
        {
            //Logging.Debug("Enter color picker");
            var value = GetColorGradientValue();

            if (value == null)
            {
                return;
            }
            var selectedIndex = SelectedIndex;

            if (selectedIndex < 0)
            {
                return;
            }
            var           handle            = _points[selectedIndex];
            var           colorPointIndexes = (List <int>)handle.Tag;
            ColorGradient holdValue;

            if (IsDiscrete)
            {
                holdValue = new ColorGradient(value);
                List <Color>      selectedColors = new List <Color>();
                List <ColorPoint> colorPoints    = new List <ColorPoint>();
                foreach (int index in colorPointIndexes)
                {
                    ColorPoint pt = holdValue.Colors[index];
                    if (pt == null)
                    {
                        continue;
                    }
                    colorPoints.Add(pt);
                    selectedColors.Add(pt.Color.ToRGB().ToArgb());
                }

                using (DiscreteColorPicker picker = new DiscreteColorPicker())
                {
                    picker.ValidColors    = ValidColors;
                    picker.SelectedColors = selectedColors;
                    if (picker.ShowDialog() == DialogResult.OK)
                    {
                        if (!picker.SelectedColors.Any())
                        {
                            DeletePoint();
                        }
                        else
                        {
                            double position = colorPoints.First().Position;
                            foreach (var colorPoint in colorPoints)
                            {
                                holdValue.Colors.Remove(colorPoint);
                            }

                            foreach (Color selectedColor in picker.SelectedColors)
                            {
                                ColorPoint newPoint = new ColorPoint(selectedColor, position);
                                holdValue.Colors.Add(newPoint);
                            }
                            SetColorGradientValue(holdValue);
                        }
                    }
                }
            }
            else
            {
                if (colorPointIndexes.Count > 1)
                {
                    //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible)
                    MessageBoxForm.msgIcon = SystemIcons.Error;                     //this is used if you want to add a system icon to the message form.
                    var messageBox = new MessageBoxForm("Non-discrete color gradient, >1 selected point. oops! please report it.", "Delete library gradient?", false, false);
                    messageBox.ShowDialog();
                }

                holdValue = new ColorGradient(value);
                ColorPoint pt = holdValue.Colors[colorPointIndexes.FirstOrDefault()];
                if (pt == null)
                {
                    return;
                }
                using (ColorPicker frm = new ColorPicker(_mode, _fader))
                {
                    frm.LockValue_V = false;
                    frm.Color       = pt.Color;
                    if (frm.ShowDialog() == DialogResult.OK)
                    {
                        pt.Color = frm.Color;
                        _mode    = frm.SecondaryMode;
                        _fader   = frm.PrimaryFader;
                        SetColorGradientValue(holdValue);
                    }
                }
            }
            //Logging.Debug("Exit normally color picker");
        }
Exemple #5
0
        // edits the selected color in the 'edit' control
        private void editSelectedPoints()
        {
            if (edit.Gradient == null || edit.FocusSelection)
            {
                return;
            }

            if (DiscreteColors)
            {
                List <Color> selectedColors = new List <Color>();
                foreach (ColorGradient.Point point in edit.Selection)
                {
                    ColorPoint pt = point as ColorPoint;
                    if (pt == null)
                    {
                        continue;
                    }
                    selectedColors.Add(pt.Color.ToRGB().ToArgb());
                }

                using (DiscreteColorPicker picker = new DiscreteColorPicker()) {
                    picker.ValidColors    = ValidDiscreteColors;
                    picker.SelectedColors = selectedColors;
                    if (picker.ShowDialog() == DialogResult.OK)
                    {
                        if (picker.SelectedColors.Count() == 0)
                        {
                            DeleteColor();
                        }
                        else if (picker.SelectedColors.Count() == selectedColors.Count)
                        {
                            int i = 0;
                            foreach (Color selectedColor in picker.SelectedColors)
                            {
                                ColorPoint pt = edit.Selection[i] as ColorPoint;
                                pt.Color = XYZ.FromRGB(selectedColor);
                            }
                        }
                        else
                        {
                            double position = edit.Selection.First().Position;

                            foreach (ColorGradient.Point point in edit.Selection)
                            {
                                edit.Gradient.Colors.Remove(point as ColorPoint);
                            }

                            foreach (Color selectedColor in picker.SelectedColors)
                            {
                                ColorPoint newPoint = new ColorPoint(selectedColor, position);
                                edit.Gradient.Colors.Add(newPoint);
                            }
                        }
                    }
                }
            }
            else
            {
                if (edit.Selection.Count > 1)
                {
                    //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible)
                    MessageBoxForm.msgIcon = SystemIcons.Error;                     //this is used if you want to add a system icon to the message form.
                    var messageBox = new MessageBoxForm("Non-discrete color gradient, >1 selected point. oops! please report it.", "Delete library gradient?", false, false);
                    messageBox.ShowDialog();
                }
                ColorPoint pt = edit.Selection.FirstOrDefault() as ColorPoint;
                if (pt == null)
                {
                    return;
                }
                using (ColorPicker frm = new ColorPicker(_mode, _fader)) {
                    frm.LockValue_V = LockColorEditorHSV_Value;
                    frm.Color       = _xyz;
                    if (frm.ShowDialog(this.FindForm()) == DialogResult.OK)
                    {
                        pt.Color             = _xyz = frm.Color;
                        lblColorSelect.Color = _xyz.ToRGB().ToArgb();
                        _mode  = frm.SecondaryMode;
                        _fader = frm.PrimaryFader;
                    }
                }
            }
        }
        // edits the selected color in the 'edit' control
        private void editSelectedPoints()
        {
            if (edit.Gradient == null || edit.FocusSelection)
            {
                return;
            }

            if (DiscreteColors)
            {
                List <Color> selectedColors = new List <Color>();
                foreach (ColorGradient.Point point in edit.Selection)
                {
                    ColorPoint pt = point as ColorPoint;
                    if (pt == null)
                    {
                        continue;
                    }
                    selectedColors.Add(pt.Color.ToRGB().ToArgb());
                }

                using (DiscreteColorPicker picker = new DiscreteColorPicker()) {
                    picker.ValidColors    = ValidDiscreteColors;
                    picker.SelectedColors = selectedColors;
                    if (picker.ShowDialog() == DialogResult.OK)
                    {
                        if (picker.SelectedColors.Count() == 0)
                        {
                            DeleteColor();
                        }
                        else if (picker.SelectedColors.Count() == selectedColors.Count)
                        {
                            int i = 0;
                            foreach (Color selectedColor in picker.SelectedColors)
                            {
                                ColorPoint pt = edit.Selection[i] as ColorPoint;
                                pt.Color = XYZ.FromRGB(selectedColor);
                            }
                        }
                        else
                        {
                            double position = edit.Selection.First().Position;

                            foreach (ColorGradient.Point point in edit.Selection)
                            {
                                edit.Gradient.Colors.Remove(point as ColorPoint);
                            }

                            foreach (Color selectedColor in picker.SelectedColors)
                            {
                                ColorPoint newPoint = new ColorPoint(selectedColor, position);
                                edit.Gradient.Colors.Add(newPoint);
                            }
                        }
                    }
                }
            }
            else
            {
                if (edit.Selection.Count > 1)
                {
                    MessageBox.Show("Non-discrete color gradient, >1 selected point. oops! please report it.");
                }
                ColorPoint pt = edit.Selection.FirstOrDefault() as ColorPoint;
                if (pt == null)
                {
                    return;
                }
                using (ColorPicker frm = new ColorPicker(_mode, _fader)) {
                    frm.LockValue_V = LockColorEditorHSV_Value;
                    frm.Color       = _xyz;
                    if (frm.ShowDialog(this.FindForm()) == DialogResult.OK)
                    {
                        pt.Color             = _xyz = frm.Color;
                        lblColorSelect.Color = _xyz.ToRGB().ToArgb();
                        _mode  = frm.SecondaryMode;
                        _fader = frm.PrimaryFader;
                    }
                }
            }
        }