Beispiel #1
0
        private void toolStripButtonEditColor_Click(object sender, EventArgs e)
        {
            if (listViewColors.SelectedItems.Count != 1)
            {
                return;
            }

            using (ColorPicker cp = new ColorPicker())
            {
                cp.LockValue_V = true;
                cp.Color       = XYZ.FromRGB((Color)listViewColors.SelectedItems[0].Tag);
                DialogResult result = cp.ShowDialog();
                if (result != DialogResult.OK)
                {
                    return;
                }
                Color colorValue = cp.Color.ToRGB().ToArgb();

                listViewColors.BeginUpdate();
                listViewColors.SelectedItems[0].ToolTipText = string.Format("R: {0} G: {1} B: {2}", colorValue.R, colorValue.G, colorValue.B);
                listViewColors.SelectedItems[0].ImageKey    = colorValue.ToString();
                listViewColors.SelectedItems[0].Tag         = colorValue;
                listViewColors.EndUpdate();

                Update_ColorOrder();
                PopulateColors();
            }
        }
Beispiel #2
0
        private static bool tryGetClipboardColor(out XYZ color)
        {
            color = default;

            if (!Clipboard.ContainsText())
            {
                return(false);
            }

            var text  = Clipboard.GetText();
            var match = _hexColorPattern.Match(text);

            if (!match.Success)
            {
                return(false);
            }


            var value = match.Groups["argb"].Value;

            if (value.Length == 6)
            {
                value = "ff" + value;
            }

            int argb = int.Parse(value, NumberStyles.HexNumber);
            var rgb  = new RGB(System.Drawing.Color.FromArgb(argb));

            color = XYZ.FromRGB(rgb);
            return(true);
        }
 private void ColorPanel_Click(object sender, EventArgs e)
 {
     using (ColorPicker picker = new ColorPicker()) {
         picker.Color = XYZ.FromRGB(Color);
         if (picker.ShowDialog() == DialogResult.OK)
         {
             Color = picker.Color.ToRGB();
         }
     }
 }
 private void panelColor_Click(object sender, EventArgs e)
 {
     using (ColorPicker cp = new ColorPicker()) {
         cp.Color = XYZ.FromRGB(panelColor.BackColor);
         DialogResult result = cp.ShowDialog();
         if (result == DialogResult.OK)
         {
             panelColor.BackColor = cp.Color.ToRGB().ToArgb();
         }
     }
 }
Beispiel #5
0
 private void panelColor_Click(object sender, EventArgs e)
 {
     using (ColorPicker cp = new ColorPicker()) {
         cp.LockValue_V = true;
         cp.Color       = XYZ.FromRGB(ColorValue);
         DialogResult result = cp.ShowDialog();
         if (result == DialogResult.OK)
         {
             ColorValue = cp.Color.ToRGB().ToArgb();
         }
     }
 }
        //active color dragged
        private void lblColorSelect_ColorChanged(object sender, EventArgs e)
        {
            if (edit.Gradient == null || edit.FocusSelection)
            {
                return;
            }
            ColorPoint pt = edit.Selection as ColorPoint;

            if (pt != null)
            {
                pt.Color = XYZ.FromRGB(new RGB(lblColorSelect.Color));
            }
        }
Beispiel #7
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);
        }
Beispiel #8
0
        private void ctxOptions_Click(object sender, System.EventArgs e)
        {
            Mode newmode = _mode;

            if (sender == ctxPrevColor)
            {
                Color = XYZ.FromRGB(lblColorOut.OldColor);
                return;
            }
            else if (sender == ctxCopy)
            {
                string str = ColorLabel.ColorToHexString(lblColorOut.Color);
                try
                {
                    Clipboard.SetDataObject(str, true);
                }
                catch {}
                return;
            }
            else if (sender == ctxPaste)
            {
                if (tryGetClipboardColor(out var xyz))
                {
                    Color = xyz;
                }

                return;
            }
            //read checkbox
            else if (sender == ctxHSV_RGB)
            {
                newmode = Mode.HSV_RGB;
            }
            else if (sender == ctxHSV_LAB)
            {
                newmode = Mode.HSV_LAB;
            }
            //compare to old
            if (newmode == _mode)
            {
                return;
            }
            //update ui
            _mode = newmode;
            UpdatectxOptions();
            ChangeDescriptions();
            ChangeModule();
            UpdatetbValue(null);
        }
