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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
use super::super::traits::*;
use super::super::deref_map::*;
use std::time::Duration;
use std::ops::Deref;
use std::sync::*;
///
/// A keyframe in a vector layer
///
pub struct VectorKeyFrame {
core: Mutex<VectorKeyFrameCore>
}
impl VectorKeyFrame {
///
/// Creates a new vector key frame
///
pub fn new(start_time: Duration) -> VectorKeyFrame {
VectorKeyFrame {
core: Mutex::new(VectorKeyFrameCore::new(start_time))
}
}
///
/// The start time of this key frame
///
pub fn start_time(&self) -> Duration {
self.core.lock().unwrap().start_time()
}
///
/// Adds a new element to the front of the vector
///
pub fn add_element(&self, when: Duration, new_element: Vector) {
self.core.lock().unwrap().add_element(when, new_element);
}
///
/// Retrieves the elements in this keyframe
///
pub fn elements<'a>(&'a self) -> Box<'a+Deref<Target=Vec<(Duration, Vector)>>> {
let core = self.core.lock().unwrap();
let elements = DerefMap::map(core, |core| &core.elements);
Box::new(elements)
}
///
/// Retrieves the properties that will be applied to the next element added to this keyframe
///
#[inline]
pub fn active_properties(&self) -> VectorProperties {
self.core.lock().unwrap().active_properties().clone()
}
}
///
/// Data storage for a vector keyframe
///
struct VectorKeyFrameCore {
/// When this frame starts
start_time: Duration,
/// The elements in this key frame (ordered from back to front)
elements: Vec<(Duration, Vector)>,
/// The properties that will apply to the next element added to this core
active_properties: VectorProperties
}
impl VectorKeyFrameCore {
///
/// Creates a new vector key frame
///
pub fn new(start_time: Duration) -> VectorKeyFrameCore {
VectorKeyFrameCore {
start_time: start_time,
elements: vec![],
active_properties: VectorProperties::default()
}
}
///
/// The start time of this key frame
///
#[inline]
pub fn start_time(&self) -> Duration {
self.start_time
}
///
/// Retrieves the properties that will be applied to the next element added to this keyframe
///
#[inline]
pub fn active_properties<'a>(&'a self) -> &'a VectorProperties {
&self.active_properties
}
///
/// Adds a new element to the front of the vector
///
#[inline]
pub fn add_element(&mut self, when: Duration, new_element: Vector) {
new_element.update_properties(&mut self.active_properties);
self.elements.push((when, new_element));
}
}