skia_safe/modules/svg/fe/
lighting.rs

1use super::{DebugAttributes, NodeSubtype};
2use crate::{impl_default_make, prelude::*, scalar};
3use skia_bindings as sb;
4
5#[repr(C)]
6#[derive(Debug, Copy, Clone)]
7pub struct KernelUnitLength {
8    pub dx: scalar,
9    pub dy: scalar,
10}
11
12impl KernelUnitLength {
13    pub fn new(dx: scalar, dy: scalar) -> Self {
14        Self { dx, dy }
15    }
16
17    pub fn new_all(value: scalar) -> Self {
18        Self {
19            dx: value,
20            dy: value,
21        }
22    }
23}
24
25native_transmutable!(sb::SkSVGFeLighting_KernelUnitLength, KernelUnitLength);
26
27pub type Lighting = RCHandle<sb::SkSVGFeLighting>;
28
29impl NodeSubtype for sb::SkSVGFeLighting {
30    type Base = sb::SkSVGFe;
31}
32
33impl DebugAttributes for Lighting {
34    const NAME: &'static str = "FeLighting";
35
36    fn _dbg(&self, builder: &mut std::fmt::DebugStruct) {
37        self.as_base()._dbg(
38            builder
39                .field("surface_scale", &self.surface_scale())
40                .field("kernel_unit_length", &self.kernel_unit_length()),
41        );
42    }
43}
44
45impl Lighting {
46    skia_svg_macros::attrs! {
47        SkSVGFeLighting => {
48            *surface_scale: scalar [get(value) => value, set(value) => value],
49            *kernel_unit_length?: KernelUnitLength [get(value) => value.map(KernelUnitLength::from_native_c), set(value) => value.into_native()]
50        }
51    }
52}
53
54pub type Specular = RCHandle<sb::SkSVGFeSpecularLighting>;
55
56impl NodeSubtype for sb::SkSVGFeSpecularLighting {
57    type Base = sb::SkSVGFeLighting;
58}
59
60impl_default_make!(Specular, sb::C_SkSVGFeSpecularLighting_Make);
61
62impl DebugAttributes for Specular {
63    const NAME: &'static str = "FeSpecularLighting";
64
65    fn _dbg(&self, builder: &mut std::fmt::DebugStruct) {
66        self.as_base()._dbg(
67            builder
68                .field("specular_constant", &self.specular_constant())
69                .field("specular_exponent", &self.specular_exponent()),
70        );
71    }
72}
73
74impl Specular {
75    skia_svg_macros::attrs! {
76        SkSVGFeSpecularLighting => {
77            *specular_constant: scalar [get(value) => value, set(value) => value],
78            *specular_exponent: scalar [get(value) => value, set(value) => value]
79        }
80    }
81}
82
83pub type Diffuse = RCHandle<sb::SkSVGFeDiffuseLighting>;
84
85impl NodeSubtype for sb::SkSVGFeDiffuseLighting {
86    type Base = sb::SkSVGFeLighting;
87}
88
89impl_default_make!(Diffuse, sb::C_SkSVGFeDiffuseLighting_Make);
90
91impl DebugAttributes for Diffuse {
92    const NAME: &'static str = "FeDiffuseLighting";
93
94    fn _dbg(&self, builder: &mut std::fmt::DebugStruct) {
95        self.as_base()
96            ._dbg(builder.field("diffuse_constant", &self.diffuse_constant()));
97    }
98}
99
100impl Diffuse {
101    skia_svg_macros::attrs! {
102        SkSVGFeDiffuseLighting => {
103            *diffuse_constant: scalar [get(value) => value, set(value) => value]
104        }
105    }
106}