use bitflags::bitflags;
use crate::Matrix;
use crate::RelativePoint;
use crate::Vector;
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::CompositionProperty;
use crate::rendering::composition::server::CompositionPropertyOf;
use crate::rendering::composition::server::IServerAnimatedPropertyHost;
use crate::rendering::composition::server::ServerPropertyValue;
use crate::rendering::composition::server::props_of;
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::sync::OnceLock;
use std::time::Duration;
bitflags! {
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct CompositionLinearGradientBrushChangedFields: u16 {
const START_POINT = 1;
const START_POINT_ANIMATED = 2;
const END_POINT = 4;
const END_POINT_ANIMATED = 8;
const ANCHOR_POINT = 16;
const ANCHOR_POINT_ANIMATED = 32;
const CENTER_POINT = 64;
const CENTER_POINT_ANIMATED = 128;
const OFFSET = 256;
const OFFSET_ANIMATED = 512;
const ROTATION_ANGLE = 1024;
const ROTATION_ANGLE_ANIMATED = 2048;
const SCALE = 4096;
const SCALE_ANIMATED = 8192;
const TRANSFORM_MATRIX = 16384;
const TRANSFORM_MATRIX_ANIMATED = 32768;
}
}
impl BatchValue for CompositionLinearGradientBrushChangedFields {
#[inline]
fn write_to(&self, out: &mut Vec<u8>) {
self.bits().write_to(out);
}
#[inline]
fn read_from(input: &mut BatchValueReader<'_>) -> Self {
CompositionLinearGradientBrushChangedFields::from_bits_retain(u16::read_from(input))
}
}
pub trait CompositionLinearGradientBrushHooks: ICompositionObjectHost {
fn base_serialize_changes_core(&self, writer: &mut BatchStreamWriter<'_>);
fn initialize_defaults_extra(&self) {}
fn validate_start_point_change(&self, _old_value: RelativePoint, _new_value: RelativePoint) {}
fn on_start_point_changed(&self) {}
fn on_start_point_changing(&self) {}
fn validate_end_point_change(&self, _old_value: RelativePoint, _new_value: RelativePoint) {}
fn on_end_point_changed(&self) {}
fn on_end_point_changing(&self) {}
fn validate_anchor_point_change(&self, _old_value: Vector, _new_value: Vector) {}
fn on_anchor_point_changed(&self) {}
fn on_anchor_point_changing(&self) {}
fn validate_center_point_change(&self, _old_value: Vector, _new_value: Vector) {}
fn on_center_point_changed(&self) {}
fn on_center_point_changing(&self) {}
fn validate_offset_change(&self, _old_value: Vector, _new_value: Vector) {}
fn on_offset_changed(&self) {}
fn on_offset_changing(&self) {}
fn validate_rotation_angle_change(&self, _old_value: f32, _new_value: f32) {}
fn on_rotation_angle_changed(&self) {}
fn on_rotation_angle_changing(&self) {}
fn validate_scale_change(&self, _old_value: Vector, _new_value: Vector) {}
fn on_scale_changed(&self) {}
fn on_scale_changing(&self) {}
fn validate_transform_matrix_change(&self, _old_value: Matrix, _new_value: Matrix) {}
fn on_transform_matrix_changed(&self) {}
fn on_transform_matrix_changing(&self) {}
}
pub struct CompositionLinearGradientBrushProps {
changed_fields_of_composition_linear_gradient_brush: Cell<CompositionLinearGradientBrushChangedFields>,
start_point: Cell<RelativePoint>,
end_point: Cell<RelativePoint>,
anchor_point: Cell<Vector>,
center_point: Cell<Vector>,
offset: Cell<Vector>,
rotation_angle: Cell<f32>,
scale: Cell<Vector>,
transform_matrix: Cell<Matrix>,
}
impl Default for CompositionLinearGradientBrushProps {
fn default() -> Self {
Self::new()
}
}
impl CompositionLinearGradientBrushProps {
pub fn new() -> Self {
Self {
changed_fields_of_composition_linear_gradient_brush: Cell::new(CompositionLinearGradientBrushChangedFields::empty()),
start_point: Cell::new(Default::default()),
end_point: Cell::new(Default::default()),
anchor_point: Cell::new(Default::default()),
center_point: Cell::new(Default::default()),
offset: Cell::new(Default::default()),
rotation_angle: Cell::new(Default::default()),
scale: Cell::new(Default::default()),
transform_matrix: Cell::new(Default::default()),
}
}
pub fn initialize_defaults(&self, host: &dyn CompositionLinearGradientBrushHooks) {
self.initialize_own_defaults(host);
}
pub fn initialize_own_defaults(&self, host: &dyn CompositionLinearGradientBrushHooks) {
CompositionLinearGradientBrushHooks::initialize_defaults_extra(host);
self.set_scale(host, Vector::new(1.0, 1.0));
self.set_transform_matrix(host, Matrix::IDENTITY);
}
pub fn start_point(&self) -> RelativePoint {
self.start_point.get()
}
pub fn set_start_point(&self, host: &dyn CompositionLinearGradientBrushHooks, value: RelativePoint) {
let mut changed = false;
let old_value = self.start_point.get();
if old_value.differs(&value) {
CompositionLinearGradientBrushHooks::validate_start_point_change(host, old_value, value);
CompositionLinearGradientBrushHooks::on_start_point_changing(host);
changed = true;
self.start_point.set(value);
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() | CompositionLinearGradientBrushChangedFields::START_POINT);
host.register_for_serialization();
host.pending_animations().remove(ServerCompositionLinearGradientBrushProps::id_of_start_point_property().base());
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() & !CompositionLinearGradientBrushChangedFields::START_POINT_ANIMATED);
if let Some(animation) = host.implicit_animation("StartPoint") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() | CompositionLinearGradientBrushChangedFields::START_POINT_ANIMATED);
host.pending_animations().set(
ServerCompositionLinearGradientBrushProps::id_of_start_point_property().base(),
a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
);
}
host.start_animation_group(&animation, "StartPoint", ExpressionVariant::create(value));
}
}
self.start_point.set(value);
if changed {
CompositionLinearGradientBrushHooks::on_start_point_changed(host);
}
}
pub fn end_point(&self) -> RelativePoint {
self.end_point.get()
}
pub fn set_end_point(&self, host: &dyn CompositionLinearGradientBrushHooks, value: RelativePoint) {
let mut changed = false;
let old_value = self.end_point.get();
if old_value.differs(&value) {
CompositionLinearGradientBrushHooks::validate_end_point_change(host, old_value, value);
CompositionLinearGradientBrushHooks::on_end_point_changing(host);
changed = true;
self.end_point.set(value);
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() | CompositionLinearGradientBrushChangedFields::END_POINT);
host.register_for_serialization();
host.pending_animations().remove(ServerCompositionLinearGradientBrushProps::id_of_end_point_property().base());
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() & !CompositionLinearGradientBrushChangedFields::END_POINT_ANIMATED);
if let Some(animation) = host.implicit_animation("EndPoint") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() | CompositionLinearGradientBrushChangedFields::END_POINT_ANIMATED);
host.pending_animations().set(
ServerCompositionLinearGradientBrushProps::id_of_end_point_property().base(),
a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
);
}
host.start_animation_group(&animation, "EndPoint", ExpressionVariant::create(value));
}
}
self.end_point.set(value);
if changed {
CompositionLinearGradientBrushHooks::on_end_point_changed(host);
}
}
pub fn anchor_point(&self) -> Vector {
self.anchor_point.get()
}
pub fn set_anchor_point(&self, host: &dyn CompositionLinearGradientBrushHooks, value: Vector) {
let mut changed = false;
let old_value = self.anchor_point.get();
if old_value.differs(&value) {
CompositionLinearGradientBrushHooks::validate_anchor_point_change(host, old_value, value);
CompositionLinearGradientBrushHooks::on_anchor_point_changing(host);
changed = true;
self.anchor_point.set(value);
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() | CompositionLinearGradientBrushChangedFields::ANCHOR_POINT);
host.register_for_serialization();
host.pending_animations().remove(ServerCompositionLinearGradientBrushProps::id_of_anchor_point_property().base());
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() & !CompositionLinearGradientBrushChangedFields::ANCHOR_POINT_ANIMATED);
if let Some(animation) = host.implicit_animation("AnchorPoint") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() | CompositionLinearGradientBrushChangedFields::ANCHOR_POINT_ANIMATED);
host.pending_animations().set(
ServerCompositionLinearGradientBrushProps::id_of_anchor_point_property().base(),
a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
);
}
host.start_animation_group(&animation, "AnchorPoint", ExpressionVariant::create(value));
}
}
self.anchor_point.set(value);
if changed {
CompositionLinearGradientBrushHooks::on_anchor_point_changed(host);
}
}
pub fn center_point(&self) -> Vector {
self.center_point.get()
}
pub fn set_center_point(&self, host: &dyn CompositionLinearGradientBrushHooks, value: Vector) {
let mut changed = false;
let old_value = self.center_point.get();
if old_value.differs(&value) {
CompositionLinearGradientBrushHooks::validate_center_point_change(host, old_value, value);
CompositionLinearGradientBrushHooks::on_center_point_changing(host);
changed = true;
self.center_point.set(value);
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() | CompositionLinearGradientBrushChangedFields::CENTER_POINT);
host.register_for_serialization();
host.pending_animations().remove(ServerCompositionLinearGradientBrushProps::id_of_center_point_property().base());
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() & !CompositionLinearGradientBrushChangedFields::CENTER_POINT_ANIMATED);
if let Some(animation) = host.implicit_animation("CenterPoint") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() | CompositionLinearGradientBrushChangedFields::CENTER_POINT_ANIMATED);
host.pending_animations().set(
ServerCompositionLinearGradientBrushProps::id_of_center_point_property().base(),
a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
);
}
host.start_animation_group(&animation, "CenterPoint", ExpressionVariant::create(value));
}
}
self.center_point.set(value);
if changed {
CompositionLinearGradientBrushHooks::on_center_point_changed(host);
}
}
pub fn offset(&self) -> Vector {
self.offset.get()
}
pub fn set_offset(&self, host: &dyn CompositionLinearGradientBrushHooks, value: Vector) {
let mut changed = false;
let old_value = self.offset.get();
if old_value.differs(&value) {
CompositionLinearGradientBrushHooks::validate_offset_change(host, old_value, value);
CompositionLinearGradientBrushHooks::on_offset_changing(host);
changed = true;
self.offset.set(value);
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() | CompositionLinearGradientBrushChangedFields::OFFSET);
host.register_for_serialization();
host.pending_animations().remove(ServerCompositionLinearGradientBrushProps::id_of_offset_property().base());
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() & !CompositionLinearGradientBrushChangedFields::OFFSET_ANIMATED);
if let Some(animation) = host.implicit_animation("Offset") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() | CompositionLinearGradientBrushChangedFields::OFFSET_ANIMATED);
host.pending_animations().set(
ServerCompositionLinearGradientBrushProps::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 {
CompositionLinearGradientBrushHooks::on_offset_changed(host);
}
}
pub fn rotation_angle(&self) -> f32 {
self.rotation_angle.get()
}
pub fn set_rotation_angle(&self, host: &dyn CompositionLinearGradientBrushHooks, value: f32) {
let mut changed = false;
let old_value = self.rotation_angle.get();
if old_value.differs(&value) {
CompositionLinearGradientBrushHooks::validate_rotation_angle_change(host, old_value, value);
CompositionLinearGradientBrushHooks::on_rotation_angle_changing(host);
changed = true;
self.rotation_angle.set(value);
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() | CompositionLinearGradientBrushChangedFields::ROTATION_ANGLE);
host.register_for_serialization();
host.pending_animations().remove(ServerCompositionLinearGradientBrushProps::id_of_rotation_angle_property().base());
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() & !CompositionLinearGradientBrushChangedFields::ROTATION_ANGLE_ANIMATED);
if let Some(animation) = host.implicit_animation("RotationAngle") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() | CompositionLinearGradientBrushChangedFields::ROTATION_ANGLE_ANIMATED);
host.pending_animations().set(
ServerCompositionLinearGradientBrushProps::id_of_rotation_angle_property().base(),
a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
);
}
host.start_animation_group(&animation, "RotationAngle", ExpressionVariant::create(value));
}
}
self.rotation_angle.set(value);
if changed {
CompositionLinearGradientBrushHooks::on_rotation_angle_changed(host);
}
}
pub fn scale(&self) -> Vector {
self.scale.get()
}
pub fn set_scale(&self, host: &dyn CompositionLinearGradientBrushHooks, value: Vector) {
let mut changed = false;
let old_value = self.scale.get();
if old_value.differs(&value) {
CompositionLinearGradientBrushHooks::validate_scale_change(host, old_value, value);
CompositionLinearGradientBrushHooks::on_scale_changing(host);
changed = true;
self.scale.set(value);
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() | CompositionLinearGradientBrushChangedFields::SCALE);
host.register_for_serialization();
host.pending_animations().remove(ServerCompositionLinearGradientBrushProps::id_of_scale_property().base());
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() & !CompositionLinearGradientBrushChangedFields::SCALE_ANIMATED);
if let Some(animation) = host.implicit_animation("Scale") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() | CompositionLinearGradientBrushChangedFields::SCALE_ANIMATED);
host.pending_animations().set(
ServerCompositionLinearGradientBrushProps::id_of_scale_property().base(),
a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
);
}
host.start_animation_group(&animation, "Scale", ExpressionVariant::create(value));
}
}
self.scale.set(value);
if changed {
CompositionLinearGradientBrushHooks::on_scale_changed(host);
}
}
pub fn transform_matrix(&self) -> Matrix {
self.transform_matrix.get()
}
pub fn set_transform_matrix(&self, host: &dyn CompositionLinearGradientBrushHooks, value: Matrix) {
let mut changed = false;
let old_value = self.transform_matrix.get();
if old_value.differs(&value) {
CompositionLinearGradientBrushHooks::validate_transform_matrix_change(host, old_value, value);
CompositionLinearGradientBrushHooks::on_transform_matrix_changing(host);
changed = true;
self.transform_matrix.set(value);
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() | CompositionLinearGradientBrushChangedFields::TRANSFORM_MATRIX);
host.register_for_serialization();
host.pending_animations().remove(ServerCompositionLinearGradientBrushProps::id_of_transform_matrix_property().base());
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() & !CompositionLinearGradientBrushChangedFields::TRANSFORM_MATRIX_ANIMATED);
if let Some(animation) = host.implicit_animation("TransformMatrix") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() | CompositionLinearGradientBrushChangedFields::TRANSFORM_MATRIX_ANIMATED);
host.pending_animations().set(
ServerCompositionLinearGradientBrushProps::id_of_transform_matrix_property().base(),
a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
);
}
host.start_animation_group(&animation, "TransformMatrix", ExpressionVariant::create(value));
}
}
self.transform_matrix.set(value);
if changed {
CompositionLinearGradientBrushHooks::on_transform_matrix_changed(host);
}
}
pub fn start_animation(
&self,
host: &dyn CompositionLinearGradientBrushHooks,
property_name: &str,
animation: &dyn ICompositionAnimation,
final_value: Option<ExpressionVariant>,
) -> bool {
if property_name == "StartPoint" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerCompositionLinearGradientBrushProps::id_of_start_point_property().base(), server);
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() | CompositionLinearGradientBrushChangedFields::START_POINT_ANIMATED);
host.register_for_serialization();
return true;
}
if property_name == "EndPoint" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerCompositionLinearGradientBrushProps::id_of_end_point_property().base(), server);
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() | CompositionLinearGradientBrushChangedFields::END_POINT_ANIMATED);
host.register_for_serialization();
return true;
}
if property_name == "AnchorPoint" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerCompositionLinearGradientBrushProps::id_of_anchor_point_property().base(), server);
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() | CompositionLinearGradientBrushChangedFields::ANCHOR_POINT_ANIMATED);
host.register_for_serialization();
return true;
}
if property_name == "CenterPoint" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerCompositionLinearGradientBrushProps::id_of_center_point_property().base(), server);
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() | CompositionLinearGradientBrushChangedFields::CENTER_POINT_ANIMATED);
host.register_for_serialization();
return true;
}
if property_name == "Offset" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerCompositionLinearGradientBrushProps::id_of_offset_property().base(), server);
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() | CompositionLinearGradientBrushChangedFields::OFFSET_ANIMATED);
host.register_for_serialization();
return true;
}
if property_name == "RotationAngle" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerCompositionLinearGradientBrushProps::id_of_rotation_angle_property().base(), server);
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() | CompositionLinearGradientBrushChangedFields::ROTATION_ANGLE_ANIMATED);
host.register_for_serialization();
return true;
}
if property_name == "Scale" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerCompositionLinearGradientBrushProps::id_of_scale_property().base(), server);
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() | CompositionLinearGradientBrushChangedFields::SCALE_ANIMATED);
host.register_for_serialization();
return true;
}
if property_name == "TransformMatrix" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerCompositionLinearGradientBrushProps::id_of_transform_matrix_property().base(), server);
self.changed_fields_of_composition_linear_gradient_brush.set(self.changed_fields_of_composition_linear_gradient_brush.get() | CompositionLinearGradientBrushChangedFields::TRANSFORM_MATRIX_ANIMATED);
host.register_for_serialization();
return true;
}
false
}
pub fn serialize_changes_core(&self, host: &dyn CompositionLinearGradientBrushHooks, writer: &mut BatchStreamWriter<'_>) {
CompositionLinearGradientBrushHooks::base_serialize_changes_core(host, writer);
let changed = self.changed_fields_of_composition_linear_gradient_brush.get();
writer.write(changed);
if changed.contains(CompositionLinearGradientBrushChangedFields::START_POINT_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerCompositionLinearGradientBrushProps::id_of_start_point_property().base()));
} else if changed.contains(CompositionLinearGradientBrushChangedFields::START_POINT) {
writer.write(self.start_point.get());
}
if changed.contains(CompositionLinearGradientBrushChangedFields::END_POINT_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerCompositionLinearGradientBrushProps::id_of_end_point_property().base()));
} else if changed.contains(CompositionLinearGradientBrushChangedFields::END_POINT) {
writer.write(self.end_point.get());
}
if changed.contains(CompositionLinearGradientBrushChangedFields::ANCHOR_POINT_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerCompositionLinearGradientBrushProps::id_of_anchor_point_property().base()));
} else if changed.contains(CompositionLinearGradientBrushChangedFields::ANCHOR_POINT) {
writer.write(self.anchor_point.get());
}
if changed.contains(CompositionLinearGradientBrushChangedFields::CENTER_POINT_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerCompositionLinearGradientBrushProps::id_of_center_point_property().base()));
} else if changed.contains(CompositionLinearGradientBrushChangedFields::CENTER_POINT) {
writer.write(self.center_point.get());
}
if changed.contains(CompositionLinearGradientBrushChangedFields::OFFSET_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerCompositionLinearGradientBrushProps::id_of_offset_property().base()));
} else if changed.contains(CompositionLinearGradientBrushChangedFields::OFFSET) {
writer.write(self.offset.get());
}
if changed.contains(CompositionLinearGradientBrushChangedFields::ROTATION_ANGLE_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerCompositionLinearGradientBrushProps::id_of_rotation_angle_property().base()));
} else if changed.contains(CompositionLinearGradientBrushChangedFields::ROTATION_ANGLE) {
writer.write(self.rotation_angle.get());
}
if changed.contains(CompositionLinearGradientBrushChangedFields::SCALE_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerCompositionLinearGradientBrushProps::id_of_scale_property().base()));
} else if changed.contains(CompositionLinearGradientBrushChangedFields::SCALE) {
writer.write(self.scale.get());
}
if changed.contains(CompositionLinearGradientBrushChangedFields::TRANSFORM_MATRIX_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerCompositionLinearGradientBrushProps::id_of_transform_matrix_property().base()));
} else if changed.contains(CompositionLinearGradientBrushChangedFields::TRANSFORM_MATRIX) {
writer.write(self.transform_matrix.get());
}
self.changed_fields_of_composition_linear_gradient_brush.set(CompositionLinearGradientBrushChangedFields::empty());
}
}
pub trait ServerCompositionLinearGradientBrushHooks: IServerAnimatedPropertyHost {
fn base_deserialize_changes_core(&self, reader: &mut BatchStreamReader<'_>, committed_at: Duration);
fn deserialize_changes_extra(&self, _reader: &mut BatchStreamReader<'_>) {}
fn on_fields_deserialized(&self, _changed: CompositionLinearGradientBrushChangedFields) {}
}
pub struct ServerCompositionLinearGradientBrushProps {
start_point: Cell<RelativePoint>,
end_point: Cell<RelativePoint>,
anchor_point: Cell<Vector>,
center_point: Cell<Vector>,
offset: Cell<Vector>,
rotation_angle: Cell<f32>,
scale: Cell<Vector>,
transform_matrix: Cell<Matrix>,
}
impl Default for ServerCompositionLinearGradientBrushProps {
fn default() -> Self {
Self::new()
}
}
impl ServerCompositionLinearGradientBrushProps {
pub fn new() -> Self {
Self {
start_point: Cell::new(Default::default()),
end_point: Cell::new(Default::default()),
anchor_point: Cell::new(Default::default()),
center_point: Cell::new(Default::default()),
offset: Cell::new(Default::default()),
rotation_angle: Cell::new(Default::default()),
scale: Cell::new(Default::default()),
transform_matrix: 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_start_point_property() -> &'static CompositionPropertyOf<RelativePoint> {
static PROPERTY: OnceLock<CompositionPropertyOf<RelativePoint>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerCompositionLinearGradientBrushProps, RelativePoint>(
"StartPoint",
"ServerCompositionLinearGradientBrush",
|obj| props_of::<ServerCompositionLinearGradientBrushProps>(obj).start_point.get(),
|obj, v| props_of::<ServerCompositionLinearGradientBrushProps>(obj).start_point.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerCompositionLinearGradientBrushProps>(obj).start_point.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerCompositionLinearGradientBrushProps>(obj).start_point.set(v.cast_or_default::<RelativePoint>())),
)
})
}
pub fn start_point(&self) -> RelativePoint {
self.start_point.get()
}
pub fn set_start_point(&self, host: &dyn ServerCompositionLinearGradientBrushHooks, value: RelativePoint) {
self.start_point.set(value);
host.remove_animation_for_property(Self::id_of_start_point_property().base());
}
pub fn id_of_end_point_property() -> &'static CompositionPropertyOf<RelativePoint> {
static PROPERTY: OnceLock<CompositionPropertyOf<RelativePoint>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerCompositionLinearGradientBrushProps, RelativePoint>(
"EndPoint",
"ServerCompositionLinearGradientBrush",
|obj| props_of::<ServerCompositionLinearGradientBrushProps>(obj).end_point.get(),
|obj, v| props_of::<ServerCompositionLinearGradientBrushProps>(obj).end_point.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerCompositionLinearGradientBrushProps>(obj).end_point.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerCompositionLinearGradientBrushProps>(obj).end_point.set(v.cast_or_default::<RelativePoint>())),
)
})
}
pub fn end_point(&self) -> RelativePoint {
self.end_point.get()
}
pub fn set_end_point(&self, host: &dyn ServerCompositionLinearGradientBrushHooks, value: RelativePoint) {
self.end_point.set(value);
host.remove_animation_for_property(Self::id_of_end_point_property().base());
}
pub fn id_of_anchor_point_property() -> &'static CompositionPropertyOf<Vector> {
static PROPERTY: OnceLock<CompositionPropertyOf<Vector>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerCompositionLinearGradientBrushProps, Vector>(
"AnchorPoint",
"ServerCompositionLinearGradientBrush",
|obj| props_of::<ServerCompositionLinearGradientBrushProps>(obj).anchor_point.get(),
|obj, v| props_of::<ServerCompositionLinearGradientBrushProps>(obj).anchor_point.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerCompositionLinearGradientBrushProps>(obj).anchor_point.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerCompositionLinearGradientBrushProps>(obj).anchor_point.set(v.cast_or_default::<Vector>())),
)
})
}
pub fn anchor_point(&self) -> Vector {
self.anchor_point.get()
}
pub fn set_anchor_point(&self, host: &dyn ServerCompositionLinearGradientBrushHooks, value: Vector) {
self.anchor_point.set(value);
host.remove_animation_for_property(Self::id_of_anchor_point_property().base());
}
pub fn id_of_center_point_property() -> &'static CompositionPropertyOf<Vector> {
static PROPERTY: OnceLock<CompositionPropertyOf<Vector>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerCompositionLinearGradientBrushProps, Vector>(
"CenterPoint",
"ServerCompositionLinearGradientBrush",
|obj| props_of::<ServerCompositionLinearGradientBrushProps>(obj).center_point.get(),
|obj, v| props_of::<ServerCompositionLinearGradientBrushProps>(obj).center_point.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerCompositionLinearGradientBrushProps>(obj).center_point.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerCompositionLinearGradientBrushProps>(obj).center_point.set(v.cast_or_default::<Vector>())),
)
})
}
pub fn center_point(&self) -> Vector {
self.center_point.get()
}
pub fn set_center_point(&self, host: &dyn ServerCompositionLinearGradientBrushHooks, value: Vector) {
self.center_point.set(value);
host.remove_animation_for_property(Self::id_of_center_point_property().base());
}
pub fn id_of_offset_property() -> &'static CompositionPropertyOf<Vector> {
static PROPERTY: OnceLock<CompositionPropertyOf<Vector>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerCompositionLinearGradientBrushProps, Vector>(
"Offset",
"ServerCompositionLinearGradientBrush",
|obj| props_of::<ServerCompositionLinearGradientBrushProps>(obj).offset.get(),
|obj, v| props_of::<ServerCompositionLinearGradientBrushProps>(obj).offset.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerCompositionLinearGradientBrushProps>(obj).offset.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerCompositionLinearGradientBrushProps>(obj).offset.set(v.cast_or_default::<Vector>())),
)
})
}
pub fn offset(&self) -> Vector {
self.offset.get()
}
pub fn set_offset(&self, host: &dyn ServerCompositionLinearGradientBrushHooks, value: Vector) {
self.offset.set(value);
host.remove_animation_for_property(Self::id_of_offset_property().base());
}
pub fn id_of_rotation_angle_property() -> &'static CompositionPropertyOf<f32> {
static PROPERTY: OnceLock<CompositionPropertyOf<f32>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerCompositionLinearGradientBrushProps, f32>(
"RotationAngle",
"ServerCompositionLinearGradientBrush",
|obj| props_of::<ServerCompositionLinearGradientBrushProps>(obj).rotation_angle.get(),
|obj, v| props_of::<ServerCompositionLinearGradientBrushProps>(obj).rotation_angle.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerCompositionLinearGradientBrushProps>(obj).rotation_angle.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerCompositionLinearGradientBrushProps>(obj).rotation_angle.set(v.cast_or_default::<f32>())),
)
})
}
pub fn rotation_angle(&self) -> f32 {
self.rotation_angle.get()
}
pub fn set_rotation_angle(&self, host: &dyn ServerCompositionLinearGradientBrushHooks, value: f32) {
self.rotation_angle.set(value);
host.remove_animation_for_property(Self::id_of_rotation_angle_property().base());
}
pub fn id_of_scale_property() -> &'static CompositionPropertyOf<Vector> {
static PROPERTY: OnceLock<CompositionPropertyOf<Vector>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerCompositionLinearGradientBrushProps, Vector>(
"Scale",
"ServerCompositionLinearGradientBrush",
|obj| props_of::<ServerCompositionLinearGradientBrushProps>(obj).scale.get(),
|obj, v| props_of::<ServerCompositionLinearGradientBrushProps>(obj).scale.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerCompositionLinearGradientBrushProps>(obj).scale.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerCompositionLinearGradientBrushProps>(obj).scale.set(v.cast_or_default::<Vector>())),
)
})
}
pub fn scale(&self) -> Vector {
self.scale.get()
}
pub fn set_scale(&self, host: &dyn ServerCompositionLinearGradientBrushHooks, value: Vector) {
self.scale.set(value);
host.remove_animation_for_property(Self::id_of_scale_property().base());
}
pub fn id_of_transform_matrix_property() -> &'static CompositionPropertyOf<Matrix> {
static PROPERTY: OnceLock<CompositionPropertyOf<Matrix>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerCompositionLinearGradientBrushProps, Matrix>(
"TransformMatrix",
"ServerCompositionLinearGradientBrush",
|obj| props_of::<ServerCompositionLinearGradientBrushProps>(obj).transform_matrix.get(),
|obj, v| props_of::<ServerCompositionLinearGradientBrushProps>(obj).transform_matrix.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerCompositionLinearGradientBrushProps>(obj).transform_matrix.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerCompositionLinearGradientBrushProps>(obj).transform_matrix.set(v.cast_or_default::<Matrix>())),
)
})
}
pub fn transform_matrix(&self) -> Matrix {
self.transform_matrix.get()
}
pub fn set_transform_matrix(&self, host: &dyn ServerCompositionLinearGradientBrushHooks, value: Matrix) {
self.transform_matrix.set(value);
host.remove_animation_for_property(Self::id_of_transform_matrix_property().base());
}
pub fn deserialize_changes_core(
&self,
host: &dyn ServerCompositionLinearGradientBrushHooks,
reader: &mut BatchStreamReader<'_>,
committed_at: Duration,
) {
ServerCompositionLinearGradientBrushHooks::base_deserialize_changes_core(host, reader, committed_at);
ServerCompositionLinearGradientBrushHooks::deserialize_changes_extra(host, reader);
let changed = reader.read::<CompositionLinearGradientBrushChangedFields>();
if changed.contains(CompositionLinearGradientBrushChangedFields::START_POINT_ANIMATED) {
let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
panic!("a batch starts an animation of `StartPoint` without an animation instance");
};
host.set_animated_value(
Self::id_of_start_point_property().base(),
ExpressionVariant::create(self.start_point.get()),
committed_at,
animation,
);
} else if changed.contains(CompositionLinearGradientBrushChangedFields::START_POINT) {
let value = reader.read::<RelativePoint>();
self.set_start_point(host, value);
}
if changed.contains(CompositionLinearGradientBrushChangedFields::END_POINT_ANIMATED) {
let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
panic!("a batch starts an animation of `EndPoint` without an animation instance");
};
host.set_animated_value(
Self::id_of_end_point_property().base(),
ExpressionVariant::create(self.end_point.get()),
committed_at,
animation,
);
} else if changed.contains(CompositionLinearGradientBrushChangedFields::END_POINT) {
let value = reader.read::<RelativePoint>();
self.set_end_point(host, value);
}
if changed.contains(CompositionLinearGradientBrushChangedFields::ANCHOR_POINT_ANIMATED) {
let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
panic!("a batch starts an animation of `AnchorPoint` without an animation instance");
};
host.set_animated_value(
Self::id_of_anchor_point_property().base(),
ExpressionVariant::create(self.anchor_point.get()),
committed_at,
animation,
);
} else if changed.contains(CompositionLinearGradientBrushChangedFields::ANCHOR_POINT) {
let value = reader.read::<Vector>();
self.set_anchor_point(host, value);
}
if changed.contains(CompositionLinearGradientBrushChangedFields::CENTER_POINT_ANIMATED) {
let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
panic!("a batch starts an animation of `CenterPoint` without an animation instance");
};
host.set_animated_value(
Self::id_of_center_point_property().base(),
ExpressionVariant::create(self.center_point.get()),
committed_at,
animation,
);
} else if changed.contains(CompositionLinearGradientBrushChangedFields::CENTER_POINT) {
let value = reader.read::<Vector>();
self.set_center_point(host, value);
}
if changed.contains(CompositionLinearGradientBrushChangedFields::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(CompositionLinearGradientBrushChangedFields::OFFSET) {
let value = reader.read::<Vector>();
self.set_offset(host, value);
}
if changed.contains(CompositionLinearGradientBrushChangedFields::ROTATION_ANGLE_ANIMATED) {
let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
panic!("a batch starts an animation of `RotationAngle` without an animation instance");
};
host.set_animated_value(
Self::id_of_rotation_angle_property().base(),
ExpressionVariant::create(self.rotation_angle.get()),
committed_at,
animation,
);
} else if changed.contains(CompositionLinearGradientBrushChangedFields::ROTATION_ANGLE) {
let value = reader.read::<f32>();
self.set_rotation_angle(host, value);
}
if changed.contains(CompositionLinearGradientBrushChangedFields::SCALE_ANIMATED) {
let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
panic!("a batch starts an animation of `Scale` without an animation instance");
};
host.set_animated_value(
Self::id_of_scale_property().base(),
ExpressionVariant::create(self.scale.get()),
committed_at,
animation,
);
} else if changed.contains(CompositionLinearGradientBrushChangedFields::SCALE) {
let value = reader.read::<Vector>();
self.set_scale(host, value);
}
if changed.contains(CompositionLinearGradientBrushChangedFields::TRANSFORM_MATRIX_ANIMATED) {
let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
panic!("a batch starts an animation of `TransformMatrix` without an animation instance");
};
host.set_animated_value(
Self::id_of_transform_matrix_property().base(),
ExpressionVariant::create(self.transform_matrix.get()),
committed_at,
animation,
);
} else if changed.contains(CompositionLinearGradientBrushChangedFields::TRANSFORM_MATRIX) {
let value = reader.read::<Matrix>();
self.set_transform_matrix(host, value);
}
ServerCompositionLinearGradientBrushHooks::on_fields_deserialized(host, changed);
}
pub fn get_composition_property(name: &str) -> Option<&'static CompositionProperty> {
if name == "StartPoint" {
return Some(Self::id_of_start_point_property().base());
}
if name == "EndPoint" {
return Some(Self::id_of_end_point_property().base());
}
if name == "AnchorPoint" {
return Some(Self::id_of_anchor_point_property().base());
}
if name == "CenterPoint" {
return Some(Self::id_of_center_point_property().base());
}
if name == "Offset" {
return Some(Self::id_of_offset_property().base());
}
if name == "RotationAngle" {
return Some(Self::id_of_rotation_angle_property().base());
}
if name == "Scale" {
return Some(Self::id_of_scale_property().base());
}
if name == "TransformMatrix" {
return Some(Self::id_of_transform_matrix_property().base());
}
None
}
}