abletk/abletk-common/src/color.rs

39 lines
958 B
Rust
Executable File

/*
* Copyright (C) 2022 Umut İnan Erdoğan <umutinanerdogan@pm.me>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#[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,
}
}
}