#nullable enable using System.Diagnostics.Contracts; using System.Numerics; namespace Terminal.Gui; public readonly partial record struct Color { /// /// /// A with all values set to , meaning /// white. /// public static Color MaxValue => new (uint.MaxValue); /// /// A with all values set to zero. /// /// Though this returns a with , , , and /// all set to zero, Terminal.Gui will treat it as black, because the alpha channel is not supported. /// public static Color MinValue => new (uint.MinValue); /// [Pure] public override int GetHashCode () { return Rgba.GetHashCode (); } /// /// Implicit conversion from to via /// where ( , , /// ) is (R,G,B). /// /// /// This cast is narrowing and drops the alpha channel. /// /// Use to maintain full value. /// [Pure] public static explicit operator Vector3 (Color color) { return new Vector3 (color.R, color.G, color.B); } /// /// Implicit conversion from to , via the /// costructor. /// [Pure] public static implicit operator Color (int rgba) { return new Color (rgba); } /// /// Implicit conversion from to , via the /// costructor. /// [Pure] public static implicit operator Color (uint u) { return new Color (u); } /// /// Implicit conversion from to via lookup from /// . /// [Pure] public static implicit operator Color (ColorName colorName) { return ColorExtensions.ColorNameToColorMap [colorName]; } /// /// Implicit conversion from to , where (, /// , , ) is (,, /// ,), via . /// [Pure] public static implicit operator Color (Vector4 v) { return new Color ((byte)v.X, (byte)v.Y, (byte)v.Z, (byte)v.W); } /// /// Implicit conversion from , where = , /// = , and = . /// [Pure] public static implicit operator Color (Vector3 v) { return new Color ((byte)v.X, (byte)v.Y, (byte)v.Z); } /// /// Implicit conversion from to by returning the value of the /// field. /// [Pure] public static implicit operator int (Color color) { return color.Rgba; } /// /// Implicit conversion from to by returning the value of the /// field. /// [Pure] public static implicit operator uint (Color color) { return color.Argb; } /// /// Implicit conversion to , where = , /// = , and = . /// [Pure] public static implicit operator Vector4 (Color color) { return new Vector4 (color.R, color.G, color.B, color.A); } }