I have a class named “Interface” in witch I’m creating some buttons.
I want to execute a function when a button is pressed.
The problem is since I want my class to be generic, I can’t write that peace of code inside my class, I need it to be in my main code.
Is there a way, then, to connect a function to a button created inside an object.
The example below show what I would like to achieve :
Interface i;
void setup() {
size(800, 600);
i = new Interface(this);
i.connectFunctionToBtn(functionToTrigger); //This is what I would like to write
}
void draw() {
background(20);
}
void functionToTrigger() {
println("Function triggered");
}
Then my class Interface would be something like this :
import controlP5.*;
class Interface {
ControlP5 cp5;
Interface(PApplet p_parent) {
cp5 = new ControlP5(p_parent);
cp5.addButton("btnTest")
.setPosition(10, 10)
.setSize(50,20);
}
// THE FUNCTION TO WRITE
void connectFunctionToBtn() {
}
}