use bitflags::bitflags;
use crate::RelativePoint;
use crate::rendering::composition::expressions::ExpressionVariant;
use crate::rendering::composition::server::CompositionProperty;
use crate::rendering::composition::server::CompositionPropertyOf;
use crate::rendering::composition::server::IServerPropertyHost;
use crate::rendering::composition::server::ServerPropertyValue;
use crate::rendering::composition::server::ServerValueChange;
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 CompositionSimpleConicGradientBrushChangedFields: u8 {
const ANGLE = 1;
const CENTER = 2;
}
}
impl BatchValue for CompositionSimpleConicGradientBrushChangedFields {
#[inline]
fn write_to(&self, out: &mut Vec<u8>) {
self.bits().write_to(out);
}
#[inline]
fn read_from(input: &mut BatchValueReader<'_>) -> Self {
CompositionSimpleConicGradientBrushChangedFields::from_bits_retain(u8::read_from(input))
}
}
pub trait ServerCompositionSimpleConicGradientBrushHooks: IServerPropertyHost {
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: CompositionSimpleConicGradientBrushChangedFields) {}
fn on_angle_changed(&self) {}
fn on_angle_changing(&self) {}
fn on_center_changed(&self) {}
fn on_center_changing(&self) {}
}
pub struct ServerCompositionSimpleConicGradientBrushProps {
angle: Cell<f64>,
center: Cell<RelativePoint>,
}
impl Default for ServerCompositionSimpleConicGradientBrushProps {
fn default() -> Self {
Self::new()
}
}
impl ServerCompositionSimpleConicGradientBrushProps {
pub fn new() -> Self {
Self {
angle: Cell::new(Default::default()),
center: 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_angle_property() -> &'static CompositionPropertyOf<f64> {
static PROPERTY: OnceLock<CompositionPropertyOf<f64>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerCompositionSimpleConicGradientBrushProps, f64>(
"Angle",
"ServerCompositionSimpleConicGradientBrush",
|obj| props_of::<ServerCompositionSimpleConicGradientBrushProps>(obj).angle.get(),
|obj, v| props_of::<ServerCompositionSimpleConicGradientBrushProps>(obj).angle.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerCompositionSimpleConicGradientBrushProps>(obj).angle.get())),
None,
)
})
}
pub fn angle(&self) -> f64 {
self.angle.get()
}
pub fn set_angle(&self, host: &dyn ServerCompositionSimpleConicGradientBrushHooks, value: f64) {
let old_value = self.angle.get();
let mut changed = false;
if old_value.differs(&value) {
ServerCompositionSimpleConicGradientBrushHooks::on_angle_changing(host);
changed = true;
}
host.set_value(
Self::id_of_angle_property().base(),
ServerValueChange {
equal: old_value.default_equals(&value),
old_resource: None,
new_resource: None,
assign: &mut || self.angle.set(value),
},
);
if changed {
ServerCompositionSimpleConicGradientBrushHooks::on_angle_changed(host);
}
}
pub fn id_of_center_property() -> &'static CompositionPropertyOf<RelativePoint> {
static PROPERTY: OnceLock<CompositionPropertyOf<RelativePoint>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerCompositionSimpleConicGradientBrushProps, RelativePoint>(
"Center",
"ServerCompositionSimpleConicGradientBrush",
|obj| props_of::<ServerCompositionSimpleConicGradientBrushProps>(obj).center.get(),
|obj, v| props_of::<ServerCompositionSimpleConicGradientBrushProps>(obj).center.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerCompositionSimpleConicGradientBrushProps>(obj).center.get())),
None,
)
})
}
pub fn center(&self) -> RelativePoint {
self.center.get()
}
pub fn set_center(&self, host: &dyn ServerCompositionSimpleConicGradientBrushHooks, value: RelativePoint) {
let old_value = self.center.get();
let mut changed = false;
if old_value.differs(&value) {
ServerCompositionSimpleConicGradientBrushHooks::on_center_changing(host);
changed = true;
}
host.set_value(
Self::id_of_center_property().base(),
ServerValueChange {
equal: old_value.default_equals(&value),
old_resource: None,
new_resource: None,
assign: &mut || self.center.set(value),
},
);
if changed {
ServerCompositionSimpleConicGradientBrushHooks::on_center_changed(host);
}
}
pub fn deserialize_changes_core(
&self,
host: &dyn ServerCompositionSimpleConicGradientBrushHooks,
reader: &mut BatchStreamReader<'_>,
committed_at: Duration,
) {
ServerCompositionSimpleConicGradientBrushHooks::base_deserialize_changes_core(host, reader, committed_at);
ServerCompositionSimpleConicGradientBrushHooks::deserialize_changes_extra(host, reader);
let changed = reader.read::<CompositionSimpleConicGradientBrushChangedFields>();
if changed.contains(CompositionSimpleConicGradientBrushChangedFields::ANGLE) {
let value = reader.read::<f64>();
self.set_angle(host, value);
}
if changed.contains(CompositionSimpleConicGradientBrushChangedFields::CENTER) {
let value = reader.read::<RelativePoint>();
self.set_center(host, value);
}
ServerCompositionSimpleConicGradientBrushHooks::on_fields_deserialized(host, changed);
}
pub fn serialize_all_changes(
writer: &mut BatchStreamWriter<'_>,
angle: f64,
center: RelativePoint,
) {
writer.write(CompositionSimpleConicGradientBrushChangedFields::ANGLE | CompositionSimpleConicGradientBrushChangedFields::CENTER);
writer.write(angle);
writer.write(center);
}
}