-
Notifications
You must be signed in to change notification settings - Fork 0
/
Timeline.pde
286 lines (242 loc) · 7.61 KB
/
Timeline.pde
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
Timeline timeline;
public final PFont BitFontStandard58 = new BitFont( CP.decodeBase64( BitFont.standard58base64 ) );
class Timeline extends MoveableGroup {
private int sliderSpacing = 3;
private int sliderHeight = 120;
private int colorBackground = 0xff003652;
private int colorActiveStep = 0xff00709B;
private int colorSelected = 0xff9B7900;
private int colorSelectedActive = 0xffFFC905;
private int[][] colorMatrix = new int[][] {{colorBackground, colorActiveStep}, {colorSelected, colorSelectedActive}};
private Numberbox numSteps;
private Numberbox duration;
private Button lshift, rshift;
private Toggle loop, smoothend;
private ScrollableList easing;
private TFTimetable fn;
Slider[] sliders;
int selectedSlider = 0;
Timeline(int animNum) {
barHeight = 12;
groupHeight = sliderHeight + 40;
groupWidth = 360;
x = width - accordion.getWidth() - groupWidth - 2*margin;
y = margin + barHeight + 1;
this.fn = (TFTimetable) selected.getAnimation(animNum).getFunction();
paramLocked = true;
group = cp5.addGroup("timeline")
.setPosition(x, y)
.setWidth(groupWidth)
//.hideBar()
.setBarHeight(barHeight)
.setBackgroundHeight(groupHeight)
.setBackgroundColor(color(0, 100))
;
//numSteps = cp5.addNumberbox("tlnumsteps"+animNum)
numSteps = new NumberboxInput(cp5, "tlnumsteps"+animNum)
.setLabel("Num steps")
.setPosition(spacing, spacing)
.setSize(60, 20)
.setRange(4, 32)
.setDirection(Controller.HORIZONTAL)
.setGroup(group)
;
duration = new NumberboxInput(cp5, "duration"+animNum)
.setLabel("duration")
.setPosition(numSteps.getPosition()[0]+numSteps.getWidth()+spacing, spacing)
.setSize(60, 20)
.setRange(0.5, 120)
.setMultiplier(0.05)
.setDirection(Controller.HORIZONTAL)
.setGroup(group)
;
easing = cp5.addScrollableList("easing"+animNum)
.setLabel("easing")
.setPosition(duration.getPosition()[0]+duration.getWidth()+spacing, spacing)
.setWidth(80)
.setBarHeight(20)
//.setItemHeight(barHeight)
.onEnter(toFront)
.onLeave(close)
.addItems(Animation.interpolationNamesSimp)
.setGroup(group)
.close()
;
lshift = cp5.addButton("tllshift"+animNum)
.setLabel("<<")
.setPosition(220, spacing)
.setSize(20, 20)
.setGroup(group)
;
cp5.addTextlabel("shiftlabel"+animNum)
.setPosition(lshift.getPosition()[0]+6, spacing+24)
.setFont(BitFontStandard58)
.setText("SHIFT")
.setGroup(group)
;
rshift = cp5.addButton("tlrshift"+animNum)
.setLabel(">>")
.setPosition(lshift.getPosition()[0]+lshift.getWidth()+spacing, spacing)
.setSize(20, 20)
.setGroup(group)
;
smoothend = cp5.addToggle("smoothend"+animNum)
.setLabelVisible(false)
.setPosition(280, spacing)
.setSize(20, 20)
.setGroup(group)
;
cp5.addTextlabel("smoothendlabel"+animNum)
.setPosition(smoothend.getPosition()[0]-15, spacing+24)
.setText("SMOOTHEND")
.setFont(BitFontStandard58)
.setGroup(group)
;
loop = cp5.addToggle("loop"+animNum)
.setLabelVisible(false)
.setPosition(330, spacing)
.setSize(20, 20)
.setGroup(group)
;
cp5.addTextlabel("looplabel"+animNum)
.setPosition(loop.getPosition()[0]-2, spacing+24)
.setFont(BitFontStandard58)
.setText("LOOP")
.setGroup(group)
;
sliders = new Slider[32];
for (int i=0; i<32; i++) {
sliders[i] = new TimelineSlider(cp5, "tlslider"+i)
.setGroup(group)
.setVisible(false)
;
}
paramLocked = false;
update();
}
public void setFunction(TFTimetable fn) {
this.fn = fn;
update();
}
public TimeFunction getFunction() {
return fn;
}
/*
public void setEasing(float idx) {
println("setEasing", idx);
fn.setEasing(Animation.interpolationNamesSimp[int(idx)]);
}*/
/*
public int getAnimNum() {
return animNum;
}*/
/* Change the size of the timeline table and update its values
*/
public void updateTable() {
int size = (int) numSteps.getValue();
float[] array = new float[size];
for (int i=0; i<size; i++) {
array[i] = sliders[i].getValue();
}
fn.setTable(array);
update();
}
public void setTableValue(int idx, float value) {
fn.setTableValue(idx, value);
selectedSlider = idx;
}
/*
public void hide() {
group.hide();
}
public void show() {
group.open().show();
}*/
public void update() {
// Update all controllers according to the function parameters
paramLocked = true;
numSteps.setValue(fn.getTable().length);
duration.setValue((float) fn.getParam("duration").getValue());
int easingNum = 0;
String easingName = (String) fn.getParam("easing").getValue();
for (int i=0; i<Animation.interpolationNamesSimp.length; i++) {
if (Animation.interpolationNamesSimp[i].equals(easingName)) {
easingNum = i;
break;
}
}
easing.setValue(easingNum);
loop.setValue((boolean) fn.getParam("loop").getValue());
smoothend.setValue((boolean) fn.getParam("smoothend").getValue());
int numSliders = fn.getTable().length;
float sliderWidthFloat = ((float) groupWidth - sliderSpacing*(numSliders-1)) / numSliders;
int sliderMinWidth = floor(sliderWidthFloat);
int sliderWidth;
float widthRemains = sliderWidthFloat - sliderMinWidth;
float widthRemainsCumul = 0f;
float posX = 0f;
for (int i=0; i<32; i++) {
widthRemainsCumul += widthRemains;
sliderWidth = sliderMinWidth+floor(widthRemainsCumul);
sliders[i].setPosition(posX, 40)
.setSize(sliderWidth, sliderHeight)
.setVisible(i<numSliders)
.setValue(i<numSliders ? fn.getTable()[i] : 0f)
;
posX += sliderWidth+sliderSpacing;
if (floor(widthRemainsCumul) > 0)
widthRemainsCumul -= floor(widthRemainsCumul);
}
paramLocked = false;
}
public void highlightSliders() {
int[] step = fn.getActiveStep();
int n = (int) numSteps.getValue();
int selected;
int active;
for (int i=0; i<n; i++) {
selected = i==selectedSlider || i==selectedSlider+1 ? 1 : 0;
active = i==step[0] || i==step[1] ? 1 : 0;
sliders[i].setColorBackground(colorMatrix[selected][active])
.setColorForeground(active==1 ? 0xff08a2cf : 0xff00698c);
}
}
public void lshift() {
int n = (int) numSteps.getValue();
float first = sliders[0].getValue();
for (int i=0; i<n-1; i++)
sliders[i].setValue(sliders[i+1].getValue());
sliders[n-1].setValue(first);
updateTable();
}
public void rshift() {
int n = (int) numSteps.getValue();
float last = sliders[n-1].getValue();
for (int i=n-1; i>0; i--)
sliders[i].setValue(sliders[i-1].getValue());
sliders[0].setValue(last);
updateTable();
}
public void remove() {
group.remove();
timeline = null;
}
class TimelineSlider extends Slider {
public TimelineSlider(ControlP5 theControlP5, String theName) {
super(theControlP5, theName);
setRange(-1, 1);
setSliderMode(Slider.FLEXIBLE);
setHandleSize(5);
setNumberOfTickMarks(3);
snapToTickMarks(false);
setLabelVisible(false);
}
@Override
protected void onMove( ) {
if (mousePressed) {
float f = _myMin + (-(_myControlWindow.getPointer().getY() - (y(_myParent.getAbsolutePosition()) + y(position)) - getHeight())) * _myUnit;
setValue( PApplet.map(f, 0, 1, _myMinReal, _myMaxReal ) );
}
}
}
}