this repo has no description
at develop 2.0 kB view raw
1using System.Drawing; 2 3namespace Peridot; 4 5/// <summary> 6/// Represetns a RGBA color with floating point values. 7/// All components must be between 0.0 and 1.0. 8/// </summary> 9public partial struct ColorB : IEquatable<ColorB> 10{ 11 /// <summary> 12 /// Constructs a new ColorB from components. 13 /// </summary> 14 /// <param name="r">Red component.</param> 15 /// <param name="g">Green component.</param> 16 /// <param name="b">Blue component.</param> 17 /// <param name="a">Alpha component.</param> 18 public ColorB(byte r, byte g, byte b, byte a) 19 { 20 (R, G, B, A) = (r, g, b, a); 21 } 22 23 /// <summary> 24 /// Constructs a new ColorB from a Color. 25 /// </summary> 26 /// <param name="color">Color.</param> 27 public ColorB(Color color) 28 { 29 (R, G, B, A) = (color.R, color.G, color.B, color.A); 30 } 31 32 /// <summary> 33 /// Constructs a new ColorB from a Vector4. 34 /// </summary> 35 /// <param name="color">Color.</param> 36 public ColorB(ColorF color) 37 { 38 color *= 255f; 39 (R, G, B, A) = ((byte)color.R, (byte)color.G, (byte)color.B, (byte)color.A); 40 } 41 42 /// <summary> 43 /// The red color component. 44 /// </summary> 45 public byte R; 46 47 /// <summary> 48 /// The green color component. 49 /// </summary> 50 public byte G; 51 52 /// <summary> 53 /// The blue color component. 54 /// </summary> 55 public byte B; 56 57 /// <summary> 58 /// The alpha color component. 59 /// </summary> 60 public byte A; 61 62 /// <inheritdoc/> 63 public bool Equals(ColorB other) 64 { 65 return (R, G, B, A) == (other.R, other.G, other.B, other.A); 66 } 67 68 /// <inheritdoc/> 69 public override bool Equals(object? obj) 70 { 71 return obj != null && obj is ColorB other && Equals(other); 72 } 73 74 /// <inheritdoc/> 75 public override int GetHashCode() 76 { 77 return HashCode.Combine(R, G, B, A); 78 } 79 80 /// <inheritdoc/> 81 public override string ToString() 82 { 83 return $"{{R: {R}, G: {G}, B: {B}, A: {A}}}"; 84 } 85}