abletk/abletk-common/src/color.rs

31 lines
670 B
Rust
Executable File

#[cfg(windows)]
use windows::Win32::Graphics::Direct2D::Common::D2D1_COLOR_F;
#[derive(Copy, Clone, Debug)]
pub enum Color {
RGBA(f32, f32, f32, f32),
RGB(f32, f32, f32),
}
impl Color {
pub fn to_rgba(&self) -> (f32, f32, f32, f32) {
match *self {
Self::RGBA(r, g, b, a) => (r, g, b, a),
Self::RGB(r, g, b) => (r, g, b, 1.0),
}
}
}
#[cfg(windows)]
impl From<Color> for D2D1_COLOR_F {
fn from(color: Color) -> Self {
let rgba = color.to_rgba();
Self {
r: rgba.0,
g: rgba.1,
b: rgba.2,
a: rgba.3,
}
}
}