Class MudColor
Represents a color with methods to manipulate color values.
public class MudColor : ISerializable, IEquatable<MudColor>
- Inheritance
-
MudColor
- Implements
- Inherited Members
- Extension Methods
Constructors
MudColor()
Constructs a default instance of MudColor with default values (black with full opacity).
public MudColor()
MudColor(byte, byte, byte, MudColor)
Initializes a new instance of the MudColor class with the specified red, green, blue, and alpha values, copying the hue value from the provided color.
public MudColor(byte r, byte g, byte b, MudColor color)
Parameters
r
byteThe red component value (0 to 255).
g
byteThe green component value (0 to 255).
b
byteThe blue component value (0 to 255).
color
MudColorThe existing color to copy the hue value from.
MudColor(byte, byte, byte, byte)
Initializes a new instance of the MudColor class with the specified red, green, blue, and alpha values.
[JsonConstructor]
public MudColor(byte r, byte g, byte b, byte a)
Parameters
r
byteThe red component value (0 to 255).
g
byteThe green component value (0 to 255).
b
byteThe blue component value (0 to 255).
a
byteThe alpha component value (0 to 255).
MudColor(double, double, double, double)
Initializes a new instance of the MudColor class with the specified hue, saturation, lightness, and alpha values.
public MudColor(double h, double s, double l, double a)
Parameters
h
doubleThe hue component value (0 to 360).
s
doubleThe saturation component value (0.0 to 1.0).
l
doubleThe lightness component value (0.0 to 1.0).
a
doubleThe alpha component value (0 to 1.0).
MudColor(double, double, double, int)
Initializes a new instance of the MudColor class with the specified hue, saturation, lightness, and alpha values.
public MudColor(double h, double s, double l, int a)
Parameters
h
doubleThe hue component value (0 to 360).
s
doubleThe saturation component value (0.0 to 1.0).
l
doubleThe lightness component value (0.0 to 1.0).
a
intThe alpha component value (0 to 255).
MudColor(int, int, int, double)
Initializes a new instance of the MudColor class with the specified RGB values and alpha component.
public MudColor(int r, int g, int b, double alpha)
Parameters
r
intThe red component value (0 to 255).
g
intThe green component value (0 to 255).
b
intThe blue component value (0 to 255).
alpha
doubleThe alpha component value (0.0 to 1.0).
MudColor(int, int, int, int)
Initializes a new instance of the MudColor class with the specified RGB values and alpha component.
public MudColor(int r, int g, int b, int alpha)
Parameters
r
intThe red component value (0 to 255).
g
intThe green component value (0 to 255).
b
intThe blue component value (0 to 255).
alpha
intThe alpha component value (0 to 255).
MudColor(SerializationInfo, StreamingContext)
Deserialization constructor for MudColor.
protected MudColor(SerializationInfo info, StreamingContext context)
Parameters
info
SerializationInfoThe SerializationInfo> containing the serialized data.
context
StreamingContextThe StreamingContext>.
MudColor(string)
Initializes a new instance of the MudColor class with the specified string representation of a color.
public MudColor(string value)
Parameters
value
stringThe string representation of a color.
Remarks
The color can be represented in various formats, including hexadecimal (with or without alpha), RGB, and RGBA. Examples of valid color strings:
- Hexadecimal format: "#ab2a3d", "#ab2a3dff"
- RGB format: "rgb(12,15,40)"
- RGBA format: "rgba(12,15,40,0.42)"
MudColor(uint)
Initializes a new instance of the MudColor class with the specified color.
public MudColor(uint rgba)
Parameters
rgba
uintthe four bytes of this 32-bit unsigned integer contain the red, green, blue and alpha components
Properties
A
Gets the alpha component value of the color.
[JsonInclude]
public byte A { get; }
Property Value
APercentage
Gets the alpha component value as a percentage (0.0 to 1.0) of the color.
[JsonIgnore]
public double APercentage { get; }
Property Value
B
Gets the blue component value of the color.
[JsonInclude]
public byte B { get; }
Property Value
G
Gets the green component value of the color.
[JsonInclude]
public byte G { get; }
Property Value
H
Gets the hue component value of the color.
[JsonIgnore]
public double H { get; }
Property Value
L
Gets the lightness component value of the color.
[JsonIgnore]
public double L { get; }
Property Value
R
Gets the red component value of the color.
[JsonInclude]
public byte R { get; }
Property Value
S
Gets the saturation component value of the color.
[JsonIgnore]
public double S { get; }
Property Value
UInt32
Gets the 32-bit unsigned integer representation of the color.
[JsonIgnore]
public uint UInt32 { get; }
Property Value
Value
Gets the hexadecimal representation of the color.
[JsonIgnore]
public string Value { get; }
Property Value
Methods
ChangeLightness(double)
Creates a new MudColor instance by adjusting the lightness component value by the specified amount.
public MudColor ChangeLightness(double amount)
Parameters
amount
doubleThe amount to adjust the lightness by (-1.0 to 1.0).
Returns
ColorDarken(double)
Creates a new MudColor instance by darkening the color.
public MudColor ColorDarken(double amount)
Parameters
amount
doubleThe amount to darken the color by.
Returns
ColorLighten(double)
Creates a new MudColor instance by lightening the color.
public MudColor ColorLighten(double amount)
Parameters
amount
doubleThe amount to lighten the color by.
Returns
ColorRgbDarken()
Creates a new MudColor instance by darkening the color using the RGB algorithm.
public MudColor ColorRgbDarken()
Returns
ColorRgbLighten()
Creates a new MudColor instance by lightening the color using the RGB algorithm.
public MudColor ColorRgbLighten()
Returns
Equals(MudColor?)
public bool Equals(MudColor? other)
Parameters
Returns
- bool
True if the instances are equal; otherwise, false.
Equals(object?)
public override bool Equals(object? obj)
Parameters
obj
object
Returns
GetHashCode()
public override int GetHashCode()
Returns
HslChanged(MudColor)
Checks whether the HSL (Hue, Saturation, lightness) values of this MudColor instance have changed compared to another MudColor instance.
public bool HslChanged(MudColor value)
Parameters
Returns
- bool
True if the HSL values have changed; otherwise, false.
SetAlpha(double)
Creates a new MudColor instance with the specified alpha value while keeping the red, green, blue values unchanged.
public MudColor SetAlpha(double a)
Parameters
a
doubleThe alpha component value (0.0 to 1.0).
Returns
SetAlpha(int)
Creates a new MudColor instance with the specified alpha value while keeping the red, green, blue values unchanged.
public MudColor SetAlpha(int a)
Parameters
a
intThe alpha component value (0 to 255).
Returns
SetB(int)
Creates a new MudColor instance with the specified blue component value while keeping the red, green, and alpha values unchanged.
public MudColor SetB(int b)
Parameters
b
intThe blue component value (0 to 255).
Returns
SetG(int)
Creates a new MudColor instance with the specified green component value while keeping the red, blue, and alpha values unchanged.
public MudColor SetG(int g)
Parameters
g
intThe green component value (0 to 255).
Returns
SetH(double)
Creates a new MudColor instance with the specified hue value while keeping the saturation, lightness, and alpha values unchanged.
public MudColor SetH(double h)
Parameters
h
doubleThe hue component value (0 to 360).
Returns
SetL(double)
Creates a new MudColor instance with the specified lightness value while keeping the hue, saturation, and alpha values unchanged.
public MudColor SetL(double l)
Parameters
l
doubleThe lightness component value (0.0 to 1.0).
Returns
SetR(int)
Creates a new MudColor instance with the specified red component value while keeping the green, blue, and alpha values unchanged.
public MudColor SetR(int r)
Parameters
r
intThe red component value (0 to 255).
Returns
SetS(double)
Creates a new MudColor instance with the specified saturation value while keeping the hue, lightness, and alpha values unchanged.
public MudColor SetS(double s)
Parameters
s
doubleThe saturation component value (0.0 to 1.0).
Returns
ToString()
public override string ToString()
Returns
ToString(MudColorOutputFormats)
Returns the string representation of the color in the specified format.
public string ToString(MudColorOutputFormats format)
Parameters
format
MudColorOutputFormatsThe format to represent the color.
Returns
- string
A string representing the color.
Operators
operator ==(MudColor?, MudColor?)
Determines whether two MudColor instances are equal.
public static bool operator ==(MudColor? lhs, MudColor? rhs)
Parameters
lhs
MudColorThe first MudColor instance to compare.
rhs
MudColorThe second MudColor instance to compare.
Returns
- bool
True if the instances are equal; otherwise, false.
explicit operator string(MudColor?)
Converts a MudColor instance to its string representation.
public static explicit operator string(MudColor? color)
Parameters
color
MudColorThe MudColor instance to convert.
Returns
- string
The string representation of the color.
explicit operator uint(MudColor)
Converts a MudColor instance to a 32-bit unsigned integer.
public static explicit operator uint(MudColor mudColor)
Parameters
mudColor
MudColorThe MudColor instance to convert.
Returns
- uint
The 32-bit unsigned integer representation of the color.
implicit operator MudColor(string)
Converts a string representation of a color to a MudColor instance.
public static implicit operator MudColor(string input)
Parameters
input
stringThe string representation of the color.
Returns
operator !=(MudColor, MudColor)
Determines whether two MudColor instances are not equal.
public static bool operator !=(MudColor lhs, MudColor rhs)
Parameters
lhs
MudColorThe first MudColor instance to compare.
rhs
MudColorThe second MudColor instance to compare.
Returns
- bool
True if the instances are not equal; otherwise, false.