110 lines
3.4 KiB
C#
110 lines
3.4 KiB
C#
namespace Voile
|
|
{
|
|
// Based on https://github.com/ppr-game/PPR/blob/engine/PER.Util/src/Color.cs
|
|
/// <summary>
|
|
/// A record struct representing a color.
|
|
/// </summary>
|
|
public record struct Color
|
|
{
|
|
// TODO: add more HTML colors.
|
|
public static Color AliceBlue = new(0xF0F8FF);
|
|
public static Color AntiqueWhite = new(0xFAEBD7);
|
|
public static Color Aqua = new(0x00FFFF);
|
|
public static Color Aquamarine = new(0x7FFFD4);
|
|
public static Color Azure = new(0xF0FFFF);
|
|
public static Color Beige = new(0xF5F5DC);
|
|
public static Color Bisque = new(0xFFE4C4);
|
|
public static Color Black = new(0x000000);
|
|
public static Color BlanchedAlmond = new(0xFFEBCD);
|
|
public static Color Blue = new(0x0000FF);
|
|
public static Color BlueViolet = new(0x8A2BE2);
|
|
public static Color Brown = new(0xA52A2A);
|
|
public static Color BurlyWood = new(0xDEB887);
|
|
public static Color CadetBlue = new(0x5F9EA0);
|
|
public static Color Chartreuse = new(0x7FFF00);
|
|
public static Color Chocolate = new(0xD2691E);
|
|
public static Color Coral = new(0xFF7F50);
|
|
public static Color CornflowerBlue = new(0x6495ED);
|
|
public static Color Cornsilk = new(0xFFF8DC);
|
|
public static Color Crimson = new(0xDC143C);
|
|
public static Color Cyan = new(0x00FFFF);
|
|
public static Color DarkBlue = new(0x00008B);
|
|
public static Color DarkCyan = new(0x008B8B);
|
|
public static Color White = new(0xFFFFFF);
|
|
public static Color Green = new(0x00FF00);
|
|
public static Color Red = new(0xFF0000);
|
|
|
|
public float R { get; set; }
|
|
public float G { get; set; }
|
|
public float B { get; set; }
|
|
public float A { get; set; }
|
|
|
|
public int Argb
|
|
{
|
|
get
|
|
{
|
|
int c = (ushort)Math.Round(A * 255f);
|
|
c <<= 8;
|
|
c |= (ushort)Math.Round(R * 255f);
|
|
c <<= 8;
|
|
c |= (ushort)Math.Round(G * 255f);
|
|
c <<= 8;
|
|
c |= (ushort)Math.Round(B * 255f);
|
|
|
|
return c;
|
|
}
|
|
}
|
|
|
|
public Color(float r, float g, float b, float a)
|
|
{
|
|
R = r;
|
|
G = g;
|
|
B = b;
|
|
A = a;
|
|
}
|
|
|
|
public Color(byte r, byte g, byte b, byte a)
|
|
{
|
|
R = r / 255f;
|
|
G = g / 255f;
|
|
B = b / 255f;
|
|
A = a / 255f;
|
|
}
|
|
|
|
public Color(int hex)
|
|
{
|
|
A = 1.0f;
|
|
B = (hex & 0xFF) / 255.0f;
|
|
hex >>= 8;
|
|
G = (hex & 0xFF) / 255.0f;
|
|
hex >>= 8;
|
|
R = (hex & 0xFF) / 255.0f;
|
|
}
|
|
|
|
public Color Lightened(float amount)
|
|
{
|
|
var result = this;
|
|
result.R = result.R + (1.0f - result.R) * amount;
|
|
result.G = result.G + (1.0f - result.G) * amount;
|
|
result.B = result.B + (1.0f - result.B) * amount;
|
|
|
|
return result;
|
|
}
|
|
|
|
public Color Darkened(float amount)
|
|
{
|
|
var result = this;
|
|
result.R = result.R * (1.0f - amount);
|
|
result.G = result.G * (1.0f - amount);
|
|
result.B = result.B * (1.0f - amount);
|
|
|
|
return result;
|
|
}
|
|
|
|
public System.Drawing.Color ToSystemColor()
|
|
{
|
|
var result = System.Drawing.Color.FromArgb(Argb);
|
|
return result;
|
|
}
|
|
}
|
|
} |