Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

How to use ControlP5 inside classes?

$
0
0

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");
  }
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles