when i use basic ( reduced from example ) code all works.
import g4p_controls.*;
GOption option0, option1, option2;
public void setup() {
size(500,500);
createGUI();
}
public void draw() {
background(100, 100, 200);
}
public void createGUI(){
int posX = 50, posY =20, dposY = 20;
GToggleGroup tg = new GToggleGroup();
option0 = new GOption(this, posX, posY, 80, 24, "A");
option0.setTextAlign(null, GAlign.BOTTOM);
option1 = new GOption(this, posX, posY+dposY, 80, 24, "B");
option1.setTextAlign(null, GAlign.BOTTOM);
option2 = new GOption(this, posX, posY+dposY+dposY, 80, 24, "C");
option2.setTextAlign(null, GAlign.BOTTOM);
// Group the option buttons
tg.addControls(option0, option1, option2);
// Must set one of the options true
option1.setSelected(true);
}
// following is not needed for the option button group to work,
// only to use the option mouse press/select events
public void handleToggleControlEvents(GToggleControl source, GEvent event) {
if (source == option0) { println("option0"); }
else if (source == option1) { println("option1"); }
else if (source == option2) { println("option2"); }
}
but try that with a second window both windows react differently on a mouse click
and the basic functionality
on click on one option the other of that group deselects
is lost.
import g4p_controls.*;
GOption option0, option1;
GOption woption0, woption1;
GWindow[] window;
public void setup() {
size(100,100);
createGUI();
createWindows();
}
public void draw() {
background(100, 100, 200);
}
public void createGUI(){
int posX = 40, posY =20, dposY = 20;
GToggleGroup tg = new GToggleGroup();
option0 = new GOption(this, posX, posY+0*dposY, 80, 24, "A");
option0.setTextAlign(null, GAlign.BOTTOM);
option1 = new GOption(this, posX, posY+1*dposY, 80, 24, "B");
option1.setTextAlign(null, GAlign.BOTTOM);
option1.setSelected(true); // Must set one of the options true
tg.addControls(option0, option1); // Group the option buttons
}
public void handleToggleControlEvents(GToggleControl source, GEvent event) {
if (source == option0) { println("option0"); } //option1.setSelected(false);
else if (source == option1) { println("option1"); } //option0.setSelected(false);
if (source == woption0) { println("woption0"); } //woption1.setSelected(false);
else if (source == woption1) { println("woption1"); } //woption0.setSelected(false);
}
//_______________________________________________________________________
public void createWindows() {
window = new GWindow[1];
// for (int i = 0; i < 1; i++) {
// window[i] = GWindow.getWindow(this, " ", 70+i*220, 160+i*50, 400, 400, JAVA2D);
// }
// menu window config
window[0] = GWindow.getWindow(this, "window2", 70, 160, 100, 100, JAVA2D);
window[0].setActionOnClose(G4P.CLOSE_WINDOW);
//window[0].addOnCloseHandler(this, "windowClosing");
//window[0].addData(new MyWinData());
window[0].addDrawHandler(this, "windowDraw");
//window[0].addMouseHandler(this, "windowMouse");
//window[0].addKeyHandler(this, "windowKey");
int posX = 40, posY =20, dposY = 20;
GToggleGroup wtg = new GToggleGroup();
woption0 = new GOption(window[0], posX, posY+0*dposY, 80, 24, "wA");
woption0.setTextAlign(null, GAlign.BOTTOM);
woption1 = new GOption(window[0], posX, posY+1*dposY, 80, 24, "wB");
woption1.setTextAlign(null, GAlign.BOTTOM);
woption1.setSelected(true); // Must set one of the options true
wtg.addControls(option0, option1); // Group the option buttons
}
//_______________________________________________________________________
public void windowDraw(PApplet appc, GWinData data) {
// MyWinData data2 = (MyWinData)data;
appc.background(200,200,0);
}
what handler i would need to register?
or just use a manual
optionX.setSelected(false);
handleToggleControlEvents does not take a this or window config.