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

controlP5 - get value when pressing a button

$
0
0

I want to get the value from the button when I press the button (but without using a function). Got two alternatives but none of them are good (most be a better way then using the if (mousePressed). How can I succed with this probably simple task. Guess i want to use some of these but I cant figure out how to implement them:

controlP5.Button : boolean isPressed()
controlP5.Controller : boolean isMousePressed()
controlP5.Controller : Button onPress(CallbackListener)

import controlP5.*;

ControlP5 cp5;

void setup() {
  size(400, 600);

  cp5 = new ControlP5(this);

  cp5.addButton("Button")
    .setValue(1)
    .setPosition(100, 100)
    .setSize(200, 19)
    ;
}

void draw() {
  background(255);

  if (mousePressed) {
    // alternative 1
    println("\nalternative 1: " + cp5.getController("Button").getValue());

    // alternative 2
    println("alternative 2: " + cp5.isMouseOver(cp5.getController("Button")));
  }
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles