pub type NodeId = u32;
pub type AnimationId = u32;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum AnimationProp {
Opacity,
BackgroundColor,
BorderColor,
Color,
ShadowColor,
ShadowOpacity,
ShadowRadius,
Transform(u8),
CanvasArg(u16),
}
impl AnimationProp {
pub fn from_name(name: &str) -> Option<AnimationProp> {
Some(match name {
"opacity" => AnimationProp::Opacity,
"backgroundColor" => AnimationProp::BackgroundColor,
"borderColor" => AnimationProp::BorderColor,
"color" => AnimationProp::Color,
"shadowColor" => AnimationProp::ShadowColor,
"shadowOpacity" => AnimationProp::ShadowOpacity,
"shadowRadius" => AnimationProp::ShadowRadius,
_ => return None,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Easing {
Linear,
EaseIn,
EaseOut,
EaseInOut,
Bezier(f32, f32, f32, f32),
Curve(Curve, EaseMode),
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Curve {
Quad,
Cubic,
Poly(f32),
Sin,
Circle,
Exp,
Elastic(f32),
Back(f32),
Bounce,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EaseMode {
In,
Out,
InOut,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Driver {
Timing {
to: f32,
duration_ms: f32,
easing: Easing,
delay_ms: f32,
},
Spring {
to: f32,
stiffness: f32,
damping: f32,
mass: f32,
velocity: Option<f32>,
},
Decay {
velocity: Option<f32>,
deceleration: f32,
clamp: Option<(f32, f32)>,
bounce: f32,
},
}
#[derive(Debug, Clone, PartialEq)]
pub enum Output {
Numbers(Vec<f32>),
Colors(Vec<u32>),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Extrapolate {
Extend,
Clamp,
Identity,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MathOp {
Mod,
Add,
Sub,
Mul,
Div,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Operand {
Node(NodeId),
Const(f32),
}
#[derive(Debug, Clone, PartialEq)]
pub enum AnimationOp {
CreateValue {
node: NodeId,
value: f32,
},
CreateInterpolate {
node: NodeId,
input: NodeId,
input_range: Vec<f32>,
output: Output,
extrapolate_left: Extrapolate,
extrapolate_right: Extrapolate,
easing: Easing,
},
CreateDiffClamp {
node: NodeId,
input: NodeId,
min: f32,
max: f32,
},
CreateMath {
node: NodeId,
op: MathOp,
a: Operand,
b: Operand,
},
SetOutput {
node: NodeId,
output: Output,
},
Set {
node: NodeId,
value: f32,
},
Start {
node: NodeId,
animation: AnimationId,
driver: Driver,
},
StartComposite {
animation: AnimationId,
key: u32,
spec: Composite,
},
ResetComposite {
key: u32,
},
ReleaseComposite {
key: u32,
},
Stop {
node: NodeId,
},
StopAnimation {
animation: AnimationId,
},
Release {
node: NodeId,
},
SetOffset {
node: NodeId,
offset: f32,
},
FlattenOffset {
node: NodeId,
},
ExtractOffset {
node: NodeId,
},
Read {
node: NodeId,
request: AnimationId,
},
}
#[derive(Debug, Clone, PartialEq)]
pub enum Composite {
Run {
node: NodeId,
driver: Driver,
},
Sequence(Vec<Composite>),
Parallel {
children: Vec<Composite>,
stop_together: bool,
},
Delay(f32),
Loop {
child: Box<Composite>,
iterations: Option<u32>,
reset: bool,
},
}
impl Composite {
pub fn nodes(&self, out: &mut Vec<NodeId>) {
match self {
Composite::Run { node, .. } => {
if !out.contains(node) {
out.push(*node);
}
}
Composite::Sequence(children) | Composite::Parallel { children, .. } => {
for c in children {
c.nodes(out);
}
}
Composite::Delay(_) => {}
Composite::Loop { child, .. } => child.nodes(out),
}
}
}