I tryed to set Id to each item and then use this Id to show the button, but probably I'm doing something very wrong...
Here is the code:
import controlP5.*;
ControlP5 cp5;
DropdownList d1, d2, d3;
// define an array of images and the variable to select between them
PImage[] images1 = new PImage[3];
PImage[] images2 = new PImage[3];
PImage[] images3 = new PImage[3];// array of images
int selectedImage1;
int selectedImage2;// the variable used to select the image to show on screen
int selectedImage3;
String selectedGroup = "ImageSelect1";
int selectedImage;
int selectedItem;
Button b1, b2;
int cnt = 0;
void setup() {
size(775, 500);
// create the controlP5dropdownlist and give it the name you will use later, in this case ImageSelect
cp5 = new ControlP5(this);
d1 = cp5.addDropdownList("ImageSelect1", width/2-50, 100, 100, 120).setPosition(0, 22);
//customize(d1);// customize the first list
d1.setBackgroundColor(color(250));
d1.setItemHeight(20);
d1.setBarHeight(20);
d1.setLabel("Interval view");
d1.captionLabel().style().marginTop = 5;
d1.captionLabel().style().marginLeft = 5;
d1.valueLabel().style().marginTop = 5;
d1.addItem("1st layer", 0)
.setId(0);
d1.addItem("2nd layer", 1)
.setId(1);
d1.addItem("3rd layer", 2)
.setId(2);
d1.setColorBackground(color(60));
d1.setColorActive(color(255, 128));
images1[0] = loadImage("visuals_1.png");
images1[1] = loadImage("visuals_2.png");
images1[2] = loadImage("visuals_3.png");
d2 = cp5.addDropdownList("ImageSelect2", width/2-50, 00, 100, 120).setPosition(102, 22);
images2[0] = loadImage("1visuals_1.png");
images2[1] = loadImage("1visuals_2.png");
images2[2] = loadImage("1visuals_3.png");
//d2.setBackgroundColor(color(250));
d2.setItemHeight(20);
d2.setLabel("Harmonic rythm view");
d2.setBarHeight(20);
d2.captionLabel().style().marginTop = 5;
d2.captionLabel().style().marginLeft = 5;
d2.valueLabel().style().marginTop = 5;
d2.addItem("1st l", 0); // give each item a value, in this example starting from zero
d2.addItem("2nd l", 1);
d2.addItem("3rd l", 2);
d2.setColorBackground(color(60));
d2.setColorActive(color(255, 128));
d3 = cp5.addDropdownList("ImageSelect3", width/2-50, 00, 100, 120).setPosition(204, 22);
images3[0] = loadImage("1visuals_1.png");
images3[1] = loadImage("1visuals_2.png");
images3[2] = loadImage("1visuals_3.png");
//d2.setBackgroundColor(color(250));
d3.setItemHeight(20);
d3.setLabel("Bind layers");
d3.setBarHeight(20);
d3.captionLabel().style().marginTop = 5;
d3.captionLabel().style().marginLeft = 5;
d3.valueLabel().style().marginTop = 5;
d3.addItem("1st l", 0);
d3.addItem("2nd l", 1);
d3.addItem("3rd l", 2);
d3.setColorBackground(color(60));
d3.setColorActive(color(255, 128));
b1 = cp5.addButton("1")
.setValue(0)
.setPosition(20, 200)
.setSize(20, 20);
b1.hide();
b2 = cp5.addButton("2")
.setValue(0)
.setPosition(20, 300)
.setSize(20, 20);
b2.hide();
}
void draw() {
background(128);
if (selectedGroup.equals("ImageSelect1")) {
image(images1[selectedImage], 0, 0);
if (selectedItem.equals(Id(0))) {
b1.show();
}
if (selectedItem.equals(Id(1))) {
b2.show();
}
}
else if (selectedGroup.equals("ImageSelect2")) {
image(images2[selectedImage], 0, 0);
}
else if (selectedGroup.equals("ImageSelect3")) {
image(images3[selectedImage], 0, 0);
}
}
void controlEvent(ControlEvent theEvent) {
if (theEvent.isGroup()) {
selectedGroup = theEvent.group().name();
selectedImage = int(theEvent.group().value());
selectedItem = int(theEvent.group().getId());
}
else if (theEvent.isController()) {
}
1