How do I get events from the ControlP5 color picker in a control frame?

edited August 2015 in Questions about Code

In the following code, the buttons trigger events, but the color picker does not. How do I set it up so that the color picker triggers an event? Also, can I get it to display color as HSB values and not RGB values?

import java.awt.BorderLayout;
import controlP5.*;
import java.awt.Frame;

private ControlP5 cp5;

ControlFrame cf;
ColorPicker cp;
void setup() {

     size(200, 200);
     cp5 = new ControlP5(this);
     cf = addControlFrame("Tools");
     cf.control().addButton("Load",1,5,10,60,20).plugTo(this);
     cf.control().addButton("Save",1,5,35,60,20).plugTo(this);
     cp = cf.control().addColorPicker("picker").setPosition(10, 300)
     .setColorValue(color(255, 128, 0, 128)).plugTo(this);    

}
void draw(){
     background(100);
}



void controlEvent(ControlEvent theEvent) {
     if(theEvent.isController()) { 
          print("control event from : "+theEvent.controller().getName());
          println(", value : "+theEvent.controller().getValue());
     }
}     


ControlFrame addControlFrame(String theName) {
  Frame f = new Frame(theName);
  ControlFrame p = new ControlFrame(this, 300, 400);
  f.add(p);
  p.init();
  f.setTitle(theName);
  f.setSize(p.w, p.h);
  f.setLocation(120, 120);
  f.setResizable(false);
  f.setVisible(true);
  return p;
}


// the ControlFrame class extends PApplet, so we 
// are creating a new processing applet inside a
// new frame with a controlP5 object loaded
public class ControlFrame extends PApplet {

  ControlP5 cp5;

  Object parent;

  int w, h;

  int abc;

  private ControlFrame() {
  }

  ControlFrame(Object theParent, int theWidth, int theHeight) {
    parent = theParent;
    w = theWidth;
    h = theHeight;
  }


  public ControlP5 control() {
    return cp5;
  }
  public void setup() {
    size(w, h);
    frameRate(25);
    cp5 = new ControlP5(this);
  }

  public void draw() {
      background(abc);
  }
}
Tagged:
Sign In or Register to comment.