Hi, I'm a noob to these forums and to programming, so I hope I'm asking this in the right place. Anyways, I'm trying to use ControlP5's dropdown list, but I can't figure out where I actually make stuff happen when I click on the items.
Here's the code I have; basically, when I click on an item, I want it to load an image, and if another item in the same menu is clicked, it will change the image to a different one.
/**
* ControlP5dropdownList
* A dropdownList controller, based on the ListBox controller.
* the currently selected dropdownlist item is displayed inside
* the menu bar of the DropdownList.
* by andreas schlegel, 2010
* www.sojamo.de/libraries/controlP5
*/
import controlP5.*;
ControlP5 controlP5;
DropdownList p1, p2;
//setting height, etc is a mess and spoiled. REPAIR
void keyPressed() {
if(key=='1') {
// set the height of a pulldown menu, should always be a multiple of itemHeight
p1.setHeight(210);
}
else if(key=='2') {
// set the height of a pulldown menu, should always be a multiple of itemHeight
p1.setHeight(120);
}
else if(key=='i') {
// set the height of a pulldown menu item, should always be a fraction of the pulldown menu
p1.setItemHeight(30);
}
else if(key=='u') {
// set the height of a pulldown menu item, should always be a fraction of the pulldown menu
p1.setItemHeight(10);
p1.setBackgroundColor(color(100,0,0));
}
else if(key=='a') {
// add new items to the pulldown menu
int n = (int)(random(100000));
p1.addItem("item "+n, n);
}
else if(key=='d') {
// remove items from the pulldown menu by name
p1.removeItem("item "+cnt);
cnt++;
}
else if(key=='c') {
p1.clear();
}
}
void controlEvent(ControlEvent theEvent) {
// PulldownMenu is if type ControlGroup.
// A controlEvent will be triggered from within the ControlGroup.
// therefore you need to check the originator of the Event with
// if (theEvent.isGroup())
// to avoid an error message from controlP5.
if (theEvent.isGroup()) {
// check if the Event was triggered from a ControlGroup
println(theEvent.group().value()+" from "+theEvent.group());
} else if(theEvent.isController()) {
println(theEvent.controller().value()+" from "+theEvent.controller());
}
}
void draw() {
background(128);
}
Sorry if this is a stupid question, I'm really new to this.