// ----------------------------------------------------------------------- // // Copyright 2014 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- namespace Perspex.Media { /// /// An ARGB color. /// public struct Color { /// /// Gets or sets the Alpha component of the color. /// public byte A { get; set; } /// /// Gets or sets the Red component of the color. /// public byte R { get; set; } /// /// Gets or sets the Green component of the color. /// public byte G { get; set; } /// /// Gets or sets the Blue component of the color. /// public byte B { get; set; } /// /// Creates a from alpha, red, green and blue components. /// /// The alpha component. /// The red component. /// The green component. /// The blue component. /// The color. public static Color FromArgb(byte a, byte r, byte g, byte b) { return new Color { A = a, R = r, G = g, B = b, }; } /// /// Creates a from red, green and blue components. /// /// The red component. /// The green component. /// The blue component. /// The color. public static Color FromRgb(byte r, byte g, byte b) { return new Color { A = 0xff, R = r, G = g, B = b, }; } /// /// Creates a from an integer. /// /// The integer value. /// The color. public static Color FromUInt32(uint value) { return new Color { A = (byte)((value >> 24) & 0xff), R = (byte)((value >> 16) & 0xff), G = (byte)((value >> 8) & 0xff), B = (byte)(value & 0xff), }; } /// /// Returns the string representation of the color. /// /// /// The string representation of the color. /// public override string ToString() { uint rgb = ((uint)this.A << 24) | ((uint)this.R << 16) | ((uint)this.G << 8) | (uint)this.B; return string.Format("#{0:x8}", rgb); } /// /// Returns the integer representation of the color. /// /// /// The integer representation of the color. /// public uint ToUint32() { return ((uint)this.A << 24) | ((uint)this.R << 16) | ((uint)this.G << 8) | (uint)this.B; } } }