Beispiel #9
0
 private ColorGradient GetNewGolorGradient(ColorGradient cg)
 {
     cg = new ColorGradient(cg);
     foreach (var color in cg.Colors)
     {
         HSV hsv = HSV.FromRGB(color.Color.ToRGB());
         if (TextFade != TextFade.None)
         {
             hsv.V *= _fade;
         }
         hsv.V      *= _level;
         color.Color = XYZ.FromRGB(hsv.ToRGB());
     }
     return(cg);
 }
Beispiel #10
0
        private ColorGradient GetNewGolorGradient(List <ColorGradient> gradientColors)
        {
            ColorGradient cg = new ColorGradient(gradientColors[_countDownNumberIteration % gradientColors.Count()]);

            foreach (var color in cg.Colors)
            {
                HSV hsv = HSV.FromRGB(color.Color.ToRGB());
                if (CountDownFade != CountDownFade.None)
                {
                    hsv.V *= _fade;
                }
                hsv.V      *= _level;
                color.Color = XYZ.FromRGB(hsv.ToRGB());
            }
            return(cg);
        }
Beispiel #11
0
        private void toolStripButtonNewColor_Click(object sender, EventArgs e)
        {
            using (ColorPicker cp = new ColorPicker())
            {
                cp.LockValue_V = true;
                cp.Color       = XYZ.FromRGB(Color.White);
                DialogResult result = cp.ShowDialog();
                if (result == DialogResult.OK)
                {
                    Color ColorValue = cp.Color.ToRGB().ToArgb();

                    colors.Add(ColorValue);
                    PopulateColors();
                    Save_ColorPaletteFile();
                }
            }
        }
Beispiel #12
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));
        }
        private Color EditColor(Color color)
        {
            //var color = Convert(brush.Color);
            var newColor = color;

            using (ColorPicker cp = new ColorPicker())
            {
                cp.LockValue_V = false;
                cp.Color       = XYZ.FromRGB(color);
                DialogResult result = cp.ShowDialog();
                if (result == DialogResult.OK)
                {
                    newColor = cp.Color.ToRGB();
                }
            }

            return(newColor);
        }
Beispiel #14
0
        internal void AddNewColor()
        {
            using (ColorPicker cp = new ColorPicker())
            {
                cp.LockValue_V = false;
                cp.Color       = XYZ.FromRGB(Color.White);
                DialogResult result = cp.ShowDialog();
                if (result != DialogResult.OK)
                {
                    return;
                }
                Color colorValue = cp.Color.ToRGB().ToArgb();

                _colors.Add(colorValue);
                PopulateColors();
                Save_ColorPaletteFile();
                OnColorsChanged();
            }
        }
Beispiel #15
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();
             }
         }
     }
 }
Beispiel #16
0
 private void AddColorToCollection()
 {
     if (_currentCollection == null)
     {
         return;
     }
     using (ColorPicker cp = new ColorPicker())
     {
         cp.LockValue_V   = true;
         cp.Color         = XYZ.FromRGB(_colorValue);
         cp.StartPosition = FormStartPosition.Manual;
         cp.Top           = Top;
         cp.Left          = Left + Width;
         DialogResult result = cp.ShowDialog();
         if (result == DialogResult.OK)
         {
             _colorValue = cp.Color.ToRGB().ToArgb();
             _currentCollection.Color.Add(_colorValue);
             _isDirty = true;
             PopulateCollectionColors(_currentCollection);
         }
     }
 }
Beispiel #17
0
 private void btnAddColor_Click(object sender, EventArgs e)
 {
     if (CurrentCollection == null)
     {
         return;
     }
     using (ColorPicker cp = new ColorPicker())
     {
         cp.LockValue_V   = true;
         cp.Color         = XYZ.FromRGB(ColorValue);
         cp.StartPosition = FormStartPosition.Manual;
         cp.Top           = this.Top;
         cp.Left          = this.Left + this.Width;
         DialogResult result = cp.ShowDialog();
         if (result == DialogResult.OK)
         {
             ColorValue = cp.Color.ToRGB().ToArgb();
             CurrentCollection.Color.Add(ColorValue);
             isDirty = true;
             PopulateCollectionColors(CurrentCollection);
         }
     }
 }
