rustyray_sys/
color.rs

1#[repr(C)]
2#[derive(Debug, Clone, Copy, PartialEq)]
3pub struct Color {
4    r: u8,
5    g: u8,
6    b: u8,
7    a: u8,
8}
9
10impl Default for Color {
11    fn default() -> Self {
12        Color::WHITE
13    }
14}
15
16impl Color {
17    pub const fn new(r: u8, g: u8, b: u8, a: u8) -> Self {
18        Self { r, g, b, a }
19    }
20
21    /// Get color with alpha applied, alpha goes from 0.0 to 1.0
22    pub fn fade(mut self, alpha: f32) -> Self {
23        self.a = (255.0 * alpha.clamp(0., 1.)) as u8;
24        self
25    }
26}
27
28impl Color {
29    /// Get hexadecimal value for a [Color] (0xRRGGBBAA)
30    pub fn to_int(&self) -> i32 {
31        ((self.r as i32) << 24) | ((self.g as i32) << 16) | ((self.b as i32) << 8) | self.a as i32
32    }
33
34    /// Get [Color] multiplied with another [Color]
35    pub fn tint(&mut self, color: &Color) -> &mut Self {
36        self.r = ((self.r as i32 * color.r as i32) / 255) as u8;
37        self.g = ((self.g as i32 * color.g as i32) / 255) as u8;
38        self.b = ((self.b as i32 * color.b as i32) / 255) as u8;
39        self.a = ((self.a as i32 * color.a as i32) / 255) as u8;
40
41        self
42    }
43}
44
45impl From<(u8, u8, u8, u8)> for Color {
46    fn from(value: (u8, u8, u8, u8)) -> Self {
47        Color::new(value.0, value.1, value.2, value.3)
48    }
49}
50
51impl From<(u8, u8, u8)> for Color {
52    fn from(value: (u8, u8, u8)) -> Self {
53        Color::new(value.0, value.1, value.2, 255)
54    }
55}
56
57impl Color {
58    pub const INDIANRED: Color = Color::new(205, 92, 92, 255);
59    pub const LIGHTCORAL: Color = Color::new(240, 128, 128, 255);
60    pub const SALMON: Color = Color::new(250, 128, 114, 255);
61    pub const DARKSALMON: Color = Color::new(233, 150, 122, 255);
62    pub const LIGHTSALMON: Color = Color::new(255, 160, 122, 255);
63    pub const CRIMSON: Color = Color::new(220, 20, 60, 255);
64    pub const RED: Color = Color::new(230, 41, 55, 255);
65    pub const FIREBRICK: Color = Color::new(178, 34, 34, 255);
66    pub const DARKRED: Color = Color::new(139, 0, 0, 255);
67    pub const PINK: Color = Color::new(255, 109, 194, 255);
68    pub const LIGHTPINK: Color = Color::new(255, 182, 193, 255);
69    pub const HOTPINK: Color = Color::new(255, 105, 180, 255);
70    pub const DEEPPINK: Color = Color::new(255, 20, 147, 255);
71    pub const MEDIUMVIOLETRED: Color = Color::new(199, 21, 133, 255);
72    pub const PALEVIOLETRED: Color = Color::new(219, 112, 147, 255);
73    pub const CORAL: Color = Color::new(255, 127, 80, 255);
74    pub const TOMATO: Color = Color::new(255, 99, 71, 255);
75    pub const ORANGERED: Color = Color::new(255, 69, 0, 255);
76    pub const DARKORANGE: Color = Color::new(255, 140, 0, 255);
77    pub const ORANGE: Color = Color::new(255, 161, 0, 255);
78    pub const GOLD: Color = Color::new(255, 203, 0, 255);
79    pub const YELLOW: Color = Color::new(253, 249, 0, 255);
80    pub const LIGHTYELLOW: Color = Color::new(255, 255, 224, 255);
81    pub const LEMONCHIFFON: Color = Color::new(255, 250, 205, 255);
82    pub const LIGHTGOLDENRODYELLOW: Color = Color::new(250, 250, 210, 255);
83    pub const PAPAYAWHIP: Color = Color::new(255, 239, 213, 255);
84    pub const MOCCASIN: Color = Color::new(255, 228, 181, 255);
85    pub const PEACHPUFF: Color = Color::new(255, 218, 185, 255);
86    pub const PALEGOLDENROD: Color = Color::new(238, 232, 170, 255);
87    pub const KHAKI: Color = Color::new(240, 230, 140, 255);
88    pub const DARKKHAKI: Color = Color::new(189, 183, 107, 255);
89    pub const LAVENDER: Color = Color::new(230, 230, 250, 255);
90    pub const THISTLE: Color = Color::new(216, 191, 216, 255);
91    pub const PLUM: Color = Color::new(221, 160, 221, 255);
92    pub const VIOLET: Color = Color::new(135, 60, 190, 255);
93    pub const ORCHID: Color = Color::new(218, 112, 214, 255);
94    pub const FUCHSIA: Color = Color::new(255, 0, 255, 255);
95    pub const MAGENTA: Color = Color::new(255, 0, 255, 255);
96    pub const MEDIUMORCHID: Color = Color::new(186, 85, 211, 255);
97    pub const MEDIUMPURPLE: Color = Color::new(147, 112, 219, 255);
98    pub const REBECCAPURPLE: Color = Color::new(102, 51, 153, 255);
99    pub const BLUEVIOLET: Color = Color::new(138, 43, 226, 255);
100    pub const DARKVIOLET: Color = Color::new(148, 0, 211, 255);
101    pub const DARKORCHID: Color = Color::new(153, 50, 204, 255);
102    pub const DARKMAGENTA: Color = Color::new(139, 0, 139, 255);
103    pub const PURPLE: Color = Color::new(200, 122, 255, 255);
104    pub const DARKPURPLE: Color = Color::new(112, 31, 126, 255);
105    pub const INDIGO: Color = Color::new(75, 0, 130, 255);
106    pub const SLATEBLUE: Color = Color::new(106, 90, 205, 255);
107    pub const DARKSLATEBLUE: Color = Color::new(72, 61, 139, 255);
108    pub const MEDIUMSLATEBLUE: Color = Color::new(123, 104, 238, 255);
109    pub const GREENYELLOW: Color = Color::new(173, 255, 47, 255);
110    pub const CHARTREUSE: Color = Color::new(127, 255, 0, 255);
111    pub const LAWNGREEN: Color = Color::new(124, 252, 0, 255);
112    pub const LIME: Color = Color::new(0, 158, 47, 255);
113    pub const LIMEGREEN: Color = Color::new(50, 205, 50, 255);
114    pub const PALEGREEN: Color = Color::new(152, 251, 152, 255);
115    pub const LIGHTGREEN: Color = Color::new(144, 238, 144, 255);
116    pub const MEDIUMSPRINGGREEN: Color = Color::new(0, 250, 154, 255);
117    pub const SPRINGGREEN: Color = Color::new(0, 255, 127, 255);
118    pub const MEDIUMSEAGREEN: Color = Color::new(60, 179, 113, 255);
119    pub const SEAGREEN: Color = Color::new(46, 139, 87, 255);
120    pub const FORESTGREEN: Color = Color::new(34, 139, 34, 255);
121    pub const GREEN: Color = Color::new(0, 228, 48, 255);
122    pub const DARKGREEN: Color = Color::new(0, 117, 44, 255);
123    pub const YELLOWGREEN: Color = Color::new(154, 205, 50, 255);
124    pub const OLIVEDRAB: Color = Color::new(107, 142, 35, 255);
125    pub const OLIVE: Color = Color::new(128, 128, 0, 255);
126    pub const DARKOLIVEGREEN: Color = Color::new(85, 107, 47, 255);
127    pub const MEDIUMAQUAMARINE: Color = Color::new(102, 205, 170, 255);
128    pub const DARKSEAGREEN: Color = Color::new(143, 188, 139, 255);
129    pub const LIGHTSEAGREEN: Color = Color::new(32, 178, 170, 255);
130    pub const DARKCYAN: Color = Color::new(0, 139, 139, 255);
131    pub const TEAL: Color = Color::new(0, 128, 128, 255);
132    pub const AQUA: Color = Color::new(0, 255, 255, 255);
133    pub const CYAN: Color = Color::new(0, 255, 255, 255);
134    pub const LIGHTCYAN: Color = Color::new(224, 255, 255, 255);
135    pub const PALETURQUOISE: Color = Color::new(175, 238, 238, 255);
136    pub const AQUAMARINE: Color = Color::new(127, 255, 212, 255);
137    pub const TURQUOISE: Color = Color::new(64, 224, 208, 255);
138    pub const MEDIUMTURQUOISE: Color = Color::new(72, 209, 204, 255);
139    pub const DARKTURQUOISE: Color = Color::new(0, 206, 209, 255);
140    pub const CADETBLUE: Color = Color::new(95, 158, 160, 255);
141    pub const STEELBLUE: Color = Color::new(70, 130, 180, 255);
142    pub const LIGHTSTEELBLUE: Color = Color::new(176, 196, 222, 255);
143    pub const POWDERBLUE: Color = Color::new(176, 224, 230, 255);
144    pub const LIGHTBLUE: Color = Color::new(173, 216, 230, 255);
145    pub const SKYBLUE: Color = Color::new(102, 191, 255, 255);
146    pub const LIGHTSKYBLUE: Color = Color::new(135, 206, 250, 255);
147    pub const DEEPSKYBLUE: Color = Color::new(0, 191, 255, 255);
148    pub const DODGERBLUE: Color = Color::new(30, 144, 255, 255);
149    pub const CORNFLOWERBLUE: Color = Color::new(100, 149, 237, 255);
150    pub const ROYALBLUE: Color = Color::new(65, 105, 225, 255);
151    pub const BLUE: Color = Color::new(0, 121, 241, 255);
152    pub const MEDIUMBLUE: Color = Color::new(0, 0, 205, 255);
153    pub const DARKBLUE: Color = Color::new(0, 82, 172, 255);
154    pub const NAVY: Color = Color::new(0, 0, 128, 255);
155    pub const MIDNIGHTBLUE: Color = Color::new(25, 25, 112, 255);
156    pub const CORNSILK: Color = Color::new(255, 248, 220, 255);
157    pub const BLANCHEDALMOND: Color = Color::new(255, 235, 205, 255);
158    pub const BISQUE: Color = Color::new(255, 228, 196, 255);
159    pub const NAVAJOWHITE: Color = Color::new(255, 222, 173, 255);
160    pub const WHEAT: Color = Color::new(245, 222, 179, 255);
161    pub const BURLYWOOD: Color = Color::new(222, 184, 135, 255);
162    pub const TAN: Color = Color::new(210, 180, 140, 255);
163    pub const ROSYBROWN: Color = Color::new(188, 143, 143, 255);
164    pub const SANDYBROWN: Color = Color::new(244, 164, 96, 255);
165    pub const GOLDENROD: Color = Color::new(218, 165, 32, 255);
166    pub const DARKGOLDENROD: Color = Color::new(184, 134, 11, 255);
167    pub const PERU: Color = Color::new(205, 133, 63, 255);
168    pub const CHOCOLATE: Color = Color::new(210, 105, 30, 255);
169    pub const SADDLEBROWN: Color = Color::new(139, 69, 19, 255);
170    pub const SIENNA: Color = Color::new(160, 82, 45, 255);
171    pub const BROWN: Color = Color::new(127, 106, 79, 255);
172    pub const DARKBROWN: Color = Color::new(76, 63, 47, 255);
173    pub const MAROON: Color = Color::new(190, 33, 55, 255);
174    pub const WHITE: Color = Color::new(255, 255, 255, 255);
175    pub const SNOW: Color = Color::new(255, 250, 250, 255);
176    pub const HONEYDEW: Color = Color::new(240, 255, 240, 255);
177    pub const MINTCREAM: Color = Color::new(245, 255, 250, 255);
178    pub const AZURE: Color = Color::new(240, 255, 255, 255);
179    pub const ALICEBLUE: Color = Color::new(240, 248, 255, 255);
180    pub const GHOSTWHITE: Color = Color::new(248, 248, 255, 255);
181    pub const WHITESMOKE: Color = Color::new(245, 245, 245, 255);
182    pub const SEASHELL: Color = Color::new(255, 245, 238, 255);
183    pub const BEIGE: Color = Color::new(211, 176, 131, 255);
184    pub const OLDLACE: Color = Color::new(253, 245, 230, 255);
185    pub const FLORALWHITE: Color = Color::new(255, 250, 240, 255);
186    pub const IVORY: Color = Color::new(255, 255, 240, 255);
187    pub const ANTIQUEWHITE: Color = Color::new(250, 235, 215, 255);
188    pub const LINEN: Color = Color::new(250, 240, 230, 255);
189    pub const LAVENDERBLUSH: Color = Color::new(255, 240, 245, 255);
190    pub const MISTYROSE: Color = Color::new(255, 228, 225, 255);
191    pub const GAINSBORO: Color = Color::new(220, 220, 220, 255);
192    pub const LIGHTGRAY: Color = Color::new(200, 200, 200, 255);
193    pub const SILVER: Color = Color::new(192, 192, 192, 255);
194    pub const DARKGRAY: Color = Color::new(80, 80, 80, 255);
195    pub const GRAY: Color = Color::new(130, 130, 130, 255);
196    pub const DIMGRAY: Color = Color::new(105, 105, 105, 255);
197    pub const LIGHTSLATEGRAY: Color = Color::new(119, 136, 153, 255);
198    pub const SLATEGRAY: Color = Color::new(112, 128, 144, 255);
199    pub const DARKSLATEGRAY: Color = Color::new(47, 79, 79, 255);
200    pub const BLACK: Color = Color::new(0, 0, 0, 255);
201    pub const BLANK: Color = Color::new(0, 0, 0, 0);
202    pub const RAYWHITE: Color = Color::new(245, 245, 245, 255);
203}