1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-06-26 06:31:42 +02:00
MLEM/MLEM/Extensions/ColorExtensions.cs

27 lines
877 B
C#
Raw Normal View History

2019-08-06 14:20:11 +02:00
using System;
2020-04-30 21:15:28 +02:00
using System.Globalization;
2019-08-06 14:20:11 +02:00
using Microsoft.Xna.Framework;
namespace MLEM.Extensions {
public static class ColorExtensions {
public static Color Invert(this Color color) {
return new Color(Math.Abs(255 - color.R), Math.Abs(255 - color.G), Math.Abs(255 - color.B), color.A);
}
public static Color FromHex(uint value) {
return new Color((int) (value >> 16 & 0xFF), (int) (value >> 8 & 0xFF), (int) (value >> 0 & 0xFF), (int) (value >> 24 & 0xFF));
}
2020-04-30 21:15:28 +02:00
public static Color FromHex(string value) {
if (value.StartsWith("#"))
value = value.Substring(1);
return FromHex(uint.Parse(value, NumberStyles.HexNumber));
}
public static Color CopyAlpha(this Color color, Color other) {
return color * (other.A / 255F);
}
2019-08-06 14:20:11 +02:00
}
}