Beispiel #18
0
 private void lblColorOut_ColorChanged(object sender, System.EventArgs e)
 {
     InternalColor = XYZ.FromRGB(lblColorOut.Color);
     _module.XYZ   = InternalColor;
     UpdatetbValue(null);
 }
Beispiel #19
0
 private void blueButton_Click(object sender, EventArgs e)
 {
     InternalColor     = XYZ.FromRGB(new RGB(0, 0, 255));
     lblColorOut.Color = InternalColor.ToRGB();
     UpdatetbValue(null);
 }
Beispiel #20
0
        public Form1()
        {
            InitializeComponent();
            rgb.ShowMessage    += (x, y) => label4.Visible = true;
            rgb.DisableMessage += (x, y) => label4.Visible = false;

            RGB1.ValueChanged    += (x, y) => RGBBar1.Value = (int)RGB1.Value;
            RGB2.ValueChanged    += (x, y) => RGBBar2.Value = (int)RGB2.Value;
            RGB3.ValueChanged    += (x, y) => RGBBar3.Value = (int)RGB3.Value;
            RGBBar1.ValueChanged += (x, y) => RGB1.Value = RGBBar1.Value;
            RGBBar2.ValueChanged += (x, y) => RGB2.Value = RGBBar2.Value;
            RGBBar3.ValueChanged += (x, y) => RGB3.Value = RGBBar3.Value;

            XYZ1.ValueChanged    += (x, y) => XYZBar1.Value = (int)(XYZ1.Value * 10000);
            XYZ2.ValueChanged    += (x, y) => XYZBar2.Value = (int)(XYZ2.Value * 10000);
            XYZ3.ValueChanged    += (x, y) => XYZBar3.Value = (int)(XYZ3.Value * 10000);
            XYZBar1.ValueChanged += (x, y) => XYZ1.Value = (decimal)(XYZBar1.Value / 10000d);
            XYZBar2.ValueChanged += (x, y) => XYZ2.Value = (decimal)(XYZBar2.Value / 10000d);
            XYZBar3.ValueChanged += (x, y) => XYZ3.Value = (decimal)(XYZBar3.Value / 10000d);

            CMYK1.ValueChanged    += (x, y) => CMYKBar1.Value = (int)CMYK1.Value;
            CMYK2.ValueChanged    += (x, y) => CMYKBar2.Value = (int)CMYK2.Value;
            CMYK3.ValueChanged    += (x, y) => CMYKBar3.Value = (int)CMYK3.Value;
            CMYK4.ValueChanged    += (x, y) => CMYKBar4.Value = (int)CMYK4.Value;
            CMYKBar1.ValueChanged += (x, y) => CMYK1.Value = CMYKBar1.Value;
            CMYKBar2.ValueChanged += (x, y) => CMYK2.Value = CMYKBar2.Value;
            CMYKBar3.ValueChanged += (x, y) => CMYK3.Value = CMYKBar3.Value;
            CMYKBar4.ValueChanged += (x, y) => CMYK4.Value = CMYKBar4.Value;

            RGB1.ValueChanged += (x, y) =>
            {
                rgb.R = (int)RGB1.Value;
                if (!rgbIsUpdate)
                {
                    cmyk.FromRGB(rgb);
                }
                if (!rgbIsUpdate)
                {
                    xyz.FromRGB(rgb);
                }
            };

            RGB2.ValueChanged += (x, y) =>
            {
                rgb.G = (int)RGB2.Value;
                if (!rgbIsUpdate)
                {
                    cmyk.FromRGB(rgb);
                }
                if (!rgbIsUpdate)
                {
                    xyz.FromRGB(rgb);
                }
            };

            RGB3.ValueChanged += (x, y) =>
            {
                rgb.B = (int)RGB3.Value;
                if (!rgbIsUpdate)
                {
                    cmyk.FromRGB(rgb);
                }
                if (!rgbIsUpdate)
                {
                    xyz.FromRGB(rgb);
                }
            };

            rgb.ColorIsChanced += (x, y) => button1.BackColor = Color.FromArgb(rgb.R, rgb.G, rgb.B);


            rgb.ColorMustUpdate += (x, y) => button1.BackColor = Color.FromArgb(rgb.R, rgb.G, rgb.B);
            rgb.ColorMustUpdate += (x, y) =>
            {
                rgbIsUpdate = true;

                RGB1.Value = rgb.R;
                RGB2.Value = rgb.G;
                RGB3.Value = rgb.B;

                rgbIsUpdate = false;
            };


            CMYK1.ValueChanged += (x, y) =>
            {
                cmyk.C = (double)(CMYK1.Value / 100);
                if (!cmykIsUpdate)
                {
                    rgb.FromCMYK(cmyk);
                    xyz.FromRGB(rgb);
                }
            };

            CMYK2.ValueChanged += (x, y) =>
            {
                cmyk.M = (double)(CMYK2.Value / 100);
                if (!cmykIsUpdate)
                {
                    rgb.FromCMYK(cmyk);
                    xyz.FromRGB(rgb);
                }
            };

            CMYK3.ValueChanged += (x, y) =>
            {
                cmyk.Y = (double)(CMYK3.Value / 100);
                if (!cmykIsUpdate)
                {
                    rgb.FromCMYK(cmyk);
                    xyz.FromRGB(rgb);
                }
            };
            CMYK4.ValueChanged += (x, y) =>
            {
                cmyk.K = (double)(CMYK4.Value / 100);
                if (!cmykIsUpdate)
                {
                    rgb.FromCMYK(cmyk);
                    xyz.FromRGB(rgb);
                }
            };

            cmyk.ColorMustUpdate += (x, y) =>
            {
                cmykIsUpdate = true;
                CMYK1.Value  = (decimal)Math.Ceiling(cmyk.C * 100);
                CMYK2.Value  = (decimal)Math.Ceiling(cmyk.M * 100);
                CMYK3.Value  = (decimal)Math.Ceiling(cmyk.Y * 100);
                CMYK4.Value  = (decimal)Math.Ceiling(cmyk.K * 100);
                cmykIsUpdate = false;
            };


            XYZ1.ValueChanged += (x, y) =>
            {
                xyz.X = (double)XYZ1.Value;
                if (!xyzIsUpdate)
                {
                    rgb.FromXYZ(xyz);
                    cmyk.FromRGB(rgb);
                }
            };

            XYZ2.ValueChanged += (x, y) =>
            {
                xyz.Y = (double)XYZ2.Value;
                if (!xyzIsUpdate)
                {
                    rgb.FromXYZ(xyz);
                    cmyk.FromRGB(rgb);
                }
            };

            XYZ3.ValueChanged += (x, y) =>
            {
                xyz.Z = (double)XYZ3.Value;
                if (!xyzIsUpdate)
                {
                    rgb.FromXYZ(xyz);
                    cmyk.FromRGB(rgb);
                }
            };

            xyz.ColorMustUpdate += (x, y) =>
            {
                xyzIsUpdate = true;
                try
                {
                    XYZ1.Value = (decimal)xyz.X / 100;
                    XYZ2.Value = (decimal)xyz.Y / 100;
                    XYZ3.Value = (decimal)xyz.Z / 100;
                }
                catch
                {
                }
                xyzIsUpdate = false;
            };

            colorWheel1.ColorChanged += (x, y) =>
            {
                RGB1.Value = colorWheel1.Color.R;
                RGB2.Value = colorWheel1.Color.G;
                RGB3.Value = colorWheel1.Color.B;
            };
        }
