With G4P Click Checkbox also triggers mouseClicked

With a G4P Checkbox when I click on it, the Processing mouseClicked() runs as well. In other environments where I’ve coded, the front-most window gets the click and doesn’t arrive on the ones behind. I’m finding myself adding code to the mouseClicked() to ignore the click if it’s on the Checkbox.

Am I missing the reason why it’s like this? Is it selectable not to have the mouseClick as well?

import g4p_controls.*;
GCheckbox cBox;
public void setup(){cBox = new GCheckbox(this, 20, 10, 80, 20, "CBox");}
void draw() {}
void mouseClicked() {println("mouseClicked");}

G4P registers itself with Processing so gets a copy of Processing events. It does not replace Processing’s event handling system.

So when you click the mouse button Processing triggers a mouse clicked event which causes the mouseClicked function to be executed. G4P also gets a copy of the event which it will process if the mouse is over a G4P control.

It is just how Processing works with third party libraries.

True but there is only one “window” in the sketch code you posted.

Thank you. Always good to know more of how it all works. I was thinking that the mouseClicked() code would have to know the coords of all the CheckBoxes. Now I’ve found that the G4P code runs before mouseClicked(). So it can set a boolean to indicate that the mouseClick should be ignored. Much more tidy.

import g4p_controls.*;
GCheckbox cBox;
boolean G4PClicked = false;
public void setup(){cBox = new GCheckbox(this, 20, 10, 80, 20, "CBox");}
void draw() {}
public void handleToggleControlEvents(GToggleControl checkbox, GEvent event) {G4PClicked = true;}
void mouseClicked() {
  if (G4PClicked) {G4PClicked = false;}
  else {print("mouseClicked ");}
}

1 Like