We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › controlP5 multilist
Page Index Toggle Pages: 1
controlP5 multilist (Read 407 times)
controlP5 multilist
Feb 20th, 2009, 4:34pm
 
Hello,

I'm trying to use the multilist to change the value of an integer, and i want the label of the main button to follow the selected item. For the moment I use it this way :

Quote:
import controlP5.*;
ControlP5 controlP5;

Exc excitator=new Exc();

class Exc {
  int type;
  int envelop;
  Exc() {
  }
  void settype(int value) {
    type=value;
  }
  void setenvelop(int value) {
    envelop=value;
  }  
}

void setup() {
  size(300,300);
  controlP5 = new ControlP5(this);  
  initInterface();
}

void draw() {
  background(0);
  controlP5.draw();
}

MultiList excType;
controlP5.MultiListButton buttonA;
controlP5.MultiListButton buttonB;

void initInterface() {
  excType = controlP5.addMultiList("excType",0,30,60,20);
  buttonA = excType.add("excTypeL1",0);
  buttonA.add("excTypeL11",0).setLabel("Brush");
  buttonA.add("excTypeL12",1).setLabel("Dice");
  buttonB = excType.add("excEnveL1",1);
  buttonB.add("excEnveL11",0).setLabel("Decay");
  buttonB.add("excEnveL12",1).setLabel("Continuous");
}

void controlEvent(ControlEvent theEvent) {
  if (theEvent.controller().name().length()>=10) {
    if (theEvent.controller().name().substring(0,7).equals("excType")) {
      excitator.settype(int(theEvent.value()));
      buttonA.setLabel(theEvent.controller().label());
    }
    if (theEvent.controller().name().substring(0,7).equals("excEnve")) {
      excitator.setenvelop(int(theEvent.value()));
      buttonB.setLabel(theEvent.controller().label());
    }    
  }
}



But I'm sure there is a better way to do than ckecking substrings in the event's name.
Page Index Toggle Pages: 1