use crate::bridge::ffi;
use crate::path::Path;
use crate::stroke_rec::{StrokeCap, StrokeJoin};
use cxx::UniquePtr;
pub use crate::bridge::ffi::PaintStyle;
impl Default for PaintStyle {
fn default() -> Self {
PaintStyle::Fill
}
}
pub struct Paint {
inner: UniquePtr<ffi::PaintHolder>,
}
impl Paint {
pub fn new() -> Self {
Self {
inner: ffi::paint_new(),
}
}
pub fn set_fill(&mut self) {
ffi::paint_set_fill(self.inner.pin_mut());
}
pub fn set_stroke(&mut self, enable: bool) {
ffi::paint_set_stroke(self.inner.pin_mut(), enable);
}
pub fn set_style(&mut self, style: PaintStyle) {
ffi::paint_set_style(self.inner.pin_mut(), style);
}
pub fn set_stroke_width(&mut self, width: f32) {
ffi::paint_set_stroke_width(self.inner.pin_mut(), width);
}
pub fn set_stroke_miter(&mut self, miter: f32) {
ffi::paint_set_stroke_miter(self.inner.pin_mut(), miter);
}
pub fn set_stroke_cap(&mut self, cap: StrokeCap) {
ffi::paint_set_stroke_cap(self.inner.pin_mut(), cap);
}
pub fn set_stroke_join(&mut self, join: StrokeJoin) {
ffi::paint_set_stroke_join(self.inner.pin_mut(), join);
}
pub fn get_fill_path(&self, path: &Path) -> Option<Path> {
let mut dst = Path::new();
let ok = ffi::paint_get_fill_path(
self.inner.as_ref().expect("Paint"),
path.as_raw(),
dst.as_raw_pin_mut(),
);
if ok {
Some(dst)
} else {
None
}
}
pub(crate) fn as_holder_ref(&self) -> &ffi::PaintHolder {
self.inner.as_ref().expect("Paint")
}
}
impl Default for Paint {
fn default() -> Self {
Self::new()
}
}
impl Clone for Paint {
fn clone(&self) -> Self {
Self {
inner: ffi::paint_clone(self.as_holder_ref()),
}
}
}