using System; using System.Runtime.InteropServices; namespace DCFApixels.DragonECS { [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class, Inherited = false, AllowMultiple = false)] public sealed class DebugColorAttribute : Attribute { private Color color; public byte r => color.r; public byte g => color.g; public byte b => color.b; public DebugColorAttribute(byte r, byte g, byte b) => color = new Color(r, g, b); public DebugColorAttribute(DebugColor color) => this.color = new Color((int)color); [StructLayout(LayoutKind.Explicit, Pack = 1, Size = 4)] internal readonly struct Color { [FieldOffset(0)] public readonly int full; [FieldOffset(3)] public readonly byte r; [FieldOffset(2)] public readonly byte g; [FieldOffset(1)] public readonly byte b; public Color(byte r, byte g, byte b) : this() { this.r = r; this.g = g; this.b = b; } public Color(int full) : this() => this.full = full; public (byte, byte, byte) ToTuple() => (r, g, b); public Color UpContrastColor() { byte minChannel = Math.Min(Math.Min(r, g), b); byte maxChannel = Math.Max(Math.Max(r, g), b); if (maxChannel == minChannel) return default; float factor = 255f / (maxChannel - minChannel); return new Color((byte)((r - minChannel) * factor), (byte)((g - minChannel) * factor), (byte)((b - minChannel) * factor)); } public static Color operator /(Color a, float b) { return new Color((byte)(a.r / b), (byte)(a.g / b), (byte)(a.b / b)); } } } public enum DebugColor { /// Red. RGB is (255, 0, 0) Red = (255 << 24) + (000 << 16) + (000 << 8), /// Green. RGB is (0, 255, 0) Green = (000 << 24) + (255 << 16) + (000 << 8), /// Blue. RGB is (0, 0, 255) Blue = (000 << 24) + (000 << 16) + (255 << 8), /// Yellow. RGB is (255, 255, 0) Yellow = (255 << 24) + (255 << 16) + (000 << 8), /// Cyan. RGB is (0, 255, 255) Cyan = (000 << 24) + (255 << 16) + (255 << 8), /// Magenta. RGB is (255, 0, 255) Magenta = (255 << 24) + (000 << 16) + (255 << 8), /// Yellow. RGB is (255, 165, 0) Orange = (255 << 24) + (165 << 16) + (000 << 8), /// Yellow. RGB is (255, 69, 0) OrangeRed = (255 << 24) + (69 << 16) + (000 << 8), /// Lime. RGB is (125, 255, 0) Lime = (125 << 24) + (255 << 16) + (000 << 8), /// Lime. RGB is (127, 255, 212) Aquamarine = (127 << 24) + (255 << 16) + (212 << 8), /// Lime. RGB is (218, 165, 32) Goldenrod = (218 << 24) + (165 << 16) + (32 << 8), /// Yellow. RGB is (255, 105, 180) DeepPink = (255 << 24) + (105 << 16) + (180 << 8), /// Yellow. RGB is (220, 20, 60) Crimson = (220 << 24) + (20 << 16) + (60 << 8), /// Yellow. RGB is (138, 43, 226) BlueViolet = (138 << 24) + (43 << 16) + (226 << 8), /// Yellow. RGB is (255, 3, 62) AmericanRose = (255 << 24) + (3 << 16) + (62 << 8), /// Grey/Gray. RGB is (127, 127, 127) Gray = (127 << 24) + (127 << 16) + (127 << 8), /// Grey/Gray. RGB is (127, 127, 127) Grey = Gray, /// Grey/Gray. RGB is (192, 192, 192) Silver = (192 << 24) + (192 << 16) + (192 << 8), /// White. RGB is (255, 255, 255) White = -1, /// Black. RGB is (0, 0, 0) Black = 0, } }