mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-12-25 09:49:23 +01:00
parent
0f8072d83e
commit
62ef75441a
2 changed files with 24 additions and 2 deletions
|
@ -20,6 +20,7 @@ Additions
|
|||
- Added GetRandomEntry and GetRandomWeightedEntry to SingleRandom
|
||||
- Added the ability to draw single corners of AutoTiling's extended auto tiles
|
||||
- Added ColorHelper.TryFromHexString, a non-throwing version of FromHexString
|
||||
- Added ToHexStringRgba and ToHexStringRgb to ColorExtensions
|
||||
|
||||
Improvements
|
||||
- Stopped the text formatter throwing if a color can't be parsed
|
||||
|
|
|
@ -37,6 +37,27 @@ namespace MLEM.Extensions {
|
|||
return new Color(color.ToVector4() * other.ToVector4());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the hexadecimal representation of this color as a string in the format <c>#AARRGGBB</c>, or optionally <c>AARRGGBB</c>, without the pound symbol.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to convert.</param>
|
||||
/// <param name="hash">Whether a # should prepend the string.</param>
|
||||
/// <returns>The resulting hex string.</returns>
|
||||
public static string ToHexStringRgba(this Color color, bool hash = true) {
|
||||
return $"{(hash ? "#" : string.Empty)}{color.A:X2}{color.R:X2}{color.G:X2}{color.B:X2}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the hexadecimal representation of this color as a string in the format <c>#RRGGBB</c>, or optionally <c>RRGGBB</c>, without the pound symbol.
|
||||
/// The alpha channel is ignored.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to convert.</param>
|
||||
/// <param name="hash">Whether a # should prepend the string.</param>
|
||||
/// <returns>The resulting hex string.</returns>
|
||||
public static string ToHexStringRgb(this Color color, bool hash = true) {
|
||||
return $"{(hash ? "#" : string.Empty)}{color.R:X2}{color.G:X2}{color.B:X2}";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -66,7 +87,7 @@ namespace MLEM.Extensions {
|
|||
|
||||
/// <summary>
|
||||
/// Parses a hexadecimal string into a color and throws a <see cref="FormatException"/> if parsing fails.
|
||||
/// The string can either be formatted as RRGGBB or AARRGGBB and can optionally start with a <c>#</c>.
|
||||
/// The string can either be formatted as <c>RRGGBB</c> or <c>AARRGGBB</c> and can optionally start with a <c>#</c>.
|
||||
/// </summary>
|
||||
/// <param name="value">The string to parse.</param>
|
||||
/// <returns>The resulting color.</returns>
|
||||
|
@ -79,7 +100,7 @@ namespace MLEM.Extensions {
|
|||
|
||||
/// <summary>
|
||||
/// Tries to parse a hexadecimal string into a color and returns whether a color was successfully parsed.
|
||||
/// The string can either be formatted as RRGGBB or AARRGGBB and can optionally start with a <c>#</c>.
|
||||
/// The string can either be formatted as <c>RRGGBB</c> or <c>AARRGGBB</c> and can optionally start with a <c>#</c>.
|
||||
/// </summary>
|
||||
/// <param name="value">The string to parse.</param>
|
||||
/// <param name="color">The resulting color.</param>
|
||||
|
|
Loading…
Reference in a new issue