We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello.
I want to make a simple gui application for controlling my Chuck programms (http://chuck.cs.princeton.edu/). My current goal is writing a class which can load and run Chuck sketch (ClipLauncher), but I got some problems:
1 - I can't make a unique class instance of ControlP5 inside my ClipLauncher class, so I adding it manualy in main sketch (ControlP5 gui, ControlP5 gui2, ... ControlP5 guiN).
2 - I can't call functions, binded to gui elements
import controlP5.*;
ControlP5 gui;
ControlP5 gui2;
ClipLauncher clip;
ClipLauncher clip2;
void setup(){
size(480, 320);
background(0);
gui = new ControlP5(this);
gui2 = new ControlP5(this);
clip = new ClipLauncher(gui, 10, 10);
clip2 = new ClipLauncher(gui2, 10, 75);
}
void draw(){
}
class ClipLauncher {
ClipLauncher(ControlP5 gui, int x, int y) {
gui.addToggle("start clip")
.setPosition(x,y)
.setSize(50,50)
.setId(1)
.setLabel("");
gui.addButton("select")
.setPosition(x + 55,y)
.setSize(100,50)
.setId(2)
.setLabel("no file selected");
}
public void controlEvent(ControlEvent theEvent) { //don't work
switch(theEvent.getController().getId()) {
case(1):
print("checkbox");
break;
case(2):
print("button");
break;
}
}
public void select() { //don't work too
println("Button from function");
}
}
Answers
You need a ControlP5 attribute inside the class and create it in the constructor. To do that you need to pass a PApplet instnace in the ctor parameters.
Just like this -
Thanks, Quark! Your tip is great, but class methods still not works.
Thanks, Quark! Your tip is great, but class methods still not works.
Ok. I solve problem with addCallback(), but now I have a problem with openFile() function visibility.
If you want to access Processing methods inside a class you need a reference to a PApplet object. Like this.