We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Not sure if I am being completely daft here, but I am finding an issue where using setLock(true) to disable a ControlP5 button works only if the button you are modifying doesn't have the mouse over it when setLock(true) is called. Example code (originally by @andreas.schlegel from his answer here)
import controlP5.*;
ControlP5 controlP5;
int col;
void setup() {
size(640,480);
smooth();
frameRate(30);
controlP5 = new ControlP5(this);
controlP5.addButton("buttonA",0,100,100,80,19);
controlP5.addButton("buttonB",255,100,120,80,19);
controlP5.addButton("buttonC",128,100,140,80,19);
// store the original background color, we gonna need it later
col = controlP5.getController("buttonC").getColor().getBackground();
// lock Controller 'buttonC'
setLock(controlP5.getController("buttonC"),true);
}
void setLock(Controller theController, boolean theValue) {
theController.setLock(theValue);
if(theValue) {
theController.setColorBackground(color(100,100));
} else {
theController.setColorBackground(color(col));
}
}
void keyPressed() {
// temporarily enable/disable Controller 'buttonC'
if(key=='1') {
setLock(controlP5.getController("buttonC"), false);
} else if(key=='2') {
setLock(controlP5.getController("buttonC"), true);
}
}
void draw() {
background(0);
}
public void controlEvent(ControlEvent theEvent) {
println(theEvent.controller().getName());
}
Run this and use the 1 and 2 keys to unlock and lock buttonC. Works well, except if you leave your mouse hovering over the buttonC while pressing 1 and 2. Has anyone come across this before? Is there a workaround? I am happy to try and work out a fix if anyone has any idea roughly where within ControlP5 to go hunting for this!!
FWIW I am using Processing 3.2.3 and ControlP5 2.2.6
Answers
This did it for me.
Kf
Thanks for the answer @kfrajer (and sorry for the delayed reply!). Just had a chance to test this - works perfectly, thank you :-bd