ControlP5 Button triggers with mouse click after it was hidden

edited April 2014 in Library Questions

Hi there, I'm relatively new to Processing and I'm facing a weird "error" with the controlP5 library. I'm trying to create an interface where I can select objects and then delete them. So I created a delete button who just appears when something is selected. So I initialize the button hidden:

      Button deleteChordButton = cp5.addButton("DeleteChord")
         .setPosition(width-175,FretBoardPosition+90)
         .setSize(165,30)
         .setGroup(editGUI)
         .hide()
         ;

After some object was selected with a mouse click the button appears with:

GuiTroller.gui.deleteChordButton.show();

So when the Button is pressed, it deletes the selected object and then hides itself again:

public void DeleteChord(int theValue) {
  println("DeleteChord Button pressed");
  if(GuiTroller.currentSong.selectedChord!=-1){
    GuiTroller.currentSong.chords.remove(GuiTroller.currentSong.selectedChord);
    GuiTroller.currentSong.selectedChord = -1;
    GuiTroller.gui.deleteChordButton.hide();
  }
}

Till now everything works fine. But if I now press the mouse again (it doesn't matter where) the DeleteChord function is triggered again. If I don't hide the button after it is triggered, it is not triggered again when I click the mouse somewhere. So I guess it has something to do with the hiding after the button was triggered. And it is not just this button, all the other buttons which are hidden after being triggered show the same behaviour. Any idea where the problem is?

Thank You very much

Tagged:

Answers

  • An example that we can run would be really helpful.

  • Thanks for the reply, and sorry for the late answer. I was not able to reproduce the problem in a small snippet of code. And I don't know how to upload the whole code with data files aso. so somebody is able to run it.

    For now I fixed the problem by setting broadcast false every time i hide the button and then set it to true again when I show it again.

    GuiTroller.gui.deleteChordButton.show();
    GuiTroller.gui.deleteChordButton.setBroadcast(true);
    

    and

    GuiTroller.gui.deleteChordButton.hide();
    GuiTroller.gui.deleteChordButton.setBroadcast(false);
    
Sign In or Register to comment.