/
BaseClasses.cs
236 lines (197 loc) · 5.96 KB
/
BaseClasses.cs
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
using System;
using System.Collections.Generic;
using System.Linq;
using VVVV.Core;
using VVVV.Core.Model;
namespace Timeliner
{
public class TLModelBase : IDContainer
{
public TLModelBase(string name)
: base(name)
{
Mapper = Shell.Instance.Root.Mapper.CreateChildMapper(this);
}
}
/// <summary>
/// Base class for keyframes, has only time and selected as property
/// </summary>
public abstract class TLKeyframeBase : TLModelBase
{
[KeyframeMenuEntry]
public EditableProperty<float> Time { get; private set; }
public EditableProperty<bool> Selected { get; private set; }
public TLKeyframeBase NeighbourLeft
{
get;
set;
}
public TLKeyframeBase NeighbourRight
{
get;
set;
}
public TLKeyframeBase()
: this(IDGenerator.NewID)
{
}
public TLKeyframeBase(string name)
: this(name, 0)
{
}
public TLKeyframeBase(string name, float time)
: base(name)
{
Time = new EditableProperty<float>("Time", time);
Selected = new EditableProperty<bool>("Selected", false);
Add(Time);
//do not add seleted to container so it will not be serialized
//Add(Selected);
Time.ValueChanged += Time_ValueChanged;
}
void Time_ValueChanged(IViewableProperty<float> property, float newValue, float oldValue)
{
if(NeighbourLeft != null)
{
if(NeighbourLeft.Time.Value > this.Time.Value)
{
NeighbourChanged();
return;
}
}
if(NeighbourRight != null)
{
if(NeighbourRight.Time.Value < this.Time.Value)
{
NeighbourChanged();
return;
}
}
}
public Action NeighbourChanged = () => {};
}
public abstract class TLTrackBase : TLModelBase
{
public float CCollapsedHeight = 15;
public abstract IEnumerable<TLKeyframeBase> KeyframeModels
{
get;
}
public EditableProperty<int> Order
{
get;
private set;
}
public EditableProperty<float> Height
{
get;
private set;
}
public EditableProperty<float> UncollapsedHeight
{
get;
private set;
}
//the Name property cannot have spaces so we need an extra Label property
[TrackMenuEntry(Order=0, Height=30)]
public EditableProperty<string> Label
{
get;
private set;
}
bool FLoading;
public bool Loading
{
get {return FLoading;}
set
{
FLoading = value;
if (!FLoading)
LoadingFinished();
}
}
public float CollapsedHeight
{
get {return CCollapsedHeight;}
}
public TLTrackBase()
: this(IDGenerator.NewID)
{
}
public TLTrackBase(string name)
: base(name)
{
UncollapsedHeight = new EditableProperty<float>("Uncollapsed Height");
UncollapsedHeight.Value = 75;
Order = new EditableProperty<int>("Order");
Height = new EditableProperty<float>("Height");
Height.Value = UncollapsedHeight.Value;
Height.AllowChange = (p, v) => v >= CollapsedHeight;
Label = new EditableProperty<string>("Label");
Label.Value = this.GetID();
Add(Order);
Add(Height);
}
public virtual void LoadingFinished()
{
}
public virtual void Evaluate(float time)
{
}
protected abstract void SortKeyframeList();
public virtual void SortAndAssignNeighbours()
{
//make sure keyframes are sorted
SortKeyframeList();
var keyframes = KeyframeModels.ToList();
//assign neighbours
if(keyframes.Count > 1)
{
//arrange neighbours
keyframes[0].NeighbourLeft = null;
keyframes[0].NeighbourRight = keyframes[1];
for (int i = 1; i < keyframes.Count-1; i++)
{
keyframes[i].NeighbourLeft = keyframes[i-1];
keyframes[i].NeighbourRight = keyframes[i+1];
}
keyframes[keyframes.Count - 1].NeighbourLeft = keyframes[keyframes.Count - 2];
keyframes[keyframes.Count - 1].NeighbourRight = null;
}
else if (keyframes.Count == 1)
{
keyframes[0].NeighbourLeft = null;
keyframes[0].NeighbourRight = null;
}
}
/// <summary>
/// For display purposes
/// </summary>
public abstract string GetCurrentValueAsString();
/// <summary>
/// The current value as object
/// </summary>
/// <returns></returns>
public abstract object GetCurrentValueAsObject();
}
[System.AttributeUsage(System.AttributeTargets.Property)]
public class TrackMenuEntryAttribute: System.Attribute
{
public int Order;
public int Height;
public TrackMenuEntryAttribute()
{
Height = 20;
}
}
[System.AttributeUsage(System.AttributeTargets.Property)]
public class KeyframeMenuEntryAttribute: System.Attribute
{
public int Order;
public int Height;
public KeyframeMenuEntryAttribute()
{
Height = 20;
}
}
}