Watch
2
0
Fork
You've already forked raylib-cs
0

Update Color.cs

This commit is contained in:
nickyMcDonald 2024-07-23 19:17:40 -04:00
commit acdc4b1b31

View file

@ -51,6 +51,14 @@ public partial struct Color
this.A = a;
}
public Color(byte r, byte g, byte b)
{
this.R = r;
this.G = g;
this.B = b;
this.A = 255;
}
public Color(int r, int g, int b, int a)
{
this.R = Convert.ToByte(r);
@ -59,6 +67,32 @@ public partial struct Color
this.A = Convert.ToByte(a);
}
public Color(int r, int g, int b)
{
this.R = Convert.ToByte(r);
this.G = Convert.ToByte(g);
this.B = Convert.ToByte(b);
this.A = 255;
}
public Color(float r, float g, float b, float a)
{
// X = (byte)Math.Clamp(MathF.Round(r * 255), 0f, 255f);
this.R = (byte)((r < 0) ? 0 : ((r > 1) ? 255 : ((r * 255) + .5f)));
this.G = (byte)((g < 0) ? 0 : ((g > 1) ? 255 : ((g * 255) + .5f)));
this.B = (byte)((b < 0) ? 0 : ((b > 1) ? 255 : ((b * 255) + .5f)));
this.A = (byte)((a < 0) ? 0 : ((a > 1) ? 255 : ((a * 255) + .5f)));
}
public Color(float r, float g, float b)
{
// X = (byte)Math.Clamp(MathF.Round(r * 255), 0f, 255f);
this.R = (byte)((r < 0) ? 0 : ((r > 1) ? 255 : ((r * 255) + .5f)));
this.G = (byte)((g < 0) ? 0 : ((g > 1) ? 255 : ((g * 255) + .5f)));
this.B = (byte)((b < 0) ? 0 : ((b > 1) ? 255 : ((b * 255) + .5f)));
this.A = 255;
}
public override string ToString()
{
return $"{{R:{R} G:{G} B:{B} A:{A}}}";