/// <summary>
        /// Gets formatted string representing the current color value.
        /// </summary>
        /// <param name="format">The color string format to use.</param>
        /// <returns>The formatted string representing the current color value.</returns>
        public string ToString(ColorStringFormat format)
        {
            float r, g, b;

            switch (format)
            {
            case ColorStringFormat.HSLAHexOpt:
                return(HsbColor32.ToHexidecimalString(_hue, _saturation, _brightness, _alpha, true));

            case ColorStringFormat.HSLAPercent:
                return(HsbColorF.ToPercentParameterString(_hue.ToDegrees(), _saturation.ToPercentage(), _brightness.ToPercentage(), _alpha.ToPercentage()));

            case ColorStringFormat.HSLAValues:
                return(HsbColor32.ToValueParameterString(_hue, _saturation, _brightness, _alpha));

            case ColorStringFormat.HSLHex:
                return(HsbColor32.ToHexidecimalString(_hue, _saturation, _brightness, false));

            case ColorStringFormat.HSLHexOpt:
                return(HsbColor32.ToHexidecimalString(_hue, _saturation, _brightness, true));

            case ColorStringFormat.HSLPercent:
                return(HsbColorF.ToPercentParameterString(_hue.ToDegrees(), _saturation.ToPercentage(), _brightness.ToPercentage()));

            case ColorStringFormat.HSLValues:
                return(HsbColor32.ToValueParameterString(_hue, _saturation, _brightness));

            case ColorStringFormat.RGBAHex:
                ColorExtensions.HSBtoRGB(_hue.ToDegrees(), _saturation.ToPercentage(), _brightness.ToPercentage(), out r, out g, out b);
                return(RgbColor32.ToHexidecimalString(r.FromPercentage(), g.FromPercentage(), b.FromPercentage(), _alpha, false));

            case ColorStringFormat.RGBAHexOpt:
                ColorExtensions.HSBtoRGB(_hue.ToDegrees(), _saturation.ToPercentage(), _brightness.ToPercentage(), out r, out g, out b);
                return(RgbColor32.ToHexidecimalString(r.FromPercentage(), g.FromPercentage(), b.FromPercentage(), _alpha, true));

            case ColorStringFormat.RGBAPercent:
                ColorExtensions.HSBtoRGB(_hue.ToDegrees(), _saturation.ToPercentage(), _brightness.ToPercentage(), out r, out g, out b);
                return(RgbColorF.ToPercentParameterString(r, g, b, _alpha.ToPercentage()));

            case ColorStringFormat.RGBAValues:
                ColorExtensions.HSBtoRGB(_hue.ToDegrees(), _saturation.ToPercentage(), _brightness.ToPercentage(), out r, out g, out b);
                return(RgbColor32.ToValueParameterString(r.FromPercentage(), g.FromPercentage(), b.FromPercentage(), _alpha));

            case ColorStringFormat.RGBHex:
                ColorExtensions.HSBtoRGB(_hue.ToDegrees(), _saturation.ToPercentage(), _brightness.ToPercentage(), out r, out g, out b);
                return(RgbColor32.ToHexidecimalString(r.FromPercentage(), g.FromPercentage(), b.FromPercentage(), false));

            case ColorStringFormat.RGBHexOpt:
                ColorExtensions.HSBtoRGB(_hue.ToDegrees(), _saturation.ToPercentage(), _brightness.ToPercentage(), out r, out g, out b);
                return(RgbColor32.ToHexidecimalString(r.FromPercentage(), g.FromPercentage(), b.FromPercentage(), true));

            case ColorStringFormat.RGBPercent:
                ColorExtensions.HSBtoRGB(_hue.ToDegrees(), _saturation.ToPercentage(), _brightness.ToPercentage(), out r, out g, out b);
                return(RgbColorF.ToPercentParameterString(r, g, b));

            case ColorStringFormat.RGBValues:
                ColorExtensions.HSBtoRGB(_hue.ToDegrees(), _saturation.ToPercentage(), _brightness.ToPercentage(), out r, out g, out b);
                return(RgbColor32.ToValueParameterString(r.FromPercentage(), g.FromPercentage(), b.FromPercentage()));
            }
            return(_value.ToString("X8"));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets formatted string representing the current color value.
        /// </summary>
        /// <param name="format">The color string format to use.</param>
        /// <returns>The formatted string representing the current color value.</returns>
        public string ToString(ColorStringFormat format)
        {
            float h, s, b;

            switch (format)
            {
            case ColorStringFormat.HSLAHex:
                ColorExtensions.RGBtoHSB(_red, _green, _blue, out h, out s, out b);
                return(HsbColor32.ToHexidecimalString(h.FromDegrees(), s.FromPercentage(), b.FromPercentage(), _alpha.FromPercentage(), false));

            case ColorStringFormat.HSLAHexOpt:
                ColorExtensions.RGBtoHSB(_red, _green, _blue, out h, out s, out b);
                return(HsbColor32.ToHexidecimalString(h.FromDegrees(), s.FromPercentage(), b.FromPercentage(), _alpha.FromPercentage(), true));

            case ColorStringFormat.HSLAPercent:
                ColorExtensions.RGBtoHSB(_red, _green, _blue, out h, out s, out b);
                return(HsbColorF.ToPercentParameterString(h, s, b, _alpha));

            case ColorStringFormat.HSLAValues:
                ColorExtensions.RGBtoHSB(_red, _green, _blue, out h, out s, out b);
                return(HsbColor32.ToValueParameterString(h.FromDegrees(), s.FromPercentage(), b.FromPercentage(), _alpha));

            case ColorStringFormat.HSLHex:
                ColorExtensions.RGBtoHSB(_red, _green, _blue, out h, out s, out b);
                return(HsbColor32.ToHexidecimalString(h.FromDegrees(), s.FromPercentage(), b.FromPercentage(), false));

            case ColorStringFormat.HSLHexOpt:
                ColorExtensions.RGBtoHSB(_red, _green, _blue, out h, out s, out b);
                return(HsbColor32.ToHexidecimalString(h.FromDegrees(), s.FromPercentage(), b.FromPercentage(), true));

            case ColorStringFormat.HSLPercent:
                ColorExtensions.RGBtoHSB(_red, _green, _blue, out h, out s, out b);
                return(HsbColorF.ToPercentParameterString(h, s, b));

            case ColorStringFormat.HSLValues:
                ColorExtensions.RGBtoHSB(_red, _green, _blue, out h, out s, out b);
                return(HsbColor32.ToValueParameterString(h.FromDegrees(), s.FromPercentage(), b.FromPercentage()));

            case ColorStringFormat.RGBAHex:
                return(RgbColor32.ToHexidecimalString(_red.FromPercentage(), _green.FromPercentage(), _blue.FromPercentage(), _alpha.FromPercentage(), false));

            case ColorStringFormat.RGBAHexOpt:
                return(RgbColor32.ToHexidecimalString(_red.FromPercentage(), _green.FromPercentage(), _blue.FromPercentage(), _alpha.FromPercentage(), true));

            case ColorStringFormat.RGBAValues:
                return(RgbColor32.ToValueParameterString(_red.FromPercentage(), _green.FromPercentage(), _blue.FromPercentage(), _alpha.FromPercentage()));

            case ColorStringFormat.RGBHex:
                return(RgbColor32.ToHexidecimalString(_red.FromPercentage(), _green.FromPercentage(), _blue.FromPercentage(), false));

            case ColorStringFormat.RGBHexOpt:
                return(RgbColor32.ToHexidecimalString(_red.FromPercentage(), _green.FromPercentage(), _blue.FromPercentage(), true));

            case ColorStringFormat.RGBPercent:
                return(ToPercentParameterString(_red, _green, _blue));

            case ColorStringFormat.RGBValues:
                return(RgbColor32.ToValueParameterString(_red.FromPercentage(), _green.FromPercentage(), _blue.FromPercentage()));
            }
            return(ToPercentParameterString(_red, _green, _blue, _alpha));
        }