Exemplo n.º 1
0
        private void CopyHSL(object sender, RoutedEventArgs e)
        {
            Color color = GetColor(sender);

            RGBandHSL.RgbToHls((int)color.R, (int)color.G, (int)color.B, out double h, out double l, out double s);
            Clipboard.SetText("hsl (" + Math.Round(h).ToString() + ", " + "%" + (Convert.ToInt32(s * 100)).ToString() + ", " + "%" + (Convert.ToInt32(l * 100)).ToString() + ")");
        }
Exemplo n.º 2
0
 private void HSLChangeSlider(Color color)
 {
     RGBandHSL.RgbToHls(color.R, color.G, color.B, out double h, out double l, out double s);
     hueSlider.Value        = h;
     saturationSlider.Value = s;
     lightnesSlider.Value   = l;
 }
Exemplo n.º 3
0
 private void HSLChangeText(Color color)
 {
     RGBandHSL.RgbToHls(color.R, color.G, color.B, out double h, out double l, out double s);
     hueTextBox.Text        = (h * 100).ToString();
     saturationTextBox.Text = (s * 100).ToString();
     lightnessTextBox.Text  = (l * 100).ToString();
 }
Exemplo n.º 4
0
        // If the hsl slider's change update the color controls and top rectangle respectively.
        private void HSL_Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            Color  color = new Color();
            int    h     = (int)hueSlider.Value;
            double s     = (double)saturationSlider.Value;
            double l     = lightnesSlider.Value;
            // Get the alpha slider value for compatability with Color.FromArgb
            int a = (int)alphaSlider.Value;

            if (hueSlider.IsFocused == true || saturationSlider.IsFocused == true || lightnesSlider.IsFocused == true)
            {
                RGBandHSL.HlsToRgb((double)h, l, s, out int r, out int g, out int b);

                color.R = (byte)r;
                color.G = (byte)g;
                color.B = (byte)b;
                color.A = (byte)a;

                RectangleChangeControl(color);
            }

            // get the rightmost saturation slider gradientstop
            s = 1;
            RGBandHSL.HlsToRgb((double)h, l, s, out int rb, out int gb, out int bb);
            color = Color.FromArgb((byte)a, (byte)rb, (byte)gb, (byte)bb);
            SaturationRectangleGradientstop.GradientStops[1].Color = color;

            // get the leftmost saturation slider gradientstop
            s = 0;
            RGBandHSL.HlsToRgb((double)h, l, s, out int rc, out int gc, out int bc);
            color = Color.FromArgb((byte)a, (byte)rc, (byte)gc, (byte)bc);
            SaturationRectangleGradientstop.GradientStops[0].Color = color;

            // get the middle lightness slider gradientstop, the first and last stop are black and white.
            // the middle gradient should be the values of saturation and hue, where lightness is held at .5.
            s = (double)saturationSlider.Value;
            l = .5;
            RGBandHSL.HlsToRgb((double)h, l, s, out int rd, out int gd, out int bd);
            color = Color.FromArgb((byte)a, (byte)rd, (byte)gd, (byte)bd);
            LightnessRectangleGradientstop.GradientStops[2].Color = color;
        }