2017-05-14 12:02:51 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
|
|
|
|
namespace Maki
|
|
|
|
|
{
|
|
|
|
|
public class DiscordColour
|
|
|
|
|
{
|
2017-05-27 08:48:11 +00:00
|
|
|
|
public DiscordColour(int raw)
|
2017-05-14 12:02:51 +00:00
|
|
|
|
{
|
|
|
|
|
Raw = raw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DiscordColour(byte red, byte green, byte blue)
|
|
|
|
|
{
|
2017-05-27 08:48:11 +00:00
|
|
|
|
Raw = (red << 16) + (green << 8) + blue;
|
2017-05-14 12:02:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DiscordColour(string hex)
|
|
|
|
|
{
|
|
|
|
|
hex = hex.ToUpper();
|
|
|
|
|
|
|
|
|
|
if (hex.Length == 3)
|
|
|
|
|
hex = new string(hex[0], 2) + new string(hex[1], 2) + new string(hex[2], 2);
|
|
|
|
|
|
|
|
|
|
if (hex.Length != 6)
|
|
|
|
|
throw new FormatException("Invalid hex colour format!");
|
2017-05-27 08:48:11 +00:00
|
|
|
|
|
2017-05-14 12:02:51 +00:00
|
|
|
|
Red = byte.Parse(hex.Substring(0, 2), NumberStyles.HexNumber);
|
|
|
|
|
Green = byte.Parse(hex.Substring(2, 2), NumberStyles.HexNumber);
|
|
|
|
|
Blue = byte.Parse(hex.Substring(4, 2), NumberStyles.HexNumber);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-27 08:48:11 +00:00
|
|
|
|
public int Raw = int.MinValue;
|
2017-05-14 12:02:51 +00:00
|
|
|
|
|
|
|
|
|
public byte Red
|
|
|
|
|
{
|
|
|
|
|
get => (byte)(Raw >> 16 & 0xFF);
|
2017-05-27 08:48:11 +00:00
|
|
|
|
set => Raw = (value << 16) + (Green << 8) + Blue;
|
2017-05-14 12:02:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public byte Green
|
|
|
|
|
{
|
|
|
|
|
get => (byte)(Raw >> 8 & 0xFF);
|
2017-05-27 08:48:11 +00:00
|
|
|
|
set => Raw = (Red << 16) + (value << 8) + Blue;
|
2017-05-14 12:02:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public byte Blue
|
|
|
|
|
{
|
|
|
|
|
get => (byte)(Raw & 0xFF);
|
2017-05-27 08:48:11 +00:00
|
|
|
|
set => Raw = (Red << 16) + (Green << 8) + value;
|
2017-05-14 12:02:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Hex => $"{Red:X2}{Green:X2}{Blue:X2}";
|
|
|
|
|
}
|
|
|
|
|
}
|