use bitflags::bitflags;
use crate::Vector3D;
use crate::media::Color;
use crate::rendering::composition::CompositionDropShadowSourcePolicy;
use crate::rendering::composition::ICompositionObject;
use crate::rendering::composition::ICompositionObjectHost;
use crate::rendering::composition::animations::AnimationInstanceFactory;
use crate::rendering::composition::animations::ICompositionAnimation;
use crate::rendering::composition::expressions::ExpressionVariant;
use crate::rendering::composition::server::AsServerRenderResource;
use crate::rendering::composition::server::CompositionProperty;
use crate::rendering::composition::server::CompositionPropertyOf;
use crate::rendering::composition::server::IServerAnimatedPropertyHost;
use crate::rendering::composition::server::IServerObject;
use crate::rendering::composition::server::ServerPropertyValue;
use crate::rendering::composition::server::ServerValueChange;
use crate::rendering::composition::server::props_of;
use crate::rendering::composition::server::read_server_object;
use crate::rendering::composition::transport::BatchStreamReader;
use crate::rendering::composition::transport::BatchStreamWriter;
use crate::rendering::composition::transport::BatchValue;
use crate::rendering::composition::transport::BatchValueReader;
use std::any::Any;
use std::any::TypeId;
use std::cell::Cell;
use std::cell::RefCell;
use std::rc::Rc;
use std::sync::OnceLock;
use std::time::Duration;
bitflags! {
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct DropShadowChangedFields: u16 {
const BLUR_RADIUS = 1;
const BLUR_RADIUS_ANIMATED = 2;
const COLOR = 4;
const COLOR_ANIMATED = 8;
const MASK = 16;
const OFFSET = 32;
const OFFSET_ANIMATED = 64;
const OPACITY = 128;
const OPACITY_ANIMATED = 256;
const SOURCE_POLICY = 512;
}
}
impl BatchValue for DropShadowChangedFields {
#[inline]
fn write_to(&self, out: &mut Vec<u8>) {
self.bits().write_to(out);
}
#[inline]
fn read_from(input: &mut BatchValueReader<'_>) -> Self {
DropShadowChangedFields::from_bits_retain(u16::read_from(input))
}
}
pub trait DropShadowHooks: ICompositionObjectHost {
fn initialize_defaults_extra(&self) {}
fn validate_blur_radius_change(&self, _old_value: f32, _new_value: f32) {}
fn on_blur_radius_changed(&self) {}
fn on_blur_radius_changing(&self) {}
fn validate_color_change(&self, _old_value: Color, _new_value: Color) {}
fn on_color_changed(&self) {}
fn on_color_changing(&self) {}
fn validate_mask_change(&self, _old_value: &Option<Rc<dyn ICompositionObject>>, _new_value: &Option<Rc<dyn ICompositionObject>>) {}
fn on_mask_changed(&self) {}
fn on_mask_changing(&self) {}
fn validate_offset_change(&self, _old_value: Vector3D, _new_value: Vector3D) {}
fn on_offset_changed(&self) {}
fn on_offset_changing(&self) {}
fn validate_opacity_change(&self, _old_value: f32, _new_value: f32) {}
fn on_opacity_changed(&self) {}
fn on_opacity_changing(&self) {}
fn validate_source_policy_change(&self, _old_value: CompositionDropShadowSourcePolicy, _new_value: CompositionDropShadowSourcePolicy) {}
fn on_source_policy_changed(&self) {}
fn on_source_policy_changing(&self) {}
}
pub struct DropShadowProps {
changed_fields_of_drop_shadow: Cell<DropShadowChangedFields>,
blur_radius: Cell<f32>,
color: Cell<Color>,
mask: RefCell<Option<Rc<dyn ICompositionObject>>>,
offset: Cell<Vector3D>,
opacity: Cell<f32>,
source_policy: Cell<CompositionDropShadowSourcePolicy>,
}
impl Default for DropShadowProps {
fn default() -> Self {
Self::new()
}
}
impl DropShadowProps {
pub fn new() -> Self {
Self {
changed_fields_of_drop_shadow: Cell::new(DropShadowChangedFields::empty()),
blur_radius: Cell::new(Default::default()),
color: Cell::new(Default::default()),
mask: RefCell::new(None),
offset: Cell::new(Default::default()),
opacity: Cell::new(Default::default()),
source_policy: Cell::new(Default::default()),
}
}
pub fn initialize_defaults(&self, host: &dyn DropShadowHooks) {
self.initialize_own_defaults(host);
}
pub fn initialize_own_defaults(&self, host: &dyn DropShadowHooks) {
DropShadowHooks::initialize_defaults_extra(host);
self.set_blur_radius(host, 9.0);
self.set_color(host, crate::media::Colors::BLACK);
self.set_opacity(host, 1.0);
}
pub fn blur_radius(&self) -> f32 {
self.blur_radius.get()
}
pub fn set_blur_radius(&self, host: &dyn DropShadowHooks, value: f32) {
let mut changed = false;
let old_value = self.blur_radius.get();
if old_value.differs(&value) {
DropShadowHooks::validate_blur_radius_change(host, old_value, value);
DropShadowHooks::on_blur_radius_changing(host);
changed = true;
self.blur_radius.set(value);
self.changed_fields_of_drop_shadow.set(self.changed_fields_of_drop_shadow.get() | DropShadowChangedFields::BLUR_RADIUS);
host.register_for_serialization();
host.pending_animations().remove(ServerDropShadowProps::id_of_blur_radius_property().base());
self.changed_fields_of_drop_shadow.set(self.changed_fields_of_drop_shadow.get() & !DropShadowChangedFields::BLUR_RADIUS_ANIMATED);
if let Some(animation) = host.implicit_animation("BlurRadius") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_drop_shadow.set(self.changed_fields_of_drop_shadow.get() | DropShadowChangedFields::BLUR_RADIUS_ANIMATED);
host.pending_animations().set(
ServerDropShadowProps::id_of_blur_radius_property().base(),
a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
);
}
host.start_animation_group(&animation, "BlurRadius", ExpressionVariant::create(value));
}
}
self.blur_radius.set(value);
if changed {
DropShadowHooks::on_blur_radius_changed(host);
}
}
pub fn color(&self) -> Color {
self.color.get()
}
pub fn set_color(&self, host: &dyn DropShadowHooks, value: Color) {
let mut changed = false;
let old_value = self.color.get();
if old_value.differs(&value) {
DropShadowHooks::validate_color_change(host, old_value, value);
DropShadowHooks::on_color_changing(host);
changed = true;
self.color.set(value);
self.changed_fields_of_drop_shadow.set(self.changed_fields_of_drop_shadow.get() | DropShadowChangedFields::COLOR);
host.register_for_serialization();
host.pending_animations().remove(ServerDropShadowProps::id_of_color_property().base());
self.changed_fields_of_drop_shadow.set(self.changed_fields_of_drop_shadow.get() & !DropShadowChangedFields::COLOR_ANIMATED);
if let Some(animation) = host.implicit_animation("Color") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_drop_shadow.set(self.changed_fields_of_drop_shadow.get() | DropShadowChangedFields::COLOR_ANIMATED);
host.pending_animations().set(
ServerDropShadowProps::id_of_color_property().base(),
a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
);
}
host.start_animation_group(&animation, "Color", ExpressionVariant::create(value));
}
}
self.color.set(value);
if changed {
DropShadowHooks::on_color_changed(host);
}
}
pub fn mask(&self) -> Option<Rc<dyn ICompositionObject>> {
self.mask.borrow().clone()
}
pub fn set_mask(&self, host: &dyn DropShadowHooks, value: Option<Rc<dyn ICompositionObject>>) {
let mut changed = false;
let old_value = self.mask.borrow().clone();
if old_value.differs(&value) {
DropShadowHooks::validate_mask_change(host, &old_value, &value);
DropShadowHooks::on_mask_changing(host);
changed = true;
*self.mask.borrow_mut() = value.clone();
self.changed_fields_of_drop_shadow.set(self.changed_fields_of_drop_shadow.get() | DropShadowChangedFields::MASK);
host.register_for_serialization();
}
*self.mask.borrow_mut() = value;
if changed {
DropShadowHooks::on_mask_changed(host);
}
}
pub fn offset(&self) -> Vector3D {
self.offset.get()
}
pub fn set_offset(&self, host: &dyn DropShadowHooks, value: Vector3D) {
let mut changed = false;
let old_value = self.offset.get();
if old_value.differs(&value) {
DropShadowHooks::validate_offset_change(host, old_value, value);
DropShadowHooks::on_offset_changing(host);
changed = true;
self.offset.set(value);
self.changed_fields_of_drop_shadow.set(self.changed_fields_of_drop_shadow.get() | DropShadowChangedFields::OFFSET);
host.register_for_serialization();
host.pending_animations().remove(ServerDropShadowProps::id_of_offset_property().base());
self.changed_fields_of_drop_shadow.set(self.changed_fields_of_drop_shadow.get() & !DropShadowChangedFields::OFFSET_ANIMATED);
if let Some(animation) = host.implicit_animation("Offset") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_drop_shadow.set(self.changed_fields_of_drop_shadow.get() | DropShadowChangedFields::OFFSET_ANIMATED);
host.pending_animations().set(
ServerDropShadowProps::id_of_offset_property().base(),
a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
);
}
host.start_animation_group(&animation, "Offset", ExpressionVariant::create(value));
}
}
self.offset.set(value);
if changed {
DropShadowHooks::on_offset_changed(host);
}
}
pub fn opacity(&self) -> f32 {
self.opacity.get()
}
pub fn set_opacity(&self, host: &dyn DropShadowHooks, value: f32) {
let mut changed = false;
let old_value = self.opacity.get();
if old_value.differs(&value) {
DropShadowHooks::validate_opacity_change(host, old_value, value);
DropShadowHooks::on_opacity_changing(host);
changed = true;
self.opacity.set(value);
self.changed_fields_of_drop_shadow.set(self.changed_fields_of_drop_shadow.get() | DropShadowChangedFields::OPACITY);
host.register_for_serialization();
host.pending_animations().remove(ServerDropShadowProps::id_of_opacity_property().base());
self.changed_fields_of_drop_shadow.set(self.changed_fields_of_drop_shadow.get() & !DropShadowChangedFields::OPACITY_ANIMATED);
if let Some(animation) = host.implicit_animation("Opacity") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_drop_shadow.set(self.changed_fields_of_drop_shadow.get() | DropShadowChangedFields::OPACITY_ANIMATED);
host.pending_animations().set(
ServerDropShadowProps::id_of_opacity_property().base(),
a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
);
}
host.start_animation_group(&animation, "Opacity", ExpressionVariant::create(value));
}
}
self.opacity.set(value);
if changed {
DropShadowHooks::on_opacity_changed(host);
}
}
pub fn source_policy(&self) -> CompositionDropShadowSourcePolicy {
self.source_policy.get()
}
pub fn set_source_policy(&self, host: &dyn DropShadowHooks, value: CompositionDropShadowSourcePolicy) {
let mut changed = false;
let old_value = self.source_policy.get();
if old_value.differs(&value) {
DropShadowHooks::validate_source_policy_change(host, old_value, value);
DropShadowHooks::on_source_policy_changing(host);
changed = true;
self.source_policy.set(value);
self.changed_fields_of_drop_shadow.set(self.changed_fields_of_drop_shadow.get() | DropShadowChangedFields::SOURCE_POLICY);
host.register_for_serialization();
}
self.source_policy.set(value);
if changed {
DropShadowHooks::on_source_policy_changed(host);
}
}
pub fn start_animation(
&self,
host: &dyn DropShadowHooks,
property_name: &str,
animation: &dyn ICompositionAnimation,
final_value: Option<ExpressionVariant>,
) -> bool {
if property_name == "BlurRadius" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerDropShadowProps::id_of_blur_radius_property().base(), server);
self.changed_fields_of_drop_shadow.set(self.changed_fields_of_drop_shadow.get() | DropShadowChangedFields::BLUR_RADIUS_ANIMATED);
host.register_for_serialization();
return true;
}
if property_name == "Color" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerDropShadowProps::id_of_color_property().base(), server);
self.changed_fields_of_drop_shadow.set(self.changed_fields_of_drop_shadow.get() | DropShadowChangedFields::COLOR_ANIMATED);
host.register_for_serialization();
return true;
}
if property_name == "Offset" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerDropShadowProps::id_of_offset_property().base(), server);
self.changed_fields_of_drop_shadow.set(self.changed_fields_of_drop_shadow.get() | DropShadowChangedFields::OFFSET_ANIMATED);
host.register_for_serialization();
return true;
}
if property_name == "Opacity" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerDropShadowProps::id_of_opacity_property().base(), server);
self.changed_fields_of_drop_shadow.set(self.changed_fields_of_drop_shadow.get() | DropShadowChangedFields::OPACITY_ANIMATED);
host.register_for_serialization();
return true;
}
false
}
pub fn serialize_changes_core(&self, host: &dyn DropShadowHooks, writer: &mut BatchStreamWriter<'_>) {
let changed = self.changed_fields_of_drop_shadow.get();
writer.write(changed);
if changed.contains(DropShadowChangedFields::BLUR_RADIUS_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerDropShadowProps::id_of_blur_radius_property().base()));
} else if changed.contains(DropShadowChangedFields::BLUR_RADIUS) {
writer.write(self.blur_radius.get());
}
if changed.contains(DropShadowChangedFields::COLOR_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerDropShadowProps::id_of_color_property().base()));
} else if changed.contains(DropShadowChangedFields::COLOR) {
writer.write(self.color.get());
}
if changed.contains(DropShadowChangedFields::MASK) {
writer.write_server_object(self.mask.borrow().clone().map(|o| o.server()));
}
if changed.contains(DropShadowChangedFields::OFFSET_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerDropShadowProps::id_of_offset_property().base()));
} else if changed.contains(DropShadowChangedFields::OFFSET) {
writer.write(self.offset.get());
}
if changed.contains(DropShadowChangedFields::OPACITY_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerDropShadowProps::id_of_opacity_property().base()));
} else if changed.contains(DropShadowChangedFields::OPACITY) {
writer.write(self.opacity.get());
}
if changed.contains(DropShadowChangedFields::SOURCE_POLICY) {
writer.write(self.source_policy.get());
}
self.changed_fields_of_drop_shadow.set(DropShadowChangedFields::empty());
}
}
pub trait ServerDropShadowHooks: IServerAnimatedPropertyHost {
fn deserialize_changes_extra(&self, _reader: &mut BatchStreamReader<'_>) {}
fn on_fields_deserialized(&self, _changed: DropShadowChangedFields) {}
fn on_mask_changed(&self) {}
fn on_mask_changing(&self) {}
fn on_source_policy_changed(&self) {}
fn on_source_policy_changing(&self) {}
}
pub struct ServerDropShadowProps {
blur_radius: Cell<f32>,
color: Cell<Color>,
mask: RefCell<Option<Rc<dyn IServerObject>>>,
offset: Cell<Vector3D>,
opacity: Cell<f32>,
source_policy: Cell<CompositionDropShadowSourcePolicy>,
}
impl Default for ServerDropShadowProps {
fn default() -> Self {
Self::new()
}
}
impl ServerDropShadowProps {
pub fn new() -> Self {
Self {
blur_radius: Cell::new(Default::default()),
color: Cell::new(Default::default()),
mask: RefCell::new(None),
offset: Cell::new(Default::default()),
opacity: Cell::new(Default::default()),
source_policy: Cell::new(Default::default()),
}
}
pub fn find_props(&self, type_id: TypeId) -> Option<&dyn Any> {
if type_id == TypeId::of::<Self>() {
return Some(self);
}
None
}
pub fn id_of_blur_radius_property() -> &'static CompositionPropertyOf<f32> {
static PROPERTY: OnceLock<CompositionPropertyOf<f32>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerDropShadowProps, f32>(
"BlurRadius",
"ServerDropShadow",
|obj| props_of::<ServerDropShadowProps>(obj).blur_radius.get(),
|obj, v| props_of::<ServerDropShadowProps>(obj).blur_radius.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerDropShadowProps>(obj).blur_radius.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerDropShadowProps>(obj).blur_radius.set(v.cast_or_default::<f32>())),
)
})
}
pub fn blur_radius(&self) -> f32 {
self.blur_radius.get()
}
pub fn set_blur_radius(&self, host: &dyn ServerDropShadowHooks, value: f32) {
self.blur_radius.set(value);
host.remove_animation_for_property(Self::id_of_blur_radius_property().base());
}
pub fn id_of_color_property() -> &'static CompositionPropertyOf<Color> {
static PROPERTY: OnceLock<CompositionPropertyOf<Color>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerDropShadowProps, Color>(
"Color",
"ServerDropShadow",
|obj| props_of::<ServerDropShadowProps>(obj).color.get(),
|obj, v| props_of::<ServerDropShadowProps>(obj).color.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerDropShadowProps>(obj).color.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerDropShadowProps>(obj).color.set(v.cast_or_default::<Color>())),
)
})
}
pub fn color(&self) -> Color {
self.color.get()
}
pub fn set_color(&self, host: &dyn ServerDropShadowHooks, value: Color) {
self.color.set(value);
host.remove_animation_for_property(Self::id_of_color_property().base());
}
pub fn id_of_mask_property() -> &'static CompositionPropertyOf<Option<Rc<dyn IServerObject>>> {
static PROPERTY: OnceLock<CompositionPropertyOf<Option<Rc<dyn IServerObject>>>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerDropShadowProps, Option<Rc<dyn IServerObject>>>(
"Mask",
"ServerDropShadow",
|obj| props_of::<ServerDropShadowProps>(obj).mask.borrow().clone(),
|obj, v| *props_of::<ServerDropShadowProps>(obj).mask.borrow_mut() = v,
None,
None,
)
})
}
pub fn mask(&self) -> Option<Rc<dyn IServerObject>> {
self.mask.borrow().clone()
}
pub fn set_mask(&self, host: &dyn ServerDropShadowHooks, value: Option<Rc<dyn IServerObject>>) {
let old_value = self.mask.borrow().clone();
let mut changed = false;
if old_value.differs(&value) {
ServerDropShadowHooks::on_mask_changing(host);
changed = true;
}
host.set_value(
Self::id_of_mask_property().base(),
ServerValueChange {
equal: old_value.default_equals(&value),
old_resource: old_value.as_server_render_resource(),
new_resource: value.as_server_render_resource(),
assign: &mut || *self.mask.borrow_mut() = value.clone(),
},
);
if changed {
ServerDropShadowHooks::on_mask_changed(host);
}
}
pub fn id_of_offset_property() -> &'static CompositionPropertyOf<Vector3D> {
static PROPERTY: OnceLock<CompositionPropertyOf<Vector3D>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerDropShadowProps, Vector3D>(
"Offset",
"ServerDropShadow",
|obj| props_of::<ServerDropShadowProps>(obj).offset.get(),
|obj, v| props_of::<ServerDropShadowProps>(obj).offset.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerDropShadowProps>(obj).offset.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerDropShadowProps>(obj).offset.set(v.cast_or_default::<Vector3D>())),
)
})
}
pub fn offset(&self) -> Vector3D {
self.offset.get()
}
pub fn set_offset(&self, host: &dyn ServerDropShadowHooks, value: Vector3D) {
self.offset.set(value);
host.remove_animation_for_property(Self::id_of_offset_property().base());
}
pub fn id_of_opacity_property() -> &'static CompositionPropertyOf<f32> {
static PROPERTY: OnceLock<CompositionPropertyOf<f32>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerDropShadowProps, f32>(
"Opacity",
"ServerDropShadow",
|obj| props_of::<ServerDropShadowProps>(obj).opacity.get(),
|obj, v| props_of::<ServerDropShadowProps>(obj).opacity.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerDropShadowProps>(obj).opacity.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerDropShadowProps>(obj).opacity.set(v.cast_or_default::<f32>())),
)
})
}
pub fn opacity(&self) -> f32 {
self.opacity.get()
}
pub fn set_opacity(&self, host: &dyn ServerDropShadowHooks, value: f32) {
self.opacity.set(value);
host.remove_animation_for_property(Self::id_of_opacity_property().base());
}
pub fn id_of_source_policy_property() -> &'static CompositionPropertyOf<CompositionDropShadowSourcePolicy> {
static PROPERTY: OnceLock<CompositionPropertyOf<CompositionDropShadowSourcePolicy>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerDropShadowProps, CompositionDropShadowSourcePolicy>(
"SourcePolicy",
"ServerDropShadow",
|obj| props_of::<ServerDropShadowProps>(obj).source_policy.get(),
|obj, v| props_of::<ServerDropShadowProps>(obj).source_policy.set(v),
None,
None,
)
})
}
pub fn source_policy(&self) -> CompositionDropShadowSourcePolicy {
self.source_policy.get()
}
pub fn set_source_policy(&self, host: &dyn ServerDropShadowHooks, value: CompositionDropShadowSourcePolicy) {
let old_value = self.source_policy.get();
let mut changed = false;
if old_value.differs(&value) {
ServerDropShadowHooks::on_source_policy_changing(host);
changed = true;
}
host.set_value(
Self::id_of_source_policy_property().base(),
ServerValueChange {
equal: old_value.default_equals(&value),
old_resource: None,
new_resource: None,
assign: &mut || self.source_policy.set(value),
},
);
if changed {
ServerDropShadowHooks::on_source_policy_changed(host);
}
}
pub fn deserialize_changes_core(
&self,
host: &dyn ServerDropShadowHooks,
reader: &mut BatchStreamReader<'_>,
committed_at: Duration,
) {
let compositor = host.server_compositor();
ServerDropShadowHooks::deserialize_changes_extra(host, reader);
let changed = reader.read::<DropShadowChangedFields>();
if changed.contains(DropShadowChangedFields::BLUR_RADIUS_ANIMATED) {
let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
panic!("a batch starts an animation of `BlurRadius` without an animation instance");
};
host.set_animated_value(
Self::id_of_blur_radius_property().base(),
ExpressionVariant::create(self.blur_radius.get()),
committed_at,
animation,
);
} else if changed.contains(DropShadowChangedFields::BLUR_RADIUS) {
let value = reader.read::<f32>();
self.set_blur_radius(host, value);
}
if changed.contains(DropShadowChangedFields::COLOR_ANIMATED) {
let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
panic!("a batch starts an animation of `Color` without an animation instance");
};
host.set_animated_value(
Self::id_of_color_property().base(),
ExpressionVariant::create(self.color.get()),
committed_at,
animation,
);
} else if changed.contains(DropShadowChangedFields::COLOR) {
let value = reader.read::<Color>();
self.set_color(host, value);
}
if changed.contains(DropShadowChangedFields::MASK) {
let value = read_server_object(reader, compositor.as_ref());
self.set_mask(host, value);
}
if changed.contains(DropShadowChangedFields::OFFSET_ANIMATED) {
let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
panic!("a batch starts an animation of `Offset` without an animation instance");
};
host.set_animated_value(
Self::id_of_offset_property().base(),
ExpressionVariant::create(self.offset.get()),
committed_at,
animation,
);
} else if changed.contains(DropShadowChangedFields::OFFSET) {
let value = reader.read::<Vector3D>();
self.set_offset(host, value);
}
if changed.contains(DropShadowChangedFields::OPACITY_ANIMATED) {
let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
panic!("a batch starts an animation of `Opacity` without an animation instance");
};
host.set_animated_value(
Self::id_of_opacity_property().base(),
ExpressionVariant::create(self.opacity.get()),
committed_at,
animation,
);
} else if changed.contains(DropShadowChangedFields::OPACITY) {
let value = reader.read::<f32>();
self.set_opacity(host, value);
}
if changed.contains(DropShadowChangedFields::SOURCE_POLICY) {
let value = reader.read::<CompositionDropShadowSourcePolicy>();
self.set_source_policy(host, value);
}
ServerDropShadowHooks::on_fields_deserialized(host, changed);
}
pub fn get_composition_property(name: &str) -> Option<&'static CompositionProperty> {
if name == "BlurRadius" {
return Some(Self::id_of_blur_radius_property().base());
}
if name == "Color" {
return Some(Self::id_of_color_property().base());
}
if name == "Offset" {
return Some(Self::id_of_offset_property().base());
}
if name == "Opacity" {
return Some(Self::id_of_opacity_property().base());
}
None
}
}