Update Color.cs
This commit is contained in:
parent
93eef0f504
commit
acdc4b1b31
1 changed files with 34 additions and 0 deletions
|
|
@ -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}}}";
|
||||
|
|
|
|||
Loading…
Reference in a new issue