use crate::bridge::ffi;
use crate::path::Path;
use crate::path_fill_type::PathFillType;
use crate::rect::Rect;
use crate::rrect::RRect;
use crate::{Direction, RectCorner};
use cxx::UniquePtr;
pub struct PathBuilder {
inner: UniquePtr<ffi::PathBuilderHolder>,
}
impl PathBuilder {
pub fn new() -> Self {
Self {
inner: ffi::path_builder_new(),
}
}
pub fn reset(&mut self) -> &mut Self {
ffi::path_builder_reset(self.inner.pin_mut());
self
}
pub fn fill_type(&self) -> PathFillType {
ffi::path_builder_fill_type(self.as_holder())
}
pub fn set_fill_type(&mut self, ft: PathFillType) -> &mut Self {
ffi::path_builder_set_fill_type(self.inner.pin_mut(), ft);
self
}
pub fn toggle_inverse_fill_type(&mut self) -> &mut Self {
ffi::path_builder_toggle_inverse_fill_type(self.inner.pin_mut());
self
}
pub fn snapshot(&self) -> Path {
Path::from_unique_ptr(ffi::path_builder_snapshot(self.as_holder()))
}
pub fn detach(&mut self) -> Path {
Path::from_unique_ptr(ffi::path_builder_detach(self.inner.pin_mut()))
}
pub fn move_to(&mut self, x: f32, y: f32) -> &mut Self {
ffi::path_builder_move_to(self.inner.pin_mut(), x, y);
self
}
pub fn line_to(&mut self, x: f32, y: f32) -> &mut Self {
ffi::path_builder_line_to(self.inner.pin_mut(), x, y);
self
}
pub fn quad_to(&mut self, x1: f32, y1: f32, x2: f32, y2: f32) -> &mut Self {
ffi::path_builder_quad_to(self.inner.pin_mut(), x1, y1, x2, y2);
self
}
pub fn cubic_to(
&mut self,
x1: f32,
y1: f32,
x2: f32,
y2: f32,
x3: f32,
y3: f32,
) -> &mut Self {
ffi::path_builder_cubic_to(self.inner.pin_mut(), x1, y1, x2, y2, x3, y3);
self
}
pub fn close(&mut self) -> &mut Self {
ffi::path_builder_close(self.inner.pin_mut());
self
}
pub fn add_rect(&mut self, rect: &Rect, dir: Direction, start: RectCorner) -> &mut Self {
let r: ffi::Rect = (*rect).into();
ffi::path_builder_add_rect(self.inner.pin_mut(), &r, dir, start);
self
}
pub fn add_oval(&mut self, rect: &Rect, dir: Direction) -> &mut Self {
let r: ffi::Rect = (*rect).into();
ffi::path_builder_add_oval(self.inner.pin_mut(), &r, dir);
self
}
pub fn add_circle(&mut self, cx: f32, cy: f32, radius: f32, dir: Direction) -> &mut Self {
ffi::path_builder_add_circle(self.inner.pin_mut(), cx, cy, radius, dir);
self
}
pub fn add_round_rect(
&mut self,
rect: &Rect,
rx: f32,
ry: f32,
dir: Direction,
) -> &mut Self {
let r: ffi::Rect = (*rect).into();
ffi::path_builder_add_round_rect(self.inner.pin_mut(), &r, rx, ry, dir);
self
}
pub fn add_rrect(&mut self, rrect: &RRect, dir: Direction) -> &mut Self {
let rr = rrect.as_ffi();
ffi::path_builder_add_rrect(self.inner.pin_mut(), &rr, dir);
self
}
pub fn add_rrect_with_start(
&mut self,
rrect: &RRect,
dir: Direction,
start: RectCorner,
) -> &mut Self {
let rr = rrect.as_ffi();
ffi::path_builder_add_rrect_start(self.inner.pin_mut(), &rr, dir, start);
self
}
pub fn add_path(&mut self, path: &Path) -> &mut Self {
ffi::path_builder_add_path(self.inner.pin_mut(), path.as_raw());
self
}
fn as_holder(&self) -> &ffi::PathBuilderHolder {
self.inner.as_ref().expect("PathBuilder")
}
}
impl Default for PathBuilder {
fn default() -> Self {
Self::new()
}
}