abletk/abletk-direct2d/src/brush.rs

49 lines
1.2 KiB
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/.
*/
use std::mem;
use windows::{
Foundation::Numerics::*,
Win32::Graphics::Direct2D::Common::*, Win32::Graphics::Direct2D::*,
};
/// The default brush color is black.
pub(crate) const DEFAULT_BRUSH_COLOR: D2D1_COLOR_F = D2D1_COLOR_F {
r: 0.0,
g: 0.0,
b: 0.0,
a: 1.0,
};
pub(crate) const DEFAULT_BRUSH_PROPERTIES: D2D1_BRUSH_PROPERTIES = D2D1_BRUSH_PROPERTIES {
opacity: 1.0,
transform: Matrix3x2::identity(),
};
#[derive(Copy, Clone, Debug)]
pub enum Brush {
Solid(D2D1_COLOR_F),
}
impl Brush {
pub(crate) fn to_brush(&self, target: &ID2D1HwndRenderTarget) -> ID2D1Brush {
match self {
Brush::Solid(color) => unsafe {
mem::transmute(
target.CreateSolidColorBrush(
color,
&DEFAULT_BRUSH_PROPERTIES,
).unwrap()
)
},
}
}
}