Beispiel #21
0
        private void tbValue_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (!(sender is TextBox))
            {
                return;
            }
            if (e.KeyCode == Keys.Return)
            {
                UpdatetbValue(null);
                e.Handled = true;
                return;
            }
            double value;

            if (!double.TryParse(((TextBox)sender).Text,
                                 System.Globalization.NumberStyles.Integer,
                                 null, out value))
            {
                return;
            }

            #region hsv  textboxes

            if (sender == tbHSV_H)
            {
                HSV chsv = HSV.FromRGB(InternalColor.ToRGB());
                chsv.H        = value / 360.0;
                InternalColor = XYZ.FromRGB(chsv.ToRGB());
            }
            else if (sender == tbHSV_S)
            {
                HSV chsv = HSV.FromRGB(InternalColor.ToRGB());
                chsv.S        = value / 100.0;
                InternalColor = XYZ.FromRGB(chsv.ToRGB());
            }
            else if (sender == tbHSV_V)
            {
                HSV chsv = HSV.FromRGB(InternalColor.ToRGB());
                chsv.V        = value / 100.0;
                InternalColor = XYZ.FromRGB(chsv.ToRGB());
            }
            #endregion
            #region secondary textboxes

            else if (_mode == Mode.HSV_RGB)
            {
                RGB crgb = InternalColor.ToRGB();
                if (sender == tbSecond_1)
                {
                    crgb.R = value / 255.0;
                }
                else if (sender == tbSecond_2)
                {
                    crgb.G = value / 255.0;
                }
                else                 //sender==tbSecond_3
                {
                    crgb.B = value / 255.0;
                }
                InternalColor = XYZ.FromRGB(crgb);
            }
            else if (_mode == Mode.HSV_LAB)
            {
                LAB clab = LAB.FromXYZ(InternalColor);
                if (sender == tbSecond_1)
                {
                    clab.L = value;
                }
                else if (sender == tbSecond_2)
                {
                    clab.a = value;
                }
                else                 //sender==tbSecond_3
                {
                    clab.b = value;
                }
                InternalColor = clab.ToXYZ();
            }

            #endregion

            //update ui
            _module.XYZ       = InternalColor;
            lblColorOut.Color = InternalColor.ToRGB();
            UpdatetbValue((TextBox)sender);
        }
