-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathModifier.pde
159 lines (131 loc) · 3.97 KB
/
Modifier.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
class Modifier extends BaseModel {
boolean isMeshCollection;
int index;
int currentIndex;
ModifierCreator modifierCreator;
Modifier (String name, int parameters) {
super(name, parameters);
}
int getY(int parameter) {
int z = my2;
if (this.index > 0) {
z += multiplyGrid(this.index);
}
for ( int x = 0 ; x < selectedModifiers.size() ; x++ ) {
if (x < this.index) {
Modifier m = selectedModifiers.get(x);
z += multiplyGrid(m.parameters + 1);
}
}
if (parameter >= 0) {
z += multiplyGrid(parameter + 1);
}
return z;
}
// display gui elements for the modifier
void menu(boolean useDefault) {
String buttonName = getButtonName(this.index);
Button button = cp5.addButton(buttonName, 0, mx2, getY(-1), Config.CP5.Controls.Width, Config.CP5.Controls.Height);
button.setLabel(this.name + " [remove]");
button.setId(this.index);
button.onClick(new CallbackListener() {
public void controlEvent(CallbackEvent theEvent) {
String buttonName = getButtonName(index);
selectedModifiers.remove(index);
cp5.remove(buttonName);
for (int i = 0; i < values.length; i++) {
cp5.remove(getSliderName(index, i));
}
createHemesh();
}
});
for (int i = 0; i < this.parameters; i++) {
cp5.addSlider(getSliderName(index, i), this.minValues[i], this.maxValues[i])
.setSize(Config.CP5.Controls.Width, Config.CP5.Controls.Height)
.setPosition(mx2, getY(i))
.setLabel(this.labels[i])
.setId(i)
.setValue(useDefault ? this.defaultValues[i] : this.values[i])
.onChange(new CallbackListener() {
public void controlEvent(CallbackEvent theEvent) {
Modifier m = (Modifier) selectedModifiers.get(index);
m.values[theEvent.getController().getId()] = theEvent.getController().getValue();
createHemesh();
}
});
}
this.ignore();
}
// reposition modifier gui if an earlier modifier is removed (aka everything moves up one place)
void update() {
if (this.index != this.currentIndex) {
cp5.remove(getButtonName(this.currentIndex));
for (int i = 0; i < this.values.length; i++) {
cp5.remove(getSliderName(this.currentIndex, i));
}
this.currentIndex = this.index;
this.menu(false);
}
}
void ignore() {
cp5.getProperties().remove(cp5.getController(getButtonName(this.index)));
for (int i = 0; i < this.parameters; i++) {
cp5.getProperties().remove(cp5.getController(getSliderName(this.index, i)));
}
}
void remove() {
cp5.remove(getButtonName(this.currentIndex));
for (int i = 0; i < this.values.length; i++) {
cp5.remove(getSliderName(this.currentIndex, i));
}
}
Modifier setMeshCollection(boolean isMeshCollection) {
this.isMeshCollection = isMeshCollection;
return this;
}
boolean getMeshCollection() {
return this.isMeshCollection;
}
Modifier setMaxValues(float[] maxValues) {
this.maxValues = maxValues;
return this;
}
Modifier setMinValues(float[] minValues) {
this.minValues = minValues;
return this;
}
Modifier setDefaultValues(float[] defaultValues) {
this.defaultValues = defaultValues;
this.values = defaultValues;
return this;
}
Modifier setLabels(String[] labels) {
this.labels = labels;
return this;
}
Modifier setCreator(ModifierCreator creator) {
this.modifierCreator = creator;
return this;
}
Modifier setIndex(int index) {
this.index = index;
this.currentIndex = index;
return this;
}
int getIndex() {
return this.index;
}
boolean hasCreator() {
return this.modifierCreator != null;
}
void create() {
if (this.modifierCreator != null) {
this.modifierCreator.create(values);
} else {
println("No modifier found");
}
}
}
interface ModifierCreator {
public void create(float[] values);
}