How to acces the number of items in the controlP5 group?
in
Contributed Library Questions
•
1 year ago
We have encountered a problem with the controlP5 library. We would like to add CheckBoxes as well as RadioButtons (see code below). But when we actually catch the controlEvent there only seem to be seven items in there and not fourteen as supposed (7 RadioButtons + 7 Checkboxes).
- import controlP5.*;
- ControlP5 cp5;
- CheckBox checkbox;
- RadioButton modus;
- PImage filterT; PImage modusT;
- PImage normal1; PImage over1; PImage aktive1;
- PImage normal2; PImage over2; PImage aktive2;
- PImage normal3; PImage over3; PImage aktive3;
- PImage normal4; PImage over4; PImage aktive4;
- PImage normal5; PImage over5; PImage aktive5;
- PImage normal6; PImage over6; PImage aktive6;
- PImage normal7; PImage over7; PImage aktive7;
- void setup()
- {
- normal1 =loadImage("n01.png"); over1 =loadImage("o01.png"); aktive1 =loadImage("a01.png");
- normal2 =loadImage("n02.png"); over2 =loadImage("o02.png"); aktive2 =loadImage("a02.png");
- normal3 =loadImage("n03.png"); over3 =loadImage("o03.png"); aktive3 =loadImage("a03.png");
- normal4 =loadImage("n04.png"); over4 =loadImage("o04.png"); aktive4 =loadImage("a04.png");
- normal5 =loadImage("n05.png"); over5 =loadImage("o05.png"); aktive5 =loadImage("a05.png");
- normal6 =loadImage("n06.png"); over6 =loadImage("o06.png"); aktive6 =loadImage("a06.png");
- normal7 =loadImage("n07.png"); over7 =loadImage("o07.png"); aktive7 =loadImage("a07.png");
- cp5 = new ControlP5(this);
- checkbox = cp5.addCheckBox("checkBox", 210, spaceTop+325);
- modus = cp5.addRadioButton("radioButton",100,490);
- // make adjustments to the layout of a checkbox.
- checkbox.setColorForeground(color(80));
- checkbox.setColorActive(color(255));
- checkbox.setColorLabel(color(80));
- checkbox.setItemsPerRow(7);
- checkbox.setSpacingColumn(space-11);
- checkbox.setColorBackground(color(20));
- // make adjustments to the a Modus Button
- modus.setItemsPerRow(7);
- modus.setSpacingColumn(32);
- modus.setItemHeight(131);
- modus.setItemWidth(131);
- // add a Modus Button
- addToRadioButton1(modus,"01",1);
- addToRadioButton2(modus,"02",2);
- addToRadioButton3(modus,"03",3);
- addToRadioButton4(modus,"04",4);
- addToRadioButton5(modus,"05",5);
- addToRadioButton6(modus,"06",6);
- addToRadioButton7(modus,"07",7);
- modus.activate(3);
- // add items to a checkbox.
- checkbox.addItem(" Connect Slider 1", 1);
- checkbox.addItem(" Connect Slider 2", 1);
- checkbox.addItem(" Connect Slider 3", 1);
- checkbox.addItem(" Connect Slider 4", 1);
- checkbox.addItem(" Connect Slider 5", 1);
- checkbox.addItem(" Connect Slider 6", 1);
- checkbox.addItem(" Connect Slider 7", 1);
- }
- void addToRadioButton1(RadioButton theRadioButton, String theName, int theValue ) {
- Toggle t = theRadioButton.addItem(theName,theValue);
- t.setImages(normal1, over1, aktive1); }
- void addToRadioButton2(RadioButton theRadioButton, String theName, int theValue ) {
- Toggle t = theRadioButton.addItem(theName,theValue);
- t.setImages(normal2, over2, aktive2);}
- void addToRadioButton3(RadioButton theRadioButton, String theName, int theValue ) {
- Toggle t = theRadioButton.addItem(theName,theValue);
- t.setImages(normal3, over3, aktive3);}
- void addToRadioButton4(RadioButton theRadioButton, String theName, int theValue ) {
- Toggle t = theRadioButton.addItem(theName,theValue);
- t.setImages(normal4, over4, aktive4);}
- void addToRadioButton5(RadioButton theRadioButton, String theName, int theValue ) {
- Toggle t = theRadioButton.addItem(theName,theValue);
- t.setImages(normal5, over5, aktive5);}
- void addToRadioButton6(RadioButton theRadioButton, String theName, int theValue ) {
- Toggle t = theRadioButton.addItem(theName,theValue);
- t.setImages(normal6, over6, aktive6);}
- void addToRadioButton7(RadioButton theRadioButton, String theName, int theValue ) {
- Toggle t = theRadioButton.addItem(theName,theValue);
- t.setImages(normal7, over7, aktive7);}
- void controlEvent(ControlEvent theEvent) {
- if (theEvent.isGroup()) {
- for (int i=0;i<theEvent.group().arrayValue().length;i++) {
- int n = (int)theEvent.group().arrayValue()[i];
- println(theEvent.group().arrayValue()[i]+ " "+ n);
- bodyModus = (int)(theEvent.group().arrayValue()[i]);
- }
- }
- }
1