Beispiel #22
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;
                    }
                }
            }
        }
Beispiel #23
0
        /// <summary>
        /// creates color blend out of color point data
        /// </summary>
        /// <returns></returns>
        private ColorBlend CreateColorBlend(Color?filterColor = null)
        {
            //sort all points
            ColorPoint[] colpoints   = Colors.SortedArray();
            AlphaPoint[] alphapoints = Alphas.SortedArray();
            //init out vars
            SortedList <float, Color> positions = new SortedList <float, Color>();

            // if we're filtering the colors, the iterate through the color list, setting all non-matching colors to black
            if (filterColor != null)
            {
                List <ColorPoint> newColorPoints = new List <ColorPoint>();
                foreach (ColorPoint colorPoint in colpoints)
                {
                    ColorPoint newPoint = (ColorPoint)colorPoint.Clone();
                    if (newPoint.Color.ToRGB().ToArgb() != filterColor)
                    {
                        // it's not the desired color. Make it black and add it, but only if there's
                        // not an entry in the list with this position already
                        if (newColorPoints.Where(x => x.Position == newPoint.Position).Count() == 0)
                        {
                            newPoint.Color = XYZ.FromRGB(Color.Black);
                            newColorPoints.Add(newPoint);
                        }
                    }
                    else
                    {
                        // it's the desired color. Find any others in the list that are in this position
                        // and black, remove them, and then replace it with this one
                        newColorPoints.RemoveAll(
                            x => x.Position == newPoint.Position && x.Color.ToRGB().ToArgb().ToArgb() == Color.Black.ToArgb());
                        newColorPoints.Add(newPoint);
                    }
                }
                colpoints = newColorPoints.ToArray();
            }
            //add color points
            for (int c = 0; c < colpoints.Length; c++)
            {
                // focus point; if filtered, non-standard focus points aren't supported.
                if (c > 0 && colpoints[c].Focus != .5 && filterColor == null)
                {
                    AddPosition(colpoints, alphapoints, positions,
                                colpoints[c - 1].Position + (colpoints[c].Position - colpoints[c - 1].Position) * colpoints[c].Focus);
                }
                //color
                AddPosition(colpoints, alphapoints, positions, colpoints[c].Position);
            }

            // We aren't using alpha points, and first/last points get added below

            ////add alpha points
            //for (int a = 0; a < alphapoints.Length; a++)
            //{
            //    if (a > 0 && alphapoints[a].Focus != .5)//focus
            //        AddPosition(colpoints, alphapoints, positions,
            //            alphapoints[a - 1].Position + (alphapoints[a].Position - alphapoints[a - 1].Position) * alphapoints[a].Focus);
            //    //alpha
            //    AddPosition(colpoints, alphapoints, positions, alphapoints[a].Position);
            //}

            //add first/last point
            if (positions.Count < 1)
            {
                positions.Add(0f, Color.Transparent);
            }
            if (!positions.ContainsKey(0f))
            {
                if (filterColor != null)
                {
                    float earliest = positions.Keys[0];
                    Color c        = Color.Black;
                    for (int i = 0; i < positions.Count && positions.Keys[i] == earliest; i++)
                    {
                        if (positions.Values[i].ToArgb() != Color.Black.ToArgb())
                        {
                            c = positions.Values[i];
                            break;
                        }
                    }
                    positions.Add(0f, c);
                }
                else
                {
                    positions.Add(0f, positions.Values[0]);
                }
            }

            if (positions.Count < 2)
            {
                Color c = positions.Values[0];
                if (filterColor != null && c.ToArgb() != ((Color)filterColor).ToArgb())
                {
                    c = Color.Black;
                }
                positions.Add(1f, c);
            }

            if (!positions.ContainsKey(1f))
            {
                if (filterColor != null)
                {
                    float latest = positions.Keys[positions.Count - 1];
                    Color c      = Color.Black;
                    for (int i = positions.Count - 1; i >= 0 && positions.Keys[i] == latest; i--)
                    {
                        if (positions.Values[i].ToArgb() != Color.Black.ToArgb())
                        {
                            c = positions.Values[i];
                            break;
                        }
                    }
                    positions.Add(1f, c);
                }
                else
                {
                    positions.Add(1f, positions.Values[positions.Count - 1]);
                }
            }

            ColorBlend ret = new ColorBlend();

            Color[] col = new Color[positions.Count];
            positions.Values.CopyTo(col, 0);
            ret.Colors = col;
            float[] pos = new float[positions.Count];
            positions.Keys.CopyTo(pos, 0);
            ret.Positions = pos;
            return(ret);
        }
        // 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;
                    }
                }
            }
        }
