Merge pull request #310 from swharden/color-overloads
Color: add overloads so `int` does not get clamped like a `float`
This commit is contained in:
Коммит
9ded78a287
|
@ -19,7 +19,7 @@ namespace Microsoft.Maui.Graphics
|
|||
public Color()
|
||||
{
|
||||
// Default Black
|
||||
Red = Green = Blue = 0;
|
||||
Red = Green = Blue = 0;
|
||||
}
|
||||
|
||||
public Color(float gray)
|
||||
|
@ -42,6 +42,38 @@ namespace Microsoft.Maui.Graphics
|
|||
Alpha = alpha.Clamp(0, 1);
|
||||
}
|
||||
|
||||
public Color(byte red, byte green, byte blue)
|
||||
{
|
||||
Red = (red / 255f).Clamp(0, 1);
|
||||
Green = (green / 255f).Clamp(0, 1);
|
||||
Blue = (blue / 255f).Clamp(0, 1);
|
||||
Alpha = 1.0f;
|
||||
}
|
||||
|
||||
public Color(byte red, byte green, byte blue, byte alpha)
|
||||
{
|
||||
Red = (red / 255f).Clamp(0, 1);
|
||||
Green = (green / 255f).Clamp(0, 1);
|
||||
Blue = (blue / 255f).Clamp(0, 1);
|
||||
Alpha = (alpha / 255f).Clamp(0, 1);
|
||||
}
|
||||
|
||||
public Color(int red, int green, int blue)
|
||||
{
|
||||
Red = (red / 255f).Clamp(0, 1);
|
||||
Green = (green / 255f).Clamp(0, 1);
|
||||
Blue = (blue / 255f).Clamp(0, 1);
|
||||
Alpha = 1.0f;
|
||||
}
|
||||
|
||||
public Color(int red, int green, int blue, int alpha)
|
||||
{
|
||||
Red = (red / 255f).Clamp(0, 1);
|
||||
Green = (green / 255f).Clamp(0, 1);
|
||||
Blue = (blue / 255f).Clamp(0, 1);
|
||||
Alpha = (alpha / 255f).Clamp(0, 1);
|
||||
}
|
||||
|
||||
public Color(Vector4 color)
|
||||
{
|
||||
Red = color.X.Clamp(0, 1);
|
||||
|
@ -267,7 +299,7 @@ namespace Microsoft.Maui.Graphics
|
|||
|
||||
public static Color FromRgb(byte red, byte green, byte blue)
|
||||
{
|
||||
return Color.FromRgba(red, green, blue, 255);
|
||||
return new Color(red / 255f, green / 255f, blue / 255f, 1f);
|
||||
}
|
||||
|
||||
public static Color FromRgba(byte red, byte green, byte blue, byte alpha)
|
||||
|
@ -275,6 +307,16 @@ namespace Microsoft.Maui.Graphics
|
|||
return new Color(red / 255f, green / 255f, blue / 255f, alpha / 255f);
|
||||
}
|
||||
|
||||
public static Color FromRgb(int red, int green, int blue)
|
||||
{
|
||||
return new Color(red / 255f, green / 255f, blue / 255f, 1f);
|
||||
}
|
||||
|
||||
public static Color FromRgba(int red, int green, int blue, int alpha)
|
||||
{
|
||||
return new Color(red / 255f, green / 255f, blue / 255f, alpha / 255f);
|
||||
}
|
||||
|
||||
public static Color FromRgb(float red, float green, float blue)
|
||||
{
|
||||
return Color.FromRgba(red, green, blue, 1);
|
||||
|
|
Загрузка…
Ссылка в новой задаче