I made a dialog window appear when one is pressing the button “red1”. The first attempt at compiling after restart is normal. When I press “ok” in that pop-up or I close it the button “red1” still stays pressed/active. And it also doesn’t matter if I press something else in the GUI at that point. The dialog always shows up (although it is only in that single if statement.). That is not intended.
The problem must be located here:
if(theEvent.isController()) {
print("\ncontrol event from : "+theEvent.getController().getName());
if(theEvent.getController().getName()=="red1") {
showMessageDialog(null,
"Please assign a keystroke\n"+ "Press any button!\n",
"Important",
YES_NO_CANCEL_OPTION);
}
if(theEvent.getController().getName()=="red2") {
}
//All the other buttons etc etc..
It might be good to know that my ultimate goal is to synchronise the Software with the Hardware (when it comes to pressing buttons) and to assign custom buttons to the keystrokes of the hardware via the software.
By the way, I also posted something similar on Stack Overflow. Here is a link to that post;
Here is the full code if someone bothers:
import controlP5.*;
import static javax.swing.JOptionPane.*;
PFont Font;
ControlP5 controlP5;
static final float startRange = -0.00001;
static final float changeEndRange = 100.0000;
static final float loopEndRange = changeEndRange + 0.0001;
void setup(){
size (500,350);// länge, breite
smooth();
controlP5 = new ControlP5(this);
controlP5.addBang("red1")
.setPosition(50,50)
.setSize(20,20)
.setSize(60,60)
.setColorForeground(0xffff0000)
.setColorActive(0xff8B0000);
controlP5.addBang("red2")
.setPosition(150,50)
.setSize(20,20)
.setSize(60,60)
.setColorForeground(0xffff0000)
.setColorActive(0xff8B0000);
controlP5.addBang("blue1")
.setPosition(50,150)
.setSize(20,20)
.setSize(60,60)
.setColorForeground(0xff00BFFF)
.setColorActive(0xff1E90FF);
controlP5.addBang("blue2")
.setPosition(150,150)
.setSize(20,20)
.setSize(60,60)
.setColorForeground(0xff00BFFF)
.setColorActive(0xff1E90FF);
controlP5.addBang("green1")
.setPosition(50,250)
.setSize(20,20)
.setSize(60,60)
.setColorForeground(0xff228B22)
.setColorActive(0xff006400);
controlP5.addBang("green2")
.setPosition(150,250)
.setSize(20,20)
.setSize(60,60)
.setColorForeground(0xff228B22)
.setColorActive(0xff006400);
controlP5.addKnob("knob2")
.setValue(0)
.setRange(startRange,loopEndRange)
.setValue(0)
.setPosition(375,200)
.setSize(80,80)
.setColorBackground(0x00000000)
.setColorForeground(0xFFFFFF00)
.setColorActive(0xFFFFFF00);
controlP5.addKnob("knob1")
.setValue(0)
.setRange(startRange,loopEndRange)
.setValue(0)
.setPosition(375,70)
.setSize(80,80)
.setColorBackground(0x00000000)
.setColorForeground(0xffff0000)
.setColorActive(0xffff0000);
}
void controlEvent(ControlEvent theEvent) {
if(theEvent.isController()) {
print("\ncontrol event from : "+theEvent.getController().getName());
if(theEvent.getController().getName()=="red1") {
showMessageDialog(null,
"Please assign a keystroke\n"+ "Press any button!\n",
"Important",
YES_NO_CANCEL_OPTION);
}
if(theEvent.getController().getName()=="red2") {
}
if(theEvent.getController().getName()=="blue1") {
}
if(theEvent.getController().getName()=="blue2") {
}
if(theEvent.getController().getName()=="green1") {
}
if(theEvent.getController().getName()=="green2") {
}
if(theEvent.getController().getName()=="knob1Red") {
println(", value : "+theEvent.getController().getValue());
float loopKnob1 = +theEvent.getController().getValue();
if(loopKnob1 > changeEndRange){
theEvent.getController().setValue(0);
println("\nloopEndRange:"+loopEndRange);
println("\nchangeEndRange:"+changeEndRange);
}else if(loopKnob1 < 0){
theEvent.getController().setValue(changeEndRange);
println("\nloopEndRange:"+loopEndRange);
println("\nchangeEndRange:"+changeEndRange);
}
}
if(theEvent.getController().getName()=="knob2Yellow") {
println(", value : "+theEvent.getController().getValue());
float loopKnob2 = +theEvent.getController().getValue();
if(loopKnob2 > changeEndRange){
theEvent.getController().setValue(0);
println("\nloopEndRange:"+loopEndRange);
println("\nchangeEndRange:"+changeEndRange);
}else if(loopKnob2 < 0){
theEvent.getController().setValue(changeEndRange);
println("\nloopEndRange:"+loopEndRange);
println("\nchangeEndRange:"+changeEndRange);
}
}
}
}
void draw () {
Font = createFont("Magneto", 17);
textFont(Font);
background(23,15,97);
text ("Racing Sim v0.1", 120, 30);