mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-26 06:28:35 +01:00
Added ColorExtensions.Multiply
This commit is contained in:
parent
c060d78010
commit
5d9cccc9fd
2 changed files with 25 additions and 14 deletions
|
@ -11,6 +11,7 @@ Jump to version:
|
||||||
### MLEM
|
### MLEM
|
||||||
Additions
|
Additions
|
||||||
- Added StringBuilder overloads to GenericFont
|
- Added StringBuilder overloads to GenericFont
|
||||||
|
- Added ColorExtensions.Multiply
|
||||||
|
|
||||||
Improvements
|
Improvements
|
||||||
- Generify GenericFont's string drawing
|
- Generify GenericFont's string drawing
|
||||||
|
|
|
@ -3,16 +3,16 @@ using Microsoft.Xna.Framework;
|
||||||
|
|
||||||
namespace MLEM.Extensions {
|
namespace MLEM.Extensions {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A set of extensions for dealing with <see cref="Color"/> objects
|
/// A set of extensions for dealing with <see cref="Color"/> objects.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class ColorExtensions {
|
public static class ColorExtensions {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Copies the alpha value from another color into this color.
|
/// Copies the alpha value from another color into this color and returns the result.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="color">The color</param>
|
/// <param name="color">The color.</param>
|
||||||
/// <param name="other">The color to copy the alpha from</param>
|
/// <param name="other">The color to copy the alpha from.</param>
|
||||||
/// <returns>The first color with the second color's alpha value</returns>
|
/// <returns>The first color with the second color's alpha value.</returns>
|
||||||
public static Color CopyAlpha(this Color color, Color other) {
|
public static Color CopyAlpha(this Color color, Color other) {
|
||||||
return color * (other.A / 255F);
|
return color * (other.A / 255F);
|
||||||
}
|
}
|
||||||
|
@ -20,16 +20,26 @@ namespace MLEM.Extensions {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns an inverted version of this color.
|
/// Returns an inverted version of this color.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="color">The color to invert</param>
|
/// <param name="color">The color to invert.</param>
|
||||||
/// <returns>The inverted color</returns>
|
/// <returns>The inverted color.</returns>
|
||||||
public static Color Invert(this Color color) {
|
public static Color Invert(this Color color) {
|
||||||
return new Color(255 - color.R, 255 - color.G, 255 - color.B, color.A);
|
return new Color(255 - color.R, 255 - color.G, 255 - color.B, color.A);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Multiplies this color with another color and returns the result.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="color">The first color.</param>
|
||||||
|
/// <param name="other">The second color.</param>
|
||||||
|
/// <returns>The two colors multiplied together.</returns>
|
||||||
|
public static Color Multiply(this Color color, Color other) {
|
||||||
|
return new Color(color.ToVector4() * other.ToVector4());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A set of utility methods for dealing with <see cref="Color"/> objects
|
/// A set of utility methods for dealing with <see cref="Color"/> objects.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class ColorHelper {
|
public static class ColorHelper {
|
||||||
|
|
||||||
|
@ -37,8 +47,8 @@ namespace MLEM.Extensions {
|
||||||
/// Parses a hexadecimal number into an rgba color.
|
/// Parses a hexadecimal number into an rgba color.
|
||||||
/// The number should be in the format <c>0xaarrggbb</c>.
|
/// The number should be in the format <c>0xaarrggbb</c>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value">The number to parse</param>
|
/// <param name="value">The number to parse.</param>
|
||||||
/// <returns>The resulting color</returns>
|
/// <returns>The resulting color.</returns>
|
||||||
public static Color FromHexRgba(int value) {
|
public static Color FromHexRgba(int value) {
|
||||||
return new Color(value >> 16 & 0xFF, value >> 8 & 0xFF, value >> 0 & 0xFF, value >> 24 & 0xFF);
|
return new Color(value >> 16 & 0xFF, value >> 8 & 0xFF, value >> 0 & 0xFF, value >> 24 & 0xFF);
|
||||||
}
|
}
|
||||||
|
@ -47,8 +57,8 @@ namespace MLEM.Extensions {
|
||||||
/// Parses a hexadecimal number into an rgb color with 100% alpha.
|
/// Parses a hexadecimal number into an rgb color with 100% alpha.
|
||||||
/// The number should be in the format <c>0xrrggbb</c>.
|
/// The number should be in the format <c>0xrrggbb</c>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value">The number to parse</param>
|
/// <param name="value">The number to parse.</param>
|
||||||
/// <returns>The resulting color</returns>
|
/// <returns>The resulting color.</returns>
|
||||||
public static Color FromHexRgb(int value) {
|
public static Color FromHexRgb(int value) {
|
||||||
return new Color(value >> 16 & 0xFF, value >> 8 & 0xFF, value >> 0 & 0xFF);
|
return new Color(value >> 16 & 0xFF, value >> 8 & 0xFF, value >> 0 & 0xFF);
|
||||||
}
|
}
|
||||||
|
@ -57,8 +67,8 @@ namespace MLEM.Extensions {
|
||||||
/// Parses a hexadecimal string into a color.
|
/// Parses a hexadecimal string into a color.
|
||||||
/// 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 RRGGBB or AARRGGBB and can optionally start with a <c>#</c>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value">The string to parse</param>
|
/// <param name="value">The string to parse.</param>
|
||||||
/// <returns>The resulting color</returns>
|
/// <returns>The resulting color.</returns>
|
||||||
public static Color FromHexString(string value) {
|
public static Color FromHexString(string value) {
|
||||||
if (value.StartsWith("#"))
|
if (value.StartsWith("#"))
|
||||||
value = value.Substring(1);
|
value = value.Substring(1);
|
||||||
|
|
Loading…
Reference in a new issue