Beispiel #25
0
        private Control createColorCell(KnownColor color)
        {
            var control = new Label
            {
                AutoSize    = false,
                Size        = _cellSize,
                Margin      = _cellMargin,
                BackColor   = Color.FromKnownColor(color),
                TextAlign   = ContentAlignment.MiddleCenter,
                BorderStyle = BorderStyle.None
            };

            control.MouseEnter += (s, e) => { selectForeColor(control, hover: true); };
            control.MouseLeave += (s, e) => { selectForeColor(control, hover: false); };

            updateText();
            ColorSchemeController.SystemColorsChanging += updateText;

            void updateText()
            {
                var result = new StringBuilder();

                result.Append(color);

                if (_controller.GetOriginalColor(color) != _controller.GetColor(color))
                {
                    result.AppendLine("*");
                    result.Append("middle-click to reset");
                }

                control.Text = result.ToString();
            }

            bindForeColor(control);

            control.SetTag(color);

            control.MouseUp += (t, te) =>
            {
                switch (te.Button)
                {
                case MouseButtons.Left:
                    _colorPicker.DialogResult = DialogResult.None;
                    _colorPicker.Color        = XYZ.FromRGB(new RGB(control.BackColor));
                    _colorPicker.Text         = color.ToString();
                    _colorPicker.SetTag(color);
                    moved(null, null);

                    if (!_colorPicker.Visible)
                    {
                        _colorPicker.Show();
                    }

                    if (!_colorPicker.Focused)
                    {
                        _colorPicker.Focus();
                    }

                    break;

                case MouseButtons.Middle:
                    _controller.Reset(color);
                    saveCurrentColorScheme();
                    break;
                }
            };

            return(control);
        }
 /// <summary>
 /// ctor
 /// </summary>
 public ColorPoint(Color color, double point)
     : this(XYZ.FromRGB(new RGB(color)), .5, point)
 {
 }