-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTransport.pde
293 lines (258 loc) · 7.59 KB
/
Transport.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
287
288
289
290
291
292
293
public class Transport extends MoveableGroup {
Textfield postureName;
Button prevPostureButton;
Button nextPostureButton;
ButtonRec buttonRec;
Numberbox animDuration;
Textlabel frameCounter;
Icon cameraToggle;
Icon playToggle;
public int frameNumber = 0;
private int textfieldWidth = 100;
private int buttonSize = 24;
private float prevAnimDuration = 0f;
public Transport() {
x = margin;
y = margin + barHeight;
barHeight = 10;
groupHeight = 20;
group = cp5.addGroup("transportgroup")
.setBarHeight(barHeight)
.setBackgroundHeight(groupHeight + 1)
.setBackgroundColor(backgroundColor)
.setCaptionLabel("transport")
.setPosition(x, y)
;
PVector pos = new PVector(0, 0);
prevPostureButton = cp5.addButton("prevposture")
.setLabel("<<")
.setPosition(pos.x, pos.y)
.setSize(buttonSize, groupHeight)
.plugTo(this, "prevPosture")
.setGroup(group)
;
prevPostureButton.onEnter(new CallbackListener() {
public void controlEvent(CallbackEvent theEvent) {
tooltip.say("Load previous posture");
}
}
);
pos.add(buttonSize + spacing, 0);
postureName = cp5.addTextfield("posturename")
//.setLabelVisible(false) // Doesn't work
.setLabel("")
.setText("posture0")
.setPosition(pos.x, pos.y)
.setSize(textfieldWidth, groupHeight)
.setFont(defaultFontSmall)
.setFocus(false)
.setColor(color(255, 255, 255))
.setAutoClear(false)
.setGroup(group)
;
postureName.onEnter(new CallbackListener() {
public void controlEvent(CallbackEvent theEvent) {
tooltip.say("Change posture name");
}
}
);
pos.add(textfieldWidth + spacing, 0);
nextPostureButton = cp5.addButton("nextposture")
.setLabel(">>")
.setPosition(pos.x, pos.y)
.setSize(buttonSize, groupHeight)
.plugTo(this, "nextPosture")
.setGroup(group)
;
nextPostureButton.onEnter(new CallbackListener() {
public void controlEvent(CallbackEvent theEvent) {
tooltip.say("Load next posture");
}
}
);
pos.add(buttonSize + 2*spacing, 0);
animDuration = new NumberboxInput(cp5, "animduration")
.setUnit(" s")
.setPosition(pos.x, pos.y)
.setSize(40, groupHeight)
.setRange(0, 999)
.setDirection(Controller.HORIZONTAL) // change the control direction to left/right
.setGroup(group)
;
animDuration.addCallback(new CallbackListener() {
public void controlEvent(CallbackEvent theEvent) {
if (theEvent.getAction() == ControlP5.ACTION_BROADCAST && animDuration.getValue() != prevAnimDuration) {
setFileDirty();
}
}
}
);
animDuration.onEnter(new CallbackListener() {
public void controlEvent(CallbackEvent theEvent) {
tooltip.say("Set this posture's total duration (in seconds)");
}
}
);
pos.add(animDuration.getWidth(), 0);
frameCounter = cp5.addTextlabel("framecounter")
.setLabel("counter")
.setText(String.valueOf(frameNumber))
.setPosition(pos.x, pos.y)
.setSize(30, groupHeight)
.setFont(defaultFontSmall)
.setColor(color(255, 255, 255))
.setGroup(group)
;
frameCounter.onEnter(new CallbackListener() {
public void controlEvent(CallbackEvent theEvent) {
tooltip.say("Frame counter");
}
}
);
pos.add(30 + spacing, 0);
new Button(cp5, "resetcounter")
.setLabel("Rst")
.setSize(buttonSize, groupHeight)
.setPosition(pos.x, pos.y)
.setGroup(group)
.plugTo(this, "resetCounter")
.onEnter(new CallbackListener() {
public void controlEvent(CallbackEvent theEvent) {
tooltip.say("Reset frame counter");
}
}
);
pos.add(buttonSize + spacing, 0);
buttonRec = new ButtonRec(cp5, "buttonrec", pos);
buttonRec.setGroup(group);
buttonRec.onEnter(new CallbackListener() {
public void controlEvent(CallbackEvent theEvent) {
tooltip.say("Record frames to disk");
}
}
);
pos.add(buttonSize + spacing, 0);
cameraToggle = cp5.addIcon("cameratoggle", 0)
.setPosition(pos.x, pos.y)
.setSize(buttonSize, groupHeight)
.setFont(iconFont)
.setFontIcons(#00f030, #00f030)
.setFontIconSize(18)
.setSwitch(true)
.showBackground()
.setGroup(group)
.plugTo(this, "onToggleCamera")
.onEnter(new CallbackListener() {
public void controlEvent(CallbackEvent theEvent) {
tooltip.say("Show / Hide camera (key 'k')");
}
}
);
pos.add(buttonSize + spacing, 0);
playToggle = cp5.addIcon("playtoggle", 0)
.setPosition(pos.x, pos.y)
.setSize(buttonSize, groupHeight)
.setFont(iconFont)
.setFontIcons(#00f04b, #00f04d)
.setFontIconSize(18)
.setSwitch(true)
.showBackground()
.setGroup(group)
.setOff()
.plugTo(this, "onTogglePlay")
.onEnter(new CallbackListener() {
public void controlEvent(CallbackEvent theEvent) {
tooltip.say("Play / Pause animation (key 'p')");
}
}
);
pos.add(buttonSize, 0);
groupWidth = (int) pos.x;
group.setWidth(groupWidth);
hide();
}
public void prevPosture() {
if (postureIndex <= 0)
return;
if (fileDirty) {
// Save fullAnimation to animationCollection
savePosture();
}
postureIndex--;
Posture prevPosture = postures.getPosture(postureIndex);
avatar.loadPosture(prevPosture);
postureName.setText(prevPosture.name);
animDuration.setValue(prevPosture.duration);
prevAnimDuration = prevPosture.duration;
avatar.resetAnimation();
mustUpdateUI = true;
}
public void nextPosture() {
if (fileDirty) {
// Save posture to postureCollection
savePosture();
}
postureIndex++;
if (postureIndex >= postures.size()) {
postureIndex = postures.size();
avatar.clearAnimation();
postureName.setText("posture" + postureIndex);
animDuration.setValue(0f);
prevAnimDuration = 0f;
} else {
Posture nextPosture = postures.getPosture(postureIndex);
avatar.loadPosture(nextPosture);
postureName.setText(nextPosture.name);
animDuration.setValue(nextPosture.duration);
prevAnimDuration = nextPosture.duration;
avatar.resetAnimation();
}
mustUpdateUI = true;
}
public void increaseCounter() {
frameCounter.setText(String.valueOf(++frameNumber));
}
public int getCounter() {
return frameNumber;
}
public void resetCounter() {
frameNumber = 0;
frameCounter.setText("0");
}
public void onToggleCamera(boolean val) {
if (val)
mainScreen.camera.show();
else
mainScreen.camera.hide();
}
public void onTogglePlay(boolean val) {
if (avatar != null) {
avatar.resetAnimation();
mainScreen.playing = val;
}
}
private class ButtonRec extends Button {
public ButtonRec(ControlP5 theControlP5, String theName, PVector position) {
super(theControlP5, theName);
setLabel("Rec");
setSize(buttonSize, groupHeight);
setPosition(position.x, position.y);
setSwitch(true);
setColorActive(color(255, 0, 0));
}
@Override
public void mousePressed() {
super.mousePressed();
if (isOn()) {
mainScreen.stopRecording();
} else {
if (animDuration.getValue() > 0f) {
mainScreen.startRecording();
} else {
tooltip.warn("Can't record. Choose the posture's duration first !");
buttonRec.setOff();
}
}
}
}
}