Example #1
0
        private void OnColorSliderValueChanged(object sender, EventArgs e)
        {
            if (IgnoreChangedEvents)
            {
                return;
            }

            PushIgnoreChangedEvents();

            if (sender == redColorSlider ||
                sender == greenColorSlider ||
                sender == blueColorSlider)
            {
                var color = ColorBgra.FromBgra(
                    blueColorSlider.Value.ClampToByte(),
                    greenColorSlider.Value.ClampToByte(),
                    redColorSlider.Value.ClampToByte(),
                    alphaColorSlider.Value.ClampToByte());

                SetColorGradientMinMaxColorsRgb(color.R, color.G, color.B);
                SetColorGradientMinMaxColorsAlpha(color.A);
                SetColorGradientValuesRgb(color.R, color.G, color.B);
                SetColorGradientMinMaxColorsAlpha(color.A);

                SyncHsvFromRgb(color);
                //OnUserColorChanged(rgbColor);
            }
            else if (
                sender == hueColorSlider ||
                sender == saturationColorSlider ||
                sender == valueColorSlider)
            {
                var oldHsv = colorWheel1.Color;
                var hsv    = new ColorHsv(
                    hueColorSlider.Value,
                    saturationColorSlider.Value,
                    valueColorSlider.Value);

                if (oldHsv != hsv)
                {
                    colorWheel1.Color = hsv;

                    SetColorGradientValuesHsv(
                        hsv.Hue,
                        hsv.Saturation,
                        hsv.Value);

                    SetColorGradientMinMaxColorsHsv(
                        hsv.Hue,
                        hsv.Saturation,
                        hsv.Value);

                    SyncRgbFromHsv(hsv);
                    //ColorRGB rgbColor = hsv.ToRgb();
                    //OnUserColorChanged(ColorBgra.FromBgra((byte)rgbColor.Blue, (byte)rgbColor.Green, (byte)rgbColor.Red, (byte)alphaUpDown.Value));
                }
            }

            PopIgnoreChangedEvents();
        }
Example #2
0
        private void GrabColor(Point point)
        {
            // center our coordinate system so the middle is (0,0), and positive Y is facing up
            var cx = point.X - (Width / 2);
            var cy = point.Y - (Height / 2);

            var theta = Math.Atan2(cy, cx);

            if (theta < 0)
            {
                theta += 2 * Math.PI;
            }

            var alpha = Math.Sqrt((cx * cx) + (cy * cy));

            var h = (int)((theta / (Math.PI * 2)) * 360.0);
            // ReSharper disable PossibleLossOfFraction
            var s = (int)Math.Min(100.0, (alpha / (Width / 2)) * 100);
            // ReSharper restore PossibleLossOfFraction
            const int v = 100;

            _Color = new ColorHsv(h, s, v);
            OnColorChanged();
            Invalidate(true);
        }
Example #3
0
        private void SetColorGradientMinMaxColorsHsv(int h, int s, int v)
        {
            var hueColors = new Color[361];

            for (var newH = 0; newH <= 360; ++newH)
            {
                var hsv = new ColorHsv(newH, 100, 100);
                hueColors[newH] = hsv.ToColor();
            }

            hueColorSlider.CustomGradient = hueColors;

            var satColors = new Color[101];

            for (var newS = 0; newS <= 100; ++newS)
            {
                var hsv = new ColorHsv(h, newS, v);
                satColors[newS] = hsv.ToColor();
            }

            saturationColorSlider.CustomGradient = satColors;

            valueColorSlider.MaxColor = new ColorHsv(h, s, 100).ToColor();
            valueColorSlider.MinColor = new ColorHsv(h, s, 0).ToColor();
        }
Example #4
0
        private void SyncHsvFromRgb(ColorBgra bgra)
        {
            var hsv = ColorHsv.FromColor(bgra.ToColor());

            SetColorGradientValuesHsv(hsv.Hue, hsv.Saturation, hsv.Value);
            SetColorGradientMinMaxColorsHsv(hsv.Hue, hsv.Saturation, hsv.Value);

            colorWheel1.Color = hsv;
        }
Example #5
0
        private Color[] GetColors()
        {
            var colors = new Color[ColorTesselation];

            for (var i = 0; i < ColorTesselation; i++)
            {
                var hue = (i * 360) / ColorTesselation;
                colors[i] = new ColorHsv(hue, 100, 100).ToColor();
            }

            return(colors);
        }
Example #6
0
        private void SyncRgbFromHsv(ColorHsv hsv)
        {
            var rgb = hsv.ToRgb();

            redColorSlider.Value   = rgb.R;
            greenColorSlider.Value = rgb.G;
            blueColorSlider.Value  = rgb.B;

            SetColorGradientValuesRgb(rgb.R, rgb.G, rgb.B);
            SetColorGradientMinMaxColorsRgb(rgb.R, rgb.G, rgb.B);
            SetColorGradientMinMaxColorsAlpha(alphaColorSlider.Value);
        }
Example #7
0
 public ColorWheel()
 {
     InitializeComponent();
     _Color = new ColorHsv(0, 0, 0);
 }
Example #8
0
 public static ColorRgb FromHsv(ColorHsv hsv)
 {
     return(hsv.ToRgb());
 }
Example #9
0
 public ColorDialog()
 {
     InitializeComponent();
     colorWheel1.Color = ColorHsv.FromColor(Color.White);
 }