using System;
using System.Runtime.InteropServices;
namespace DCFApixels.DragonECS
{
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
public sealed class DebugColorAttribute : Attribute
{
private ColorRecord color;
public byte r => color.r;
public byte g => color.g;
public byte b => color.b;
public float rn => color.r / 255f;
public float gn => color.g / 255f;
public float bn => color.b / 255f;
public DebugColorAttribute(byte r, byte g, byte b)
{
color = new ColorRecord(r, g, b);
}
public DebugColorAttribute(DebugColor color)
{
this.color = new ColorRecord((int)color);
}
[StructLayout(LayoutKind.Explicit, Pack = 1, Size = 4)]
private readonly struct ColorRecord // Union
{
[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 ColorRecord(byte r, byte g, byte b) : this()
{
this.r = r;
this.g = g;
this.b = b;
}
public ColorRecord(int full) : this()
{
this.full = full;
}
}
}
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, 127, 0)
Orange = (255 << 24) + (127 << 16) + (000 << 8),
/// Grey/Gray. RGB is (127, 127, 127)
Gray = (127 << 24) + (127 << 16) + (127 << 8),
/// Grey/Gray. RGB is (127, 127, 127)
Grey = Gray,
/// White. RGB is (255, 255, 255)
White = -1,
/// Black. RGB is (0, 0, 0)
Black = 0,
}
}