sharp-chat/SharpChatCommon/ColourInheritable.cs

17 lines
797 B
C#
Raw Permalink Normal View History

namespace SharpChat;
2025-04-26 13:15:27 +00:00
2025-04-27 22:31:35 +00:00
public readonly record struct ColourInheritable(ColourRgb? Rgb) {
public static readonly ColourInheritable None = new(null);
2025-04-27 22:31:35 +00:00
public override string ToString() => Rgb.HasValue ? Rgb.Value.ToString() : "inherit";
public bool Inherits => !Rgb.HasValue;
2025-04-26 13:15:27 +00:00
public static ColourInheritable FromRaw(int? raw) => raw is null ? None : new(new ColourRgb(raw.Value));
public static ColourInheritable FromRgb(byte red, byte green, byte blue) => new(ColourRgb.FromRgb(red, green, blue));
// these should go Away
private const int MSZ_INHERIT = 0x40000000;
2025-04-27 22:31:35 +00:00
public int ToMisuzu() => Rgb.HasValue ? Rgb.Value.Raw : MSZ_INHERIT;
public static ColourInheritable FromMisuzu(int msz) => (msz & MSZ_INHERIT) > 0 ? None : new(new ColourRgb(msz & 0xFFFFFF));
2025-04-26 13:15:27 +00:00
}