1use crate::bridge::ffi;
4use crate::path::Path;
5use crate::stroke_rec::{StrokeCap, StrokeJoin};
6use cxx::UniquePtr;
7
8pub use crate::bridge::ffi::PaintStyle;
9
10impl Default for PaintStyle {
11 fn default() -> Self {
12 PaintStyle::Fill
13 }
14}
15
16pub struct Paint {
22 inner: UniquePtr<ffi::PaintHolder>,
23}
24
25impl Paint {
26 pub fn new() -> Self {
28 Self {
29 inner: ffi::paint_new(),
30 }
31 }
32
33 pub fn set_fill(&mut self) {
35 ffi::paint_set_fill(self.inner.pin_mut());
36 }
37
38 pub fn set_stroke(&mut self, enable: bool) {
40 ffi::paint_set_stroke(self.inner.pin_mut(), enable);
41 }
42
43 pub fn set_style(&mut self, style: PaintStyle) {
45 ffi::paint_set_style(self.inner.pin_mut(), style);
46 }
47
48 pub fn set_stroke_width(&mut self, width: f32) {
50 ffi::paint_set_stroke_width(self.inner.pin_mut(), width);
51 }
52
53 pub fn set_stroke_miter(&mut self, miter: f32) {
55 ffi::paint_set_stroke_miter(self.inner.pin_mut(), miter);
56 }
57
58 pub fn set_stroke_cap(&mut self, cap: StrokeCap) {
60 ffi::paint_set_stroke_cap(self.inner.pin_mut(), cap);
61 }
62
63 pub fn set_stroke_join(&mut self, join: StrokeJoin) {
65 ffi::paint_set_stroke_join(self.inner.pin_mut(), join);
66 }
67
68 pub fn get_fill_path(&self, path: &Path) -> Option<Path> {
74 let mut dst = Path::new();
75 let ok = ffi::paint_get_fill_path(
76 self.inner.as_ref().expect("Paint"),
77 path.as_raw(),
78 dst.as_raw_pin_mut(),
79 );
80 if ok {
81 Some(dst)
82 } else {
83 None
84 }
85 }
86
87 pub(crate) fn as_holder_ref(&self) -> &ffi::PaintHolder {
89 self.inner.as_ref().expect("Paint")
90 }
91}
92
93impl Default for Paint {
94 fn default() -> Self {
95 Self::new()
96 }
97}
98
99impl Clone for Paint {
100 fn clone(&self) -> Self {
101 Self {
102 inner: ffi::paint_clone(self.as_holder_ref()),
103 }
104 }
105}