1 module d2d.rendering.color; 2 3 import d2d; 4 5 /// Color structure for Bitmaps and converting HSL -> RGB and Hex -> float[3]. 6 /// Can be converted to a `SDL_Color`. 7 /// Only contains RGB Colors. 8 struct Color 9 { 10 /// HTML color <span style='background-color: AliceBlue'>AliceBlue</span> 11 public static const Color AliceBlue = Color.fromRGB(0xF0F8FF); 12 /// HTML color <span style='background-color: AntiqueWhite'>AntiqueWhite</span> 13 public static const Color AntiqueWhite = Color.fromRGB(0xFAEBD7); 14 /// HTML color <span style='background-color: Aqua'>Aqua</span> 15 public static const Color Aqua = Color.fromRGB(0x00FFFF); 16 /// HTML color <span style='background-color: Aquamarine'>Aquamarine</span> 17 public static const Color Aquamarine = Color.fromRGB(0x7FFFD4); 18 /// HTML color <span style='background-color: Azure'>Azure</span> 19 public static const Color Azure = Color.fromRGB(0xF0FFFF); 20 /// HTML color <span style='background-color: Beige'>Beige</span> 21 public static const Color Beige = Color.fromRGB(0xF5F5DC); 22 /// HTML color <span style='background-color: Bisque'>Bisque</span> 23 public static const Color Bisque = Color.fromRGB(0xFFE4C4); 24 /// HTML color <span style='background-color: Black'>Black</span> 25 public static const Color Black = Color.fromRGB(0x000000); 26 /// HTML color <span style='background-color: BlanchedAlmond'>BlanchedAlmond</span> 27 public static const Color BlanchedAlmond = Color.fromRGB(0xFFEBCD); 28 /// HTML color <span style='background-color: Blue'>Blue</span> 29 public static const Color Blue = Color.fromRGB(0x0000FF); 30 /// HTML color <span style='background-color: BlueViolet'>BlueViolet</span> 31 public static const Color BlueViolet = Color.fromRGB(0x8A2BE2); 32 /// HTML color <span style='background-color: Brown'>Brown</span> 33 public static const Color Brown = Color.fromRGB(0xA52A2A); 34 /// HTML color <span style='background-color: BurlyWood'>BurlyWood</span> 35 public static const Color BurlyWood = Color.fromRGB(0xDEB887); 36 /// HTML color <span style='background-color: CadetBlue'>CadetBlue</span> 37 public static const Color CadetBlue = Color.fromRGB(0x5F9EA0); 38 /// HTML color <span style='background-color: Chartreuse'>Chartreuse</span> 39 public static const Color Chartreuse = Color.fromRGB(0x7FFF00); 40 /// HTML color <span style='background-color: Chocolate'>Chocolate</span> 41 public static const Color Chocolate = Color.fromRGB(0xD2691E); 42 /// HTML color <span style='background-color: Coral'>Coral</span> 43 public static const Color Coral = Color.fromRGB(0xFF7F50); 44 /// HTML color <span style='background-color: CornflowerBlue'>CornflowerBlue</span> 45 public static const Color CornflowerBlue = Color.fromRGB(0x6495ED); 46 /// HTML color <span style='background-color: Cornsilk'>Cornsilk</span> 47 public static const Color Cornsilk = Color.fromRGB(0xFFF8DC); 48 /// HTML color <span style='background-color: Crimson'>Crimson</span> 49 public static const Color Crimson = Color.fromRGB(0xDC143C); 50 /// HTML color <span style='background-color: Cyan'>Cyan</span> 51 public static const Color Cyan = Color.fromRGB(0x00FFFF); 52 /// HTML color <span style='background-color: DarkBlue'>DarkBlue</span> 53 public static const Color DarkBlue = Color.fromRGB(0x00008B); 54 /// HTML color <span style='background-color: DarkCyan'>DarkCyan</span> 55 public static const Color DarkCyan = Color.fromRGB(0x008B8B); 56 /// HTML color <span style='background-color: DarkGoldenRod'>DarkGoldenRod</span> 57 public static const Color DarkGoldenRod = Color.fromRGB(0xB8860B); 58 /// HTML color <span style='background-color: DarkGray'>DarkGray</span> 59 public static const Color DarkGray = Color.fromRGB(0xA9A9A9); 60 /// HTML color <span style='background-color: DarkGreen'>DarkGreen</span> 61 public static const Color DarkGreen = Color.fromRGB(0x006400); 62 /// HTML color <span style='background-color: DarkKhaki'>DarkKhaki</span> 63 public static const Color DarkKhaki = Color.fromRGB(0xBDB76B); 64 /// HTML color <span style='background-color: DarkMagenta'>DarkMagenta</span> 65 public static const Color DarkMagenta = Color.fromRGB(0x8B008B); 66 /// HTML color <span style='background-color: DarkOliveGreen'>DarkOliveGreen</span> 67 public static const Color DarkOliveGreen = Color.fromRGB(0x556B2F); 68 /// HTML color <span style='background-color: DarkOrange'>DarkOrange</span> 69 public static const Color DarkOrange = Color.fromRGB(0xFF8C00); 70 /// HTML color <span style='background-color: DarkOrchid'>DarkOrchid</span> 71 public static const Color DarkOrchid = Color.fromRGB(0x9932CC); 72 /// HTML color <span style='background-color: DarkRed'>DarkRed</span> 73 public static const Color DarkRed = Color.fromRGB(0x8B0000); 74 /// HTML color <span style='background-color: DarkSalmon'>DarkSalmon</span> 75 public static const Color DarkSalmon = Color.fromRGB(0xE9967A); 76 /// HTML color <span style='background-color: DarkSeaGreen'>DarkSeaGreen</span> 77 public static const Color DarkSeaGreen = Color.fromRGB(0x8FBC8F); 78 /// HTML color <span style='background-color: DarkSlateBlue'>DarkSlateBlue</span> 79 public static const Color DarkSlateBlue = Color.fromRGB(0x483D8B); 80 /// HTML color <span style='background-color: DarkSlateGray'>DarkSlateGray</span> 81 public static const Color DarkSlateGray = Color.fromRGB(0x2F4F4F); 82 /// HTML color <span style='background-color: DarkTurquoise'>DarkTurquoise</span> 83 public static const Color DarkTurquoise = Color.fromRGB(0x00CED1); 84 /// HTML color <span style='background-color: DarkViolet'>DarkViolet</span> 85 public static const Color DarkViolet = Color.fromRGB(0x9400D3); 86 /// HTML color <span style='background-color: DeepPink'>DeepPink</span> 87 public static const Color DeepPink = Color.fromRGB(0xFF1493); 88 /// HTML color <span style='background-color: DeepSkyBlue'>DeepSkyBlue</span> 89 public static const Color DeepSkyBlue = Color.fromRGB(0x00BFFF); 90 /// HTML color <span style='background-color: DimGray'>DimGray</span> 91 public static const Color DimGray = Color.fromRGB(0x696969); 92 /// HTML color <span style='background-color: DodgerBlue'>DodgerBlue</span> 93 public static const Color DodgerBlue = Color.fromRGB(0x1E90FF); 94 /// HTML color <span style='background-color: FireBrick'>FireBrick</span> 95 public static const Color FireBrick = Color.fromRGB(0xB22222); 96 /// HTML color <span style='background-color: FloralWhite'>FloralWhite</span> 97 public static const Color FloralWhite = Color.fromRGB(0xFFFAF0); 98 /// HTML color <span style='background-color: ForestGreen'>ForestGreen</span> 99 public static const Color ForestGreen = Color.fromRGB(0x228B22); 100 /// HTML color <span style='background-color: Fuchsia'>Fuchsia</span> 101 public static const Color Fuchsia = Color.fromRGB(0xFF00FF); 102 /// HTML color <span style='background-color: Gainsboro'>Gainsboro</span> 103 public static const Color Gainsboro = Color.fromRGB(0xDCDCDC); 104 /// HTML color <span style='background-color: GhostWhite'>GhostWhite</span> 105 public static const Color GhostWhite = Color.fromRGB(0xF8F8FF); 106 /// HTML color <span style='background-color: Gold'>Gold</span> 107 public static const Color Gold = Color.fromRGB(0xFFD700); 108 /// HTML color <span style='background-color: GoldenRod'>GoldenRod</span> 109 public static const Color GoldenRod = Color.fromRGB(0xDAA520); 110 /// HTML color <span style='background-color: Gray'>Gray</span> 111 public static const Color Gray = Color.fromRGB(0x808080); 112 /// HTML color <span style='background-color: Green'>Green</span> 113 public static const Color Green = Color.fromRGB(0x008000); 114 /// HTML color <span style='background-color: GreenYellow'>GreenYellow</span> 115 public static const Color GreenYellow = Color.fromRGB(0xADFF2F); 116 /// HTML color <span style='background-color: HoneyDew'>HoneyDew</span> 117 public static const Color HoneyDew = Color.fromRGB(0xF0FFF0); 118 /// HTML color <span style='background-color: HotPink'>HotPink</span> 119 public static const Color HotPink = Color.fromRGB(0xFF69B4); 120 /// HTML color <span style='background-color: IndianRed'>IndianRed</span> 121 public static const Color IndianRed = Color.fromRGB(0xCD5C5C); 122 /// HTML color <span style='background-color: Indigo'>Indigo</span> 123 public static const Color Indigo = Color.fromRGB(0x4B0082); 124 /// HTML color <span style='background-color: Ivory'>Ivory</span> 125 public static const Color Ivory = Color.fromRGB(0xFFFFF0); 126 /// HTML color <span style='background-color: Khaki'>Khaki</span> 127 public static const Color Khaki = Color.fromRGB(0xF0E68C); 128 /// HTML color <span style='background-color: Lavender'>Lavender</span> 129 public static const Color Lavender = Color.fromRGB(0xE6E6FA); 130 /// HTML color <span style='background-color: LavenderBlush'>LavenderBlush</span> 131 public static const Color LavenderBlush = Color.fromRGB(0xFFF0F5); 132 /// HTML color <span style='background-color: LawnGreen'>LawnGreen</span> 133 public static const Color LawnGreen = Color.fromRGB(0x7CFC00); 134 /// HTML color <span style='background-color: LemonChiffon'>LemonChiffon</span> 135 public static const Color LemonChiffon = Color.fromRGB(0xFFFACD); 136 /// HTML color <span style='background-color: LightBlue'>LightBlue</span> 137 public static const Color LightBlue = Color.fromRGB(0xADD8E6); 138 /// HTML color <span style='background-color: LightCoral'>LightCoral</span> 139 public static const Color LightCoral = Color.fromRGB(0xF08080); 140 /// HTML color <span style='background-color: LightCyan'>LightCyan</span> 141 public static const Color LightCyan = Color.fromRGB(0xE0FFFF); 142 /// HTML color <span style='background-color: LightGoldenRodYellow'>LightGoldenRodYellow</span> 143 public static const Color LightGoldenRodYellow = Color.fromRGB(0xFAFAD2); 144 /// HTML color <span style='background-color: LightGray'>LightGray</span> 145 public static const Color LightGray = Color.fromRGB(0xD3D3D3); 146 /// HTML color <span style='background-color: LightGreen'>LightGreen</span> 147 public static const Color LightGreen = Color.fromRGB(0x90EE90); 148 /// HTML color <span style='background-color: LightPink'>LightPink</span> 149 public static const Color LightPink = Color.fromRGB(0xFFB6C1); 150 /// HTML color <span style='background-color: LightSalmon'>LightSalmon</span> 151 public static const Color LightSalmon = Color.fromRGB(0xFFA07A); 152 /// HTML color <span style='background-color: LightSeaGreen'>LightSeaGreen</span> 153 public static const Color LightSeaGreen = Color.fromRGB(0x20B2AA); 154 /// HTML color <span style='background-color: LightSkyBlue'>LightSkyBlue</span> 155 public static const Color LightSkyBlue = Color.fromRGB(0x87CEFA); 156 /// HTML color <span style='background-color: LightSlateGray'>LightSlateGray</span> 157 public static const Color LightSlateGray = Color.fromRGB(0x778899); 158 /// HTML color <span style='background-color: LightSteelBlue'>LightSteelBlue</span> 159 public static const Color LightSteelBlue = Color.fromRGB(0xB0C4DE); 160 /// HTML color <span style='background-color: LightYellow'>LightYellow</span> 161 public static const Color LightYellow = Color.fromRGB(0xFFFFE0); 162 /// HTML color <span style='background-color: Lime'>Lime</span> 163 public static const Color Lime = Color.fromRGB(0x00FF00); 164 /// HTML color <span style='background-color: LimeGreen'>LimeGreen</span> 165 public static const Color LimeGreen = Color.fromRGB(0x32CD32); 166 /// HTML color <span style='background-color: Linen'>Linen</span> 167 public static const Color Linen = Color.fromRGB(0xFAF0E6); 168 /// HTML color <span style='background-color: Magenta'>Magenta</span> 169 public static const Color Magenta = Color.fromRGB(0xFF00FF); 170 /// HTML color <span style='background-color: Maroon'>Maroon</span> 171 public static const Color Maroon = Color.fromRGB(0x800000); 172 /// HTML color <span style='background-color: MediumAquaMarine'>MediumAquaMarine</span> 173 public static const Color MediumAquaMarine = Color.fromRGB(0x66CDAA); 174 /// HTML color <span style='background-color: MediumBlue'>MediumBlue</span> 175 public static const Color MediumBlue = Color.fromRGB(0x0000CD); 176 /// HTML color <span style='background-color: MediumOrchid'>MediumOrchid</span> 177 public static const Color MediumOrchid = Color.fromRGB(0xBA55D3); 178 /// HTML color <span style='background-color: MediumPurple'>MediumPurple</span> 179 public static const Color MediumPurple = Color.fromRGB(0x9370DB); 180 /// HTML color <span style='background-color: MediumSeaGreen'>MediumSeaGreen</span> 181 public static const Color MediumSeaGreen = Color.fromRGB(0x3CB371); 182 /// HTML color <span style='background-color: MediumSlateBlue'>MediumSlateBlue</span> 183 public static const Color MediumSlateBlue = Color.fromRGB(0x7B68EE); 184 /// HTML color <span style='background-color: MediumSpringGreen'>MediumSpringGreen</span> 185 public static const Color MediumSpringGreen = Color.fromRGB(0x00FA9A); 186 /// HTML color <span style='background-color: MediumTurquoise'>MediumTurquoise</span> 187 public static const Color MediumTurquoise = Color.fromRGB(0x48D1CC); 188 /// HTML color <span style='background-color: MediumVioletRed'>MediumVioletRed</span> 189 public static const Color MediumVioletRed = Color.fromRGB(0xC71585); 190 /// HTML color <span style='background-color: MidnightBlue'>MidnightBlue</span> 191 public static const Color MidnightBlue = Color.fromRGB(0x191970); 192 /// HTML color <span style='background-color: MintCream'>MintCream</span> 193 public static const Color MintCream = Color.fromRGB(0xF5FFFA); 194 /// HTML color <span style='background-color: MistyRose'>MistyRose</span> 195 public static const Color MistyRose = Color.fromRGB(0xFFE4E1); 196 /// HTML color <span style='background-color: Moccasin'>Moccasin</span> 197 public static const Color Moccasin = Color.fromRGB(0xFFE4B5); 198 /// HTML color <span style='background-color: NavajoWhite'>NavajoWhite</span> 199 public static const Color NavajoWhite = Color.fromRGB(0xFFDEAD); 200 /// HTML color <span style='background-color: Navy'>Navy</span> 201 public static const Color Navy = Color.fromRGB(0x000080); 202 /// HTML color <span style='background-color: OldLace'>OldLace</span> 203 public static const Color OldLace = Color.fromRGB(0xFDF5E6); 204 /// HTML color <span style='background-color: Olive'>Olive</span> 205 public static const Color Olive = Color.fromRGB(0x808000); 206 /// HTML color <span style='background-color: OliveDrab'>OliveDrab</span> 207 public static const Color OliveDrab = Color.fromRGB(0x6B8E23); 208 /// HTML color <span style='background-color: Orange'>Orange</span> 209 public static const Color Orange = Color.fromRGB(0xFFA500); 210 /// HTML color <span style='background-color: OrangeRed'>OrangeRed</span> 211 public static const Color OrangeRed = Color.fromRGB(0xFF4500); 212 /// HTML color <span style='background-color: Orchid'>Orchid</span> 213 public static const Color Orchid = Color.fromRGB(0xDA70D6); 214 /// HTML color <span style='background-color: PaleGoldenRod'>PaleGoldenRod</span> 215 public static const Color PaleGoldenRod = Color.fromRGB(0xEEE8AA); 216 /// HTML color <span style='background-color: PaleGreen'>PaleGreen</span> 217 public static const Color PaleGreen = Color.fromRGB(0x98FB98); 218 /// HTML color <span style='background-color: PaleTurquoise'>PaleTurquoise</span> 219 public static const Color PaleTurquoise = Color.fromRGB(0xAFEEEE); 220 /// HTML color <span style='background-color: PaleVioletRed'>PaleVioletRed</span> 221 public static const Color PaleVioletRed = Color.fromRGB(0xDB7093); 222 /// HTML color <span style='background-color: PapayaWhip'>PapayaWhip</span> 223 public static const Color PapayaWhip = Color.fromRGB(0xFFEFD5); 224 /// HTML color <span style='background-color: PeachPuff'>PeachPuff</span> 225 public static const Color PeachPuff = Color.fromRGB(0xFFDAB9); 226 /// HTML color <span style='background-color: Peru'>Peru</span> 227 public static const Color Peru = Color.fromRGB(0xCD853F); 228 /// HTML color <span style='background-color: Pink'>Pink</span> 229 public static const Color Pink = Color.fromRGB(0xFFC0CB); 230 /// HTML color <span style='background-color: Plum'>Plum</span> 231 public static const Color Plum = Color.fromRGB(0xDDA0DD); 232 /// HTML color <span style='background-color: PowderBlue'>PowderBlue</span> 233 public static const Color PowderBlue = Color.fromRGB(0xB0E0E6); 234 /// HTML color <span style='background-color: Purple'>Purple</span> 235 public static const Color Purple = Color.fromRGB(0x800080); 236 /// HTML color <span style='background-color: RebeccaPurple'>RebeccaPurple</span> 237 public static const Color RebeccaPurple = Color.fromRGB(0x663399); 238 /// HTML color <span style='background-color: Red'>Red</span> 239 public static const Color Red = Color.fromRGB(0xFF0000); 240 /// HTML color <span style='background-color: RosyBrown'>RosyBrown</span> 241 public static const Color RosyBrown = Color.fromRGB(0xBC8F8F); 242 /// HTML color <span style='background-color: RoyalBlue'>RoyalBlue</span> 243 public static const Color RoyalBlue = Color.fromRGB(0x4169E1); 244 /// HTML color <span style='background-color: SaddleBrown'>SaddleBrown</span> 245 public static const Color SaddleBrown = Color.fromRGB(0x8B4513); 246 /// HTML color <span style='background-color: Salmon'>Salmon</span> 247 public static const Color Salmon = Color.fromRGB(0xFA8072); 248 /// HTML color <span style='background-color: SandyBrown'>SandyBrown</span> 249 public static const Color SandyBrown = Color.fromRGB(0xF4A460); 250 /// HTML color <span style='background-color: SeaGreen'>SeaGreen</span> 251 public static const Color SeaGreen = Color.fromRGB(0x2E8B57); 252 /// HTML color <span style='background-color: SeaShell'>SeaShell</span> 253 public static const Color SeaShell = Color.fromRGB(0xFFF5EE); 254 /// HTML color <span style='background-color: Sienna'>Sienna</span> 255 public static const Color Sienna = Color.fromRGB(0xA0522D); 256 /// HTML color <span style='background-color: Silver'>Silver</span> 257 public static const Color Silver = Color.fromRGB(0xC0C0C0); 258 /// HTML color <span style='background-color: SkyBlue'>SkyBlue</span> 259 public static const Color SkyBlue = Color.fromRGB(0x87CEEB); 260 /// HTML color <span style='background-color: SlateBlue'>SlateBlue</span> 261 public static const Color SlateBlue = Color.fromRGB(0x6A5ACD); 262 /// HTML color <span style='background-color: SlateGray'>SlateGray</span> 263 public static const Color SlateGray = Color.fromRGB(0x708090); 264 /// HTML color <span style='background-color: Snow'>Snow</span> 265 public static const Color Snow = Color.fromRGB(0xFFFAFA); 266 /// HTML color <span style='background-color: SpringGreen'>SpringGreen</span> 267 public static const Color SpringGreen = Color.fromRGB(0x00FF7F); 268 /// HTML color <span style='background-color: SteelBlue'>SteelBlue</span> 269 public static const Color SteelBlue = Color.fromRGB(0x4682B4); 270 /// HTML color <span style='background-color: Tan'>Tan</span> 271 public static const Color Tan = Color.fromRGB(0xD2B48C); 272 /// HTML color <span style='background-color: Teal'>Teal</span> 273 public static const Color Teal = Color.fromRGB(0x008080); 274 /// HTML color <span style='background-color: Thistle'>Thistle</span> 275 public static const Color Thistle = Color.fromRGB(0xD8BFD8); 276 /// HTML color <span style='background-color: Tomato'>Tomato</span> 277 public static const Color Tomato = Color.fromRGB(0xFF6347); 278 /// HTML color <span style='background-color: Turquoise'>Turquoise</span> 279 public static const Color Turquoise = Color.fromRGB(0x40E0D0); 280 /// HTML color <span style='background-color: Violet'>Violet</span> 281 public static const Color Violet = Color.fromRGB(0xEE82EE); 282 /// HTML color <span style='background-color: Wheat'>Wheat</span> 283 public static const Color Wheat = Color.fromRGB(0xF5DEB3); 284 /// HTML color <span style='background-color: White'>White</span> 285 public static const Color White = Color.fromRGB(0xFFFFFF); 286 /// HTML color <span style='background-color: WhiteSmoke'>WhiteSmoke</span> 287 public static const Color WhiteSmoke = Color.fromRGB(0xF5F5F5); 288 /// HTML color <span style='background-color: Yellow'>Yellow</span> 289 public static const Color Yellow = Color.fromRGB(0xFFFF00); 290 /// HTML color <span style='background-color: YellowGreen'>YellowGreen</span> 291 public static const Color YellowGreen = Color.fromRGB(0x9ACD32); 292 293 /// Creates a new 24 bit color using 3x 8 bit components. 294 /// Params: 295 /// r = Red value in range 0 - 255 296 /// g = Green value in range 0 - 255 297 /// b = Blue value in range 0 - 255 298 public this(ubyte r, ubyte g, ubyte b) 299 { 300 _r = r; 301 _g = g; 302 _b = b; 303 } 304 305 /// Creates a new 24 bit color. 306 /// Params: 307 /// hex = integer in RGB byte order 308 public static Color fromRGB(const int hex) 309 { 310 return Color((hex >> 16) & 0xFF, (hex >> 8) & 0xFF, hex & 0xFF); 311 } 312 313 /// Creates a new 24 bit color. 314 /// Params: 315 /// hex = integer in BGR byte order 316 public static Color fromBGR(const int hex) 317 { 318 return Color(hex & 0xFF, (hex >> 8) & 0xFF, (hex >> 16) & 0xFF); 319 } 320 321 /// Converts from HSL to RGB 322 /// Params: 323 /// hue = Hue in range 0 - 1 324 /// saturation = Saturation in range 0 - 1 325 /// lightness = Lightness in range 0 - 1 326 public void fromHSL(double hue, double saturation, double lightness) 327 { 328 immutable double v = lightness <= 0.5 ? (lightness * (1 + saturation)) : (1 + saturation - lightness * saturation); 329 double r, g, b; 330 r = g = b = 1; 331 332 if (v > 0) 333 { 334 double m; 335 double sv; 336 int sextant; 337 double fract, vsf, mid1, mid2; 338 339 m = lightness + lightness - v; 340 sv = (v - m) / v; 341 hue *= 6.0; 342 sextant = cast(int) hue; 343 fract = hue - sextant; 344 vsf = v * sv * fract; 345 mid1 = m + vsf; 346 mid2 = v - vsf; 347 switch (sextant) 348 { 349 case 0: 350 r = v; 351 g = mid1; 352 b = m; 353 break; 354 case 1: 355 r = mid2; 356 g = v; 357 b = m; 358 break; 359 case 2: 360 r = m; 361 g = v; 362 b = mid1; 363 break; 364 case 3: 365 r = m; 366 g = mid2; 367 b = v; 368 break; 369 case 4: 370 r = mid1; 371 g = m; 372 b = v; 373 break; 374 case 5: 375 r = v; 376 g = m; 377 b = mid2; 378 break; 379 default: 380 break; 381 } 382 } 383 _r = cast(ubyte) (r * 255); 384 _g = cast(ubyte) (g * 255); 385 _b = cast(ubyte) (b * 255); 386 } 387 388 public override bool opEquals()(auto ref const Color color) const 389 { 390 return _r == color._r && _g == color._g && _b == color._b; 391 } 392 393 /// Creates an SDL_Color from `this`. 394 public @property SDL_Color sdl_color() const 395 { 396 return SDL_Color(_r, _g, _b, 255); 397 } 398 399 /// Red value in range 0 - 255 as a ubyte. 400 public @property ref ubyte R() 401 { 402 return _r; 403 } 404 405 /// Green value in range 0 - 255 as a ubyte. 406 public @property ref ubyte G() 407 { 408 return _g; 409 } 410 411 /// Blue value in range 0 - 255 as a ubyte. 412 public @property ref ubyte B() 413 { 414 return _b; 415 } 416 417 /// Red value in range 0 - 1 as a float. 418 public @property float fR() const 419 { 420 return _r * 0.00392156862f; 421 } 422 423 /// Green value in range 0 - 1 as a float. 424 public @property float fG() const 425 { 426 return _g * 0.00392156862f; 427 } 428 429 /// Blue value in range 0 - 1 as a float. 430 public @property float fB() const 431 { 432 return _b * 0.00392156862f; 433 } 434 435 /// RGB in range 0 - 1 as vec3 436 public @property vec3 f() const 437 { 438 return vec3(fR, fG, fB); 439 } 440 441 /// Color as RGB hex. 442 public @property int RGB() const 443 { 444 return _r << 16 | _g << 8 | _b; 445 } 446 447 /// Color as BGR hex. 448 public @property int BGR() const 449 { 450 return _r | _g << 8 | _b << 16; 451 } 452 453 private ubyte _r, _g, _b; 454 }