/// <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); }
/// <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))); }
/// <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); }
/// <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)); }
/// <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)); }
/// <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)); }
/// <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)); }
/// <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)); }
/// <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)); }
/// <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))); }