/** * ControlP5 Checkbox * an example demonstrating the use of a checkbox in controlP5. * CheckBox extends the RadioButton class. * to control a checkbox use: * activate(), deactivate(), activateAll(), deactivateAll(), toggle(), getState() * * find a list of public methods available for the Checkbox Controller * at the bottom of this sketch's source code * * by Andreas Schlegel, 2012 * www.sojamo.de/libraries/controlP5 * */ import controlP5.*; ControlP5 cp5; CheckBox checkbox; int myColorBackground; void setup() { size(700, 400); smooth(); cp5 = new ControlP5(this); checkbox = cp5.addCheckBox("checkBox") .setPosition(100, 200) .setSize(40, 40) .setItemsPerRow(3) .setSpacingColumn(30) .setSpacingRow(20) .addItem("0", 0) .addItem("50", 50) .addItem("100", 100) .addItem("150", 150) .addItem("200", 200) .addItem("255", 255) ; } void keyPressed() { if (key==' ') { checkbox.deactivateAll(); } else { for (int i=0;i<6;i++) { // check if key 0-5 have been pressed and toggle // the checkbox item accordingly. if (keyCode==(48 + i)) { // the index of checkbox items start at 0 checkbox.toggle(i); println("toggle "+checkbox.getItem(i).getName()); // also see // checkbox.activate(index); // checkbox.deactivate(index); } } } } void draw() { background(170); pushMatrix(); translate(width/2 + 200, height/2); stroke(255); strokeWeight(2); fill(myColorBackground); ellipse(0,0,200,200); popMatrix(); } void controlEvent(ControlEvent theEvent) { if (theEvent.isFrom(checkbox)) { myColorBackground = 0; print("got an event from "+checkbox.getName()+"\t\n"); // checkbox uses arrayValue to store the state of // individual checkbox-items. usage: println(checkbox.getArrayValue()); int col = 0; for (int i=0;i