1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
use crate::prelude::*; use crate::{scalar, Canvas, Color, Path, Point3}; use core::borrow::BorrowMut; use skia_bindings as sb; use skia_bindings::SkShadowUtils; bitflags! { pub struct ShadowFlags: u32 { const TRANSPARENT_OCCLUDER = sb::SkShadowFlags_kTransparentOccluder_ShadowFlag as u32; const GEOMETRIC_ONLY = sb::SkShadowFlags_kGeometricOnly_ShadowFlag as u32; const ALL = Self::TRANSPARENT_OCCLUDER.bits | Self::GEOMETRIC_ONLY.bits; } } #[allow(clippy::too_many_arguments)] pub fn draw_shadow( mut canvas: impl AsMut<Canvas>, path: &Path, z_plane_params: impl Into<Point3>, light_pos: impl Into<Point3>, light_radius: scalar, ambient_color: impl Into<Color>, spot_color: impl Into<Color>, flags: impl Into<Option<ShadowFlags>>, ) { unsafe { SkShadowUtils::DrawShadow( canvas.as_mut().native_mut(), path.native(), z_plane_params.into().native(), light_pos.into().native(), light_radius, ambient_color.into().into_native(), spot_color.into().into_native(), flags.into().unwrap_or_else(ShadowFlags::empty).bits(), ) } } impl Canvas { #[allow(clippy::too_many_arguments)] pub fn draw_shadow( &mut self, path: &Path, z_plane_params: impl Into<Point3>, light_pos: impl Into<Point3>, light_radius: scalar, ambient_color: impl Into<Color>, spot_color: impl Into<Color>, flags: impl Into<Option<ShadowFlags>>, ) -> &mut Self { draw_shadow( self.borrow_mut(), path, z_plane_params, light_pos, light_radius, ambient_color, spot_color, flags, ); self } } pub fn compute_tonal_colors( ambient_color: impl Into<Color>, spot_color: impl Into<Color>, ) -> (Color, Color) { let mut out_ambient_color = Color::default(); let mut out_spot_color = Color::default(); unsafe { SkShadowUtils::ComputeTonalColors( ambient_color.into().into_native(), spot_color.into().into_native(), out_ambient_color.native_mut(), out_spot_color.native_mut(), ) } (out_ambient_color, out_spot_color) }