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!(
26    sb::SkSVGFeLighting_KernelUnitLength,
27    KernelUnitLength,
28    svg_kernel_unit_length_layout
29);
30
31pub type Lighting = RCHandle<sb::SkSVGFeLighting>;
32
33impl NodeSubtype for sb::SkSVGFeLighting {
34    type Base = sb::SkSVGFe;
35}
36
37impl DebugAttributes for Lighting {
38    const NAME: &'static str = "FeLighting";
39
40    fn _dbg(&self, builder: &mut std::fmt::DebugStruct) {
41        self.as_base()._dbg(
42            builder
43                .field("surface_scale", &self.surface_scale())
44                .field("kernel_unit_length", &self.kernel_unit_length()),
45        );
46    }
47}
48
49impl Lighting {
50    skia_svg_macros::attrs! {
51        SkSVGFeLighting => {
52            *surface_scale: scalar [get(value) => value, set(value) => value],
53            *kernel_unit_length?: KernelUnitLength [get(value) => value.map(KernelUnitLength::from_native_c), set(value) => value.into_native()]
54        }
55    }
56}
57
58pub type Specular = RCHandle<sb::SkSVGFeSpecularLighting>;
59
60impl NodeSubtype for sb::SkSVGFeSpecularLighting {
61    type Base = sb::SkSVGFeLighting;
62}
63
64impl_default_make!(Specular, sb::C_SkSVGFeSpecularLighting_Make);
65
66impl DebugAttributes for Specular {
67    const NAME: &'static str = "FeSpecularLighting";
68
69    fn _dbg(&self, builder: &mut std::fmt::DebugStruct) {
70        self.as_base()._dbg(
71            builder
72                .field("specular_constant", &self.specular_constant())
73                .field("specular_exponent", &self.specular_exponent()),
74        );
75    }
76}
77
78impl Specular {
79    skia_svg_macros::attrs! {
80        SkSVGFeSpecularLighting => {
81            *specular_constant: scalar [get(value) => value, set(value) => value],
82            *specular_exponent: scalar [get(value) => value, set(value) => value]
83        }
84    }
85}
86
87pub type Diffuse = RCHandle<sb::SkSVGFeDiffuseLighting>;
88
89impl NodeSubtype for sb::SkSVGFeDiffuseLighting {
90    type Base = sb::SkSVGFeLighting;
91}
92
93impl_default_make!(Diffuse, sb::C_SkSVGFeDiffuseLighting_Make);
94
95impl DebugAttributes for Diffuse {
96    const NAME: &'static str = "FeDiffuseLighting";
97
98    fn _dbg(&self, builder: &mut std::fmt::DebugStruct) {
99        self.as_base()
100            ._dbg(builder.field("diffuse_constant", &self.diffuse_constant()));
101    }
102}
103
104impl Diffuse {
105    skia_svg_macros::attrs! {
106        SkSVGFeDiffuseLighting => {
107            *diffuse_constant: scalar [get(value) => value, set(value) => value]
108        }
109    }
110}