Hi, I’m using G4P, wonderful lib! I’ve found a way to programmatically create windows and hide them - based on posts here and Peter’s fab library! All Peter’s code; works great.
What I haven’t found is a way to create a new window using the GUI Builder, and have it initially hidden.
Is this possible to do with the GUI Builder? Or maybe add some code to make it work that way? I can set it invisible immediately after creation, but it shows for a split second; but you do notice it. Not ideal.
Otherwise, I can do this all with code but I love being able to lay things out with the GUI Builder.
In G4P every extra window is effectively an instance of PApplet. The process of launching a PApplet will create a visible window which can be set invisible immediately but the user will still see the flash of a visible window.
So when I said “no” before it was not because I am unwilling to update my libraries but I don’t know of any possible way to avoid the window-flash.
Forgive me if it sounded as if I was insinuating your were unwilling! Nothing could be further from the truth.
This latest version is proof that’s not true!!! You literally updated the library because I asked if you’d include a feature (well, maybe you already were going to, but that’s how it seemed).
I know that if something is possible, and feasible, you do it, if it makes sense. You’re just awesome that way
So thank you!
By the way, I did try exactly that scenario, making the window then hiding it, but as you say, it flashes up for a second and doesn’t look good.
I also thought of making it, but having it off the screen initially, but can’t seem to get a large enough initial value for the window XY coordinates for it to work right.
Hmmm…I wonder if something like adding “noLoop()” when it’s created would work? Or something sneaky like that? Then adding back loop()? Have to think about it or experiment I guess.
As I said, I have “invisible” initial windows working fine through straight code, from your other generous examples here on the board.
void createPreferencesWindow() {
preferences = GWindow.getWindow(this, "Options", width/2 + 120, height/2 + 70, 240, 140, JAVA2D);
preferences.setActionOnClose(G4P.HIDE_WINDOW);
preferences.addDrawHandler(this, "preferencesDraw");
preferences.addMouseHandler(this, "preferencesMouse");
preferences.addKeyHandler(this, "preferencesKey");
preferences.addData(new MyData());
}
public void preferencesDraw(PApplet app, GWinData data){
// Saves doing it for every variable in MyData class
MyData myData = (MyData) data;
app.background(127);
app.strokeWeight(2);
//// Draw red line to last click position.
app.stroke(255,0,0);
app.line(app.width / 2, app.height/2, myData.lastClickX, myData.lastClickY);
//// draw black line to current mouse position
app.stroke(0);
app.line(app.width / 2, app.height/2, app.mouseX, app.mouseY);
}
public void preferencesMouse(PApplet app, GWinData data, MouseEvent event) {
// Saves doing it for every variable in MyData class
MyData myData = (MyData) data;
if(event.getAction() == MouseEvent.CLICK){
myData.lastClickX = mouseX;
myData.lastClickY = mouseY;
}
}
public void preferencesKey(PApplet app, GWinData data, KeyEvent event) {
}
public class MyData extends GWinData {
// The variables can be anything you like.
public int lastClickX,lastClickY;
}
etc...
Works great! Thanks to you and the guy who prompted the question in another post!