Пример #1
0
        /// <summary>
        /// Converts a <see cref="SplatColor"/> into the XAML <see cref="SolidColorBrush"/>.
        /// </summary>
        /// <param name="value">The color to convert.</param>
        /// <returns>The <see cref="SolidColorBrush"/> generated.</returns>
        public static SolidColorBrush ToNativeBrush(this SplatColor value)
        {
            var ret = new SolidColorBrush(value.ToNative());

            ret.Freeze();
            return(ret);
        }
Пример #2
0
        /// <summary>
        /// Converts a <see cref="NSColor"/> into the cocoa native <see cref="SplatColor"/>.
        /// </summary>
        /// <param name="value">The color to convert.</param>
        /// <returns>The <see cref="SplatColor"/> generated.</returns>
        public static SplatColor FromNative(this NSColor value)
        {
            if (value is null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            value.GetRgba(out var r, out var g, out var b, out var a);
            return(SplatColor.FromArgb((int)(a * 255.0f), (int)(r * 255.0f), (int)(g * 255.0f), (int)(b * 255.0f)));
        }
Пример #3
0
        /// <summary>
        /// Find a SplatColor which matches a <see cref="KnownColors"/>.
        /// </summary>
        /// <param name="c">The color to get the color match for.</param>
        /// <returns>A <see cref="SplatColor"/> which matched or <see cref="SplatColor.Empty"/> otherwise.</returns>
        public static SplatColor FindColorMatch(SplatColor c)
        {
            // FIXME: Linear scan
            uint argb = (uint)c.ToArgb();

            // 1-based
            const int first_real_color_index = (int)KnownColor.AliceBlue;
            const int last_real_color_index  = (int)KnownColor.YellowGreen;

            for (int i = first_real_color_index - 1; i < last_real_color_index; i++)
            {
                if (argb == KnownColors.ArgbValues[i])
                {
                    return(KnownColors.FromKnownColor((KnownColor)i));
                }
            }

            return(SplatColor.Empty);
        }
Пример #4
0
 /// <summary>
 /// Converts a <see cref="SplatColor"/> into the cocoa native <see cref="NSColor"/>.
 /// </summary>
 /// <param name="value">The color to convert.</param>
 /// <returns>The <see cref="NSColor"/> generated.</returns>
 public static NSColor ToNative(this SplatColor value)
 {
     return(NSColor.FromSrgb(value.R / 255.0f, value.G / 255.0f, value.B / 255.0f, value.A / 255.0f));
 }
Пример #5
0
 /// <summary>
 /// Converts a <see cref="SplatColor"/> into the cocoa native <see cref="UIColor"/>.
 /// </summary>
 /// <param name="value">The color to convert.</param>
 /// <returns>The <see cref="UIColor"/> generated value.</returns>
 public static UIColor ToNative(this SplatColor value)
 {
     return(new UIColor(value.R / 255.0f, value.G / 255.0f, value.B / 255.0f, value.A / 255.0f));
 }
Пример #6
0
 /// <summary>
 /// Converts a <see cref="Color"/> into the android native <see cref="SplatColor"/>.
 /// </summary>
 /// <param name="value">The color to convert.</param>
 /// <returns>The <see cref="SplatColor"/> generated.</returns>
 public static SplatColor FromNative(this Color value)
 {
     return(SplatColor.FromArgb(value.A, value.R, value.G, value.B));
 }
Пример #7
0
 /// <summary>
 /// Converts a <see cref="SplatColor"/> into the android native <see cref="Color"/>.
 /// </summary>
 /// <param name="value">The color to convert.</param>
 /// <returns>The <see cref="Color"/> generated.</returns>
 public static Color ToNative(this SplatColor value)
 {
     return(new Color(value.R, value.G, value.B, value.A));
 }
Пример #8
0
 /// <summary>
 /// Converts a <see cref="SplatColor"/> into the XAML <see cref="Color"/>.
 /// </summary>
 /// <param name="value">The color to convert.</param>
 /// <returns>The <see cref="Color"/> generated.</returns>
 public static Color ToNative(this SplatColor value)
 {
     return(Color.FromArgb(value.A, value.R, value.G, value.B));
 }
Пример #9
0
 /// <summary>
 /// Gets a SplatColor from a <see cref="KnownColor"/>.
 /// </summary>
 /// <param name="kc">The value to get the color for.</param>
 /// <returns>A <see cref="SplatColor"/> representing the value.</returns>
 public static SplatColor FromKnownColor(KnownColor kc)
 {
     return(SplatColor.FromKnownColor(kc));
 }
Пример #10
0
 /// <summary>
 /// Converts a <see cref="NSColor"/> into the cocoa native <see cref="SplatColor"/>.
 /// </summary>
 /// <param name="value">The color to convert.</param>
 /// <returns>The <see cref="SplatColor"/> generated.</returns>
 public static SplatColor FromNative(this NSColor value)
 {
     value.GetRgba(out var r, out var g, out var b, out var a);
     return(SplatColor.FromArgb((int)(a * 255.0f), (int)(r * 255.0f), (int)(g * 255.0f), (int)(b * 255.0f)));
 }