-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButtonMatrix.pde
More file actions
52 lines (49 loc) · 1.68 KB
/
ButtonMatrix.pde
File metadata and controls
52 lines (49 loc) · 1.68 KB
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
class ButtonMatrix{ //generates a Matrix of Buttons, given by an array of Strings
private ControlP5 cp5;
private String name;
private int cols, x0, y0, colMargin, rowMargin, buttonWidth, buttonHeight;
private ArrayList<Button> buttons;
private int value;
private int lastId;
public ButtonMatrix(ControlP5 cp5, String name, int value, int cols, int x0, int y0, int colMargin, int rowMargin, int buttonWidth, int buttonHeight)
{
this.cp5 = cp5; this.name = name; this.value = value; this.cols = cols; this.x0 = x0; this.y0 = y0; this.colMargin = colMargin; this.rowMargin = rowMargin; this.buttonWidth = buttonWidth; this.buttonHeight = buttonHeight;
buttons = new ArrayList<Button>();
lastId = 0;
}
public void addButton(String name)
{
Button b = new Button(cp5, name);
b.setBroadcast(false); // turn broadcast off so it doesnt auto-trigger
b.setValue(float(value));
b.setId(lastId);
lastId++;
b.setWidth(buttonWidth);
b.setHeight(buttonHeight);
b.setPosition(x0 + colMargin + (colMargin+buttonWidth)*(buttons.size()%cols), y0 + rowMargin + int(buttons.size()/cols)*(buttonHeight+rowMargin));
b.setBroadcast(true); // turn broadcast on again
buttons.add(b);
println("Buttons Created: " + buttons.size());
}
public void addButtonList(ArrayList stringList)
{
this.clear();
for(int i = 0; i < stringList.size(); i++)
{
addButton(stringList.get(i).toString());
}
}
public void clear()
{
for(int i = 0; i < buttons.size(); i++)
{
deleteButton();
}
lastId = 0;
}
private void deleteButton()
{
cp5.remove(buttons.remove(buttons.size()-1).getName());
lastId--;
}
}