pub const BLUE: RGBA = RGBA {
r: 0,
g: 0,
b: 255,
a: 255,
};
pub const GREEN: RGBA = RGBA {
r: 0,
g: 255,
b: 0,
a: 255,
};
pub const RED: RGBA = RGBA {
r: 255,
g: 0,
b: 0,
a: 255,
};
pub const TRANSPARENT: RGBA = RGBA {
r: 0,
g: 0,
b: 0,
a: 0,
};
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct RGBA {
pub r: u32,
pub g: u32,
pub b: u32,
pub a: u32,
}
impl Default for RGBA {
fn default() -> Self {
RGBA {
r: 0,
g: 0,
b: 0,
a: 0,
}
}
}
impl RGBA {
pub fn new(r: u32, g: u32, b: u32, a: u32) -> Self {
Self { r, g, b, a }
}
pub fn from_hex(value: u32) -> Self {
Self {
r: ((value >> 24) & 0xFF) / 255, g: ((value >> 16) & 0xFF) / 255, b: ((value >> 8) & 0xFF) / 255, a: ((value) & 0xFF) / 255, }
}
pub fn to_hex(&self) -> u32 {
(self.a << 24) | (self.b << 16) | (self.g << 8) | self.r
}
}