using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using UnityEngine;
namespace X10D.Unity.Drawing;
///
/// Drawing-related extensions for .
///
public static class Color32Extensions
{
///
/// Returns a new with the red, green, and blue components inverted. Alpha is not affected.
///
/// The color to invert.
/// The inverted color.
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Color32 Inverted(this Color32 color)
{
return new Color32((byte)(255 - color.r), (byte)(255 - color.g), (byte)(255 - color.b), color.a);
}
///
/// Returns a vector whose red, green, and blue components are the same as the specified color, and whose alpha component
/// is a new value.
///
/// The color to copy.
/// The new alpha component value.
///
/// A new instance of whose , , and
/// components are the same as that of , and whose
/// component is .
///
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Color32 WithA(this Color32 color, byte a)
{
return color with {a = a};
}
///
/// Returns a vector whose red, green, and alpha components are the same as the specified color, and whose blue component
/// is a new value.
///
/// The color to copy.
/// The new blue component value.
///
/// A new instance of whose , , and
/// components are the same as that of , and whose
/// component is .
///
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Color32 WithB(this Color32 color, byte b)
{
return color with {b = b};
}
///
/// Returns a vector whose red, blue, and alpha components are the same as the specified color, and whose green component
/// is a new value.
///
/// The color to copy.
/// The new green component value.
///
/// A new instance of whose , , and
/// components are the same as that of , and whose
/// component is .
///
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Color32 WithG(this Color32 color, byte g)
{
return color with {g = g};
}
///
/// Returns a vector whose green, blue, and alpha components are the same as the specified color, and whose red component
/// is a new value.
///
/// The color to copy.
/// The new red component value.
///
/// A new instance of whose , , and
/// components are the same as that of , and whose
/// component is .
///
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Color32 WithR(this Color32 color, byte r)
{
return color with {r = r};
}
}